Skip to content

Commit 4083b3e

Browse files
committed
Updated constantine version
1 parent d43b875 commit 4083b3e

File tree

8 files changed

+228
-222
lines changed

8 files changed

+228
-222
lines changed

Cargo.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

constantine/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ blst = "0.3.11"
88
kzg = { path = "../kzg", default-features = false }
99
libc = { version = "0.2.148", default-features = false }
1010
once_cell = { version = "1.18.0", features = ["critical-section"], default-features = false }
11-
constantine-ethereum-kzg = { 'git' = 'https://github.com/mratsim/constantine.git' , branch='constantine-public-sys' }
12-
constantine-sys = { 'git' = 'https://github.com/mratsim/constantine.git' , branch='constantine-public-sys' }
13-
constantine-core = { 'git' = 'https://github.com/mratsim/constantine.git' , branch='constantine-public-sys' }
11+
constantine-ethereum-kzg = { 'git' = 'https://github.com/mratsim/constantine.git', rev = "3ed6eeac4f0a9b0092bb4234b61768dfde25cdbe" } # branch constantine-public-sys
12+
constantine-sys = { 'git' = 'https://github.com/mratsim/constantine.git', rev = "3ed6eeac4f0a9b0092bb4234b61768dfde25cdbe" } # branch constantine-public-sys
13+
constantine-core = { 'git' = 'https://github.com/mratsim/constantine.git', rev = "3ed6eeac4f0a9b0092bb4234b61768dfde25cdbe" } # branch constantine-public-sys
1414
rand = { version = "0.8.5", optional = true }
1515
rayon = { version = "1.8.0", optional = true }
1616
smallvec = { version = "1.11.1", features = ["const_generics"] }

constantine/benches/eip_4844_constantine_no_conv.rs

