Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
392 changes: 391 additions & 1 deletion artifacts/zk/commitment.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions circuits/lib/src/validation/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ pub fn validate_commitment(computed: Field, expected: Field) {
pub fn validate_nullifier_hash(computed: Field, expected: Field) {
nullifier::validate_nullifier_hash(computed, expected);
}

pub fn validate_denomination(amount: Field, denomination: Field) {
denomination::validate_denomination(amount, denomination);
}
12 changes: 10 additions & 2 deletions circuits/lib/src/validation/test_helpers.nr
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ pub struct WithdrawalBuilder {
pub amount: Field,
pub relayer: Field,
pub fee: Field,
pub denomination: Field,

pub override_hash_path: bool,
pub hash_path: [Field; 20],
Expand All @@ -298,6 +299,7 @@ impl WithdrawalBuilder {
amount: KAT_AMOUNT,
relayer: 0,
fee: 0,
denomination: KAT_AMOUNT,

override_hash_path: false,
hash_path: [0; 20],
Expand Down Expand Up @@ -350,6 +352,11 @@ impl WithdrawalBuilder {
self
}

pub fn with_denomination(mut self, denomination: Field) -> Self {
self.denomination = denomination;
self
}

pub fn with_root(mut self, root: Field) -> Self {
self.override_root = true;
self.root = root;
Expand All @@ -370,7 +377,7 @@ impl WithdrawalBuilder {

/// Builds the full witness tuple, computing the commitment, path, root, and nullifier_hash
/// dynamically unless overridden.
pub fn build(self) -> (Field, Field, Field, [Field; 20], Field, Field, Field, Field, Field, Field, Field) {
pub fn build(self) -> (Field, Field, Field, [Field; 20], Field, Field, Field, Field, Field, Field, Field, Field) {
let commitment = hash::compute_commitment(self.nullifier, self.secret, self.pool_id);

let hash_path = if self.override_hash_path {
Expand Down Expand Up @@ -402,7 +409,8 @@ impl WithdrawalBuilder {
self.recipient,
self.amount,
self.relayer,
self.fee
self.fee,
self.denomination
)
}
}
14 changes: 7 additions & 7 deletions circuits/withdraw/src/tests.nr
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use lib::hash;
use lib::merkle;

fn execute(builder: WithdrawalBuilder) {
let (n, s, li, hp, p, r, nh, rec, a, rel, f) = builder.build();
main(n, s, li, hp, p, r, nh, rec, a, rel, f);
let (n, s, li, hp, p, r, nh, rec, a, rel, f, d) = builder.build();
main(n, s, li, hp, p, r, nh, rec, a, rel, f, d);
}

#[test]
Expand Down Expand Up @@ -305,7 +305,7 @@ fn test_leaf_index_exceeds_tree_capacity() {
// 2^20 = 1,048,576 -- first invalid index
main(
nullifier, secret, 1_048_576, hash_path,
pool_id, root, nullifier_hash, 0xFFFF, 100_0000000, 0, 0,
pool_id, root, nullifier_hash, 0xFFFF, 100_0000000, 0, 0, 100_0000000,
);
}

Expand All @@ -322,7 +322,7 @@ fn test_leaf_index_large_out_of_range() {
// Far outside valid range
main(
nullifier, secret, 99_999_999, hash_path,
pool_id, root, nullifier_hash, 0xFFFF, 100_0000000, 0, 0,
pool_id, root, nullifier_hash, 0xFFFF, 100_0000000, 0, 0, 100_0000000,
);
}

Expand All @@ -340,7 +340,7 @@ fn test_leaf_index_zero_boundary() {

main(
nullifier, secret, leaf_index, hash_path,
pool_id, root, nullifier_hash, 0x1234, 100_0000000, 0, 0,
pool_id, root, nullifier_hash, 0x1234, 100_0000000, 0, 0, 100_0000000,
);
}

Expand All @@ -358,7 +358,7 @@ fn test_leaf_index_max_boundary() {

main(
nullifier, secret, leaf_index, hash_path,
pool_id, root, nullifier_hash, 0x5678, 100_0000000, 0, 0,
pool_id, root, nullifier_hash, 0x5678, 100_0000000, 0, 0, 100_0000000,
);
}

Expand All @@ -376,6 +376,6 @@ fn test_leaf_index_high_bit_only() {

main(
nullifier, secret, leaf_index, hash_path,
pool_id, root, nullifier_hash, 0x9ABC, 100_0000000, 0, 0,
pool_id, root, nullifier_hash, 0x9ABC, 100_0000000, 0, 0, 100_0000000,
);
}
Loading