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

Compute and provide proof at client #24

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

Conversation

bxue-l2
Copy link
Collaborator

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

Implement a witness generation at custom client

@bxue-l2 bxue-l2 requested a review from samlaf January 13, 2025 22:35

# General
sha2 = { version = "0.10.8", default-features = false }
c-kzg = { version = "2.0.0", default-features = false }
anyhow = { version = "1.0.95", default-features = false }
thiserror = { version = "2.0.9", default-features = false }
rust-kzg-bn254 = { version = "0.2.1", default-features = false }
rust-kzg-bn254 = { git = "https://github.com/Layr-Labs/rust-kzg-bn254", rev = "4ad14ea4ce9473e13ed6437140fcbbff3a8ccce1", default-features = false }
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should talk with anup about publishing new versions of the rust-kzg-bn254 lib so we don't need to rely on git dependencies like this (they tend to cause more dependency problems in my experience)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

need to have all imporant issues resolved

@@ -192,20 +192,20 @@ where
)?;
}

// TODO proof is at the random point, but we need to figure out where to generate
//
// proof is at the random point
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need this comment? What does it mean? Is it talking about the length proof? Which random point is it evaluated at? Need more context here.

Comment on lines 196 to 197
// Write the KZG Proof as the last element, needed for ZK
//blob_key[88..].copy_from_slice((blob_length).to_be_bytes().as_ref());
//let blob_key_hash = keccak256(blob_key.as_ref());
blob_key[88..].copy_from_slice((blob_length).to_be_bytes().as_ref());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this a KZG proof? Isn't blob_length just... a blob length? Should we be using the length_proof instead?
image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it is datalength

Comment on lines 19 to 21
eigenda_blobs: Vec::new(),
commitments: Vec::new(),
proofs: Vec::new(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we have any idea ahead of time as to how many blobs we will be reading? Would be useful to preallocate some capacity 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.

no, a derivation pipeline could be arbitrarily long, and it is stack dependent

Comment on lines 33 to 36
// TODO we should have to specify the details to get a kzg to perform a verification
let kzg = match KZG::setup(
"resources/g1.32mb.point",
"",
Copy link
Collaborator

Choose a reason for hiding this comment

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

what does this comment mean?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we should not need so many g1 and g2 points for kzg verification

Comment on lines 81 to 84
let mut kzg = match KZG::setup(
"resources/g1.32mb.point",
"",
"resources/g2.point.powerOf2",
Copy link
Collaborator

Choose a reason for hiding this comment

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

does this work? I thought the client doesn't have access to the fs? What if its running inside a zkvm..?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this code only runs natively to fetch all witnesses you would need. For verification, the kzg library should just provide a helper function

Comment on lines 87 to 92
) {
Ok(k) => k,
Err(_) => return Err(OracleProviderError::Preimage(
PreimageOracleError::Other("does not contain header".into(),
))),
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Changing these everywhere to use something like

.map_err(|_| OracleProviderError::Preimage(
    PreimageOracleError::Other("does not contain header".into())
))?

will be cleaner

))),
};

let output = self.compute_and_save_witness(&b)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

don't use generic names like "output". better to use self-documenting names, makes the code much more easily readable.


// nitro code https://github.com/Layr-Labs/nitro/blob/14f09745b74321f91d1f702c3e7bb5eb7d0e49ce/arbitrator/prover/src/kzgbn254.rs#L30
impl<T: CommsClient + Sync + Send> CachedOracleEigenDAProvider<T> {
fn compute_and_save_witness(&mut self, blob: &[u8]) -> Result<Vec<u8>, OracleProviderError> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

you are not saving the witness in this function. change name

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

haha

Comment on lines 57 to 61
let commitment = Bytes::copy_from_slice(
&[cert_blob_info.blob_header.commitment.x, cert_blob_info.blob_header.commitment.y]
.concat());

let kzg_proof = Bytes::copy_from_slice(&output[64..128]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

can't you use &output[..64] for the commitment given you've already verified it above?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes

@bxue-l2
Copy link
Collaborator Author

bxue-l2 commented Jan 15, 2025

Thanks for review @samlaf, but just intend to be a draft PR and walk you through it, didn't expect so much comments, but thx

@bxue-l2 bxue-l2 marked this pull request as ready for review January 23, 2025 21:34
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