Skip to content

Commit

Permalink
feat(stdlib)!: update stdlib functions to return bool where appropr…
Browse files Browse the repository at this point in the history
…iate (#1409)

feat(stdlib)!: return update verification functions to return `bool`
  • Loading branch information
TomAFrench authored May 26, 2023
1 parent e9d22c9 commit 2b2be1e
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions crates/nargo_cli/tests/test_data/ecdsa_secp256k1/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ fn main(message : [u8;38],hashed_message : [u8;32], pub_key_x : [u8;32], pub_key
let expected= std::hash::sha256(message);
assert(hashed_message == expected);

let x = std::ecdsa_secp256k1::verify_signature(pub_key_x, pub_key_y, signature, hashed_message);
assert(x == 1);
let valid_signature = std::ecdsa_secp256k1::verify_signature(pub_key_x, pub_key_y, signature, hashed_message);
assert(valid_signature);
}
2 changes: 1 addition & 1 deletion crates/nargo_cli/tests/test_data/merkle_insert/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main(
mimc_input: [Field; 4],
) {
let old_leaf_exists = std::merkle::check_membership(old_root, old_leaf, index, old_hash_path);
assert(old_leaf_exists == 1);
assert(old_leaf_exists);
assert(old_root == std::merkle::compute_root_from_leaf(old_leaf, index, old_hash_path));
let calculated_root = std::merkle::compute_merkle_root(leaf, index, old_hash_path);
assert(new_root == calculated_root);
Expand Down
4 changes: 2 additions & 2 deletions crates/nargo_cli/tests/test_data/schnorr/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ use dep::std;
fn main(message: [u8; 10], pub_key_x: Field, pub_key_y: Field, signature: [u8; 64]) {
// Is there ever a situation where someone would want
// to ensure that a signature was invalid?
let x = std::schnorr::verify_signature(pub_key_x,pub_key_y,signature, message);
assert(x == 1);
let valid_signature = std::schnorr::verify_signature(pub_key_x,pub_key_y,signature, message);
assert(valid_signature);
}
2 changes: 1 addition & 1 deletion crates/nargo_cli/tests/test_data/simple_shield/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn main(

// Check that the input note nullifier is in the root
let is_member = std::merkle::check_membership(note_root, note_commitment[0], index, note_hash_path);
assert(is_member == 1);
assert(is_member);

[nullifier[0], receiver_note_commitment[0]]
}
2 changes: 1 addition & 1 deletion noir_stdlib/src/ecdsa_secp256k1.nr
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#[foreign(ecdsa_secp256k1)]
fn verify_signature(_public_key_x : [u8; 32], _public_key_y : [u8; 32], _signature: [u8; 64], _message_hash: [u8]) -> Field {}
fn verify_signature(_public_key_x : [u8; 32], _public_key_y : [u8; 32], _signature: [u8; 64], _message_hash: [u8]) -> bool {}
4 changes: 2 additions & 2 deletions noir_stdlib/src/merkle.nr
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// and the hashpath proves this
// Currently we assume that it is a binary tree, so depth k implies a width of 2^k
// XXX: In the future we can add an arity parameter
fn check_membership(_root : Field, _leaf : Field, _index : Field, _hash_path: [Field]) -> Field {
(compute_merkle_root(_leaf, _index, _hash_path) == _root) as Field
fn check_membership(_root : Field, _leaf : Field, _index : Field, _hash_path: [Field]) -> bool {
compute_merkle_root(_leaf, _index, _hash_path) == _root
}

#[foreign(compute_merkle_root)]
Expand Down
2 changes: 1 addition & 1 deletion noir_stdlib/src/schnorr.nr
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#[foreign(schnorr_verify)]
fn verify_signature(_public_key_x: Field, _public_key_y: Field, _signature: [u8; 64], _message: [u8]) -> Field {}
fn verify_signature(_public_key_x: Field, _public_key_y: Field, _signature: [u8; 64], _message: [u8]) -> bool {}

0 comments on commit 2b2be1e

Please sign in to comment.