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

Seperate crate for blob crypto #28

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

bxue-l2
Copy link
Collaborator

@bxue-l2 bxue-l2 commented Jan 24, 2025

This PR creates a cryptography crate that contains std library. The crate

  • uses the latest rust-kzg-bn254 to verify the blob
  • make blob witness into its own module, such that it can be used by both client and host

TODO in the next PR

  • make resources/g1.point configurable via config
  • have a run native-client option for the purpose of generating the witness

@bxue-l2 bxue-l2 marked this pull request as ready for review January 24, 2025 22:53
@bxue-l2 bxue-l2 requested a review from samlaf January 24, 2025 22:53
@@ -0,0 +1,3 @@
# `cryptography`

This crate contains bn254 logics for generating kzg proof for either client or host. This crate uses STD.
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not call this crate kzg-proof or something more explicit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

call it kzg-crypto

@@ -100,27 +100,4 @@ impl<T: CommsClient + Sync + Send> EigenDABlobProvider for OracleEigenDAProvider

Ok(blob.into())
}

async fn get_element(&mut self, cert: &Bytes, element: &Bytes) -> Result<Bytes, Self::Error> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are we deleting this?

Copy link
Collaborator Author

@bxue-l2 bxue-l2 Jan 29, 2025

Choose a reason for hiding this comment

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

we don't need this. By having the cache module, we don't need this additional interface

/// that provides efficient verification between the commitment and the blob
/// without actually commiting the blob
#[derive(Debug, Clone, Default)]
pub struct EigenDABlobWitness {
Copy link
Collaborator

Choose a reason for hiding this comment

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

since this is the only struct in this crate cryptography sounds like not such a good name. it sounds too low level.

Copy link
Collaborator Author

@bxue-l2 bxue-l2 Jan 30, 2025

Choose a reason for hiding this comment

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

kzg-crypto

#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]

pub mod witness;
Copy link
Collaborator

Choose a reason for hiding this comment

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

how about exporting EigenDABlobWitness given its the only struct in here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sg


/// This function computes a witness for a eigenDA blob
/// nitro code <https://github.com/Layr-Labs/nitro/blob/14f09745b74321f91d1f702c3e7bb5eb7d0e49ce/arbitrator/prover/src/kzgbn254.rs#L141>
/// could refactor in the future, such that both host and client can compute the proof
Copy link
Collaborator

Choose a reason for hiding this comment

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

?? you mention elsewhere that this crate is meant to be used by both host and client. guess its only for host right now? good to add more details, explain why not, how it can be refactored, etc. Even you will forget these details.

Comment on lines 64 to 56
if let Err(e) = witness.push_witness(&blob, &self.srs) {
return Err(OracleProviderError::Preimage(PreimageOracleError::Other(
e.to_string(),
)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

you use different ways to deal with errors in multiple places: match / if let Err(). Prob best to be consistent, and use same method everywhere. map_err(...)? is prob best

}
};

let mut witness = self.witness.lock().unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

propagate error instead of unwrapping which panics

Comment on lines +70 to +63
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[..]
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 push_witness function and let it validate and return an error if it doesnt validate. Think that's what austin is doing in the golang lib

@@ -51,6 +57,14 @@ 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 srs = SRS::new("resources/g1.point", 268435456, 1024).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why load 256MiB? Is this really needed? can we make this a configurable flag? Or is this going to change soon anyways?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually now I'm confused why do we need this many points? Don't we only support up to 16MiB blobs?

Comment on lines +121 to +117
if !witness.batch_verify() {
panic!("batch verify wrong");
}
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 unwrap everywhere, and instead propagate errors?

@bxue-l2 bxue-l2 force-pushed the seperate-crate-for-blob-crypto branch from df8e963 to 14aad44 Compare January 30, 2025 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants