-
Notifications
You must be signed in to change notification settings - Fork 263
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
Conversation
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.
The changes look great! Just a nit on the test assertions and one set of println
s to remove
zk-sdk/src/range_proof/mod.rs
Outdated
assert!(proof | ||
.verify( | ||
vec![&commitment_1, &commitment_2, &commitment_3], | ||
vec![64, 32, 32], | ||
&mut transcript_verify, | ||
) | ||
.is_ok()); |
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.
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
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.
Yep, updated!
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()); |
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.
nit: same here, prefer unwrap()
over assert!(...is_ok())
|
||
let mut verifier_transcript = Transcript::new(b"Test"); | ||
|
||
assert!(proof |
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.
nit: same here
|
||
let mut verifier_transcript = Transcript::new(b"Test"); | ||
|
||
assert!(proof |
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.
nit: same here
|
||
let mut verifier_transcript = Transcript::new(b"Test"); | ||
|
||
assert!(proof |
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.
nit: same here
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); |
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.
Looks like these got left in 😄
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.
Oops!
|
||
let mut verifier_transcript = Transcript::new(b"Test"); | ||
|
||
assert!(proof |
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.
nit: same here with the assert
|
||
let mut verifier_transcript = Transcript::new(b"test"); | ||
|
||
assert!(proof |
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.
nit: same here with unwrap()
|
||
let mut verifier_transcript = Transcript::new(b"test"); | ||
|
||
assert!(proof.verify(&pubkey, &mut verifier_transcript).is_ok()); |
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.
nit: same here with unwrap
|
||
let mut verifier_transcript = Transcript::new(b"test"); | ||
|
||
assert!(proof |
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.
nit: same here with unwrap()
* 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
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
, andFrom<[u8; _]>
for the pod proof types as well as some of the ElGamal types, which would be useful more generally as well.Fixes #