Skip to content

Commit

Permalink
refactor: Change interface to include "logical" values
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Oct 31, 2023
1 parent 8b0fc9b commit a04c30f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
10 changes: 5 additions & 5 deletions yarn-project/end-to-end/src/e2e_slow_tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('e2e_slow_tree', () => {
logger('Initial state');
await status(key);
await wallet.addMint(getMembershipMint(await getMembershipProof(key, true)));
await contract.methods.read_at().send().wait();
await contract.methods.read_at(key).send().wait();

logger(`Updating tree[${key}] to 1 from public`);
await contract.methods
Expand All @@ -104,7 +104,7 @@ describe('e2e_slow_tree', () => {
const zeroProof = await getMembershipProof(key, false);
logger(`"Reads" tree[${zeroProof.index}] from the tree, equal to ${zeroProof.value}`);
await wallet.addMint(getMembershipMint({ ...zeroProof, value: new Fr(0) }));
await contract.methods.read_at().send().wait();
await contract.methods.read_at(key).send().wait();

// Progress time to beyond the update and thereby commit it to the tree.
await cheatCodes.aztec.warp((await cheatCodes.eth.timestamp()) + 1000);
Expand All @@ -116,17 +116,17 @@ describe('e2e_slow_tree', () => {
`Tries to "read" tree[${zeroProof.index}] from the tree, but is rejected as value is not ${zeroProof.value}`,
);
await wallet.addMint(getMembershipMint({ ...zeroProof, value: new Fr(0) }));
await expect(contract.methods.read_at().simulate()).rejects.toThrowError(
await expect(contract.methods.read_at(key).simulate()).rejects.toThrowError(
'Assertion failed: Root does not match expected',
);

logger(`"Reads" tree[${key}], expect to be 1`);
await wallet.addMint(getMembershipMint({ ...zeroProof, value: new Fr(1) }));
await contract.methods.read_at().send().wait();
await contract.methods.read_at(key).send().wait();

logger(`Updating tree[${key}] to 4 from private`);
await wallet.addMint(getUpdateMint(await getUpdateProof(4n, key)));
await contract.methods.update_at_private().send().wait();
await contract.methods.update_at_private(key, 4n).send().wait();
await tree.updateLeaf(new Fr(4).toBuffer(), key);

await status(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ contract SlowTree {
}

#[aztec(private)]
fn read_at() -> Field {
fn read_at(index: Field) -> Field {
let fields = pop_mint();
let p: MembershipProof<TREE_HEIGHT, MEMBERSHIP_SIZE> = deserialize_membership_proof(fields);
assert(index == p.index, "Index does not match expected");

let expected_root = compute_merkle_root(p.value, p.index, p.sibling_path);
let selector = compute_selector("_assert_current_root(Field,Field)");
Expand All @@ -102,9 +103,11 @@ contract SlowTree {
}

#[aztec(private)]
fn update_at_private() {
fn update_at_private(index: Field, new_value: Field) {
let fields = pop_mint();
let p: SlowUpdateProof<TREE_HEIGHT, UPDATE_SIZE> = deserialize_slow_update_proof(fields);
assert(index == p.index, "Index does not match expected");
assert(new_value == p.new_value, "New value does not match expected");

// We compute the root before.
let before_root = compute_merkle_root(p.before.value, p.index, p.before.sibling_path);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@




// A single inclusion proof.
// M = N + 2
struct MembershipProof<N, M> {
Expand Down

0 comments on commit a04c30f

Please sign in to comment.