Skip to content

Commit

Permalink
zcash_primitives: Add RedJubjub test vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
str4d committed Dec 1, 2023
1 parent 5ccba3e commit f9b4c53
Show file tree
Hide file tree
Showing 3 changed files with 508 additions and 2 deletions.
3 changes: 3 additions & 0 deletions zcash_primitives/src/sapling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ pub mod testing {
note::testing::arb_note, tree::testing::arb_node,
};
}

#[cfg(test)]
mod test_vectors;

Check failure on line 39 in zcash_primitives/src/sapling.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

file not found for module `test_vectors`

error[E0583]: file not found for module `test_vectors` --> zcash_primitives/src/sapling.rs:39:1 | 39 | mod test_vectors; | ^^^^^^^^^^^^^^^^^ | = help: to create the module `test_vectors`, create file "zcash_primitives/src/sapling/test_vectors.rs" or "zcash_primitives/src/sapling/test_vectors/mod.rs"
31 changes: 29 additions & 2 deletions zcash_primitives/src/sapling/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,8 @@ pub mod testing {
mod tests {
use group::{Group, GroupEncoding};

use super::FullViewingKey;
use crate::sapling::constants::SPENDING_KEY_GENERATOR;
use super::{FullViewingKey, SpendAuthorizingKey, SpendValidatingKey};
use crate::sapling::{constants::SPENDING_KEY_GENERATOR, test_vectors};

#[test]
fn ak_must_be_prime_order() {
Expand All @@ -716,4 +716,31 @@ mod tests {
// nk is allowed to be the identity.
assert!(FullViewingKey::read(&buf[..]).is_ok());
}

#[test]
fn spend_auth_sig_test_vectors() {
for tv in test_vectors::signatures::make_test_vectors() {

Check failure on line 722 in zcash_primitives/src/sapling/keys.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

failed to resolve: could not find `signatures` in `test_vectors`

error[E0433]: failed to resolve: could not find `signatures` in `test_vectors` --> zcash_primitives/src/sapling/keys.rs:722:33 | 722 | for tv in test_vectors::signatures::make_test_vectors() { | ^^^^^^^^^^ could not find `signatures` in `test_vectors`
let sk = SpendAuthorizingKey::from_bytes(&tv.sk).unwrap();
let vk = SpendValidatingKey::from_bytes(&tv.vk).unwrap();
let rvk = redjubjub::VerificationKey::try_from(tv.rvk).unwrap();
let sig = redjubjub::Signature::from(tv.sig);
let rsig = redjubjub::Signature::from(tv.rsig);

let alpha = jubjub::Scalar::from_bytes(&tv.alpha).unwrap();

assert_eq!(<[u8; 32]>::from(sk.randomize(&alpha)), tv.rsk);
assert_eq!(vk.randomize(&alpha), rvk);

// assert_eq!(vk.0.verify(&tv.m, &sig), Ok(()));
// assert_eq!(rvk.verify(&tv.m, &rsig), Ok(()));
assert_eq!(
vk.0.verify(&tv.m, &rsig),
Err(redjubjub::Error::InvalidSignature),
);
assert_eq!(
rvk.verify(&tv.m, &sig),
Err(redjubjub::Error::InvalidSignature),
);
}
}
}

0 comments on commit f9b4c53

Please sign in to comment.