Skip to content

Commit

Permalink
Updated constantine version
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtiomTr authored and sauliusgrigaitis committed Feb 12, 2025
1 parent 878c977 commit 6ea2a2a
Show file tree
Hide file tree
Showing 10 changed files with 249 additions and 223 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/backend-benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:
exclude:
- os: windows-latest
backend: mcl
# FIXME: enable macos, when fixes are merged into constantine-public-sys branch
- os: macos-latest
backend: constantine

steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/backend-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ jobs:
exclude:
- os: windows-latest
backend: mcl
# FIXME: enable macos, when fixes are merged into constantine-public-sys branch
- os: macos-latest
backend: constantine

steps:
- uses: actions/checkout@v2
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions constantine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ blst = "0.3.11"
kzg = { path = "../kzg", default-features = false }
libc = { version = "0.2.148", default-features = false }
once_cell = { version = "1.18.0", features = ["critical-section"], default-features = false }
constantine-ethereum-kzg = { 'git' = 'https://github.com/mratsim/constantine.git' , branch='constantine-public-sys' }
constantine-sys = { 'git' = 'https://github.com/mratsim/constantine.git' , branch='constantine-public-sys' }
constantine-core = { 'git' = 'https://github.com/mratsim/constantine.git' , branch='constantine-public-sys' }
constantine-ethereum-kzg = { 'git' = 'https://github.com/mratsim/constantine.git', rev = "3ed6eeac4f0a9b0092bb4234b61768dfde25cdbe" } # branch constantine-public-sys
constantine-sys = { 'git' = 'https://github.com/mratsim/constantine.git', rev = "3ed6eeac4f0a9b0092bb4234b61768dfde25cdbe" } # branch constantine-public-sys
constantine-core = { 'git' = 'https://github.com/mratsim/constantine.git', rev = "3ed6eeac4f0a9b0092bb4234b61768dfde25cdbe" } # branch constantine-public-sys
rand = { version = "0.8.5", optional = true }
rayon = { version = "1.8.0", optional = true }
smallvec = { version = "1.11.1", features = ["const_generics"] }
Expand Down
113 changes: 28 additions & 85 deletions constantine/benches/eip_4844_constantine_no_conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use kzg::eip_4844::{BYTES_PER_BLOB, TRUSTED_SETUP_PATH};

use kzg_bench::set_trusted_setup_dir;
use kzg_bench::tests::eip_4844::{generate_random_blob_bytes, generate_random_field_element_bytes};
use rand::random;
use rust_kzg_constantine::mixed_kzg::mixed_kzg_settings::CttContext;

fn bench_eip_4844_constantine_no_conv_(c: &mut Criterion) {
Expand All @@ -23,104 +24,59 @@ fn bench_eip_4844_constantine_no_conv_(c: &mut Criterion) {

let commitments: Vec<[u8; 48]> = blobs
.iter()
.map(|blob| ctx.ctx.blob_to_kzg_commitment(blob).unwrap())
.map(|blob| ctx.blob_to_kzg_commitment(blob).unwrap())
.collect();

let proofs: Vec<[u8; 48]> = blobs
.iter()
.zip(commitments.iter())
.map(|(blob, commitment)| ctx.ctx.compute_blob_kzg_proof(blob, commitment).unwrap())
.map(|(blob, commitment)| ctx.compute_blob_kzg_proof(blob, commitment).unwrap())
.collect();

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

c.bench_function("blob_to_kzg_commitment", |b| {
#[cfg(feature = "parallel")]
b.iter(|| {
ctx.ctx
.blob_to_kzg_commitment_parallel(&ctx.pool, blobs.first().unwrap())
});

#[cfg(not(feature = "parallel"))]
b.iter(|| ctx.ctx.blob_to_kzg_commitment(blobs.first().unwrap()));
b.iter(|| ctx.blob_to_kzg_commitment(blobs.first().unwrap()));
});

c.bench_function("compute_kzg_proof", |b| {
#[cfg(feature = "parallel")]
b.iter(|| {
ctx.ctx.compute_kzg_proof_parallel(
&ctx.pool,
blobs.first().unwrap(),
fields.first().unwrap(),
)
});

#[cfg(not(feature = "parallel"))]
b.iter(|| {
ctx.ctx
.compute_kzg_proof(blobs.first().unwrap(), fields.first().unwrap())
});
b.iter(|| ctx.compute_kzg_proof(blobs.first().unwrap(), fields.first().unwrap()));
});

c.bench_function("verify_kzg_proof", |b| {
b.iter(|| {
ctx.ctx
.verify_kzg_proof(
commitments.first().unwrap(),
fields.first().unwrap(),
fields.first().unwrap(),
proofs.first().unwrap(),
)
.unwrap()
ctx.verify_kzg_proof(
commitments.first().unwrap(),
fields.first().unwrap(),
fields.first().unwrap(),
proofs.first().unwrap(),
)
.unwrap()
})
});

c.bench_function("compute_blob_kzg_proof", |b| {
#[cfg(feature = "parallel")]
b.iter(|| {
ctx.ctx.compute_blob_kzg_proof_parallel(
&ctx.pool,
blobs.first().unwrap(),
commitments.first().unwrap(),
)
});

#[cfg(not(feature = "parallel"))]
b.iter(|| {
ctx.ctx
.compute_blob_kzg_proof(blobs.first().unwrap(), commitments.first().unwrap())
ctx.compute_blob_kzg_proof(blobs.first().unwrap(), commitments.first().unwrap())
.unwrap();
});
});

c.bench_function("verify_blob_kzg_proof", |b| {
#[cfg(feature = "parallel")]
b.iter(|| {
ctx.ctx
.verify_blob_kzg_proof_parallel(
&ctx.pool,
blobs.first().unwrap(),
commitments.first().unwrap(),
proofs.first().unwrap(),
)
.unwrap()
});

#[cfg(not(feature = "parallel"))]
b.iter(|| {
ctx.ctx
.verify_blob_kzg_proof(
blobs.first().unwrap(),
commitments.first().unwrap(),
proofs.first().unwrap(),
)
.unwrap()
ctx.verify_blob_kzg_proof(
blobs.first().unwrap(),
commitments.first().unwrap(),
proofs.first().unwrap(),
)
.unwrap()
});
});

let mut group = c.benchmark_group("verify_blob_kzg_proof_batch");
let rand_thing = [0u8; 32];
let rand_thing = random();
for count in [1, 2, 4, 8, 16, 32, 64] {
group.throughput(Throughput::Elements(count as u64));
group.bench_with_input(BenchmarkId::from_parameter(count), &count, |b, &count| {
Expand All @@ -137,26 +93,13 @@ fn bench_eip_4844_constantine_no_conv_(c: &mut Criterion) {
(blobs_subset, commitments_subset, proofs_subset)
},
|(blobs_subset, commitments_subset, proofs_subset)| {
#[cfg(feature = "parallel")]
ctx.ctx
.verify_blob_kzg_proof_batch_parallel(
&ctx.pool,
blobs_subset,
commitments_subset,
proofs_subset,
&rand_thing,
)
.unwrap();

#[cfg(not(feature = "parallel"))]
ctx.ctx
.verify_blob_kzg_proof_batch(
blobs_subset,
commitments_subset,
proofs_subset,
&rand_thing,
)
.unwrap();
ctx.verify_blob_kzg_proof_batch(
blobs_subset,
commitments_subset,
proofs_subset,
&rand_thing,
)
.unwrap();
},
BatchSize::LargeInput,
);
Expand Down
Loading

0 comments on commit 6ea2a2a

Please sign in to comment.