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
27 changes: 27 additions & 0 deletions yarn-project/aztec-node/src/aztec-node/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,33 @@ describe('aztec node', () => {
});
});

describe('getLowNullifierMembershipWitness', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added 2 tests here. Otherwise this is not unit tested at all. (not the scope of fairies team)

beforeEach(() => {
lastBlockNumber = BlockNumber(1);
});

it('throws when nullifier already exists in the tree', async () => {
const nullifier = Fr.random();
merkleTreeOps.getPreviousValueIndex.mockImplementation((treeId: MerkleTreeId, value: bigint) => {
if (treeId === MerkleTreeId.NULLIFIER_TREE && value === nullifier.toBigInt()) {
return Promise.resolve({ index: 42n, alreadyPresent: true });
}
return Promise.resolve(undefined);
});

await expect(node.getLowNullifierMembershipWitness('latest', nullifier)).rejects.toThrow(
/Cannot prove nullifier non-inclusion/,
);
});

it('returns undefined when nullifier not found', async () => {
merkleTreeOps.getPreviousValueIndex.mockResolvedValue(undefined);

const result = await node.getLowNullifierMembershipWitness('latest', Fr.random());
expect(result).toBeUndefined();
});
});

describe('findLeavesIndexes', () => {
const blockHash1 = Fr.random();
const blockHash2 = Fr.random();
Expand Down
19 changes: 3 additions & 16 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1133,21 +1133,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
return new NullifierMembershipWitness(index, leafPreimage as NullifierLeafPreimage, path);
}

/**
* Returns a low nullifier membership witness for a given nullifier at a given block.
Copy link
Contributor Author

@benesjan benesjan Mar 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dropped the docs from here as they were a duplicate of docs from AztecNode and I think these duplicates are bad (they can become stale).

* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
* @param nullifier - Nullifier we try to find the low nullifier witness for.
* @returns The low nullifier membership witness (if found).
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
* we are trying to prove non-inclusion for.
*
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
* index of the nullifier itself when it already exists in the tree.
* TODO: This is a confusing behavior and we should eventually address that.
*/
public async getLowNullifierMembershipWitness(
referenceBlock: BlockParameter,
nullifier: Fr,
Expand All @@ -1159,7 +1144,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
}
const { index, alreadyPresent } = findResult;
if (alreadyPresent) {
this.log.warn(`Nullifier ${nullifier.toBigInt()} already exists in the tree`);
throw new Error(
`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`,
);
}
const preimageData = (await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index))!;

Expand Down
1 change: 1 addition & 0 deletions yarn-project/stdlib/src/interfaces/aztec-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export interface AztecNode
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data.
* @param nullifier - Nullifier we try to find the low nullifier witness for.
* @returns The low nullifier membership witness (if found).
* @throws If the nullifier already exists in the tree, since non-inclusion cannot be proven.
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
* we are trying to prove non-inclusion for.
Expand Down
Loading