@@ -28,13 +28,11 @@ export class NoteHashExists extends Instruction {
28
28
}
29
29
30
30
public async execute ( context : AvmContext ) : Promise < void > {
31
- const memoryOperations = { reads : 2 , writes : 1 , indirect : this . indirect } ;
32
31
const memory = context . machineState . memory . track ( this . type ) ;
33
32
context . machineState . consumeGas ( this . gasCost ( ) ) ;
34
- const [ noteHashOffset , leafIndexOffset , existsOffset ] = Addressing . fromWire ( this . indirect ) . resolve (
35
- [ this . noteHashOffset , this . leafIndexOffset , this . existsOffset ] ,
36
- memory ,
37
- ) ;
33
+ const operands = [ this . noteHashOffset , this . leafIndexOffset , this . existsOffset ] ;
34
+ const addressing = Addressing . fromWire ( this . indirect , operands . length ) ;
35
+ const [ noteHashOffset , leafIndexOffset , existsOffset ] = addressing . resolve ( operands , memory ) ;
38
36
memory . checkTags ( TypeTag . FIELD , noteHashOffset , leafIndexOffset ) ;
39
37
40
38
// Note that this instruction accepts any type in memory, and converts to Field.
@@ -48,7 +46,7 @@ export class NoteHashExists extends Instruction {
48
46
) ;
49
47
memory . set ( existsOffset , exists ? new Uint8 ( 1 ) : new Uint8 ( 0 ) ) ;
50
48
51
- memory . assert ( memoryOperations ) ;
49
+ memory . assert ( { reads : 2 , writes : 1 , addressing } ) ;
52
50
context . machineState . incrementPc ( ) ;
53
51
}
54
52
}
@@ -64,11 +62,12 @@ export class EmitNoteHash extends Instruction {
64
62
}
65
63
66
64
public async execute ( context : AvmContext ) : Promise < void > {
67
- const memoryOperations = { reads : 1 , indirect : this . indirect } ;
68
65
const memory = context . machineState . memory . track ( this . type ) ;
69
66
context . machineState . consumeGas ( this . gasCost ( ) ) ;
70
67
71
- const [ noteHashOffset ] = Addressing . fromWire ( this . indirect ) . resolve ( [ this . noteHashOffset ] , memory ) ;
68
+ const operands = [ this . noteHashOffset ] ;
69
+ const addressing = Addressing . fromWire ( this . indirect , operands . length ) ;
70
+ const [ noteHashOffset ] = addressing . resolve ( operands , memory ) ;
72
71
memory . checkTag ( TypeTag . FIELD , noteHashOffset ) ;
73
72
74
73
if ( context . environment . isStaticCall ) {
@@ -78,7 +77,7 @@ export class EmitNoteHash extends Instruction {
78
77
const noteHash = memory . get ( noteHashOffset ) . toFr ( ) ;
79
78
context . persistableState . writeNoteHash ( context . environment . storageAddress , noteHash ) ;
80
79
81
- memory . assert ( memoryOperations ) ;
80
+ memory . assert ( { reads : 1 , addressing } ) ;
82
81
context . machineState . incrementPc ( ) ;
83
82
}
84
83
}
@@ -105,14 +104,12 @@ export class NullifierExists extends Instruction {
105
104
}
106
105
107
106
public async execute ( context : AvmContext ) : Promise < void > {
108
- const memoryOperations = { reads : 2 , writes : 1 , indirect : this . indirect } ;
109
107
const memory = context . machineState . memory . track ( this . type ) ;
110
108
context . machineState . consumeGas ( this . gasCost ( ) ) ;
111
109
112
- const [ nullifierOffset , addressOffset , existsOffset ] = Addressing . fromWire ( this . indirect ) . resolve (
113
- [ this . nullifierOffset , this . addressOffset , this . existsOffset ] ,
114
- memory ,
115
- ) ;
110
+ const operands = [ this . nullifierOffset , this . addressOffset , this . existsOffset ] ;
111
+ const addressing = Addressing . fromWire ( this . indirect , operands . length ) ;
112
+ const [ nullifierOffset , addressOffset , existsOffset ] = addressing . resolve ( operands , memory ) ;
116
113
memory . checkTags ( TypeTag . FIELD , nullifierOffset , addressOffset ) ;
117
114
118
115
const nullifier = memory . get ( nullifierOffset ) . toFr ( ) ;
@@ -121,7 +118,7 @@ export class NullifierExists extends Instruction {
121
118
122
119
memory . set ( existsOffset , exists ? new Uint8 ( 1 ) : new Uint8 ( 0 ) ) ;
123
120
124
- memory . assert ( memoryOperations ) ;
121
+ memory . assert ( { reads : 2 , writes : 1 , addressing } ) ;
125
122
context . machineState . incrementPc ( ) ;
126
123
}
127
124
}
@@ -141,11 +138,12 @@ export class EmitNullifier extends Instruction {
141
138
throw new StaticCallAlterationError ( ) ;
142
139
}
143
140
144
- const memoryOperations = { reads : 1 , indirect : this . indirect } ;
145
141
const memory = context . machineState . memory . track ( this . type ) ;
146
142
context . machineState . consumeGas ( this . gasCost ( ) ) ;
147
143
148
- const [ nullifierOffset ] = Addressing . fromWire ( this . indirect ) . resolve ( [ this . nullifierOffset ] , memory ) ;
144
+ const operands = [ this . nullifierOffset ] ;
145
+ const addressing = Addressing . fromWire ( this . indirect , operands . length ) ;
146
+ const [ nullifierOffset ] = addressing . resolve ( operands , memory ) ;
149
147
memory . checkTag ( TypeTag . FIELD , nullifierOffset ) ;
150
148
151
149
const nullifier = memory . get ( nullifierOffset ) . toFr ( ) ;
@@ -162,7 +160,7 @@ export class EmitNullifier extends Instruction {
162
160
}
163
161
}
164
162
165
- memory . assert ( memoryOperations ) ;
163
+ memory . assert ( { reads : 1 , addressing } ) ;
166
164
context . machineState . incrementPc ( ) ;
167
165
}
168
166
}
@@ -189,14 +187,12 @@ export class L1ToL2MessageExists extends Instruction {
189
187
}
190
188
191
189
public async execute ( context : AvmContext ) : Promise < void > {
192
- const memoryOperations = { reads : 2 , writes : 1 , indirect : this . indirect } ;
193
190
const memory = context . machineState . memory . track ( this . type ) ;
194
191
context . machineState . consumeGas ( this . gasCost ( ) ) ;
195
192
196
- const [ msgHashOffset , msgLeafIndexOffset , existsOffset ] = Addressing . fromWire ( this . indirect ) . resolve (
197
- [ this . msgHashOffset , this . msgLeafIndexOffset , this . existsOffset ] ,
198
- memory ,
199
- ) ;
193
+ const operands = [ this . msgHashOffset , this . msgLeafIndexOffset , this . existsOffset ] ;
194
+ const addressing = Addressing . fromWire ( this . indirect , operands . length ) ;
195
+ const [ msgHashOffset , msgLeafIndexOffset , existsOffset ] = addressing . resolve ( operands , memory ) ;
200
196
memory . checkTags ( TypeTag . FIELD , msgHashOffset , msgLeafIndexOffset ) ;
201
197
202
198
const msgHash = memory . get ( msgHashOffset ) . toFr ( ) ;
@@ -208,7 +204,7 @@ export class L1ToL2MessageExists extends Instruction {
208
204
) ;
209
205
memory . set ( existsOffset , exists ? new Uint8 ( 1 ) : new Uint8 ( 0 ) ) ;
210
206
211
- memory . assert ( memoryOperations ) ;
207
+ memory . assert ( { reads : 2 , writes : 1 , addressing } ) ;
212
208
context . machineState . incrementPc ( ) ;
213
209
}
214
210
}
@@ -230,22 +226,20 @@ export class EmitUnencryptedLog extends Instruction {
230
226
231
227
const memory = context . machineState . memory . track ( this . type ) ;
232
228
233
- const [ logOffset , logSizeOffset ] = Addressing . fromWire ( this . indirect ) . resolve (
234
- [ this . logOffset , this . logSizeOffset ] ,
235
- memory ,
236
- ) ;
229
+ const operands = [ this . logOffset , this . logSizeOffset ] ;
230
+ const addressing = Addressing . fromWire ( this . indirect , operands . length ) ;
231
+ const [ logOffset , logSizeOffset ] = addressing . resolve ( operands , memory ) ;
237
232
memory . checkTag ( TypeTag . UINT32 , logSizeOffset ) ;
238
233
const logSize = memory . get ( logSizeOffset ) . toNumber ( ) ;
239
234
memory . checkTagsRange ( TypeTag . FIELD , logOffset , logSize ) ;
240
235
241
236
const contractAddress = context . environment . address ;
242
237
243
- const memoryOperations = { reads : 1 + logSize , indirect : this . indirect } ;
244
238
context . machineState . consumeGas ( this . gasCost ( logSize ) ) ;
245
239
const log = memory . getSlice ( logOffset , logSize ) . map ( f => f . toFr ( ) ) ;
246
240
context . persistableState . writeUnencryptedLog ( contractAddress , log ) ;
247
241
248
- memory . assert ( memoryOperations ) ;
242
+ memory . assert ( { reads : 1 + logSize , addressing } ) ;
249
243
context . machineState . incrementPc ( ) ;
250
244
}
251
245
}
@@ -265,20 +259,18 @@ export class SendL2ToL1Message extends Instruction {
265
259
throw new StaticCallAlterationError ( ) ;
266
260
}
267
261
268
- const memoryOperations = { reads : 2 , indirect : this . indirect } ;
269
262
const memory = context . machineState . memory . track ( this . type ) ;
270
263
context . machineState . consumeGas ( this . gasCost ( ) ) ;
271
264
272
- const [ recipientOffset , contentOffset ] = Addressing . fromWire ( this . indirect ) . resolve (
273
- [ this . recipientOffset , this . contentOffset ] ,
274
- memory ,
275
- ) ;
265
+ const operands = [ this . recipientOffset , this . contentOffset ] ;
266
+ const addressing = Addressing . fromWire ( this . indirect , operands . length ) ;
267
+ const [ recipientOffset , contentOffset ] = addressing . resolve ( operands , memory ) ;
276
268
277
269
const recipient = memory . get ( recipientOffset ) . toFr ( ) ;
278
270
const content = memory . get ( contentOffset ) . toFr ( ) ;
279
271
context . persistableState . writeL2ToL1Message ( recipient , content ) ;
280
272
281
- memory . assert ( memoryOperations ) ;
273
+ memory . assert ( { reads : 2 , addressing } ) ;
282
274
context . machineState . incrementPc ( ) ;
283
275
}
284
276
}
0 commit comments