Skip to content

Commit

Permalink
chore: update peerdas-kzg library (#6118)
Browse files Browse the repository at this point in the history
* chore: update peerDAS lib

* chore: update library

* chore: update library to version that include "init context" benchmarks and optional validation checks

* chore: (can remove) -- Add benchmarks for init context
  • Loading branch information
kevaundray authored Jul 17, 2024
1 parent 55a3be7 commit 04d9eef
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
13 changes: 8 additions & 5 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ delay_map = "0.3"
derivative = "2"
dirs = "3"
either = "1.9"
peerdas-kzg = { git = "https://github.com/crate-crypto/peerdas-kzg", rev = "bb8295011cf27dc663699539c7f9a17fe273e896", package = "eip7594" }
peerdas-kzg = { git = "https://github.com/crate-crypto/peerdas-kzg", rev = "55ae9e9011d792a2998d242c2a71d822ba909fa9", package = "eip7594" }
discv5 = { version = "0.4.1", features = ["libp2p"] }
env_logger = "0.9"
error-chain = "0.12"
Expand Down
9 changes: 9 additions & 0 deletions crypto/kzg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,12 @@ ethereum_hashing = { workspace = true }
c-kzg = { workspace = true }
peerdas-kzg = { workspace = true }
mockall = { workspace = true }

[dev-dependencies]
criterion = { workspace = true }
serde_json = { workspace = true }
eth2_network_config = { workspace = true }

[[bench]]
name = "benchmark"
harness = false
27 changes: 27 additions & 0 deletions crypto/kzg/benches/benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use c_kzg::KzgSettings;
use criterion::{criterion_group, criterion_main, Criterion};
use eth2_network_config::TRUSTED_SETUP_BYTES;
use kzg::TrustedSetup;
use peerdas_kzg::{PeerDASContext, TrustedSetup as PeerDASTrustedSetup};

pub fn bench_init_context(c: &mut Criterion) {
c.bench_function(&format!("Initialize context peerdas-kzg"), |b| {
b.iter(|| {
const NUM_THREADS: usize = 1;
let trusted_setup = PeerDASTrustedSetup::default();
PeerDASContext::with_threads(&trusted_setup, NUM_THREADS)
})
});
c.bench_function(&format!("Initialize context c-kzg (4844)"), |b| {
b.iter(|| {
let trusted_setup: TrustedSetup = serde_json::from_reader(TRUSTED_SETUP_BYTES)
.map_err(|e| format!("Unable to read trusted setup file: {}", e))
.expect("should have trusted setup");
KzgSettings::load_trusted_setup(&trusted_setup.g1_points(), &trusted_setup.g2_points())
.unwrap()
})
});
}

criterion_group!(benches, bench_init_context);
criterion_main!(benches);
6 changes: 2 additions & 4 deletions crypto/kzg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use mockall::automock;

pub use peerdas_kzg::{
constants::{BYTES_PER_CELL, CELLS_PER_EXT_BLOB},
Cell, CellID, CellRef, TrustedSetup as PeerDASTrustedSetup,
Cell, CellIndex as CellID, CellRef, TrustedSetup as PeerDASTrustedSetup,
};
use peerdas_kzg::{prover::ProverError, verifier::VerifierError, PeerDASContext};
pub type CellsAndKzgProofs = ([Cell; CELLS_PER_EXT_BLOB], [KzgProof; CELLS_PER_EXT_BLOB]);
Expand Down Expand Up @@ -181,7 +181,6 @@ impl Kzg {

let (cells, proofs) = self
.context
.prover_ctx()
.compute_cells_and_kzg_proofs(blob_bytes)
.map_err(Error::ProverKZG)?;

Expand Down Expand Up @@ -212,7 +211,7 @@ impl Kzg {
.iter()
.map(|commitment| commitment.as_ref())
.collect();
let verification_result = self.context.verifier_ctx().verify_cell_kzg_proof_batch(
let verification_result = self.context.verify_cell_kzg_proof_batch(
commitments.to_vec(),
rows,
columns,
Expand All @@ -236,7 +235,6 @@ impl Kzg {
) -> Result<CellsAndKzgProofs, Error> {
let (cells, proofs) = self
.context
.prover_ctx()
.recover_cells_and_proofs(cell_ids.to_vec(), cells.to_vec())
.map_err(Error::ProverKZG)?;

Expand Down

0 comments on commit 04d9eef

Please sign in to comment.