Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
bxue-l2 committed Jan 24, 2025
1 parent 6862bb3 commit e781e65
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 26 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

24 changes: 16 additions & 8 deletions bin/client/src/cached_eigenda_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ use async_trait::async_trait;
use kona_preimage::errors::PreimageOracleError;
use kona_preimage::CommsClient;

use hokulea_cryptography::witness::EigenDABlobWitness;
use hokulea_eigenda::BlobInfo;
use hokulea_eigenda::EigenDABlobProvider;
use hokulea_proof::eigenda_provider::OracleEigenDAProvider;
use hokulea_cryptography::witness::EigenDABlobWitness;

use kona_proof::errors::OracleProviderError;

use std::sync::Mutex;
use alloc::sync::Arc;
use rust_kzg_bn254::srs::SRS;
use std::sync::Mutex;

/// CachedOracleEigenDAProvider is a wrapper outside OracleEigenDAProvider. Its intended use
/// case is to fetch all eigenda blobs received during the derivation pipeline. So that it
Expand All @@ -31,8 +31,16 @@ pub struct CachedOracleEigenDAProvider<T: CommsClient> {

impl<T: CommsClient> CachedOracleEigenDAProvider<T> {
/// Constructs a new oracle-backed EigenDA provider.
pub fn new(oracle: OracleEigenDAProvider<T>, witness: Arc<Mutex<EigenDABlobWitness>>, srs: SRS) -> Self {
Self { oracle, witness, srs }
pub fn new(
oracle: OracleEigenDAProvider<T>,
witness: Arc<Mutex<EigenDABlobWitness>>,
srs: SRS,
) -> Self {
Self {
oracle,
witness,
srs,
}
}
}

Expand All @@ -54,9 +62,9 @@ impl<T: CommsClient + Sync + Send> EigenDABlobProvider for CachedOracleEigenDAPr
let mut witness = self.witness.lock().unwrap();

let _ = witness.push_witness(&blob, &self.srs).map_err(|e| {
return Err::<T, kona_proof::errors::OracleProviderError>(OracleProviderError::Preimage(PreimageOracleError::Other(
e.to_string(),
)));
return Err::<T, kona_proof::errors::OracleProviderError>(
OracleProviderError::Preimage(PreimageOracleError::Other(e.to_string())),
);
});

let last_commitment = witness.commitments.last().unwrap();
Expand All @@ -72,4 +80,4 @@ impl<T: CommsClient + Sync + Send> EigenDABlobProvider for CachedOracleEigenDAPr

Ok(blob)
}
}
}
12 changes: 8 additions & 4 deletions bin/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use kona_proof::{
};
use tracing::{error, info};

use hokulea_proof::eigenda_provider::OracleEigenDAProvider;
use hokulea_cryptography::witness::EigenDABlobWitness;
use hokulea_proof::eigenda_provider::OracleEigenDAProvider;
use rust_kzg_bn254::srs::SRS;

