-
Notifications
You must be signed in to change notification settings - Fork 0
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
Seperate crate for blob crypto #28
base: master
Are you sure you want to change the base?
Changes from all commits
bdf0f34
bff6d13
298793d
1c3f2c0
a1c9374
755a5c8
be6e64e
14aad44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,72 @@ | ||||||
use alloy_primitives::Bytes; | ||||||
use alloy_rlp::Decodable; | ||||||
use async_trait::async_trait; | ||||||
use kona_preimage::errors::PreimageOracleError; | ||||||
use kona_preimage::CommsClient; | ||||||
|
||||||
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; | ||||||
|
||||||
/// CachedOracleEigenDAProvider is a wrapper outside OracleEigenDAProvider. Its intended use | ||||||
/// case is to fetch all eigenda blobs received during the derivation pipeline. So that it | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
/// is able to compute and cache the kzg witnesses, which can be verified inside ZKVM by checking | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we create a zkvm crate or somethign of that effect? Would be good to separate the structs and logic that is only used for zkvm vs those that are used for fraud proofs. |
||||||
/// the point opening at the random Fiat Shamir evaluation index. | ||||||
#[derive(Debug, Clone)] | ||||||
pub struct CachedOracleEigenDAProvider<T: CommsClient> { | ||||||
/// The preimage oracle client. | ||||||
oracle: OracleEigenDAProvider<T>, | ||||||
/// kzg proof witness | ||||||
pub witness: Arc<Mutex<EigenDABlobWitness>>, | ||||||
} | ||||||
|
||||||
impl<T: CommsClient> CachedOracleEigenDAProvider<T> { | ||||||
/// Constructs a new oracle-backed EigenDA provider. | ||||||
pub fn new(oracle: OracleEigenDAProvider<T>, witness: Arc<Mutex<EigenDABlobWitness>>) -> Self { | ||||||
Self { oracle, witness } | ||||||
} | ||||||
} | ||||||
|
||||||
#[async_trait] | ||||||
impl<T: CommsClient + Sync + Send> EigenDABlobProvider for CachedOracleEigenDAProvider<T> { | ||||||
type Error = OracleProviderError; | ||||||
|
||||||
async fn get_blob(&mut self, cert: &Bytes) -> Result<Bytes, Self::Error> { | ||||||
let blob = self.oracle.get_blob(cert).await?; | ||||||
let cert_blob_info = match BlobInfo::decode(&mut &cert[4..]) { | ||||||
Ok(c) => c, | ||||||
Err(_) => { | ||||||
return Err(OracleProviderError::Preimage(PreimageOracleError::Other( | ||||||
"does not contain header".into(), | ||||||
))); | ||||||
Comment on lines
+42
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use map_err(...)? instead There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also isnt there a way to actually wrap the error? "does not contain header" is potentially wrong. could just be that elements are not bn254 FEs right? |
||||||
} | ||||||
}; | ||||||
|
||||||
let mut witness = self.witness.lock().unwrap(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. propagate error instead of unwrapping which panics |
||||||
|
||||||
let _ = witness.push_witness(&blob).map_err(|e| { | ||||||
return Err::<T, kona_proof::errors::OracleProviderError>(OracleProviderError::Preimage(PreimageOracleError::Other( | ||||||
e.to_string(), | ||||||
))); | ||||||
}); | ||||||
|
||||||
let last_commitment = witness.commitments.last().unwrap(); | ||||||
|
||||||
// make sure locally computed proof equals to returned proof from the provider | ||||||
if last_commitment[..32] != cert_blob_info.blob_header.commitment.x[..] | ||||||
|| last_commitment[32..64] != cert_blob_info.blob_header.commitment.y[..] | ||||||
Comment on lines
+59
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these abstractions are super leaky. Better to create abstractions that only require local reasoning. Should in principle never have to index into a struct's fields like this for validation. That should all be handled by the struct itself. Maybe pass the commitment to the |
||||||
{ | ||||||
return Err(OracleProviderError::Preimage(PreimageOracleError::Other( | ||||||
"proxy commitment is different from computed commitment proxy".into(), | ||||||
))); | ||||||
}; | ||||||
|
||||||
Ok(blob) | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ use kona_preimage::{ | |
}; | ||
|
||
use alloc::sync::Arc; | ||
use std::sync::Mutex; | ||
|
||
use core::fmt::Debug; | ||
use kona_executor::TrieDBProvider; | ||
use kona_proof::{ | ||
|
@@ -21,6 +23,9 @@ use kona_proof::{ | |
use tracing::{error, info}; | ||
|
||
use hokulea_proof::eigenda_provider::OracleEigenDAProvider; | ||
use hokulea_cryptography::witness::EigenDABlobWitness; | ||
|
||
pub mod cached_eigenda_provider; | ||
|
||
#[inline] | ||
pub async fn run<P, H>(oracle_client: P, hint_client: H) -> Result<(), FaultProofProgramError> | ||
|
@@ -41,7 +46,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()); | ||
} | ||
|
@@ -51,6 +56,9 @@ where | |
let beacon = OracleBlobProvider::new(oracle.clone()); | ||
let eigenda_blob_provider = OracleEigenDAProvider::new(oracle.clone()); | ||
|
||
let eigenda_blob_witness = Arc::new(Mutex::new(EigenDABlobWitness::new())); | ||
let cached_eigenda_blob_provider = cached_eigenda_provider::CachedOracleEigenDAProvider::new(eigenda_blob_provider, eigenda_blob_witness); | ||
|
||
// If the claimed L2 block number is less than the safe head of the L2 chain, the claim is | ||
// invalid. | ||
let safe_head = fetch_safe_head(oracle.as_ref(), boot.as_ref(), &mut l2_provider).await?; | ||
|
@@ -91,17 +99,23 @@ where | |
beacon, | ||
l1_provider.clone(), | ||
l2_provider.clone(), | ||
eigenda_blob_provider.clone(), | ||
cached_eigenda_blob_provider.clone(), | ||
); | ||
let executor = KonaExecutor::new(&cfg, l2_provider.clone(), l2_provider, None, None); | ||
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?; | ||
|
||
// batch Verify cache | ||
let witness = cached_eigenda_blob_provider.witness.lock().unwrap(); | ||
if !witness.batch_verify() { | ||
panic!("batch verify wrong"); | ||
} | ||
Comment on lines
+115
to
+117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rust has asserts. But why do we panic? prob should not panic and |
||
|
||
//////////////////////////////////////////////////////////////// | ||
// EPILOGUE // | ||
//////////////////////////////////////////////////////////////// | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "hokulea-cryptography" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
|
||
[dependencies] | ||
rust-kzg-bn254-verifier.workspace = true | ||
rust-kzg-bn254-prover.workspace = true | ||
rust-kzg-bn254-primitives.workspace = true | ||
num.workspace = true | ||
ark-bn254.workspace = true | ||
ark-ff.workspace = true | ||
|
||
tracing.workspace = true | ||
alloy-primitives.workspace = true | ||
thiserror.workspace = true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# `cryptography` | ||
|
||
This crate contains bn254 logics for generating kzg proof for either client or host. This crate uses STD. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't client not have access to std? or do some zkvms have access to the stdlib? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not call this crate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. crates dir contains a list of crates, some are std some are not it does both prove and verify,. But sg. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. call it kzg-crypto |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#![doc = include_str!("../README.md")] | ||
#![warn( | ||
missing_debug_implementations, | ||
missing_docs, | ||
unreachable_pub, | ||
rustdoc::all | ||
)] | ||
#![deny(unused_must_use, rust_2018_idioms)] | ||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] | ||
#![cfg_attr(not(test), warn(unused_crate_dependencies))] | ||
|
||
pub mod witness; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.