From 297779ae64af33687256f1ced11b1aee3fd29946 Mon Sep 17 00:00:00 2001 From: Facundo Date: Fri, 10 May 2024 17:35:27 +0100 Subject: [PATCH] fix(circuits.js): fix nullifier non existent hints (#6346) If the nullifier got into the pending set AFTER the request, it's not a problem. --- ...ild_nullifier_non_existent_read_request_hints.test.ts | 4 +++- .../build_nullifier_non_existent_read_request_hints.ts | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/yarn-project/circuits.js/src/hints/build_nullifier_non_existent_read_request_hints.test.ts b/yarn-project/circuits.js/src/hints/build_nullifier_non_existent_read_request_hints.test.ts index 89a2fb7ed6d..7c5834fe945 100644 --- a/yarn-project/circuits.js/src/hints/build_nullifier_non_existent_read_request_hints.test.ts +++ b/yarn-project/circuits.js/src/hints/build_nullifier_non_existent_read_request_hints.test.ts @@ -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.', + ); }); }); diff --git a/yarn-project/circuits.js/src/hints/build_nullifier_non_existent_read_request_hints.ts b/yarn-project/circuits.js/src/hints/build_nullifier_non_existent_read_request_hints.ts index 5bb6fa3eb76..b2393cf4bc4 100644 --- a/yarn-project/circuits.js/src/hints/build_nullifier_non_existent_read_request_hints.ts +++ b/yarn-project/circuits.js/src/hints/build_nullifier_non_existent_read_request_hints.ts @@ -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);