@aztec/simulator 0.0.1-commit.c7c42ec → 0.0.1-commit.d1f2d6c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dest/common/errors.d.ts +7 -1
- package/dest/common/errors.d.ts.map +1 -1
- package/dest/private/circuit_recording/circuit_recorder.d.ts +1 -1
- package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/circuit_recorder.js +15 -14
- package/dest/public/avm/avm_memory_types.d.ts +1 -1
- package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/public/avm/avm_memory_types.js +3 -0
- package/dest/public/avm/opcodes/accrued_substate.d.ts +15 -15
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/accrued_substate.js +29 -29
- package/dest/public/avm/opcodes/arithmetic.d.ts +8 -8
- package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/public/avm/opcodes/arithmetic.js +1 -1
- package/dest/public/avm/opcodes/bitwise.d.ts +7 -7
- package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/public/avm/opcodes/bitwise.js +5 -5
- package/dest/public/avm/opcodes/comparators.d.ts +4 -4
- package/dest/public/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/public/avm/opcodes/comparators.js +1 -1
- package/dest/public/avm/opcodes/contract.d.ts +3 -3
- package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/public/avm/opcodes/contract.js +8 -8
- package/dest/public/avm/opcodes/control_flow.d.ts +3 -3
- package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
- package/dest/public/avm/opcodes/control_flow.js +4 -4
- package/dest/public/avm/opcodes/conversion.d.ts +3 -3
- package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/public/avm/opcodes/conversion.js +4 -4
- package/dest/public/avm/opcodes/ec_add.d.ts +4 -4
- package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/public/avm/opcodes/ec_add.js +15 -6
- package/dest/public/avm/opcodes/environment_getters.d.ts +5 -5
- package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/public/avm/opcodes/environment_getters.js +6 -6
- package/dest/public/avm/opcodes/external_calls.d.ts +9 -9
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.js +17 -16
- package/dest/public/avm/opcodes/hashing.d.ts +8 -8
- package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/public/avm/opcodes/hashing.js +12 -12
- package/dest/public/avm/opcodes/instruction_impl.d.ts +4 -4
- package/dest/public/avm/opcodes/instruction_impl.d.ts.map +1 -1
- package/dest/public/avm/opcodes/instruction_impl.js +4 -4
- package/dest/public/avm/opcodes/memory.d.ts +14 -14
- package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.js +24 -24
- package/dest/public/avm/opcodes/misc.d.ts +3 -3
- package/dest/public/avm/opcodes/misc.d.ts.map +1 -1
- package/dest/public/avm/opcodes/misc.js +4 -4
- package/dest/public/avm/opcodes/storage.d.ts +16 -15
- package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/public/avm/opcodes/storage.js +34 -24
- package/dest/public/executor_metrics.d.ts +1 -1
- package/dest/public/executor_metrics.d.ts.map +1 -1
- package/dest/public/executor_metrics.js +8 -34
- package/dest/public/fixtures/bulk_test.d.ts +3 -3
- package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
- package/dest/public/fixtures/bulk_test.js +1 -17
- package/dest/public/fixtures/custom_bytecode_tests.d.ts +11 -11
- package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
- package/dest/public/fixtures/custom_bytecode_tests.js +18 -18
- package/dest/public/fixtures/minimal_public_tx.js +2 -2
- package/dest/public/fixtures/opcode_spammer.d.ts +1 -1
- package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -1
- package/dest/public/fixtures/opcode_spammer.js +92 -80
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +21 -7
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -1
- package/dest/public/fuzzing/avm_fuzzer_simulator.js +42 -10
- package/dest/public/fuzzing/avm_simulator_bin.js +29 -11
- package/dest/public/hinting_db_sources.js +3 -1
- package/dest/public/public_processor/guarded_merkle_tree.js +3 -1
- package/dest/public/public_processor/public_processor.d.ts +2 -2
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +402 -21
- package/dest/public/public_processor/public_processor_metrics.d.ts +1 -1
- package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor_metrics.js +12 -45
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +1 -1
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +2 -1
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +4 -3
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +5 -3
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +395 -19
- package/dest/public/side_effect_trace.d.ts +2 -1
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.d.ts +1 -1
- package/dest/public/state_manager/state_manager.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.js +2 -2
- package/package.json +17 -17
- package/src/private/circuit_recording/circuit_recorder.ts +16 -15
- package/src/public/avm/avm_memory_types.ts +4 -0
- package/src/public/avm/opcodes/accrued_substate.ts +15 -15
- package/src/public/avm/opcodes/arithmetic.ts +1 -1
- package/src/public/avm/opcodes/bitwise.ts +3 -3
- package/src/public/avm/opcodes/comparators.ts +1 -1
- package/src/public/avm/opcodes/contract.ts +4 -7
- package/src/public/avm/opcodes/control_flow.ts +2 -2
- package/src/public/avm/opcodes/conversion.ts +3 -3
- package/src/public/avm/opcodes/ec_add.ts +13 -4
- package/src/public/avm/opcodes/environment_getters.ts +7 -7
- package/src/public/avm/opcodes/external_calls.ts +10 -9
- package/src/public/avm/opcodes/hashing.ts +6 -6
- package/src/public/avm/opcodes/instruction_impl.ts +2 -2
- package/src/public/avm/opcodes/memory.ts +18 -18
- package/src/public/avm/opcodes/misc.ts +2 -2
- package/src/public/avm/opcodes/storage.ts +30 -22
- package/src/public/executor_metrics.ts +7 -34
- package/src/public/fixtures/bulk_test.ts +2 -2
- package/src/public/fixtures/custom_bytecode_tests.ts +27 -18
- package/src/public/fixtures/minimal_public_tx.ts +2 -2
- package/src/public/fixtures/opcode_spammer.ts +197 -81
- package/src/public/fuzzing/avm_fuzzer_simulator.ts +60 -12
- package/src/public/fuzzing/avm_simulator_bin.ts +43 -8
- package/src/public/public_processor/public_processor.ts +3 -2
- package/src/public/public_processor/public_processor_metrics.ts +11 -45
- package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +9 -1
- package/src/public/public_tx_simulator/public_tx_simulator.ts +4 -2
- package/src/public/state_manager/state_manager.ts +2 -16
|
@@ -108,16 +108,16 @@ export class CircuitRecorder {
|
|
|
108
108
|
* contracts as protocol circuits artifacts always contain a single entrypoint function called 'main'.
|
|
109
109
|
*/
|
|
110
110
|
start(input: ACVMWitness, circuitBytecode: Buffer, circuitName: string, functionName: string): Promise<void> {
|
|
111
|
-
const parentRef = this.recording;
|
|
112
111
|
if (this.newCircuit) {
|
|
112
|
+
const parentRef = this.recording;
|
|
113
113
|
this.recording = new CircuitRecording(
|
|
114
114
|
circuitName,
|
|
115
115
|
functionName,
|
|
116
116
|
sha512(circuitBytecode).toString('hex'),
|
|
117
117
|
Object.fromEntries(input),
|
|
118
118
|
);
|
|
119
|
+
this.recording.setParent(parentRef);
|
|
119
120
|
}
|
|
120
|
-
this.recording!.setParent(parentRef);
|
|
121
121
|
|
|
122
122
|
return Promise.resolve();
|
|
123
123
|
}
|
|
@@ -173,22 +173,22 @@ export class CircuitRecorder {
|
|
|
173
173
|
if (result instanceof Promise) {
|
|
174
174
|
return result.then(async r => {
|
|
175
175
|
// Once we leave the nested circuit, we decrease the stack depth and set newCircuit to false
|
|
176
|
-
//
|
|
176
|
+
// so that the parent circuit continues with its existing recording
|
|
177
|
+
// Note: recording restoration is handled by finish()
|
|
177
178
|
if (isExternalCall) {
|
|
178
179
|
this.stackDepth--;
|
|
179
180
|
this.newCircuit = false;
|
|
180
|
-
this.recording = this.recording!.parent;
|
|
181
181
|
}
|
|
182
182
|
await this.recordCall(name, args, r, timer.ms(), this.stackDepth);
|
|
183
183
|
return r;
|
|
184
184
|
}) as ReturnType<typeof fn>;
|
|
185
185
|
}
|
|
186
186
|
// Once we leave the nested circuit, we decrease the stack depth and set newCircuit to false
|
|
187
|
-
//
|
|
187
|
+
// so that the parent circuit continues with its existing recording
|
|
188
|
+
// Note: recording restoration is handled by finish()
|
|
188
189
|
if (isExternalCall) {
|
|
189
190
|
this.stackDepth--;
|
|
190
191
|
this.newCircuit = false;
|
|
191
|
-
this.recording = this.recording!.parent;
|
|
192
192
|
}
|
|
193
193
|
void this.recordCall(name, args, result, timer.ms(), this.stackDepth);
|
|
194
194
|
return result;
|
|
@@ -239,6 +239,12 @@ export class CircuitRecorder {
|
|
|
239
239
|
if (!result!.parent) {
|
|
240
240
|
this.newCircuit = true;
|
|
241
241
|
this.recording = undefined;
|
|
242
|
+
} else {
|
|
243
|
+
// For nested circuits (utility calls, nested contract calls), restore to parent recording
|
|
244
|
+
// Note: we don't set newCircuit=false here because:
|
|
245
|
+
// - For privateCallPrivateFunction, the callback wrapper will set it to false
|
|
246
|
+
// - For utility calls, we want newCircuit to remain true so the next circuit creates its own recording
|
|
247
|
+
this.recording = result!.parent;
|
|
242
248
|
}
|
|
243
249
|
return Promise.resolve(result!);
|
|
244
250
|
}
|
|
@@ -247,14 +253,9 @@ export class CircuitRecorder {
|
|
|
247
253
|
* Finalizes the recording by resetting the state and returning the recording object with an attached error.
|
|
248
254
|
* @param error - The error that occurred during circuit execution
|
|
249
255
|
*/
|
|
250
|
-
finishWithError(error: unknown): Promise<CircuitRecording> {
|
|
251
|
-
const result = this.
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
this.newCircuit = true;
|
|
255
|
-
this.recording = undefined;
|
|
256
|
-
}
|
|
257
|
-
result!.error = JSON.stringify(error);
|
|
258
|
-
return Promise.resolve(result!);
|
|
256
|
+
async finishWithError(error: unknown): Promise<CircuitRecording> {
|
|
257
|
+
const result = await this.finish();
|
|
258
|
+
result.error = JSON.stringify(error);
|
|
259
|
+
return result;
|
|
259
260
|
}
|
|
260
261
|
}
|
|
@@ -369,6 +369,10 @@ export class TaggedMemory implements TaggedMemoryInterface {
|
|
|
369
369
|
* Check tags for all memory in the specified range.
|
|
370
370
|
*/
|
|
371
371
|
public checkTagsRange(tag: TypeTag, startOffset: number, size: number) {
|
|
372
|
+
if (startOffset + size > TaggedMemory.MAX_MEMORY_SIZE) {
|
|
373
|
+
throw new MemorySliceOutOfRangeError(startOffset, size);
|
|
374
|
+
}
|
|
375
|
+
|
|
372
376
|
for (let offset = startOffset; offset < startOffset + size; offset++) {
|
|
373
377
|
this.checkTag(tag, offset);
|
|
374
378
|
}
|
|
@@ -19,7 +19,7 @@ export class NoteHashExists extends Instruction {
|
|
|
19
19
|
];
|
|
20
20
|
|
|
21
21
|
constructor(
|
|
22
|
-
private
|
|
22
|
+
private addressingMode: number,
|
|
23
23
|
private noteHashOffset: number,
|
|
24
24
|
private leafIndexOffset: number,
|
|
25
25
|
private existsOffset: number,
|
|
@@ -29,7 +29,7 @@ export class NoteHashExists extends Instruction {
|
|
|
29
29
|
|
|
30
30
|
public async execute(context: AvmContext): Promise<void> {
|
|
31
31
|
const memory = context.machineState.memory;
|
|
32
|
-
const addressing = Addressing.fromWire(this.
|
|
32
|
+
const addressing = Addressing.fromWire(this.addressingMode);
|
|
33
33
|
|
|
34
34
|
context.machineState.consumeGas(
|
|
35
35
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
@@ -55,7 +55,7 @@ export class EmitNoteHash extends Instruction {
|
|
|
55
55
|
static readonly wireFormat = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT16];
|
|
56
56
|
|
|
57
57
|
constructor(
|
|
58
|
-
private
|
|
58
|
+
private addressingMode: number,
|
|
59
59
|
private noteHashOffset: number,
|
|
60
60
|
) {
|
|
61
61
|
super();
|
|
@@ -63,7 +63,7 @@ export class EmitNoteHash extends Instruction {
|
|
|
63
63
|
|
|
64
64
|
public async execute(context: AvmContext): Promise<void> {
|
|
65
65
|
const memory = context.machineState.memory;
|
|
66
|
-
const addressing = Addressing.fromWire(this.
|
|
66
|
+
const addressing = Addressing.fromWire(this.addressingMode);
|
|
67
67
|
|
|
68
68
|
context.machineState.consumeGas(
|
|
69
69
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
@@ -95,7 +95,7 @@ export class NullifierExists extends Instruction {
|
|
|
95
95
|
];
|
|
96
96
|
|
|
97
97
|
constructor(
|
|
98
|
-
private
|
|
98
|
+
private addressingMode: number,
|
|
99
99
|
private nullifierOffset: number,
|
|
100
100
|
private addressOffset: number,
|
|
101
101
|
private existsOffset: number,
|
|
@@ -105,7 +105,7 @@ export class NullifierExists extends Instruction {
|
|
|
105
105
|
|
|
106
106
|
public async execute(context: AvmContext): Promise<void> {
|
|
107
107
|
const memory = context.machineState.memory;
|
|
108
|
-
const addressing = Addressing.fromWire(this.
|
|
108
|
+
const addressing = Addressing.fromWire(this.addressingMode);
|
|
109
109
|
|
|
110
110
|
context.machineState.consumeGas(
|
|
111
111
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
@@ -130,7 +130,7 @@ export class EmitNullifier extends Instruction {
|
|
|
130
130
|
static readonly wireFormat = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT16];
|
|
131
131
|
|
|
132
132
|
constructor(
|
|
133
|
-
private
|
|
133
|
+
private addressingMode: number,
|
|
134
134
|
private nullifierOffset: number,
|
|
135
135
|
) {
|
|
136
136
|
super();
|
|
@@ -142,7 +142,7 @@ export class EmitNullifier extends Instruction {
|
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
const memory = context.machineState.memory;
|
|
145
|
-
const addressing = Addressing.fromWire(this.
|
|
145
|
+
const addressing = Addressing.fromWire(this.addressingMode);
|
|
146
146
|
|
|
147
147
|
context.machineState.consumeGas(
|
|
148
148
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
@@ -181,7 +181,7 @@ export class L1ToL2MessageExists extends Instruction {
|
|
|
181
181
|
];
|
|
182
182
|
|
|
183
183
|
constructor(
|
|
184
|
-
private
|
|
184
|
+
private addressingMode: number,
|
|
185
185
|
private msgHashOffset: number,
|
|
186
186
|
private msgLeafIndexOffset: number,
|
|
187
187
|
private existsOffset: number,
|
|
@@ -191,7 +191,7 @@ export class L1ToL2MessageExists extends Instruction {
|
|
|
191
191
|
|
|
192
192
|
public async execute(context: AvmContext): Promise<void> {
|
|
193
193
|
const memory = context.machineState.memory;
|
|
194
|
-
const addressing = Addressing.fromWire(this.
|
|
194
|
+
const addressing = Addressing.fromWire(this.addressingMode);
|
|
195
195
|
|
|
196
196
|
context.machineState.consumeGas(
|
|
197
197
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
@@ -218,7 +218,7 @@ export class EmitUnencryptedLog extends Instruction {
|
|
|
218
218
|
static readonly wireFormat = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT16, OperandType.UINT16];
|
|
219
219
|
|
|
220
220
|
constructor(
|
|
221
|
-
private
|
|
221
|
+
private addressingMode: number,
|
|
222
222
|
private logSizeOffset: number,
|
|
223
223
|
private logOffset: number,
|
|
224
224
|
) {
|
|
@@ -231,7 +231,7 @@ export class EmitUnencryptedLog extends Instruction {
|
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
const memory = context.machineState.memory;
|
|
234
|
-
const addressing = Addressing.fromWire(this.
|
|
234
|
+
const addressing = Addressing.fromWire(this.addressingMode);
|
|
235
235
|
|
|
236
236
|
context.machineState.consumeGas(
|
|
237
237
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
@@ -241,11 +241,11 @@ export class EmitUnencryptedLog extends Instruction {
|
|
|
241
241
|
const [logSizeOffset, logOffset] = addressing.resolve(operands, memory);
|
|
242
242
|
memory.checkTag(TypeTag.UINT32, logSizeOffset);
|
|
243
243
|
const logSize = memory.get(logSizeOffset).toNumber();
|
|
244
|
-
memory.checkTagsRange(TypeTag.FIELD, logOffset, logSize);
|
|
245
244
|
|
|
246
245
|
const contractAddress = context.environment.address;
|
|
247
246
|
|
|
248
247
|
context.machineState.consumeGas(this.dynamicGasCost(logSize));
|
|
248
|
+
memory.checkTagsRange(TypeTag.FIELD, logOffset, logSize);
|
|
249
249
|
const log = memory.getSlice(logOffset, logSize).map(f => f.toFr());
|
|
250
250
|
context.persistableState.writePublicLog(contractAddress, log);
|
|
251
251
|
}
|
|
@@ -258,7 +258,7 @@ export class SendL2ToL1Message extends Instruction {
|
|
|
258
258
|
static readonly wireFormat = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT16, OperandType.UINT16];
|
|
259
259
|
|
|
260
260
|
constructor(
|
|
261
|
-
private
|
|
261
|
+
private addressingMode: number,
|
|
262
262
|
private recipientOffset: number,
|
|
263
263
|
private contentOffset: number,
|
|
264
264
|
) {
|
|
@@ -271,7 +271,7 @@ export class SendL2ToL1Message extends Instruction {
|
|
|
271
271
|
}
|
|
272
272
|
|
|
273
273
|
const memory = context.machineState.memory;
|
|
274
|
-
const addressing = Addressing.fromWire(this.
|
|
274
|
+
const addressing = Addressing.fromWire(this.addressingMode);
|
|
275
275
|
|
|
276
276
|
context.machineState.consumeGas(
|
|
277
277
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
@@ -15,7 +15,7 @@ import { ThreeOperandInstruction } from './instruction_impl.js';
|
|
|
15
15
|
export abstract class ThreeOperandArithmeticInstruction extends ThreeOperandInstruction {
|
|
16
16
|
public async execute(context: AvmContext): Promise<void> {
|
|
17
17
|
const memory = context.machineState.memory;
|
|
18
|
-
const addressing = Addressing.fromWire(this.
|
|
18
|
+
const addressing = Addressing.fromWire(this.addressingMode);
|
|
19
19
|
|
|
20
20
|
context.machineState.consumeGas(
|
|
21
21
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
@@ -9,7 +9,7 @@ import { ThreeOperandInstruction } from './instruction_impl.js';
|
|
|
9
9
|
abstract class ThreeOperandBitwiseInstruction extends ThreeOperandInstruction {
|
|
10
10
|
public async execute(context: AvmContext): Promise<void> {
|
|
11
11
|
const memory = context.machineState.memory;
|
|
12
|
-
const addressing = Addressing.fromWire(this.
|
|
12
|
+
const addressing = Addressing.fromWire(this.addressingMode);
|
|
13
13
|
|
|
14
14
|
context.machineState.consumeGas(
|
|
15
15
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
@@ -87,7 +87,7 @@ export class Not extends Instruction {
|
|
|
87
87
|
static readonly wireFormat16 = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT16, OperandType.UINT16];
|
|
88
88
|
|
|
89
89
|
constructor(
|
|
90
|
-
private
|
|
90
|
+
private addressingMode: number,
|
|
91
91
|
private srcOffset: number,
|
|
92
92
|
private dstOffset: number,
|
|
93
93
|
) {
|
|
@@ -96,7 +96,7 @@ export class Not extends Instruction {
|
|
|
96
96
|
|
|
97
97
|
public async execute(context: AvmContext): Promise<void> {
|
|
98
98
|
const memory = context.machineState.memory;
|
|
99
|
-
const addressing = Addressing.fromWire(this.
|
|
99
|
+
const addressing = Addressing.fromWire(this.addressingMode);
|
|
100
100
|
|
|
101
101
|
context.machineState.consumeGas(
|
|
102
102
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
@@ -7,7 +7,7 @@ import { ThreeOperandInstruction } from './instruction_impl.js';
|
|
|
7
7
|
abstract class ComparatorInstruction extends ThreeOperandInstruction {
|
|
8
8
|
public async execute(context: AvmContext): Promise<void> {
|
|
9
9
|
const memory = context.machineState.memory;
|
|
10
|
-
const addressing = Addressing.fromWire(this.
|
|
10
|
+
const addressing = Addressing.fromWire(this.addressingMode);
|
|
11
11
|
|
|
12
12
|
context.machineState.consumeGas(
|
|
13
13
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
@@ -17,14 +17,14 @@ export class GetContractInstance extends Instruction {
|
|
|
17
17
|
// Informs (de)serialization. See Instruction.deserialize.
|
|
18
18
|
static readonly wireFormat: OperandType[] = [
|
|
19
19
|
OperandType.UINT8, // opcode
|
|
20
|
-
OperandType.UINT8, //
|
|
20
|
+
OperandType.UINT8, // addressing_mode bits
|
|
21
21
|
OperandType.UINT16, // addressOffset
|
|
22
22
|
OperandType.UINT16, // dstOffset
|
|
23
23
|
OperandType.UINT8, // member enum (immediate)
|
|
24
24
|
];
|
|
25
25
|
|
|
26
26
|
constructor(
|
|
27
|
-
private
|
|
27
|
+
private addressingMode: number,
|
|
28
28
|
private addressOffset: number,
|
|
29
29
|
private dstOffset: number,
|
|
30
30
|
private memberEnum: number,
|
|
@@ -34,7 +34,7 @@ export class GetContractInstance extends Instruction {
|
|
|
34
34
|
|
|
35
35
|
async execute(context: AvmContext): Promise<void> {
|
|
36
36
|
const memory = context.machineState.memory;
|
|
37
|
-
const addressing = Addressing.fromWire(this.
|
|
37
|
+
const addressing = Addressing.fromWire(this.addressingMode);
|
|
38
38
|
|
|
39
39
|
context.machineState.consumeGas(
|
|
40
40
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
@@ -67,9 +67,6 @@ export class GetContractInstance extends Instruction {
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
const memberValueOffset = dstOffset + 1;
|
|
72
|
-
memory.set(existsOffset, new Uint1(exists ? 1 : 0));
|
|
73
|
-
memory.set(memberValueOffset, memberValue);
|
|
70
|
+
memory.setSlice(dstOffset, [new Uint1(exists ? 1 : 0), memberValue]);
|
|
74
71
|
}
|
|
75
72
|
}
|
|
@@ -39,7 +39,7 @@ export class JumpI extends Instruction {
|
|
|
39
39
|
];
|
|
40
40
|
|
|
41
41
|
constructor(
|
|
42
|
-
private
|
|
42
|
+
private addressingMode: number,
|
|
43
43
|
private condOffset: number,
|
|
44
44
|
private loc: number,
|
|
45
45
|
) {
|
|
@@ -48,7 +48,7 @@ export class JumpI extends Instruction {
|
|
|
48
48
|
|
|
49
49
|
public async execute(context: AvmContext): Promise<void> {
|
|
50
50
|
const memory = context.machineState.memory;
|
|
51
|
-
const addressing = Addressing.fromWire(this.
|
|
51
|
+
const addressing = Addressing.fromWire(this.addressingMode);
|
|
52
52
|
|
|
53
53
|
context.machineState.consumeGas(
|
|
54
54
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
@@ -12,7 +12,7 @@ export class ToRadixBE extends Instruction {
|
|
|
12
12
|
// Informs (de)serialization. See Instruction.deserialize.
|
|
13
13
|
static readonly wireFormat: OperandType[] = [
|
|
14
14
|
OperandType.UINT8, // Opcode
|
|
15
|
-
OperandType.UINT16, //
|
|
15
|
+
OperandType.UINT16, // addressing_mode
|
|
16
16
|
OperandType.UINT16, // src memory address
|
|
17
17
|
OperandType.UINT16, // radix memory address
|
|
18
18
|
OperandType.UINT16, // number of limbs address
|
|
@@ -21,7 +21,7 @@ export class ToRadixBE extends Instruction {
|
|
|
21
21
|
];
|
|
22
22
|
|
|
23
23
|
constructor(
|
|
24
|
-
private
|
|
24
|
+
private addressingMode: number,
|
|
25
25
|
private srcOffset: number,
|
|
26
26
|
private radixOffset: number,
|
|
27
27
|
private numLimbsOffset: number,
|
|
@@ -33,7 +33,7 @@ export class ToRadixBE extends Instruction {
|
|
|
33
33
|
|
|
34
34
|
public async execute(context: AvmContext): Promise<void> {
|
|
35
35
|
const memory = context.machineState.memory;
|
|
36
|
-
const addressing = Addressing.fromWire(this.
|
|
36
|
+
const addressing = Addressing.fromWire(this.addressingMode);
|
|
37
37
|
|
|
38
38
|
context.machineState.consumeGas(
|
|
39
39
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
@@ -26,7 +26,7 @@ export class EcAdd extends Instruction {
|
|
|
26
26
|
];
|
|
27
27
|
|
|
28
28
|
constructor(
|
|
29
|
-
private
|
|
29
|
+
private addressingMode: number,
|
|
30
30
|
private p1XOffset: number,
|
|
31
31
|
private p1YOffset: number,
|
|
32
32
|
private p1IsInfiniteOffset: number,
|
|
@@ -40,7 +40,7 @@ export class EcAdd extends Instruction {
|
|
|
40
40
|
|
|
41
41
|
public async execute(context: AvmContext): Promise<void> {
|
|
42
42
|
const memory = context.machineState.memory;
|
|
43
|
-
const addressing = Addressing.fromWire(this.
|
|
43
|
+
const addressing = Addressing.fromWire(this.addressingMode);
|
|
44
44
|
|
|
45
45
|
context.machineState.consumeGas(
|
|
46
46
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
@@ -79,12 +79,21 @@ export class EcAdd extends Instruction {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
let dest;
|
|
82
|
-
if (p1IsInfinite) {
|
|
82
|
+
if (p1IsInfinite && p2IsInfinite) {
|
|
83
|
+
dest = Point.ZERO;
|
|
84
|
+
} else if (p1IsInfinite) {
|
|
83
85
|
dest = p2;
|
|
84
86
|
} else if (p2IsInfinite) {
|
|
85
87
|
dest = p1;
|
|
86
88
|
} else {
|
|
87
|
-
|
|
89
|
+
// TS<>BB ecc add communication is broken for points that add up to infinity.
|
|
90
|
+
// However, here we know that both points are on the curve, and that none is infinity
|
|
91
|
+
// so we can check for the case where you add p + (-p) = infinity.
|
|
92
|
+
if (p1.x.equals(p2.x) && !p1.y.equals(p2.y)) {
|
|
93
|
+
dest = Point.ZERO;
|
|
94
|
+
} else {
|
|
95
|
+
dest = await Grumpkin.add(p1, p2);
|
|
96
|
+
}
|
|
88
97
|
}
|
|
89
98
|
|
|
90
99
|
// Important to use setSlice() and not set() in the two following statements as
|
|
@@ -13,8 +13,8 @@ export enum EnvironmentVariable {
|
|
|
13
13
|
VERSION,
|
|
14
14
|
BLOCKNUMBER,
|
|
15
15
|
TIMESTAMP,
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
MINFEEPERL2GAS,
|
|
17
|
+
MINFEEPERDAGAS,
|
|
18
18
|
ISSTATICCALL,
|
|
19
19
|
L2GASLEFT,
|
|
20
20
|
DAGASLEFT,
|
|
@@ -36,9 +36,9 @@ function getValue(varEnum: EnvironmentVariable, ctx: AvmContext) {
|
|
|
36
36
|
return new Uint32(ctx.environment.globals.blockNumber);
|
|
37
37
|
case EnvironmentVariable.TIMESTAMP:
|
|
38
38
|
return new Uint64(ctx.environment.globals.timestamp);
|
|
39
|
-
case EnvironmentVariable.
|
|
39
|
+
case EnvironmentVariable.MINFEEPERL2GAS:
|
|
40
40
|
return new Uint128(ctx.environment.globals.gasFees.feePerL2Gas);
|
|
41
|
-
case EnvironmentVariable.
|
|
41
|
+
case EnvironmentVariable.MINFEEPERDAGAS:
|
|
42
42
|
return new Uint128(ctx.environment.globals.gasFees.feePerDaGas);
|
|
43
43
|
case EnvironmentVariable.ISSTATICCALL:
|
|
44
44
|
return new Uint1(ctx.environment.isStaticCall ? 1 : 0);
|
|
@@ -56,13 +56,13 @@ export class GetEnvVar extends Instruction {
|
|
|
56
56
|
public static readonly opcode: Opcode = Opcode.GETENVVAR_16;
|
|
57
57
|
static readonly wireFormat16: OperandType[] = [
|
|
58
58
|
OperandType.UINT8, // opcode
|
|
59
|
-
OperandType.UINT8, //
|
|
59
|
+
OperandType.UINT8, // addressing_mode
|
|
60
60
|
OperandType.UINT16, // dstOffset
|
|
61
61
|
OperandType.UINT8, // variable enum (immediate)
|
|
62
62
|
];
|
|
63
63
|
|
|
64
64
|
constructor(
|
|
65
|
-
private
|
|
65
|
+
private addressingMode: number,
|
|
66
66
|
private dstOffset: number,
|
|
67
67
|
private varEnum: number,
|
|
68
68
|
) {
|
|
@@ -71,7 +71,7 @@ export class GetEnvVar extends Instruction {
|
|
|
71
71
|
|
|
72
72
|
public async execute(context: AvmContext): Promise<void> {
|
|
73
73
|
const memory = context.machineState.memory;
|
|
74
|
-
const addressing = Addressing.fromWire(this.
|
|
74
|
+
const addressing = Addressing.fromWire(this.addressingMode);
|
|
75
75
|
|
|
76
76
|
context.machineState.consumeGas(
|
|
77
77
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
@@ -9,7 +9,7 @@ abstract class ExternalCall extends Instruction {
|
|
|
9
9
|
// Informs (de)serialization. See Instruction.deserialize.
|
|
10
10
|
static readonly wireFormat: OperandType[] = [
|
|
11
11
|
OperandType.UINT8,
|
|
12
|
-
OperandType.UINT16, //
|
|
12
|
+
OperandType.UINT16, // addressing_mode
|
|
13
13
|
OperandType.UINT16, // L2 gas offset
|
|
14
14
|
OperandType.UINT16, // DA gas offset
|
|
15
15
|
OperandType.UINT16, // Address offset
|
|
@@ -18,7 +18,7 @@ abstract class ExternalCall extends Instruction {
|
|
|
18
18
|
];
|
|
19
19
|
|
|
20
20
|
constructor(
|
|
21
|
-
private
|
|
21
|
+
private addressingMode: number,
|
|
22
22
|
private l2GasOffset: number,
|
|
23
23
|
private daGasOffset: number,
|
|
24
24
|
private addrOffset: number,
|
|
@@ -30,7 +30,7 @@ abstract class ExternalCall extends Instruction {
|
|
|
30
30
|
|
|
31
31
|
public async execute(context: AvmContext) {
|
|
32
32
|
const memory = context.machineState.memory;
|
|
33
|
-
const addressing = Addressing.fromWire(this.
|
|
33
|
+
const addressing = Addressing.fromWire(this.addressingMode);
|
|
34
34
|
|
|
35
35
|
context.machineState.consumeGas(
|
|
36
36
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
@@ -45,6 +45,7 @@ abstract class ExternalCall extends Instruction {
|
|
|
45
45
|
memory.checkTag(TypeTag.UINT32, argsSizeOffset);
|
|
46
46
|
|
|
47
47
|
const calldataSize = memory.get(argsSizeOffset).toNumber();
|
|
48
|
+
// This is a DOS vector. CalldataSize is chosen by the bytecode, and can be arbitrarily large leading to a OOM here.
|
|
48
49
|
const calldata = memory.getSlice(argsOffset, calldataSize).map(f => f.toFr());
|
|
49
50
|
|
|
50
51
|
const callAddress = memory.getAs<Field>(addrOffset);
|
|
@@ -136,7 +137,7 @@ export class SuccessCopy extends Instruction {
|
|
|
136
137
|
];
|
|
137
138
|
|
|
138
139
|
constructor(
|
|
139
|
-
private
|
|
140
|
+
private addressingMode: number,
|
|
140
141
|
private dstOffset: number,
|
|
141
142
|
) {
|
|
142
143
|
super();
|
|
@@ -144,7 +145,7 @@ export class SuccessCopy extends Instruction {
|
|
|
144
145
|
|
|
145
146
|
public async execute(context: AvmContext): Promise<void> {
|
|
146
147
|
const memory = context.machineState.memory;
|
|
147
|
-
const addressing = Addressing.fromWire(this.
|
|
148
|
+
const addressing = Addressing.fromWire(this.addressingMode);
|
|
148
149
|
|
|
149
150
|
context.machineState.consumeGas(
|
|
150
151
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
@@ -173,7 +174,7 @@ export class Return extends Instruction {
|
|
|
173
174
|
];
|
|
174
175
|
|
|
175
176
|
constructor(
|
|
176
|
-
private
|
|
177
|
+
private addressingMode: number,
|
|
177
178
|
private returnSizeOffset: number,
|
|
178
179
|
private returnOffset: number,
|
|
179
180
|
) {
|
|
@@ -182,7 +183,7 @@ export class Return extends Instruction {
|
|
|
182
183
|
|
|
183
184
|
public async execute(context: AvmContext): Promise<void> {
|
|
184
185
|
const memory = context.machineState.memory;
|
|
185
|
-
const addressing = Addressing.fromWire(this.
|
|
186
|
+
const addressing = Addressing.fromWire(this.addressingMode);
|
|
186
187
|
|
|
187
188
|
context.machineState.consumeGas(
|
|
188
189
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
@@ -222,7 +223,7 @@ export class Revert extends Instruction {
|
|
|
222
223
|
];
|
|
223
224
|
|
|
224
225
|
constructor(
|
|
225
|
-
private
|
|
226
|
+
private addressingMode: number,
|
|
226
227
|
private retSizeOffset: number,
|
|
227
228
|
private returnOffset: number,
|
|
228
229
|
) {
|
|
@@ -231,7 +232,7 @@ export class Revert extends Instruction {
|
|
|
231
232
|
|
|
232
233
|
public async execute(context: AvmContext): Promise<void> {
|
|
233
234
|
const memory = context.machineState.memory;
|
|
234
|
-
const addressing = Addressing.fromWire(this.
|
|
235
|
+
const addressing = Addressing.fromWire(this.addressingMode);
|
|
235
236
|
|
|
236
237
|
context.machineState.consumeGas(
|
|
237
238
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
@@ -22,7 +22,7 @@ export class Poseidon2 extends Instruction {
|
|
|
22
22
|
];
|
|
23
23
|
|
|
24
24
|
constructor(
|
|
25
|
-
private
|
|
25
|
+
private addressingMode: number,
|
|
26
26
|
private inputStateOffset: number,
|
|
27
27
|
private outputStateOffset: number,
|
|
28
28
|
) {
|
|
@@ -31,7 +31,7 @@ export class Poseidon2 extends Instruction {
|
|
|
31
31
|
|
|
32
32
|
public async execute(context: AvmContext): Promise<void> {
|
|
33
33
|
const memory = context.machineState.memory;
|
|
34
|
-
const addressing = Addressing.fromWire(this.
|
|
34
|
+
const addressing = Addressing.fromWire(this.addressingMode);
|
|
35
35
|
|
|
36
36
|
context.machineState.consumeGas(
|
|
37
37
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
@@ -65,7 +65,7 @@ export class KeccakF1600 extends Instruction {
|
|
|
65
65
|
];
|
|
66
66
|
|
|
67
67
|
constructor(
|
|
68
|
-
private
|
|
68
|
+
private addressingMode: number,
|
|
69
69
|
private dstOffset: number,
|
|
70
70
|
private inputOffset: number,
|
|
71
71
|
) {
|
|
@@ -76,7 +76,7 @@ export class KeccakF1600 extends Instruction {
|
|
|
76
76
|
public async execute(context: AvmContext): Promise<void> {
|
|
77
77
|
const inputSize = 25;
|
|
78
78
|
const memory = context.machineState.memory;
|
|
79
|
-
const addressing = Addressing.fromWire(this.
|
|
79
|
+
const addressing = Addressing.fromWire(this.addressingMode);
|
|
80
80
|
|
|
81
81
|
context.machineState.consumeGas(
|
|
82
82
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
@@ -109,7 +109,7 @@ export class Sha256Compression extends Instruction {
|
|
|
109
109
|
];
|
|
110
110
|
|
|
111
111
|
constructor(
|
|
112
|
-
private
|
|
112
|
+
private addressingMode: number,
|
|
113
113
|
private outputOffset: number,
|
|
114
114
|
private stateOffset: number,
|
|
115
115
|
private inputsOffset: number,
|
|
@@ -122,7 +122,7 @@ export class Sha256Compression extends Instruction {
|
|
|
122
122
|
const INPUTS_SIZE = 16;
|
|
123
123
|
|
|
124
124
|
const memory = context.machineState.memory;
|
|
125
|
-
const addressing = Addressing.fromWire(this.
|
|
125
|
+
const addressing = Addressing.fromWire(this.addressingMode);
|
|
126
126
|
|
|
127
127
|
context.machineState.consumeGas(
|
|
128
128
|
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
@@ -19,14 +19,14 @@ export const ThreeOperandWireFormat16 = [
|
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Covers (de)serialization for an instruction with:
|
|
22
|
-
*
|
|
22
|
+
* addressing mode, inTag, and three operands.
|
|
23
23
|
*/
|
|
24
24
|
export abstract class ThreeOperandInstruction extends Instruction {
|
|
25
25
|
static readonly wireFormat8: OperandType[] = ThreeOperandWireFormat8;
|
|
26
26
|
static readonly wireFormat16: OperandType[] = ThreeOperandWireFormat16;
|
|
27
27
|
|
|
28
28
|
constructor(
|
|
29
|
-
protected
|
|
29
|
+
protected addressingMode: number,
|
|
30
30
|
protected aOffset: number,
|
|
31
31
|
protected bOffset: number,
|
|
32
32
|
protected dstOffset: number,
|