Skip to content

fix(aztec-node): throw on existing nullifier in getLowNullifierMembershipWitness#21472

Merged
PhilWindle merged 2 commits intomerge-train/fairiesfrom
be/fix-low-nullifier-witness-error
Mar 16, 2026
Merged

fix(aztec-node): throw on existing nullifier in getLowNullifierMembershipWitness#21472
PhilWindle merged 2 commits intomerge-train/fairiesfrom
be/fix-low-nullifier-witness-error

Conversation

@benesjan
Copy link
Contributor

@benesjan benesjan commented Mar 13, 2026

As I was going through TODOs I found this ancient TODO of mine (from November 2023):

   * 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.

In this PR i handle it by instead throwing an error in this scenario.

This doesn't modify the interface so it was not urgent to do but felt like it makes sense to do now anyway so I went with it.

(Pinged this PR to alpha team)

Summary

  • getLowNullifierMembershipWitness now throws a descriptive error when the queried nullifier already exists in the tree, instead of silently returning the nullifier's own witness (which is wrong for a non-inclusion proof)
  • Removes the long-standing TODO about confusing behavior (open since Nov 2023)
  • Adds @throws JSDoc to both the interface and implementation
  • Adds unit tests for the throw and undefined-return paths

Context

Previously, getPreviousValueIndex returns the nullifier's own index when alreadyPresent: true. The method just logged a warning and returned that witness anyway. The Noir circuit would catch this implicitly (the low < target assertion fails), but the error surfaced as a cryptic circuit assertion rather than a clear "nullifier already exists" message.

Test plan

  • Unit tests added in server.test.ts covering both the throw-on-exists and return-undefined paths
  • All 34 existing tests in server.test.ts continue to pass
  • Build, format, and lint pass

🤖 Generated with Claude Code

}

/**
* 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).

});
});

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)

benesjan and others added 2 commits March 16, 2026 08:55
… nullifier exists

Previously, getLowNullifierMembershipWitness would log a warning and return the
nullifier's own witness when it already existed in the tree. This is wrong for a
non-inclusion proof and led to cryptic circuit assertion failures downstream.
Now it throws a descriptive error early.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@benesjan benesjan force-pushed the be/fix-low-nullifier-witness-error branch from dd3ea83 to 4639347 Compare March 16, 2026 08:55
Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@benesjan benesjan requested a review from mverzilli March 16, 2026 09:17
@PhilWindle PhilWindle merged commit bd5b6c3 into merge-train/fairies Mar 16, 2026
14 checks passed
@PhilWindle PhilWindle deleted the be/fix-low-nullifier-witness-error branch March 16, 2026 09:48
github-merge-queue bot pushed a commit that referenced this pull request Mar 16, 2026
BEGIN_COMMIT_OVERRIDE
feat: add public log filtering by tag (#21561)
feat: default to kernelless simulations (#21575)
fix(aztec-node): throw on existing nullifier in
getLowNullifierMembershipWitness (#21472)
fix: update nullifier non-inclusion test expectations after early oracle
throw (#21600)
refactor(pxe): type and audit legacy oracle mappings (#21569)
END_COMMIT_OVERRIDE
AztecBot pushed a commit that referenced this pull request Mar 17, 2026
…shipWitness (#21472)

As I was going through TODOs I found this ancient TODO of mine (from
November 2023):

```
   * 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.
```

In this PR i handle it by instead throwing an error in this scenario.

This doesn't modify the interface so it was not urgent to do but felt
like it makes sense to do now anyway so I went with it.

(Pinged this PR to alpha team)

## Summary

- `getLowNullifierMembershipWitness` now throws a descriptive error when
the queried nullifier already exists in the tree, instead of silently
returning the nullifier's own witness (which is wrong for a
non-inclusion proof)
- Removes the long-standing TODO about confusing behavior (open since
Nov 2023)
- Adds `@throws` JSDoc to both the interface and implementation
- Adds unit tests for the throw and undefined-return paths

## Context

Previously, `getPreviousValueIndex` returns the nullifier's own index
when `alreadyPresent: true`. The method just logged a warning and
returned that witness anyway. The Noir circuit would catch this
implicitly (the `low < target` assertion fails), but the error surfaced
as a cryptic circuit assertion rather than a clear "nullifier already
exists" message.

## Test plan

- Unit tests added in `server.test.ts` covering both the throw-on-exists
and return-undefined paths
- All 34 existing tests in `server.test.ts` continue to pass
- Build, format, and lint pass


🤖 Generated with [Claude Code](https://claude.com/claude-code)
@AztecBot
Copy link
Collaborator

✅ Successfully backported to backport-to-v4-next-staging #21654.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants