Skip to content

Commit

Permalink
Fix tests after the switch to blstrs
Browse files Browse the repository at this point in the history
  • Loading branch information
andiflabs committed Oct 24, 2024
1 parent e114106 commit c0e1d15
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion components/zcash_note_encryption/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ subtle = { version = "2.2.3", default-features = false }
[dev-dependencies]
ff = { version = "0.12", default-features = false }
zcash_primitives = { version = "0.7", path = "../../zcash_primitives" }
jubjub = "0.9"
jubjub = { git = "https://github.com/iron-fish/jubjub.git", branch = "blstrs" }

[features]
default = ["alloc"]
Expand Down
12 changes: 6 additions & 6 deletions zcash_primitives/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,12 @@ mod tests {
#[test]
fn no_duplicate_fixed_base_generators() {
let fixed_base_generators = [
PROOF_GENERATION_KEY_GENERATOR,
NOTE_COMMITMENT_RANDOMNESS_GENERATOR,
NULLIFIER_POSITION_GENERATOR,
VALUE_COMMITMENT_VALUE_GENERATOR,
VALUE_COMMITMENT_RANDOMNESS_GENERATOR,
SPENDING_KEY_GENERATOR,
*PROOF_GENERATION_KEY_GENERATOR,
*NOTE_COMMITMENT_RANDOMNESS_GENERATOR,
*NULLIFIER_POSITION_GENERATOR,
*VALUE_COMMITMENT_VALUE_GENERATOR,
*VALUE_COMMITMENT_RANDOMNESS_GENERATOR,
*SPENDING_KEY_GENERATOR,
];

// Check for duplicates, far worse than spec inconsistencies!
Expand Down
2 changes: 1 addition & 1 deletion zcash_primitives/src/sapling/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ mod tests {
);

// Set ak to a basepoint.
let basepoint = SPENDING_KEY_GENERATOR;
let basepoint = &*SPENDING_KEY_GENERATOR;
buf[0..32].copy_from_slice(&basepoint.to_bytes());

// nk is allowed to be the identity.
Expand Down
4 changes: 2 additions & 2 deletions zcash_primitives/src/sapling/pedersen_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ pub mod test {
))
.to_affine();

assert_eq!(p.get_u().to_string(), v.hash_u);
assert_eq!(p.get_v().to_string(), v.hash_v);
assert_eq!(p.get_u().to_string(), format!("Scalar({})", v.hash_u));
assert_eq!(p.get_v().to_string(), format!("Scalar({})", v.hash_v));
}
}
}
2 changes: 1 addition & 1 deletion zcash_primitives/src/sapling/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub mod mock {
.into();

let rk =
PublicKey(proof_generation_key.ak.into()).randomize(ar, SPENDING_KEY_GENERATOR);
PublicKey(proof_generation_key.ak.into()).randomize(ar, *SPENDING_KEY_GENERATOR);

Ok(([0u8; GROTH_PROOF_SIZE], cv, rk))
}
Expand Down
8 changes: 4 additions & 4 deletions zcash_primitives/src/sapling/redjubjub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ mod tests {
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06,
0xbc, 0xe5,
]);
let p_g = SPENDING_KEY_GENERATOR;
let p_g = *SPENDING_KEY_GENERATOR;

let sk1 = PrivateKey(jubjub::Fr::random(&mut rng));
let vk1 = PublicKey::from_private(&sk1, p_g);
Expand Down Expand Up @@ -266,7 +266,7 @@ mod tests {
0xbc, 0xe5,
]);
let zero = jubjub::ExtendedPoint::identity();
let p_g = SPENDING_KEY_GENERATOR;
let p_g = *SPENDING_KEY_GENERATOR;

let jubjub_modulus_bytes = [
0xb7, 0x2c, 0xf7, 0xd6, 0x5e, 0x0e, 0x97, 0xd0, 0x82, 0x10, 0xc8, 0xcc, 0x93, 0x20,
Expand Down Expand Up @@ -307,7 +307,7 @@ mod tests {
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06,
0xbc, 0xe5,
]);
let p_g = SPENDING_KEY_GENERATOR;
let p_g = *SPENDING_KEY_GENERATOR;

for _ in 0..1000 {
let sk = PrivateKey(jubjub::Fr::random(&mut rng));
Expand Down Expand Up @@ -342,7 +342,7 @@ mod tests {
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06,
0xbc, 0xe5,
]);
let p_g = SPENDING_KEY_GENERATOR;
let p_g = *SPENDING_KEY_GENERATOR;

