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