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

[zk-sdk] Add fixed string tests for proofs #2814

Merged
merged 8 commits into from
Sep 4, 2024

Conversation

samkim-crypto
Copy link

@samkim-crypto samkim-crypto commented Sep 3, 2024

Problem

Currently, all the tests for the sigma and range proofs in zk-sdk verify fresh proofs that are randomly generated using the proof constructors. Although these tests are useful for testing the correctness of the proof generation and verification logic, they fail to detect potential changes to the code that are not backwards compatible.

For example, suppose that there is a breaking change in the curve25519-dalek crate (e.g. a group generator constant was updated). An upgrade to the curve25519-dalek crate would apply to both the proof generation and verification code so that their correctness is maintained. However, the old proofs (new proofs) will not verify with respect to the new verification logic (old verification logic).

Summary of Changes

I added tests that deserializes a string representation of proofs and verifies them. In the process, I implemented Display, FromStr, and From<[u8; _]> for the pod proof types as well as some of the ElGamal types, which would be useful more generally as well.

Fixes #

@samkim-crypto samkim-crypto marked this pull request as ready for review September 3, 2024 08:21
Copy link

@joncinque joncinque left a comment

Choose a reason for hiding this comment

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

The changes look great! Just a nit on the test assertions and one set of printlns to remove

Comment on lines 535 to 541
assert!(proof
.verify(
vec![&commitment_1, &commitment_2, &commitment_3],
vec![64, 32, 32],
&mut transcript_verify,
)
.is_ok());

Choose a reason for hiding this comment

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

nit: up to you, but I typically lean towards result.unwrap() instead of assert!(result.is_ok()), so that if it fails, you get a better error message

Copy link
Author

Choose a reason for hiding this comment

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

Yep, updated!

Comment on lines 229 to 241
assert!(proof
.verify(
&first_pubkey,
&second_pubkey,
&commitment_lo,
&commitment_hi,
&first_handle_lo,
&first_handle_hi,
&second_handle_lo,
&second_handle_hi,
&mut verifier_transcript,
)
.is_ok());

Choose a reason for hiding this comment

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

nit: same here, prefer unwrap() over assert!(...is_ok())


let mut verifier_transcript = Transcript::new(b"Test");

assert!(proof

Choose a reason for hiding this comment

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

nit: same here


let mut verifier_transcript = Transcript::new(b"Test");

assert!(proof

Choose a reason for hiding this comment

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

nit: same here


let mut verifier_transcript = Transcript::new(b"Test");

assert!(proof

Choose a reason for hiding this comment

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

nit: same here

Comment on lines 315 to 329
let pod_commitment: PodPedersenCommitment = commitment.into();
println!("commitment: {}", pod_commitment);
println!("first_pubkey: {}", first_pubkey);
println!("second_pubkey: {}", second_pubkey);
println!("third_pubkey: {}", third_pubkey);

let pod_first_handle: PodDecryptHandle = first_handle.into();
let pod_second_handle: PodDecryptHandle = second_handle.into();
let pod_third_handle: PodDecryptHandle = third_handle.into();

println!("first_handle: {}", pod_first_handle);
println!("second_handle: {}", pod_second_handle);
println!("third_handle: {}", pod_third_handle);
let pod_proof: PodGroupedCiphertext3HandlesValidityProof = proof.clone().into();
println!("pod proof: {}", pod_proof);

Choose a reason for hiding this comment

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

Looks like these got left in 😄

Copy link
Author

Choose a reason for hiding this comment

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

Oops!


let mut verifier_transcript = Transcript::new(b"Test");

assert!(proof

Choose a reason for hiding this comment

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

nit: same here with the assert


let mut verifier_transcript = Transcript::new(b"test");

assert!(proof

Choose a reason for hiding this comment

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

nit: same here with unwrap()


let mut verifier_transcript = Transcript::new(b"test");

assert!(proof.verify(&pubkey, &mut verifier_transcript).is_ok());

Choose a reason for hiding this comment

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

nit: same here with unwrap


let mut verifier_transcript = Transcript::new(b"test");

assert!(proof

Choose a reason for hiding this comment

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

nit: same here with unwrap()

@samkim-crypto samkim-crypto merged commit b5432b0 into anza-xyz:master Sep 4, 2024
40 checks passed
ray-kast pushed a commit to abklabs/agave that referenced this pull request Nov 27, 2024
* refactor `impl_from_str` and `impl_from_bytes` macros

* impl `Display`, `FromStr`, `From<[u8; _]>` for sigma and range proof pod types

* impl `Display` for Pedersen commitment and grouped ElGamal ciphertext pod types

* impl `Display`, `FromStr`, `From<[u8; _]>` for decrypt handle pod type

* add fixed proof string tests

* cargo clippy

* remove println's

* update `assert!` and `.is_ok()` with `unwrap`'s
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