Skip to content

Commit

Permalink
Copy existing trusted setup into PeerDASTrustedSetup for consistenc…
Browse files Browse the repository at this point in the history
…y and maintain `--trusted-setup` functionality.
  • Loading branch information
jimmygchen committed Aug 7, 2024
1 parent 9b69f1d commit 11c53a8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
6 changes: 5 additions & 1 deletion crypto/kzg/benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ use kzg::TrustedSetup;
use rust_eth_kzg::{DASContext, TrustedSetup as PeerDASTrustedSetup};

pub fn bench_init_context(c: &mut Criterion) {
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");

c.bench_function(&format!("Initialize context rust_eth_kzg"), |b| {
b.iter(|| {
const NUM_THREADS: usize = 1;
let trusted_setup = PeerDASTrustedSetup::default();
let trusted_setup = PeerDASTrustedSetup::from(&trusted_setup);
DASContext::with_threads(&trusted_setup, NUM_THREADS)
})
});
Expand Down
2 changes: 1 addition & 1 deletion crypto/kzg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Kzg {
//
// Note: One can also use `from_json` to initialize it from the consensus-specs
// json string.
let peerdas_trusted_setup = PeerDASTrustedSetup::default();
let peerdas_trusted_setup = PeerDASTrustedSetup::from(&trusted_setup);
// Set the number of threads to be used
//
// we set it to 1 to match the c-kzg performance
Expand Down
23 changes: 23 additions & 0 deletions crypto/kzg/src/trusted_setup.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::PeerDASTrustedSetup;
use c_kzg::{BYTES_PER_G1_POINT, BYTES_PER_G2_POINT};
use serde::{
de::{self, Deserializer, Visitor},
Expand Down Expand Up @@ -43,6 +44,28 @@ impl TrustedSetup {
}
}

impl From<&TrustedSetup> for PeerDASTrustedSetup {
fn from(trusted_setup: &TrustedSetup) -> Self {
Self {
g1_monomial: trusted_setup
.g1_monomial_points
.iter()
.map(|g1_point| format!("0x{}", hex::encode(g1_point.0)))
.collect::<Vec<_>>(),
g1_lagrange: trusted_setup
.g1_points
.iter()
.map(|g1_point| format!("0x{}", hex::encode(g1_point.0)))
.collect::<Vec<_>>(),
g2_monomial: trusted_setup
.g2_points
.iter()
.map(|g2_point| format!("0x{}", hex::encode(g2_point.0)))
.collect::<Vec<_>>(),
}
}
}

impl Serialize for G1Point {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand Down

0 comments on commit 11c53a8

Please sign in to comment.