for _ in 0..1000 {
let sk = PrivateKey(jubjub::Fr::random(&mut rng));
Expand Down
22 changes: 13 additions & 9 deletions zcash_primitives/src/transaction/components/sapling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,11 @@ pub mod testing {
/// roundtrip testing).
fn arb_spend_description()(
cv in arb_extended_point(),
anchor in vec(any::<u8>(), 64)
.prop_map(|v| <[u8;64]>::try_from(v.as_slice()).unwrap())
.prop_map(|v| blstrs::Scalar::from_bytes_wide(&v)),
anchor in vec(any::<u8>(), 32)
.prop_map(|v| <[u8;32]>::try_from(v.as_slice()).unwrap())
.prop_map(|mut v| { v[0] = 0; v })
.prop_map(|v| blstrs::Scalar::from_bytes_be(&v))
.prop_map(|v| Option::from(v).unwrap()),
nullifier in prop::array::uniform32(any::<u8>())
.prop_map(|v| Nullifier::from_slice(&v).unwrap()),
zkproof in vec(any::<u8>(), GROTH_PROOF_SIZE)
Expand All @@ -469,14 +471,14 @@ pub mod testing {
) -> SpendDescription<Authorized> {
let mut rng = StdRng::from_seed(rng_seed);
let sk1 = PrivateKey(jubjub::Fr::random(&mut rng));
let rk = PublicKey::from_private(&sk1, SPENDING_KEY_GENERATOR);
let rk = PublicKey::from_private(&sk1, *SPENDING_KEY_GENERATOR);
SpendDescription {
cv,
anchor,
nullifier,
rk,
zkproof,
spend_auth_sig: sk1.sign(&fake_sighash_bytes, &mut rng, SPENDING_KEY_GENERATOR),
spend_auth_sig: sk1.sign(&fake_sighash_bytes, &mut rng, *SPENDING_KEY_GENERATOR),
}
}
}
Expand All @@ -486,9 +488,11 @@ pub mod testing {
/// roundtrip testing).
pub fn arb_output_description()(
cv in arb_extended_point(),
cmu in vec(any::<u8>(), 64)
.prop_map(|v| <[u8;64]>::try_from(v.as_slice()).unwrap())
.prop_map(|v| blstrs::Scalar::from_bytes_wide(&v)),
cmu in vec(any::<u8>(), 32)
.prop_map(|v| <[u8;32]>::try_from(v.as_slice()).unwrap())
.prop_map(|mut v| { v[0] = 0; v })
.prop_map(|v| blstrs::Scalar::from_bytes_be(&v))
.prop_map(|v| Option::from(v).unwrap()),
enc_ciphertext in vec(any::<u8>(), 580)
.prop_map(|v| <[u8;580]>::try_from(v.as_slice()).unwrap()),
epk in arb_extended_point(),
Expand Down Expand Up @@ -527,7 +531,7 @@ pub mod testing {
shielded_spends,
shielded_outputs,
value_balance,
authorization: Authorized { binding_sig: bsk.sign(&fake_bvk_bytes, &mut rng, VALUE_COMMITMENT_RANDOMNESS_GENERATOR) },
authorization: Authorized { binding_sig: bsk.sign(&fake_bvk_bytes, &mut rng, *VALUE_COMMITMENT_RANDOMNESS_GENERATOR) },
}
)
}
Expand Down
2 changes: 1 addition & 1 deletion zcash_proofs/src/circuit/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ mod test {
for _ in 0..100 {
let mut cs = TestConstraintSystem::<blstrs::Scalar>::new();

let p = zcash_primitives::constants::NOTE_COMMITMENT_RANDOMNESS_GENERATOR;
let p = &*zcash_primitives::constants::NOTE_COMMITMENT_RANDOMNESS_GENERATOR;
let s = jubjub::Fr::random(&mut rng);
let q = jubjub::ExtendedPoint::from(p * s).to_affine();
let (u1, v1) = (q.get_u(), q.get_v());
Expand Down
6 changes: 3 additions & 3 deletions zcash_proofs/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,20 @@ mod tests {
// d = -(10240/10241)
assert_eq!(
-Scalar::from(10240) * Scalar::from(10241).invert().unwrap(),
EDWARDS_D
*EDWARDS_D
);
}

#[test]
fn montgomery_a() {
assert_eq!(Scalar::from(40962), MONTGOMERY_A);
assert_eq!(Scalar::from(40962), *MONTGOMERY_A);
}

#[test]
fn montgomery_scale() {
// scaling factor = sqrt(4 / (a - d))
assert_eq!(
MONTGOMERY_SCALE.square() * (-Scalar::one() - EDWARDS_D),
MONTGOMERY_SCALE.square() * (-Scalar::one() - *EDWARDS_D),
Scalar::from(4),
);
}
Expand Down

0 comments on commit c0e1d15

Please sign in to comment.