Skip to content

Commit

Permalink
test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jul 10, 2024
1 parent b2697f9 commit e5c5757
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ fn main(priv_key: Field, pub_x: pub Field, pub_y: pub Field) {
let scalar = std::embedded_curve_ops::EmbeddedCurveScalar { lo: priv_key, hi: 0 };
// Test that multi_scalar_mul correctly derives the public key
let res = std::embedded_curve_ops::multi_scalar_mul([g1], [scalar]);
assert(res[0] == pub_x);
assert(res[1] == pub_y);
assert(res.x == pub_x);
assert(res.y == pub_y);

// Test that double function calling embedded_curve_add works as expected
let pub_point = std::embedded_curve_ops::EmbeddedCurvePoint { x: pub_x, y: pub_y, is_infinite: false };
Expand All @@ -18,5 +18,5 @@ fn main(priv_key: Field, pub_x: pub Field, pub_y: pub Field) {
let res = std::embedded_curve_ops::multi_scalar_mul([g1, g1], [scalar, scalar]);

// The results should be double the g1 point because the scalars are 1 and we pass in g1 twice
assert(double.x == res[0]);
assert(double.x == res.x);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ fn main(is_active: bool) {
[a, bad],
[EmbeddedCurveScalar { lo: 1, hi: 0 }, EmbeddedCurveScalar { lo: 1, hi: 0 }]
);
assert(e[0] != d.x);
assert(e.x != d.x);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn verify_signature_noir<M>(public_key: embedded_curve_ops::EmbeddedCurvePoi
let g1 = embedded_curve_ops::EmbeddedCurvePoint { x: 1, y: 17631683881184975370165255887551781615748388533673675138860, is_infinite: false };
let r = embedded_curve_ops::multi_scalar_mul([g1, public_key], [sig_s, sig_e]);
// compare the _hashes_ rather than field elements modulo r
let pedersen_hash = std::hash::pedersen_hash([r[0], public_key.x, public_key.y]);
let pedersen_hash = std::hash::pedersen_hash([r.x, public_key.x, public_key.y]);
let mut hash_input = [0; M];
let pde = pedersen_hash.to_be_bytes(32);

Expand All @@ -62,7 +62,7 @@ pub fn verify_signature_noir<M>(public_key: embedded_curve_ops::EmbeddedCurvePoi
}
let result = std::hash::blake2s(hash_input);

is_ok = (r[2] == 0);
is_ok = !r.is_infinite;
for i in 0..32 {
if result[i] != signature[32 + i] {
is_ok = false;
Expand Down Expand Up @@ -101,7 +101,7 @@ pub fn assert_valid_signature<M>(public_key: embedded_curve_ops::EmbeddedCurvePo
let g1 = embedded_curve_ops::EmbeddedCurvePoint { x: 1, y: 17631683881184975370165255887551781615748388533673675138860, is_infinite: false };
let r = embedded_curve_ops::multi_scalar_mul([g1, public_key], [sig_s, sig_e]);
// compare the _hashes_ rather than field elements modulo r
let pedersen_hash = std::hash::pedersen_hash([r[0], public_key.x, public_key.y]);
let pedersen_hash = std::hash::pedersen_hash([r.x, public_key.x, public_key.y]);
let mut hash_input = [0; M];
let pde = pedersen_hash.to_be_bytes(32);

Expand All @@ -113,7 +113,7 @@ pub fn assert_valid_signature<M>(public_key: embedded_curve_ops::EmbeddedCurvePo
}
let result = std::hash::blake2s(hash_input);

assert(r[2] == 0);
assert(!r.is_infinite);
for i in 0..32 {
assert(result[i] == signature[32 + i]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ fn main(
to_pubkey_x: Field,
to_pubkey_y: Field
) -> pub [Field; 2] {
let priv_key_as_scalar = std::embedded_curve_ops::EmbeddedCurveScalar::new(priv_key, 0);
// Compute public key from private key to show ownership
let pubkey = std::embedded_curve_ops::fixed_base_scalar_mul(priv_key, 0);
let pubkey_x = pubkey[0];
let pubkey_y = pubkey[1];
let pubkey = std::embedded_curve_ops::fixed_base_scalar_mul(priv_key_as_scalar);
// Compute input note commitment
let note_commitment = std::hash::pedersen_commitment([pubkey_x, pubkey_y]);
let note_commitment = std::hash::pedersen_commitment([pubkey.x, pubkey.y]);
// Compute input note nullifier
let nullifier = std::hash::pedersen_commitment([note_commitment.x, index, priv_key]);
// Compute output note nullifier
Expand Down

0 comments on commit e5c5757

Please sign in to comment.