@aztec/simulator 0.0.1-commit.d1f2d6c → 0.0.1-commit.e61ad554
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/dest/public/avm/avm_context.d.ts +3 -3
- package/dest/public/avm/avm_context.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.d.ts +6 -6
- package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.js +3 -3
- package/dest/public/avm/avm_execution_environment.d.ts +6 -5
- package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/public/avm/avm_machine_state.d.ts +6 -5
- package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/public/avm/avm_machine_state.js +3 -2
- package/dest/public/avm/avm_simulator.d.ts +3 -2
- package/dest/public/avm/avm_simulator.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.js +5 -4
- package/dest/public/avm/calldata.d.ts +51 -0
- package/dest/public/avm/calldata.d.ts.map +1 -0
- package/dest/public/avm/calldata.js +63 -0
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.js +3 -2
- package/dest/public/avm/fixtures/initializers.d.ts +1 -1
- package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
- package/dest/public/avm/fixtures/initializers.js +2 -1
- package/dest/public/avm/opcodes/accrued_substate.d.ts +1 -1
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/accrued_substate.js +4 -0
- package/dest/public/avm/opcodes/external_calls.d.ts +1 -1
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.js +7 -7
- package/dest/public/avm/opcodes/memory.js +1 -1
- package/dest/public/debug_fn_name.d.ts +4 -4
- package/dest/public/debug_fn_name.d.ts.map +1 -1
- package/dest/public/debug_fn_name.js +7 -5
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +4 -3
- package/package.json +16 -16
- package/src/public/avm/avm_context.ts +2 -2
- package/src/public/avm/avm_contract_call_result.ts +8 -6
- package/src/public/avm/avm_execution_environment.ts +9 -4
- package/src/public/avm/avm_machine_state.ts +6 -5
- package/src/public/avm/avm_simulator.ts +8 -5
- package/src/public/avm/calldata.ts +100 -0
- package/src/public/avm/fixtures/avm_simulation_tester.ts +8 -2
- package/src/public/avm/fixtures/initializers.ts +2 -1
- package/src/public/avm/opcodes/accrued_substate.ts +6 -0
- package/src/public/avm/opcodes/external_calls.ts +8 -7
- package/src/public/avm/opcodes/memory.ts +1 -1
- package/src/public/debug_fn_name.ts +10 -8
- package/src/public/public_tx_simulator/public_tx_simulator.ts +8 -3
|
@@ -19,6 +19,7 @@ import { AvmContext } from '../avm_context.js';
|
|
|
19
19
|
import { AvmExecutionEnvironment } from '../avm_execution_environment.js';
|
|
20
20
|
import { AvmMachineState } from '../avm_machine_state.js';
|
|
21
21
|
import { AvmSimulator } from '../avm_simulator.js';
|
|
22
|
+
import { CallDataArray } from '../calldata.js';
|
|
22
23
|
import { DEFAULT_TIMESTAMP } from './utils.js';
|
|
23
24
|
|
|
24
25
|
/**
|
|
@@ -70,7 +71,7 @@ export function initExecutionEnvironment(overrides?: Partial<AvmExecutionEnviron
|
|
|
70
71
|
overrides?.transactionFee ?? Fr.zero(),
|
|
71
72
|
overrides?.globals ?? GlobalVariables.empty(),
|
|
72
73
|
overrides?.isStaticCall ?? false,
|
|
73
|
-
overrides?.calldata ?? [],
|
|
74
|
+
overrides?.calldata ?? new CallDataArray([]),
|
|
74
75
|
overrides?.config ?? PublicSimulatorConfig.empty(),
|
|
75
76
|
);
|
|
76
77
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { MAX_ETH_ADDRESS_VALUE } from '@aztec/constants';
|
|
2
|
+
|
|
1
3
|
import { NullifierCollisionError } from '../../side_effect_errors.js';
|
|
2
4
|
import type { AvmContext } from '../avm_context.js';
|
|
3
5
|
import { TypeTag, Uint1 } from '../avm_memory_types.js';
|
|
@@ -282,6 +284,10 @@ export class SendL2ToL1Message extends Instruction {
|
|
|
282
284
|
memory.checkTags(TypeTag.FIELD, recipientOffset, contentOffset);
|
|
283
285
|
|
|
284
286
|
const recipient = memory.get(recipientOffset).toFr();
|
|
287
|
+
|
|
288
|
+
if (recipient.toBigInt() > MAX_ETH_ADDRESS_VALUE) {
|
|
289
|
+
throw new InstructionExecutionError(`SENDL2TOL1MSG: Recipient address is too large`);
|
|
290
|
+
}
|
|
285
291
|
const content = memory.get(contentOffset).toFr();
|
|
286
292
|
context.persistableState.writeL2ToL1Message(context.environment.address, recipient, content);
|
|
287
293
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AvmContext } from '../avm_context.js';
|
|
2
2
|
import type { AvmContractCallResult } from '../avm_contract_call_result.js';
|
|
3
3
|
import { type Field, TypeTag, Uint1 } from '../avm_memory_types.js';
|
|
4
|
+
import { CallDataMemory, ReturnDataMemory } from '../calldata.js';
|
|
4
5
|
import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
|
|
5
6
|
import { Addressing } from './addressing_mode.js';
|
|
6
7
|
import { Instruction } from './instruction.js';
|
|
@@ -45,8 +46,8 @@ abstract class ExternalCall extends Instruction {
|
|
|
45
46
|
memory.checkTag(TypeTag.UINT32, argsSizeOffset);
|
|
46
47
|
|
|
47
48
|
const calldataSize = memory.get(argsSizeOffset).toNumber();
|
|
48
|
-
|
|
49
|
-
const calldata = memory
|
|
49
|
+
|
|
50
|
+
const calldata = new CallDataMemory(memory, argsOffset, calldataSize);
|
|
50
51
|
|
|
51
52
|
const callAddress = memory.getAs<Field>(addrOffset);
|
|
52
53
|
// If we are already in a static call, we propagate the environment.
|
|
@@ -73,8 +74,8 @@ abstract class ExternalCall extends Instruction {
|
|
|
73
74
|
const success = !nestedCallResults.reverted;
|
|
74
75
|
|
|
75
76
|
// Save return/revert data for later.
|
|
76
|
-
const
|
|
77
|
-
context.machineState.nestedReturndata =
|
|
77
|
+
const returnData = nestedCallResults.output;
|
|
78
|
+
context.machineState.nestedReturndata = returnData;
|
|
78
79
|
|
|
79
80
|
// Track the success status directly
|
|
80
81
|
context.machineState.nestedCallSuccess = success;
|
|
@@ -89,7 +90,7 @@ abstract class ExternalCall extends Instruction {
|
|
|
89
90
|
// (in Noir code).
|
|
90
91
|
if (!success) {
|
|
91
92
|
context.machineState.collectedRevertInfo = {
|
|
92
|
-
revertDataRepresentative:
|
|
93
|
+
revertDataRepresentative: returnData.bestEffortReadAll(),
|
|
93
94
|
recursiveRevertReason: nestedCallResults.revertReason!,
|
|
94
95
|
};
|
|
95
96
|
}
|
|
@@ -195,7 +196,7 @@ export class Return extends Instruction {
|
|
|
195
196
|
memory.checkTag(TypeTag.UINT32, returnSizeOffset);
|
|
196
197
|
const returnSize = memory.get(returnSizeOffset).toNumber();
|
|
197
198
|
|
|
198
|
-
const output = memory
|
|
199
|
+
const output = new ReturnDataMemory(memory, returnOffset, returnSize);
|
|
199
200
|
|
|
200
201
|
context.machineState.return(output);
|
|
201
202
|
}
|
|
@@ -243,7 +244,7 @@ export class Revert extends Instruction {
|
|
|
243
244
|
|
|
244
245
|
memory.checkTag(TypeTag.UINT32, retSizeOffset);
|
|
245
246
|
const retSize = memory.get(retSizeOffset).toNumber();
|
|
246
|
-
const output = memory
|
|
247
|
+
const output = new ReturnDataMemory(memory, returnOffset, retSize);
|
|
247
248
|
|
|
248
249
|
context.machineState.revert(output);
|
|
249
250
|
}
|
|
@@ -242,7 +242,7 @@ export class ReturndataSize extends Instruction {
|
|
|
242
242
|
const operands = [this.dstOffset];
|
|
243
243
|
const [dstOffset] = addressing.resolve(operands, memory);
|
|
244
244
|
|
|
245
|
-
memory.set(dstOffset, new Uint32(context.machineState.nestedReturndata.length));
|
|
245
|
+
memory.set(dstOffset, new Uint32(context.machineState.nestedReturndata.length()));
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
248
|
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
1
|
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
3
2
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
3
|
|
|
4
|
+
import type { CallData } from './avm/calldata.js';
|
|
5
5
|
import type { PublicContractsDBInterface } from './db_interfaces.js';
|
|
6
6
|
|
|
7
7
|
export async function getPublicFunctionDebugName(
|
|
8
8
|
db: PublicContractsDBInterface,
|
|
9
9
|
contractAddress: AztecAddress,
|
|
10
|
-
calldata:
|
|
10
|
+
calldata: CallData,
|
|
11
11
|
): Promise<string> {
|
|
12
12
|
// Public function is dispatched and therefore the target function is passed in the first argument.
|
|
13
|
-
|
|
13
|
+
const selectorField = calldata.read(0);
|
|
14
|
+
if (!selectorField) {
|
|
14
15
|
return `<calldata[0] undefined> (Contract Address: ${contractAddress})`;
|
|
15
16
|
}
|
|
16
|
-
const fallbackName = `<calldata[0]:${
|
|
17
|
-
const selector = FunctionSelector.fromFieldOrUndefined(
|
|
17
|
+
const fallbackName = `<calldata[0]:${selectorField.toString()}> (Contract Address: ${contractAddress})`;
|
|
18
|
+
const selector = FunctionSelector.fromFieldOrUndefined(selectorField);
|
|
18
19
|
if (!selector) {
|
|
19
20
|
return fallbackName;
|
|
20
21
|
}
|
|
@@ -32,13 +33,14 @@ export async function getPublicFunctionDebugName(
|
|
|
32
33
|
export async function getPublicFunctionSelectorAndName(
|
|
33
34
|
db: PublicContractsDBInterface,
|
|
34
35
|
contractAddress: AztecAddress,
|
|
35
|
-
calldata:
|
|
36
|
+
calldata: CallData,
|
|
36
37
|
): Promise<{ functionSelector?: FunctionSelector; functionName?: string }> {
|
|
37
38
|
// Public function is dispatched and therefore the target function is passed in the first argument.
|
|
38
|
-
|
|
39
|
+
const selectorField = calldata.read(0);
|
|
40
|
+
if (!selectorField) {
|
|
39
41
|
return {};
|
|
40
42
|
}
|
|
41
|
-
const selector = FunctionSelector.fromFieldOrUndefined(
|
|
43
|
+
const selector = FunctionSelector.fromFieldOrUndefined(selectorField);
|
|
42
44
|
if (!selector) {
|
|
43
45
|
return {};
|
|
44
46
|
}
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
import { strict as assert } from 'assert';
|
|
20
20
|
|
|
21
21
|
import type { AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
|
|
22
|
+
import { CallDataArray } from '../avm/calldata.js';
|
|
22
23
|
import { AvmSimulator } from '../avm/index.js';
|
|
23
24
|
import { getPublicFunctionDebugName } from '../debug_fn_name.js';
|
|
24
25
|
import { HintingMerkleWriteOperations, HintingPublicContractsDB } from '../hinting_db_sources.js';
|
|
@@ -267,7 +268,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
267
268
|
|
|
268
269
|
const enqueuedCallResult = await this.simulateEnqueuedCall(phase, context, callRequest);
|
|
269
270
|
|
|
270
|
-
returnValues.push(new NestedProcessReturnValues(enqueuedCallResult.output));
|
|
271
|
+
returnValues.push(new NestedProcessReturnValues(enqueuedCallResult.output.bestEffortReadAll()));
|
|
271
272
|
|
|
272
273
|
if (enqueuedCallResult.reverted) {
|
|
273
274
|
reverted = true;
|
|
@@ -297,7 +298,11 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
297
298
|
): Promise<AvmFinalizedCallResult> {
|
|
298
299
|
const stateManager = context.state.getActiveStateManager();
|
|
299
300
|
const contractAddress = callRequest.request.contractAddress;
|
|
300
|
-
const fnName = await getPublicFunctionDebugName(
|
|
301
|
+
const fnName = await getPublicFunctionDebugName(
|
|
302
|
+
this.contractsDB,
|
|
303
|
+
contractAddress,
|
|
304
|
+
new CallDataArray(callRequest.calldata),
|
|
305
|
+
);
|
|
301
306
|
|
|
302
307
|
const allocatedGas = context.getGasLeftAtPhase(phase);
|
|
303
308
|
|
|
@@ -357,7 +362,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
357
362
|
transactionFee,
|
|
358
363
|
this.globalVariables,
|
|
359
364
|
request.isStaticCall,
|
|
360
|
-
calldata,
|
|
365
|
+
new CallDataArray(calldata),
|
|
361
366
|
allocatedGas,
|
|
362
367
|
this.config,
|
|
363
368
|
);
|