Skip to content

Commit

Permalink
fix(circuits.js): fix nullifier non existent hints (#6346)
Browse files Browse the repository at this point in the history
If the nullifier got into the pending set AFTER the request, it's not a
problem.
  • Loading branch information
fcarreiro committed May 10, 2024
1 parent 84878d1 commit 297779a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ describe('buildNullifierNonExistentReadRequestHints', () => {

nonExistentReadRequests[0] = makeReadRequest(innerNullifier(2));

await expect(() => buildHints()).rejects.toThrow('Nullifier exists in the pending set.');
await expect(() => buildHints()).rejects.toThrow(
'Nullifier DOES exists in the pending set at the time of reading, but there is a NonExistentReadRequest for it.',
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ export async function buildNullifierNonExistentReadRequestHints(
let nextPendingValueIndex = sortedValues.findIndex(v => !v.value.lt(siloedValue));
if (nextPendingValueIndex == -1) {
nextPendingValueIndex = numPendingNullifiers;
} else if (sortedValues[nextPendingValueIndex].value.equals(siloedValue)) {
throw new Error('Nullifier exists in the pending set.');
} else if (
sortedValues[nextPendingValueIndex].value.equals(siloedValue) &&
sortedValues[nextPendingValueIndex].counter < readRequest.counter
) {
throw new Error(
'Nullifier DOES exists in the pending set at the time of reading, but there is a NonExistentReadRequest for it.',
);
}

builder.addHint(membershipWitness, leafPreimage, nextPendingValueIndex);
Expand Down

0 comments on commit 297779a

Please sign in to comment.