Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update peerdas-kzg library #6118

Merged
merged 4 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(|| {
Comment on lines +7 to +16
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commenting on this, so we remember to remove it if not needed -- should be able to run cargo bench to check the time it takes to initialize the context

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
Loading