+26-84
Original file line numberDiff line numberDiff line change
@@ -23,99 +23,54 @@ fn bench_eip_4844_constantine_no_conv_(c: &mut Criterion) {
2323

2424
let commitments: Vec<[u8; 48]> = blobs
2525
.iter()
26-
.map(|blob| ctx.ctx.blob_to_kzg_commitment(blob).unwrap())
26+
.map(|blob| ctx.blob_to_kzg_commitment(blob).unwrap())
2727
.collect();
2828

2929
let proofs: Vec<[u8; 48]> = blobs
3030
.iter()
3131
.zip(commitments.iter())
32-
.map(|(blob, commitment)| ctx.ctx.compute_blob_kzg_proof(blob, commitment).unwrap())
32+
.map(|(blob, commitment)| ctx.compute_blob_kzg_proof(blob, commitment).unwrap())
3333
.collect();
3434

3535
let fields: Vec<[u8; 32]> = (0..MAX_COUNT)
3636
.map(|_| generate_random_field_element_bytes(&mut rng))
3737
.collect();
3838

3939
c.bench_function("blob_to_kzg_commitment", |b| {
40-
#[cfg(feature = "parallel")]
41-
b.iter(|| {
42-
ctx.ctx
43-
.blob_to_kzg_commitment_parallel(&ctx.pool, blobs.first().unwrap())
44-
});
45-
46-
#[cfg(not(feature = "parallel"))]
47-
b.iter(|| ctx.ctx.blob_to_kzg_commitment(blobs.first().unwrap()));
40+
b.iter(|| ctx.blob_to_kzg_commitment(blobs.first().unwrap()));
4841
});
4942

5043
c.bench_function("compute_kzg_proof", |b| {
51-
#[cfg(feature = "parallel")]
52-
b.iter(|| {
53-
ctx.ctx.compute_kzg_proof_parallel(
54-
&ctx.pool,
55-
blobs.first().unwrap(),
56-
fields.first().unwrap(),
57-
)
58-
});
59-
60-
#[cfg(not(feature = "parallel"))]
61-
b.iter(|| {
62-
ctx.ctx
63-
.compute_kzg_proof(blobs.first().unwrap(), fields.first().unwrap())
64-
});
44+
b.iter(|| ctx.compute_kzg_proof(blobs.first().unwrap(), fields.first().unwrap()));
6545
});
6646

6747
c.bench_function("verify_kzg_proof", |b| {
6848
b.iter(|| {
69-
ctx.ctx
70-
.verify_kzg_proof(
71-
commitments.first().unwrap(),
72-
fields.first().unwrap(),
73-
fields.first().unwrap(),
74-
proofs.first().unwrap(),
75-
)
76-
.unwrap()
49+
ctx.verify_kzg_proof(
50+
commitments.first().unwrap(),
51+
fields.first().unwrap(),
52+
fields.first().unwrap(),
53+
proofs.first().unwrap(),
54+
)
55+
.unwrap()
7756
})
7857
});
7958

8059
c.bench_function("compute_blob_kzg_proof", |b| {
81-
#[cfg(feature = "parallel")]
82-
b.iter(|| {
83-
ctx.ctx.compute_blob_kzg_proof_parallel(
84-
&ctx.pool,
85-
blobs.first().unwrap(),
86-
commitments.first().unwrap(),
87-
)
88-
});
89-
90-
#[cfg(not(feature = "parallel"))]
9160
b.iter(|| {
92-
ctx.ctx
93-
.compute_blob_kzg_proof(blobs.first().unwrap(), commitments.first().unwrap())
61+
ctx.compute_blob_kzg_proof(blobs.first().unwrap(), commitments.first().unwrap())
62+
.unwrap();
9463
});
9564
});
9665

9766
c.bench_function("verify_blob_kzg_proof", |b| {
98-
#[cfg(feature = "parallel")]
9967
b.iter(|| {
100-
ctx.ctx
101-
.verify_blob_kzg_proof_parallel(
102-
&ctx.pool,
103-
blobs.first().unwrap(),
104-
commitments.first().unwrap(),
105-
proofs.first().unwrap(),
106-
)
107-
.unwrap()
108-
});
109-
110-
#[cfg(not(feature = "parallel"))]
111-
b.iter(|| {
112-
ctx.ctx
113-
.verify_blob_kzg_proof(
114-
blobs.first().unwrap(),
115-
commitments.first().unwrap(),
116-
proofs.first().unwrap(),
117-
)
118-
.unwrap()
68+
ctx.verify_blob_kzg_proof(
69+
blobs.first().unwrap(),
70+
commitments.first().unwrap(),
71+
proofs.first().unwrap(),
72+
)
73+
.unwrap()
11974
});
12075
});
12176

@@ -137,26 +92,13 @@ fn bench_eip_4844_constantine_no_conv_(c: &mut Criterion) {
13792
(blobs_subset, commitments_subset, proofs_subset)
13893
},
13994
|(blobs_subset, commitments_subset, proofs_subset)| {
140-
#[cfg(feature = "parallel")]
141-
ctx.ctx
142-
.verify_blob_kzg_proof_batch_parallel(
143-
&ctx.pool,
144-
blobs_subset,
145-
commitments_subset,
146-
proofs_subset,
147-
&rand_thing,
148-
)
149-
.unwrap();
150-
151-
#[cfg(not(feature = "parallel"))]
152-
ctx.ctx
153-
.verify_blob_kzg_proof_batch(
154-
blobs_subset,
155-
commitments_subset,
156-
proofs_subset,
157-
&rand_thing,
158-
)
159-
.unwrap();
95+
ctx.verify_blob_kzg_proof_batch(
96+
blobs_subset,
97+
commitments_subset,
98+
proofs_subset,
99+
&rand_thing,
100+
)
101+
.unwrap();
160102
},
161103
BatchSize::LargeInput,
162104
);

constantine/src/mixed_kzg/mixed_eip_4844.rs

+32-96
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ fn blob_fr_to_byte(blob: &[CtFr]) -> Result<[u8; BYTES_PER_BLOB], String> {
4040
// unsafe { Ok(std::mem::transmute(blob.as_ptr() as *const [u8; BYTES_PER_BLOB])) }
4141
}
4242

