diff --git a/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts b/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts index 298ff392724b..1feedd2864c4 100644 --- a/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts @@ -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'; @@ -111,10 +111,12 @@ 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(), @@ -122,15 +124,15 @@ describe('e2e_inclusion_proofs_contract', () => { }); 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( @@ -139,9 +141,8 @@ 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]; @@ -149,9 +150,8 @@ describe('e2e_inclusion_proofs_contract', () => { }); 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( @@ -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)); + }; }); diff --git a/yarn-project/world-state/src/merkle-tree/merkle_tree_snapshot_operations_facade.ts b/yarn-project/world-state/src/merkle-tree/merkle_tree_snapshot_operations_facade.ts index 450b6c5bca8b..54308855517d 100644 --- a/yarn-project/world-state/src/merkle-tree/merkle_tree_snapshot_operations_facade.ts +++ b/yarn-project/world-state/src/merkle-tree/merkle_tree_snapshot_operations_facade.ts @@ -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< | { /** @@ -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(treeId: MerkleTreeId, index: bigint): Promise> {