Skip to content

Commit

Permalink
feat: enabling nullifier tree snapshot (AztecProtocol#3670)
Browse files Browse the repository at this point in the history
In this PR I enable nullifier tree snapshot and I use that in the
inclusion proofs test.
  • Loading branch information
benesjan authored Dec 13, 2023
1 parent 5513624 commit b47d49d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
29 changes: 17 additions & 12 deletions yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AccountWallet, AztecAddress, CompleteAddress, Fr, PXE } from '@aztec/aztec.js';
import { AccountWallet, AztecAddress, CompleteAddress, Fr, INITIAL_L2_BLOCK_NUM, PXE } from '@aztec/aztec.js';
import { InclusionProofsContract } from '@aztec/noir-contracts/types';

import { jest } from '@jest/globals';
Expand Down Expand Up @@ -111,26 +111,28 @@ describe('e2e_inclusion_proofs_contract', () => {
});

it('note existence failure case', async () => {
// Owner of a note
// Owner of a note - ignored in the contract since the note won't be found and the spare random note commitment
// will be used instead
const owner = AztecAddress.random();

const blockNumber = await pxe.getBlockNumber();
// Choose random block number between deployment and current block number to test archival node
const blockNumber = await getRandomBlockNumberSinceDeployment();
const randomNoteCommitment = Fr.random();
await expect(
contract.methods.test_note_inclusion_proof(owner, blockNumber, randomNoteCommitment).send().wait(),
).rejects.toThrow(/Leaf value: 0x[0-9a-fA-F]+ not found in NOTE_HASH_TREE/);
});

it('proves an existence of a public value in private context', async () => {
// Chose random block number between deployment and current block number to test archival node
// Choose random block number between deployment and current block number to test archival node
const blockNumber = await getRandomBlockNumberSinceDeployment();

await contract.methods.test_public_value_inclusion_proof(publicValue, blockNumber).send().wait();
});

it('public value existence failure case', async () => {
// Chose random block number between deployment and current block number to test archival node
const blockNumber = await getRandomBlockNumberSinceDeployment();
// Choose random block number between first block and current block number to test archival node
const blockNumber = await getRandomBlockNumber();

const randomPublicValue = Fr.random();
await expect(
Expand All @@ -139,19 +141,17 @@ describe('e2e_inclusion_proofs_contract', () => {
});

it('proves existence of a nullifier in private context', async () => {
// TODO(#3535): Test this at "random" block to test archival node. This is currently not possible because of
// issue https://github.com/AztecProtocol/aztec-packages/issues/3535
const blockNumber = await pxe.getBlockNumber();
// Choose random block number between deployment and current block number to test archival node
const blockNumber = await getRandomBlockNumberSinceDeployment();
const block = await pxe.getBlock(blockNumber);
const nullifier = block?.newNullifiers[0];

await contract.methods.test_nullifier_inclusion_proof(nullifier!, blockNumber).send().wait();
});

it('nullifier existence failure case', async () => {
// TODO(#3535): Test this at "random" block to test archival node. This is currently not possible because of
// issue https://github.com/AztecProtocol/aztec-packages/issues/3535
const blockNumber = await pxe.getBlockNumber();
// Choose random block number between first block and current block number to test archival node
const blockNumber = await getRandomBlockNumber();
const randomNullifier = Fr.random();

await expect(
Expand All @@ -163,4 +163,9 @@ describe('e2e_inclusion_proofs_contract', () => {
const currentBlockNumber = await pxe.getBlockNumber();
return deploymentBlockNumber + Math.floor(Math.random() * (currentBlockNumber - deploymentBlockNumber));
};

const getRandomBlockNumber = async () => {
const currentBlockNumber = await pxe.getBlockNumber();
return deploymentBlockNumber + Math.floor(Math.random() * (currentBlockNumber - INITIAL_L2_BLOCK_NUM));
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ export class MerkleTreeSnapshotOperationsFacade implements MerkleTreeOperations
return snapshot.getLeafValue(BigInt(index));
}

getPreviousValueIndex(
_treeId: MerkleTreeId.NULLIFIER_TREE,
_value: bigint,
async getPreviousValueIndex(
treeId: MerkleTreeId.NULLIFIER_TREE,
value: bigint,
): Promise<
| {
/**
Expand All @@ -65,7 +65,8 @@ export class MerkleTreeSnapshotOperationsFacade implements MerkleTreeOperations
}
| undefined
> {
return Promise.reject(new Error('Snapshots not implemented for nullifier tree'));
const snapshot = (await this.#getTreeSnapshot(treeId)) as IndexedTreeSnapshot;
return snapshot.findIndexOfPreviousKey(value);
}

async getSiblingPath<N extends number>(treeId: MerkleTreeId, index: bigint): Promise<SiblingPath<N>> {
Expand Down

0 comments on commit b47d49d

Please sign in to comment.