43-
pub fn load_trusted_setup_filename_mixed(filepath: &str) -> Result<MixedKzgSettings, String> {
43+
pub fn load_trusted_setup_filename_mixed(
44+
filepath: &str,
45+
) -> Result<MixedKzgSettings<'static>, String> {
4446
MixedKzgSettings::new_from_path(Path::new(filepath))
4547
}
4648

@@ -52,19 +54,10 @@ pub fn blob_to_kzg_commitment_mixed(
5254
MixedKzgSettings::Constantine(ctt_context) => {
5355
let blob_bytes = blob_fr_to_byte(blob)?;
5456

55-
#[cfg(feature = "parallel")]
56-
let res = ctt_context
57-
.ctx
58-
.blob_to_kzg_commitment_parallel(&ctt_context.pool, &blob_bytes);
59-
60-
#[cfg(not(feature = "parallel"))]
61-
let res = ctt_context.ctx.blob_to_kzg_commitment(&blob_bytes);
62-
63-
match res {
64-
Ok(commitment) => CtG1::from_bytes(&commitment),
65-
Err(x) => Err(x.to_string()),
66-
}
67-
// return blob_to_kzg_commitment_rust(blob, ctt_context);
57+
ctt_context
58+
.blob_to_kzg_commitment(&blob_bytes)
59+
.map_err(|e| e.to_string())
60+
.and_then(|b| CtG1::from_bytes(&b))
6861
}
6962
MixedKzgSettings::Generic(generic_context) => {
7063
blob_to_kzg_commitment_rust(blob, generic_context)
@@ -81,22 +74,10 @@ pub fn compute_kzg_proof_mixed(
8174
MixedKzgSettings::Constantine(ctt_context) => {
8275
let blob_bytes = blob_fr_to_byte(blob)?;
8376

84-
#[cfg(feature = "parallel")]
85-
let res = ctt_context.ctx.compute_kzg_proof_parallel(
86-
&ctt_context.pool,
87-
&blob_bytes,
88-
&z.to_bytes(),
89-
);
90-
91-
#[cfg(not(feature = "parallel"))]
92-
let res = ctt_context
93-
.ctx
94-
.compute_kzg_proof(&blob_bytes, &z.to_bytes());
95-
96-
match res {
97-
Ok((proof, y)) => Ok((CtG1::from_bytes(&proof)?, CtFr::from_bytes(&y)?)),
98-
Err(x) => Err(x.to_string()),
99-
}
77+
ctt_context
78+
.compute_kzg_proof(&blob_bytes, &z.to_bytes())
79+
.map_err(|e| e.to_string())
80+
.and_then(|(proof, y)| Ok((CtG1::from_bytes(&proof)?, CtFr::from_bytes(&y)?)))
10081
}
10182
MixedKzgSettings::Generic(generic_context) => {
10283
compute_kzg_proof_rust(blob, z, generic_context)
@@ -113,22 +94,10 @@ pub fn compute_blob_kzg_proof_mixed(
11394
MixedKzgSettings::Constantine(ctt_context) => {
11495
let blob_bytes = blob_fr_to_byte(blob)?;
11596

116-
#[cfg(feature = "parallel")]
117-
let res = ctt_context.ctx.compute_blob_kzg_proof_parallel(
118-
&ctt_context.pool,
119-
&blob_bytes,
120-
&commitment.to_bytes(),
121-
);
122-
123-
#[cfg(not(feature = "parallel"))]
124-
let res = ctt_context
125-
.ctx
126-
.compute_blob_kzg_proof(&blob_bytes, &commitment.to_bytes());
127-
128-
match res {
129-
Ok(proof) => CtG1::from_bytes(&proof),
130-
Err(x) => Err(x.to_string()),
131-
}
97+
ctt_context
98+
.compute_blob_kzg_proof(&blob_bytes, &commitment.to_bytes())
99+
.map_err(|e| e.to_string())
100+
.and_then(|proof| CtG1::from_bytes(&proof))
132101
}
133102
MixedKzgSettings::Generic(generic_context) => {
134103
compute_blob_kzg_proof_rust(blob, commitment, generic_context)
@@ -144,18 +113,14 @@ pub fn verify_kzg_proof_mixed(
144113
s: &MixedKzgSettings,
145114
) -> Result<bool, String> {
146115
match s {
147-
MixedKzgSettings::Constantine(ctt_context) => {
148-
let res = ctt_context.ctx.verify_kzg_proof(
116+
MixedKzgSettings::Constantine(ctt_context) => ctt_context
117+
.verify_kzg_proof(
149118
&commitment.to_bytes(),
150119
&z.to_bytes(),
151120
&y.to_bytes(),
152121
&proof.to_bytes(),
153-
);
154-
match res {
155-
Ok(x) => Ok(x),
156-
Err(x) => Err(x.to_string()),
157-
}
158-
}
122+
)
123+
.map_err(|e| e.to_string()),
159124
MixedKzgSettings::Generic(generic_context) => {
160125
verify_kzg_proof_rust(commitment, z, y, proof, generic_context)
161126
}
@@ -172,25 +137,9 @@ pub fn verify_blob_kzg_proof_mixed(
172137
MixedKzgSettings::Constantine(ctt_context) => {
173138
let blob_bytes = blob_fr_to_byte(blob)?;
174139

175-
#[cfg(feature = "parallel")]
176-
let res = ctt_context.ctx.verify_blob_kzg_proof_parallel(
177-
&ctt_context.pool,
178-
&blob_bytes,
179-
&commitment_g1.to_bytes(),
180-
&proof_g1.to_bytes(),
181-
);
182-
183-
#[cfg(not(feature = "parallel"))]
184-
let res = ctt_context.ctx.verify_blob_kzg_proof(
185-
&blob_bytes,
186-
&commitment_g1.to_bytes(),
187-
&proof_g1.to_bytes(),
188-
);
189-
190-
match res {
191-
Ok(x) => Ok(x),
192-
Err(x) => Err(x.to_string()),
193-
}
140+
ctt_context
141+
.verify_blob_kzg_proof(&blob_bytes, &commitment_g1.to_bytes(), &proof_g1.to_bytes())
142+
.map_err(|e| e.to_string())
194143
}
195144
MixedKzgSettings::Generic(generic_context) => {
196145
verify_blob_kzg_proof_rust(blob, commitment_g1, proof_g1, generic_context)
@@ -220,29 +169,16 @@ pub fn verify_blob_kzg_proof_batch_mixed(
220169
.collect::<Vec<_>>();
221170
let proofs_g1 = proofs_g1.iter().map(|x| x.to_bytes()).collect::<Vec<_>>();
222171

223-
let rand_thing = [0u8; 32];
224-
225-
#[cfg(feature = "parallel")]
226-
let res = ctt_context.ctx.verify_blob_kzg_proof_batch_parallel(
227-
&ctt_context.pool,
228-
blobs_storage.as_slice(),
229-
commitments.as_slice(),
230-
proofs_g1.as_slice(),
231-
&rand_thing,
232-
);
233-
234-
#[cfg(not(feature = "parallel"))]
235-
let res = ctt_context.ctx.verify_blob_kzg_proof_batch(
236-
blobs_storage.as_slice(),
237-
commitments.as_slice(),
238-
proofs_g1.as_slice(),
239-
&rand_thing,
240-
);
241-
242-
match res {
243-
Ok(x) => Ok(x),
244-
Err(x) => Err(x.to_string()),
245-
}
172+
let rand_thing = rand::random();
173+
174+
ctt_context
175+
.verify_blob_kzg_proof_batch(
176+
blobs_storage.as_slice(),
177+
commitments.as_slice(),
178+
proofs_g1.as_slice(),
179+
&rand_thing,
180+
)
181+
.map_err(|e| e.to_string())
246182
}
247183
MixedKzgSettings::Generic(generic_context) => {
248184
verify_blob_kzg_proof_batch_rust(blobs, commitments_g1, proofs_g1, generic_context)

0 commit comments

Comments
 (0)