pub mod cached_eigenda_provider;
Expand All @@ -47,7 +47,7 @@ where
));
let boot = match BootInfo::load(oracle.as_ref()).await {
Ok(boot) => Arc::new(boot),
Err(e ) => {
Err(e) => {
error!(target: "client", "Failed to load boot info: {:?}", e);
return Err(e.into());
}
Expand All @@ -59,7 +59,11 @@ where

let eigenda_blob_witness = Arc::new(Mutex::new(EigenDABlobWitness::new()));
let srs = SRS::new("resources/g1.point", 268435456, 1024).unwrap();
let cached_eigenda_blob_provider = cached_eigenda_provider::CachedOracleEigenDAProvider::new(eigenda_blob_provider, eigenda_blob_witness, srs);
let cached_eigenda_blob_provider = cached_eigenda_provider::CachedOracleEigenDAProvider::new(
eigenda_blob_provider,
eigenda_blob_witness,
srs,
);

// If the claimed L2 block number is less than the safe head of the L2 chain, the claim is
// invalid.
Expand Down Expand Up @@ -107,7 +111,7 @@ where
let mut driver = Driver::new(cursor, executor, pipeline);

// Run the derivation pipeline until we are able to produce the output root of the claimed
// L2 block.
// L2 block.
let (number, output_root) = driver
.advance_to_target(&boot.rollup_config, Some(boot.claimed_l2_block_number))
.await?;
Expand Down
3 changes: 1 addition & 2 deletions crates/cryptography/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ ark-bn254.workspace = true
ark-ff.workspace = true

tracing.workspace = true
alloy-primitives.workspace = true
thiserror.workspace = true
alloy-primitives.workspace = true
2 changes: 1 addition & 1 deletion crates/cryptography/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]

pub mod witness;
pub mod witness;
29 changes: 19 additions & 10 deletions crates/cryptography/src/witness.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
//! Contains the [EigenDABlobWitness], which is a utility struct for temporarily
//! storing blob, commitmenta and proof used to check the interity of the eigenda
//! blob.
extern crate alloc;
use alloc::vec::Vec;
use alloy_primitives::Bytes;
use ark_bn254::{Fq, G1Affine};
use ark_ff::PrimeField;
use num::BigUint;
use rust_kzg_bn254::batch;
use rust_kzg_bn254::blob::Blob;
use rust_kzg_bn254::errors::KzgError;
use rust_kzg_bn254::kzg::KZG;
use rust_kzg_bn254::srs::SRS;
use rust_kzg_bn254::batch;
use tracing::info;
use num::BigUint;
use rust_kzg_bn254::errors::KzgError;

/// A data structure for storing blobs, the commitment of the blob and the proof
/// that provides efficient verification between the commitment and the blob
/// that provides efficient verification between the commitment and the blob
/// without actually commiting the blob
#[derive(Debug, Clone, Default)]
pub struct EigenDABlobWitness {
Expand All @@ -24,7 +28,7 @@ pub struct EigenDABlobWitness {
pub proofs: Vec<Bytes>,
}

///
///
impl EigenDABlobWitness {
/// Create a default struct
pub fn new() -> Self {
Expand All @@ -45,7 +49,8 @@ impl EigenDABlobWitness {
let input = Blob::new(blob);
let input_poly = input.to_polynomial_eval_form();

kzg.calculate_and_store_roots_of_unity(blob.len() as u64).unwrap();
kzg.calculate_and_store_roots_of_unity(blob.len() as u64)
.unwrap();

let mut commitment_bytes = vec![0u8; 0];

Expand All @@ -69,7 +74,11 @@ impl EigenDABlobWitness {
append_left_padded_biguint_be(&mut proof_bytes, &proof_y_bigint);

// push data into witness
self.write(Bytes::copy_from_slice(blob), Bytes::copy_from_slice(&commitment_bytes), proof_bytes.into());
self.write(
Bytes::copy_from_slice(blob),
Bytes::copy_from_slice(&commitment_bytes),
proof_bytes.into(),
);

Ok(())
}
Expand Down Expand Up @@ -111,17 +120,17 @@ impl EigenDABlobWitness {
G1Affine::new(x, y)
})
.collect();
let pairing_result = batch::verify_blob_kzg_proof(&lib_blobs, &lib_commitments, &lib_proofs).unwrap();
let pairing_result =
batch::verify_blob_kzg_proof(&lib_blobs, &lib_commitments, &lib_proofs).unwrap();

pairing_result
}
}


/// This function convert a BigUint into 32Bytes vector in big endian format
pub fn append_left_padded_biguint_be(vec: &mut Vec<u8>, biguint: &BigUint) {
let bytes = biguint.to_bytes_be();
let padding = 32 - bytes.len();
vec.extend(std::iter::repeat(0).take(padding));
vec.extend_from_slice(&bytes);
}
}

0 comments on commit e781e65

Please sign in to comment.