diff --git a/testing/ef_tests/src/cases/kzg_blob_to_kzg_commitment.rs b/testing/ef_tests/src/cases/kzg_blob_to_kzg_commitment.rs index 5194c3336c8..fa16a5fcb7a 100644 --- a/testing/ef_tests/src/cases/kzg_blob_to_kzg_commitment.rs +++ b/testing/ef_tests/src/cases/kzg_blob_to_kzg_commitment.rs @@ -36,7 +36,7 @@ impl Case for KZGBlobToKZGCommitment { } fn result(&self, _case_index: usize, _fork_name: ForkName) -> Result<(), Error> { - let kzg = get_kzg()?; + let kzg = get_kzg(); let commitment = parse_blob::(&self.input.blob).and_then(|blob| { blob_to_kzg_commitment::(&kzg, &blob).map_err(|e| { Error::InternalError(format!("Failed to compute kzg commitment: {:?}", e)) diff --git a/testing/ef_tests/src/cases/kzg_compute_blob_kzg_proof.rs b/testing/ef_tests/src/cases/kzg_compute_blob_kzg_proof.rs index 61e7248deeb..694013e2513 100644 --- a/testing/ef_tests/src/cases/kzg_compute_blob_kzg_proof.rs +++ b/testing/ef_tests/src/cases/kzg_compute_blob_kzg_proof.rs @@ -43,7 +43,7 @@ impl Case for KZGComputeBlobKZGProof { Ok((blob, commitment)) }; - let kzg = get_kzg()?; + let kzg = get_kzg(); let proof = parse_input(&self.input).and_then(|(blob, commitment)| { compute_blob_kzg_proof::(&kzg, &blob, commitment) .map_err(|e| Error::InternalError(format!("Failed to compute kzg proof: {:?}", e))) diff --git a/testing/ef_tests/src/cases/kzg_compute_cells_and_kzg_proofs.rs b/testing/ef_tests/src/cases/kzg_compute_cells_and_kzg_proofs.rs index 74a44fdddfc..2a9f8ceeef3 100644 --- a/testing/ef_tests/src/cases/kzg_compute_cells_and_kzg_proofs.rs +++ b/testing/ef_tests/src/cases/kzg_compute_cells_and_kzg_proofs.rs @@ -35,7 +35,7 @@ impl Case for KZGComputeCellsAndKZGProofs { let blob = blob.as_ref().try_into().map_err(|e| { Error::InternalError(format!("Failed to convert blob to kzg blob: {e:?}")) })?; - let kzg = get_kzg()?; + let kzg = get_kzg(); kzg.compute_cells_and_proofs(blob).map_err(|e| { Error::InternalError(format!("Failed to compute cells and kzg proofs: {e:?}")) }) diff --git a/testing/ef_tests/src/cases/kzg_compute_kzg_proof.rs b/testing/ef_tests/src/cases/kzg_compute_kzg_proof.rs index ca19882d501..6f53038f28e 100644 --- a/testing/ef_tests/src/cases/kzg_compute_kzg_proof.rs +++ b/testing/ef_tests/src/cases/kzg_compute_kzg_proof.rs @@ -50,7 +50,7 @@ impl Case for KZGComputeKZGProof { Ok((blob, z)) }; - let kzg = get_kzg()?; + let kzg = get_kzg(); let proof = parse_input(&self.input).and_then(|(blob, z)| { compute_kzg_proof::(&kzg, &blob, z) .map_err(|e| Error::InternalError(format!("Failed to compute kzg proof: {:?}", e))) diff --git a/testing/ef_tests/src/cases/kzg_recover_cells_and_kzg_proofs.rs b/testing/ef_tests/src/cases/kzg_recover_cells_and_kzg_proofs.rs index fc41f1f2a62..890cf7889e2 100644 --- a/testing/ef_tests/src/cases/kzg_recover_cells_and_kzg_proofs.rs +++ b/testing/ef_tests/src/cases/kzg_recover_cells_and_kzg_proofs.rs @@ -59,7 +59,7 @@ impl Case for KZGRecoverCellsAndKZGProofs { let result = parse_input(&self.input).and_then(|(input_proofs, input_cells, cell_indices)| { let input_cells_ref: Vec<_> = input_cells.iter().map(|cell| &**cell).collect(); - let kzg = get_kzg()?; + let kzg = get_kzg(); let (cells, proofs) = kzg .recover_cells_and_compute_kzg_proofs( cell_indices.as_slice(), diff --git a/testing/ef_tests/src/cases/kzg_verify_blob_kzg_proof.rs b/testing/ef_tests/src/cases/kzg_verify_blob_kzg_proof.rs index 4e56b2b44c3..da7f2405690 100644 --- a/testing/ef_tests/src/cases/kzg_verify_blob_kzg_proof.rs +++ b/testing/ef_tests/src/cases/kzg_verify_blob_kzg_proof.rs @@ -5,14 +5,23 @@ use eth2_network_config::TRUSTED_SETUP_BYTES; use kzg::{Cell, Error as KzgError, Kzg, KzgCommitment, KzgProof, TrustedSetup}; use serde::Deserialize; use std::marker::PhantomData; +use std::sync::Arc; +use std::sync::LazyLock; use types::Blob; -pub fn get_kzg() -> Result { +static KZG: LazyLock> = LazyLock::new(|| { let trusted_setup: TrustedSetup = serde_json::from_reader(TRUSTED_SETUP_BYTES) - .map_err(|e| Error::InternalError(format!("Failed to initialize kzg: {:?}", e)))?; + .map_err(|e| Error::InternalError(format!("Failed to initialize trusted setup: {:?}", e))) + .expect("failed to initialize trusted setup"); // TODO(das): need to enable these tests when rayon issues in rust_eth_kzg are fixed - Kzg::new_from_trusted_setup(trusted_setup) + let kzg = Kzg::new_from_trusted_setup(trusted_setup) .map_err(|e| Error::InternalError(format!("Failed to initialize kzg: {:?}", e))) + .expect("failed to initialize kzg"); + Arc::new(kzg) +}); + +pub fn get_kzg() -> Arc { + Arc::clone(&KZG) } pub fn parse_cells_and_proofs( @@ -120,7 +129,7 @@ impl Case for KZGVerifyBlobKZGProof { Ok((blob, commitment, proof)) }; - let kzg = get_kzg()?; + let kzg = get_kzg(); let result = parse_input(&self.input).and_then(|(blob, commitment, proof)| { match validate_blob::(&kzg, &blob, commitment, proof) { Ok(_) => Ok(true), diff --git a/testing/ef_tests/src/cases/kzg_verify_blob_kzg_proof_batch.rs b/testing/ef_tests/src/cases/kzg_verify_blob_kzg_proof_batch.rs index cfe15d5c05a..80cd0a28496 100644 --- a/testing/ef_tests/src/cases/kzg_verify_blob_kzg_proof_batch.rs +++ b/testing/ef_tests/src/cases/kzg_verify_blob_kzg_proof_batch.rs @@ -57,7 +57,7 @@ impl Case for KZGVerifyBlobKZGProofBatch { Ok((commitments, blobs, proofs)) }; - let kzg = get_kzg()?; + let kzg = get_kzg(); let result = parse_input(&self.input).and_then( |(commitments, blobs, proofs)| match validate_blobs::( diff --git a/testing/ef_tests/src/cases/kzg_verify_cell_kzg_proof_batch.rs b/testing/ef_tests/src/cases/kzg_verify_cell_kzg_proof_batch.rs index 9c651d2d633..1f55f6dbfda 100644 --- a/testing/ef_tests/src/cases/kzg_verify_cell_kzg_proof_batch.rs +++ b/testing/ef_tests/src/cases/kzg_verify_cell_kzg_proof_batch.rs @@ -61,7 +61,7 @@ impl Case for KZGVerifyCellKZGProofBatch { .into_iter() .map(|(_row, col)| col) .collect::>(); - let kzg = get_kzg()?; + let kzg = get_kzg(); match kzg.verify_cell_proof_batch(&cells, &proofs, column_indices, &commitments) { Ok(_) => Ok(true), Err(KzgError::KzgVerificationFailed) => Ok(false), diff --git a/testing/ef_tests/src/cases/kzg_verify_kzg_proof.rs b/testing/ef_tests/src/cases/kzg_verify_kzg_proof.rs index 4468176c277..ed7583dbd0a 100644 --- a/testing/ef_tests/src/cases/kzg_verify_kzg_proof.rs +++ b/testing/ef_tests/src/cases/kzg_verify_kzg_proof.rs @@ -46,7 +46,7 @@ impl Case for KZGVerifyKZGProof { Ok((commitment, z, y, proof)) }; - let kzg = get_kzg()?; + let kzg = get_kzg(); let result = parse_input(&self.input).and_then(|(commitment, z, y, proof)| { verify_kzg_proof::(&kzg, commitment, proof, z, y) .map_err(|e| Error::InternalError(format!("Failed to validate proof: {:?}", e)))