@@ -9,15 +9,9 @@ uint32 constant MAX_NOTES_PER_ROLLUP = 64;
99// Note: keep in sync with other languages
1010uint32 constant MAX_NULLIFIERS_PER_ROLLUP = 64 ;
1111
12- // Note: keep in sync with other languages
13- uint256 constant NOTE_HASH_OR_NULLIFIER_STATE_NOT_EXISTS = 0 ;
14- // Note: keep in sync with other languages
15- uint256 constant NOTE_HASH_OR_NULLIFIER_STATE_PENDING = 1 ;
16- // Note: keep in sync with other languages
17- uint256 constant NOTE_HASH_OR_NULLIFIER_STATE_ROLLED_UP = 2 ;
18-
1912struct PendingTx {
2013 bool rolledUp;
14+ // TODO(perf): store a hash of the noteHashes and nullifiers and check when rolling up
2115 Fr[] noteHashes;
2216 Fr[] nullifiers;
2317}
@@ -32,10 +26,8 @@ contract PoolGeneric {
3226 IVerifier rollupVerifier;
3327 PendingTx[] allPendingTxs;
3428 AppendOnlyTreeSnapshot noteHashTree;
35- mapping (Fr => uint256 ) noteHashState; // TODO(perf): nuke this
3629 uint256 noteHashBatchIndex;
3730 AppendOnlyTreeSnapshot nullifierTree;
38- mapping (Fr => uint256 ) nullifierState; // TODO(perf): nuke this
3931 uint256 nullifierBatchIndex;
4032 }
4133
@@ -47,14 +39,12 @@ contract PoolGeneric {
4739 uint256 indexed index ,
4840 Fr[MAX_NOTES_PER_ROLLUP] noteHashes
4941 );
50- error NoteHashExists (Fr noteHash );
5142
5243 // TODO(perf): use dynamic array to save on gas costs
5344 event Nullifiers (
5445 uint256 indexed index ,
5546 Fr[MAX_NULLIFIERS_PER_ROLLUP] nullifiers
5647 );
57- error NullifierExists (Fr nullifier );
5848
5949 constructor (IVerifier rollupVerifier_ ) {
6050 _poolGenericStorage ().rollupVerifier = rollupVerifier_;
@@ -147,20 +137,12 @@ contract PoolGeneric {
147137 );
148138 _poolGenericStorage ().noteHashTree = newNoteHashTree;
149139 _poolGenericStorage ().nullifierTree = newNullifierTree;
150- // TODO(perf): remove this disgusting gas waste
151- for (uint256 i = 0 ; i < pendingNoteHashes.length ; i++ ) {
152- _poolGenericStorage ().noteHashState[
153- pendingNoteHashes[i]
154- ] = NOTE_HASH_OR_NULLIFIER_STATE_ROLLED_UP;
155- }
156- // TODO(perf): remove this disgusting gas waste
157- for (uint256 i = 0 ; i < pendingNullifiers.length ; i++ ) {
158- _poolGenericStorage ().nullifierState[
159- pendingNullifiers[i]
160- ] = NOTE_HASH_OR_NULLIFIER_STATE_ROLLED_UP;
161- }
162140 }
163141
142+ /**
143+ * @dev REQUIREMENT: noteHashes do not exist in the noteHashTree and nullifiers do not exist in the nullifierTree.
144+ * If they do, the tx will never be rolled up.
145+ */
164146 function _PoolGeneric_addPendingTx (
165147 NoteInput[] memory noteInputs ,
166148 bytes32 [] memory nullifiers
@@ -178,28 +160,12 @@ contract PoolGeneric {
178160
179161 for (uint256 i = 0 ; i < noteInputs.length ; i++ ) {
180162 Fr noteHash = FrLib.tryFrom (noteInputs[i].noteHash);
181- require (
182- _poolGenericStorage ().noteHashState[noteHash] ==
183- NOTE_HASH_OR_NULLIFIER_STATE_NOT_EXISTS,
184- NoteHashExists (noteHash)
185- );
186- _poolGenericStorage ().noteHashState[
187- noteHash
188- ] = NOTE_HASH_OR_NULLIFIER_STATE_PENDING;
189163 // TODO(perf): this is a waste of gas
190164 pendingTx.noteHashes.push (noteHash);
191165 }
192166
193167 for (uint256 i = 0 ; i < nullifiers.length ; i++ ) {
194168 Fr nullifier = FrLib.tryFrom (nullifiers[i]);
195- require (
196- _poolGenericStorage ().nullifierState[nullifier] ==
197- NOTE_HASH_OR_NULLIFIER_STATE_NOT_EXISTS,
198- NullifierExists (nullifier)
199- );
200- _poolGenericStorage ().nullifierState[
201- nullifier
202- ] = NOTE_HASH_OR_NULLIFIER_STATE_PENDING;
203169 // TODO(perf): this is a waste of gas
204170 pendingTx.nullifiers.push (nullifier);
205171 }
@@ -227,14 +193,6 @@ contract PoolGeneric {
227193 return _poolGenericStorage ().nullifierTree;
228194 }
229195
230- function noteHashState (bytes32 noteHash ) external view returns (uint256 ) {
231- return _poolGenericStorage ().noteHashState[FrLib.tryFrom (noteHash)];
232- }
233-
234- function nullifierState (bytes32 nullifier ) external view returns (uint256 ) {
235- return _poolGenericStorage ().nullifierState[FrLib.tryFrom (nullifier)];
236- }
237-
238196 function _poolGenericStorage ()
239197 private
240198 pure
0 commit comments