Commit bd5b6c3
authored
fix(aztec-node): throw on existing nullifier in getLowNullifierMembershipWitness (#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)3 files changed
Lines changed: 31 additions & 16 deletions
File tree
- yarn-project
- aztec-node/src/aztec-node
- stdlib/src/interfaces
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
401 | 428 | | |
402 | 429 | | |
403 | 430 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1133 | 1133 | | |
1134 | 1134 | | |
1135 | 1135 | | |
1136 | | - | |
1137 | | - | |
1138 | | - | |
1139 | | - | |
1140 | | - | |
1141 | | - | |
1142 | | - | |
1143 | | - | |
1144 | | - | |
1145 | | - | |
1146 | | - | |
1147 | | - | |
1148 | | - | |
1149 | | - | |
1150 | | - | |
1151 | 1136 | | |
1152 | 1137 | | |
1153 | 1138 | | |
| |||
1159 | 1144 | | |
1160 | 1145 | | |
1161 | 1146 | | |
1162 | | - | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
1163 | 1150 | | |
1164 | 1151 | | |
1165 | 1152 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| 125 | + | |
125 | 126 | | |
126 | 127 | | |
127 | 128 | | |
| |||
0 commit comments