Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enabling nullifier tree snapshot #3670

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 10 additions & 10 deletions yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,27 @@ 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
// Choose random block number between deployment and current block number to test archival node
const blockNumber = await getRandomBlockNumberSinceDeployment();

const randomPublicValue = Fr.random();
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 deployment and current block number to test archival node
const blockNumber = await getRandomBlockNumberSinceDeployment();
const randomNullifier = Fr.random();

await expect(
Expand Down
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