@aztec/simulator 0.44.0 → 0.45.0

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.
Files changed (110) hide show
  1. package/dest/acvm/oracle/oracle.d.ts +1 -1
  2. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  3. package/dest/acvm/oracle/oracle.js +3 -3
  4. package/dest/acvm/oracle/typed_oracle.d.ts +1 -1
  5. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  6. package/dest/acvm/oracle/typed_oracle.js +2 -2
  7. package/dest/avm/avm_context.d.ts +1 -1
  8. package/dest/avm/avm_context.d.ts.map +1 -1
  9. package/dest/avm/avm_context.js +3 -3
  10. package/dest/avm/{avm_message_call_result.d.ts → avm_contract_call_result.d.ts} +2 -2
  11. package/dest/avm/avm_contract_call_result.d.ts.map +1 -0
  12. package/dest/avm/avm_contract_call_result.js +18 -0
  13. package/dest/avm/avm_execution_environment.d.ts +7 -11
  14. package/dest/avm/avm_execution_environment.d.ts.map +1 -1
  15. package/dest/avm/avm_execution_environment.js +11 -20
  16. package/dest/avm/avm_gas.js +2 -2
  17. package/dest/avm/avm_simulator.d.ts +4 -4
  18. package/dest/avm/avm_simulator.d.ts.map +1 -1
  19. package/dest/avm/avm_simulator.js +7 -7
  20. package/dest/avm/bytecode_utils.d.ts +5 -0
  21. package/dest/avm/bytecode_utils.d.ts.map +1 -0
  22. package/dest/avm/bytecode_utils.js +29 -0
  23. package/dest/avm/errors.js +2 -2
  24. package/dest/avm/fixtures/index.d.ts.map +1 -1
  25. package/dest/avm/fixtures/index.js +3 -3
  26. package/dest/avm/journal/journal.d.ts +5 -5
  27. package/dest/avm/journal/journal.d.ts.map +1 -1
  28. package/dest/avm/journal/journal.js +9 -7
  29. package/dest/avm/journal/public_storage.d.ts +1 -1
  30. package/dest/avm/journal/public_storage.d.ts.map +1 -1
  31. package/dest/avm/journal/public_storage.js +2 -2
  32. package/dest/avm/opcodes/accrued_substate.d.ts +1 -2
  33. package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
  34. package/dest/avm/opcodes/accrued_substate.js +6 -15
  35. package/dest/avm/opcodes/environment_getters.d.ts +13 -8
  36. package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
  37. package/dest/avm/opcodes/environment_getters.js +20 -13
  38. package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
  39. package/dest/avm/opcodes/external_calls.js +1 -2
  40. package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
  41. package/dest/avm/serialization/bytecode_serialization.js +5 -5
  42. package/dest/avm/serialization/instruction_serialization.d.ts +9 -9
  43. package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
  44. package/dest/avm/serialization/instruction_serialization.js +10 -10
  45. package/dest/client/client_execution_context.d.ts +3 -1
  46. package/dest/client/client_execution_context.d.ts.map +1 -1
  47. package/dest/client/client_execution_context.js +6 -4
  48. package/dest/client/view_data_oracle.d.ts +3 -1
  49. package/dest/client/view_data_oracle.d.ts.map +1 -1
  50. package/dest/client/view_data_oracle.js +6 -4
  51. package/dest/mocks/fixtures.d.ts +3 -3
  52. package/dest/mocks/fixtures.d.ts.map +1 -1
  53. package/dest/mocks/fixtures.js +4 -4
  54. package/dest/public/abstract_phase_manager.js +12 -12
  55. package/dest/public/execution.d.ts +6 -5
  56. package/dest/public/execution.d.ts.map +1 -1
  57. package/dest/public/execution.js +2 -2
  58. package/dest/public/executor.d.ts +4 -4
  59. package/dest/public/executor.d.ts.map +1 -1
  60. package/dest/public/executor.js +19 -14
  61. package/dest/public/hints_builder.d.ts +1 -1
  62. package/dest/public/index.d.ts +1 -1
  63. package/dest/public/index.d.ts.map +1 -1
  64. package/dest/public/index.js +1 -1
  65. package/dest/public/public_kernel.d.ts +1 -1
  66. package/dest/public/public_kernel.d.ts.map +1 -1
  67. package/dest/public/public_kernel.js +2 -2
  68. package/dest/public/side_effect_trace.d.ts +5 -4
  69. package/dest/public/side_effect_trace.d.ts.map +1 -1
  70. package/dest/public/side_effect_trace.js +23 -9
  71. package/dest/public/side_effect_trace_interface.d.ts +3 -3
  72. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  73. package/dest/rollup/rollup.d.ts +1 -1
  74. package/dest/rollup/rollup.d.ts.map +1 -1
  75. package/dest/rollup/rollup.js +2 -2
  76. package/package.json +9 -9
  77. package/src/acvm/oracle/oracle.ts +12 -2
  78. package/src/acvm/oracle/typed_oracle.ts +6 -1
  79. package/src/avm/avm_context.ts +2 -2
  80. package/src/avm/{avm_message_call_result.ts → avm_contract_call_result.ts} +1 -1
  81. package/src/avm/avm_execution_environment.ts +10 -27
  82. package/src/avm/avm_gas.ts +1 -1
  83. package/src/avm/avm_simulator.ts +9 -11
  84. package/src/avm/bytecode_utils.ts +32 -0
  85. package/src/avm/errors.ts +1 -1
  86. package/src/avm/fixtures/index.ts +3 -6
  87. package/src/avm/journal/journal.ts +14 -11
  88. package/src/avm/journal/public_storage.ts +2 -2
  89. package/src/avm/opcodes/accrued_substate.ts +6 -19
  90. package/src/avm/opcodes/environment_getters.ts +23 -14
  91. package/src/avm/opcodes/external_calls.ts +2 -3
  92. package/src/avm/serialization/bytecode_serialization.ts +4 -3
  93. package/src/avm/serialization/instruction_serialization.ts +3 -3
  94. package/src/client/client_execution_context.ts +12 -3
  95. package/src/client/view_data_oracle.ts +12 -3
  96. package/src/mocks/fixtures.ts +5 -5
  97. package/src/public/abstract_phase_manager.ts +15 -15
  98. package/src/public/execution.ts +10 -6
  99. package/src/public/executor.ts +35 -20
  100. package/src/public/index.ts +1 -1
  101. package/src/public/public_kernel.ts +2 -1
  102. package/src/public/side_effect_trace.ts +31 -13
  103. package/src/public/side_effect_trace_interface.ts +3 -3
  104. package/src/rollup/rollup.ts +3 -1
  105. package/dest/avm/avm_message_call_result.d.ts.map +0 -1
  106. package/dest/avm/avm_message_call_result.js +0 -18
  107. package/dest/public/transitional_adaptors.d.ts +0 -17
  108. package/dest/public/transitional_adaptors.d.ts.map +0 -1
  109. package/dest/public/transitional_adaptors.js +0 -42
  110. package/src/public/transitional_adaptors.ts +0 -70
@@ -5,8 +5,8 @@ import { SerializableContractInstance } from '@aztec/types/contracts';
5
5
 
6
6
  import { type TracedContractInstance } from '../../public/side_effect_trace.js';
7
7
  import { type PublicSideEffectTraceInterface } from '../../public/side_effect_trace_interface.js';
8
+ import { type AvmContractCallResult } from '../avm_contract_call_result.js';
8
9
  import { type AvmExecutionEnvironment } from '../avm_execution_environment.js';
9
- import { type AvmContractCallResults } from '../avm_message_call_result.js';
10
10
  import { type HostStorage } from './host_storage.js';
11
11
  import { NullifierManager } from './nullifiers.js';
12
12
  import { PublicStorage } from './public_storage.js';
@@ -25,10 +25,11 @@ export class AvmPersistableStateManager {
25
25
 
26
26
  constructor(
27
27
  /** Reference to node storage */
28
- private hostStorage: HostStorage,
28
+ private readonly hostStorage: HostStorage,
29
29
  /** Side effect trace */
30
- private trace: PublicSideEffectTraceInterface,
30
+ private readonly trace: PublicSideEffectTraceInterface,
31
31
  /** Public storage, including cached writes */
32
+ // TODO(5818): make private once no longer accessed in executor
32
33
  public readonly publicStorage: PublicStorage,
33
34
  /** Nullifier set, including cached/recently-emitted nullifiers */
34
35
  private readonly nullifiers: NullifierManager,
@@ -197,9 +198,9 @@ export class AvmPersistableStateManager {
197
198
  * @param event - log event selector
198
199
  * @param log - log contents
199
200
  */
200
- public writeUnencryptedLog(contractAddress: Fr, event: Fr, log: Fr[]) {
201
- this.log.debug(`UnencryptedL2Log(${contractAddress}) += event ${event} with ${log.length} fields.`);
202
- this.trace.traceUnencryptedLog(contractAddress, event, log);
201
+ public writeUnencryptedLog(contractAddress: Fr, log: Fr[]) {
202
+ this.log.debug(`UnencryptedL2Log(${contractAddress}) += event with ${log.length} fields.`);
203
+ this.trace.traceUnencryptedLog(contractAddress, log);
203
204
  }
204
205
 
205
206
  /**
@@ -243,21 +244,23 @@ export class AvmPersistableStateManager {
243
244
  */
244
245
  public async processNestedCall(
245
246
  nestedState: AvmPersistableStateManager,
246
- success: boolean,
247
247
  nestedEnvironment: AvmExecutionEnvironment,
248
248
  startGasLeft: Gas,
249
249
  endGasLeft: Gas,
250
250
  bytecode: Buffer,
251
- avmCallResults: AvmContractCallResults,
251
+ avmCallResults: AvmContractCallResult,
252
252
  ) {
253
- if (success) {
253
+ if (!avmCallResults.reverted) {
254
254
  this.acceptNestedCallState(nestedState);
255
255
  }
256
256
  const functionName =
257
257
  (await nestedState.hostStorage.contractsDb.getDebugFunctionName(
258
258
  nestedEnvironment.address,
259
- nestedEnvironment.temporaryFunctionSelector,
260
- )) ?? `${nestedEnvironment.address}:${nestedEnvironment.temporaryFunctionSelector}`;
259
+ nestedEnvironment.functionSelector,
260
+ )) ?? `${nestedEnvironment.address}:${nestedEnvironment.functionSelector}`;
261
+
262
+ this.log.verbose(`[AVM] Calling nested function ${functionName}`);
263
+
261
264
  this.trace.traceNestedCall(
262
265
  nestedState.trace,
263
266
  nestedEnvironment,
@@ -16,7 +16,7 @@ type PublicStorageReadResult = {
16
16
  */
17
17
  export class PublicStorage {
18
18
  /** Cached storage writes. */
19
- private cache: PublicStorageCache;
19
+ private readonly cache: PublicStorageCache;
20
20
 
21
21
  constructor(
22
22
  /** Reference to node storage. Checked on parent cache-miss. */
@@ -134,7 +134,7 @@ class PublicStorageCache {
134
134
  * mapping storage slot to latest staged write value.
135
135
  */
136
136
  public cachePerContract: Map<bigint, Map<bigint, Fr>> = new Map();
137
- // FIXME: storage ^ should be private, but its value is used in tests for "currentStorageValue"
137
+ // FIXME: storage ^ should be private, but its value is used in commitToDB
138
138
 
139
139
  /**
140
140
  * Read a staged value from storage, if it has been previously written to.
@@ -217,20 +217,9 @@ export class EmitUnencryptedLog extends Instruction {
217
217
  static type: string = 'EMITUNENCRYPTEDLOG';
218
218
  static readonly opcode: Opcode = Opcode.EMITUNENCRYPTEDLOG;
219
219
  // Informs (de)serialization. See Instruction.deserialize.
220
- static readonly wireFormat = [
221
- OperandType.UINT8,
222
- OperandType.UINT8,
223
- OperandType.UINT32,
224
- OperandType.UINT32,
225
- OperandType.UINT32,
226
- ];
220
+ static readonly wireFormat = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT32, OperandType.UINT32];
227
221
 
228
- constructor(
229
- private indirect: number,
230
- private eventSelectorOffset: number,
231
- private logOffset: number,
232
- private logSizeOffset: number,
233
- ) {
222
+ constructor(private indirect: number, private logOffset: number, private logSizeOffset: number) {
234
223
  super();
235
224
  }
236
225
 
@@ -241,22 +230,20 @@ export class EmitUnencryptedLog extends Instruction {
241
230
 
242
231
  const memory = context.machineState.memory.track(this.type);
243
232
 
244
- const [eventSelectorOffset, logOffset, logSizeOffset] = Addressing.fromWire(this.indirect).resolve(
245
- [this.eventSelectorOffset, this.logOffset, this.logSizeOffset],
233
+ const [logOffset, logSizeOffset] = Addressing.fromWire(this.indirect).resolve(
234
+ [this.logOffset, this.logSizeOffset],
246
235
  memory,
247
236
  );
248
- memory.checkTag(TypeTag.FIELD, eventSelectorOffset);
249
237
  memory.checkTag(TypeTag.UINT32, logSizeOffset);
250
238
  const logSize = memory.get(logSizeOffset).toNumber();
251
239
  memory.checkTagsRange(TypeTag.FIELD, logOffset, logSize);
252
240
 
253
241
  const contractAddress = context.environment.address;
254
- const event = memory.get(eventSelectorOffset).toFr();
255
242
 
256
- const memoryOperations = { reads: 2 + logSize, indirect: this.indirect };
243
+ const memoryOperations = { reads: 1 + logSize, indirect: this.indirect };
257
244
  context.machineState.consumeGas(this.gasCost(memoryOperations));
258
245
  const log = memory.getSlice(logOffset, logSize).map(f => f.toFr());
259
- context.persistableState.writeUnencryptedLog(contractAddress, event, log);
246
+ context.persistableState.writeUnencryptedLog(contractAddress, log);
260
247
 
261
248
  memory.assert(memoryOperations);
262
249
  context.machineState.incrementPc();
@@ -1,6 +1,6 @@
1
1
  import type { AvmContext } from '../avm_context.js';
2
2
  import type { AvmExecutionEnvironment } from '../avm_execution_environment.js';
3
- import { Field, type MemoryValue, Uint64 } from '../avm_memory_types.js';
3
+ import { Field, type MemoryValue, Uint32, Uint64 } from '../avm_memory_types.js';
4
4
  import { Opcode } from '../serialization/instruction_serialization.js';
5
5
  import { GetterInstruction } from './instruction_impl.js';
6
6
 
@@ -39,21 +39,12 @@ export class Sender extends EnvironmentGetterInstruction {
39
39
  }
40
40
  }
41
41
 
42
- export class FeePerL2Gas extends EnvironmentGetterInstruction {
43
- static type: string = 'FEEPERL2GAS';
44
- static readonly opcode: Opcode = Opcode.FEEPERL2GAS;
45
-
46
- protected getEnvironmentValue(env: AvmExecutionEnvironment) {
47
- return new Field(env.feePerL2Gas);
48
- }
49
- }
50
-
51
- export class FeePerDAGas extends EnvironmentGetterInstruction {
52
- static type: string = 'FEEPERDAGAS';
53
- static readonly opcode: Opcode = Opcode.FEEPERDAGAS;
42
+ export class FunctionSelector extends EnvironmentGetterInstruction {
43
+ static type: string = 'FUNCTIONSELECTOR';
44
+ static readonly opcode: Opcode = Opcode.FUNCTIONSELECTOR;
54
45
 
55
46
  protected getEnvironmentValue(env: AvmExecutionEnvironment) {
56
- return new Field(env.feePerDaGas);
47
+ return new Uint32(env.functionSelector.value);
57
48
  }
58
49
  }
59
50
 
@@ -101,3 +92,21 @@ export class Timestamp extends EnvironmentGetterInstruction {
101
92
  return new Uint64(env.globals.timestamp.toBigInt());
102
93
  }
103
94
  }
95
+
96
+ export class FeePerL2Gas extends EnvironmentGetterInstruction {
97
+ static type: string = 'FEEPERL2GAS';
98
+ static readonly opcode: Opcode = Opcode.FEEPERL2GAS;
99
+
100
+ protected getEnvironmentValue(env: AvmExecutionEnvironment) {
101
+ return new Field(env.globals.gasFees.feePerL2Gas);
102
+ }
103
+ }
104
+
105
+ export class FeePerDAGas extends EnvironmentGetterInstruction {
106
+ static type: string = 'FEEPERDAGAS';
107
+ static readonly opcode: Opcode = Opcode.FEEPERDAGAS;
108
+
109
+ protected getEnvironmentValue(env: AvmExecutionEnvironment) {
110
+ return new Field(env.globals.gasFees.feePerDaGas);
111
+ }
112
+ }
@@ -2,9 +2,9 @@ import { FunctionSelector, Gas } from '@aztec/circuits.js';
2
2
  import { padArrayEnd } from '@aztec/foundation/collection';
3
3
 
4
4
  import type { AvmContext } from '../avm_context.js';
5
+ import { type AvmContractCallResult } from '../avm_contract_call_result.js';
5
6
  import { gasLeftToGas } from '../avm_gas.js';
6
7
  import { Field, TypeTag, Uint8 } from '../avm_memory_types.js';
7
- import { type AvmContractCallResults } from '../avm_message_call_result.js';
8
8
  import { AvmSimulator } from '../avm_simulator.js';
9
9
  import { RethrownError } from '../errors.js';
10
10
  import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
@@ -88,7 +88,7 @@ abstract class ExternalCall extends Instruction {
88
88
  );
89
89
 
90
90
  const simulator = new AvmSimulator(nestedContext);
91
- const nestedCallResults: AvmContractCallResults = await simulator.execute();
91
+ const nestedCallResults: AvmContractCallResult = await simulator.execute();
92
92
  const success = !nestedCallResults.reverted;
93
93
 
94
94
  // TRANSITIONAL: We rethrow here so that the MESSAGE gets propagated.
@@ -120,7 +120,6 @@ abstract class ExternalCall extends Instruction {
120
120
  // Accept the nested call's state and trace the nested call
121
121
  await context.persistableState.processNestedCall(
122
122
  /*nestedState=*/ nestedContext.persistableState,
123
- /*success=*/ success,
124
123
  /*nestedEnvironment=*/ nestedContext.environment,
125
124
  /*startGasLeft=*/ Gas.from(allocatedGas),
126
125
  /*endGasLeft=*/ Gas.from(nestedContext.machineState.gasLeft),
@@ -21,6 +21,7 @@ import {
21
21
  FeePerDAGas,
22
22
  FeePerL2Gas,
23
23
  FieldDiv,
24
+ FunctionSelector,
24
25
  GetContractInstance,
25
26
  InternalCall,
26
27
  InternalReturn,
@@ -85,16 +86,16 @@ const INSTRUCTION_SET = () =>
85
86
  [Address.opcode, Address],
86
87
  [StorageAddress.opcode, StorageAddress],
87
88
  [Sender.opcode, Sender],
88
- [FeePerL2Gas.opcode, FeePerL2Gas],
89
- [FeePerDAGas.opcode, FeePerDAGas],
89
+ [FunctionSelector.opcode, FunctionSelector],
90
90
  [TransactionFee.opcode, TransactionFee],
91
- //[Contractcalldepth.opcode, Contractcalldepth],
92
91
  // Execution Environment - Globals
93
92
  [ChainId.opcode, ChainId],
94
93
  [Version.opcode, Version],
95
94
  [BlockNumber.opcode, BlockNumber],
96
95
  [Timestamp.opcode, Timestamp],
97
96
  //[Coinbase.opcode, Coinbase],
97
+ [FeePerL2Gas.opcode, FeePerL2Gas],
98
+ [FeePerDAGas.opcode, FeePerDAGas],
98
99
  //[Blockl2gaslimit.opcode, Blockl2gaslimit],
99
100
  //[Blockdagaslimit.opcode, Blockdagaslimit],
100
101
  // Execution Environment - Calldata
@@ -27,15 +27,15 @@ export enum Opcode {
27
27
  ADDRESS,
28
28
  STORAGEADDRESS,
29
29
  SENDER,
30
- FEEPERL2GAS,
31
- FEEPERDAGAS,
30
+ FUNCTIONSELECTOR,
32
31
  TRANSACTIONFEE,
33
- CONTRACTCALLDEPTH,
34
32
  CHAINID,
35
33
  VERSION,
36
34
  BLOCKNUMBER,
37
35
  TIMESTAMP,
38
36
  COINBASE,
37
+ FEEPERL2GAS,
38
+ FEEPERDAGAS,
39
39
  BLOCKL2GASLIMIT,
40
40
  BLOCKDAGASLIMIT,
41
41
  CALLDATACOPY,
@@ -678,16 +678,25 @@ export class ClientExecutionContext extends ViewDataOracle {
678
678
 
679
679
  /**
680
680
  * Read the public storage data.
681
+ * @param contractAddress - The address to read storage from.
681
682
  * @param startStorageSlot - The starting storage slot.
683
+ * @param blockNumber - The block number to read storage at.
682
684
  * @param numberOfElements - Number of elements to read from the starting storage slot.
683
685
  */
684
- public override async storageRead(startStorageSlot: Fr, numberOfElements: number): Promise<Fr[]> {
686
+ public override async storageRead(
687
+ contractAddress: Fr,
688
+ startStorageSlot: Fr,
689
+ blockNumber: number,
690
+ numberOfElements: number,
691
+ ): Promise<Fr[]> {
685
692
  const values = [];
686
693
  for (let i = 0n; i < numberOfElements; i++) {
687
694
  const storageSlot = new Fr(startStorageSlot.value + i);
688
695
 
689
- const value = await this.aztecNode.getPublicStorageAt(this.callContext.storageContractAddress, storageSlot);
690
- this.log.debug(`Oracle storage read: slot=${storageSlot.toString()} value=${value}`);
696
+ const value = await this.aztecNode.getPublicStorageAt(contractAddress, storageSlot, blockNumber);
697
+ this.log.debug(
698
+ `Oracle storage read: slot=${storageSlot.toString()} address-${contractAddress.toString()} value=${value}`,
699
+ );
691
700
 
692
701
  values.push(value);
693
702
  }
@@ -260,16 +260,25 @@ export class ViewDataOracle extends TypedOracle {
260
260
 
261
261
  /**
262
262
  * Read the public storage data.
263
+ * @param contractAddress - The address to read storage from.
263
264
  * @param startStorageSlot - The starting storage slot.
265
+ * @param blockNumber - The block number to read storage at.
264
266
  * @param numberOfElements - Number of elements to read from the starting storage slot.
265
267
  */
266
- public override async storageRead(startStorageSlot: Fr, numberOfElements: number) {
268
+ public override async storageRead(
269
+ contractAddress: Fr,
270
+ startStorageSlot: Fr,
271
+ blockNumber: number,
272
+ numberOfElements: number,
273
+ ) {
267
274
  const values = [];
268
275
  for (let i = 0n; i < numberOfElements; i++) {
269
276
  const storageSlot = new Fr(startStorageSlot.value + i);
270
- const value = await this.aztecNode.getPublicStorageAt(this.contractAddress, storageSlot);
277
+ const value = await this.aztecNode.getPublicStorageAt(contractAddress, storageSlot, blockNumber);
271
278
 
272
- this.log.debug(`Oracle storage read: slot=${storageSlot.toString()} value=${value}`);
279
+ this.log.debug(
280
+ `Oracle storage read: slot=${storageSlot.toString()} address-${contractAddress.toString()} value=${value}`,
281
+ );
273
282
  values.push(value);
274
283
  }
275
284
  return values;
@@ -14,10 +14,10 @@ import { makeAztecAddress, makeSelector } from '@aztec/circuits.js/testing';
14
14
  import { FunctionType } from '@aztec/foundation/abi';
15
15
  import { padArrayEnd } from '@aztec/foundation/collection';
16
16
 
17
- import { type PublicExecution, type PublicExecutionResult } from '../public/execution.js';
17
+ import { type PublicExecutionRequest, type PublicExecutionResult } from '../public/execution.js';
18
18
 
19
19
  export class PublicExecutionResultBuilder {
20
- private _execution: PublicExecution;
20
+ private _executionRequest: PublicExecutionRequest;
21
21
  private _nestedExecutions: PublicExecutionResult[] = [];
22
22
  private _contractStorageUpdateRequests: ContractStorageUpdateRequest[] = [];
23
23
  private _contractStorageReads: ContractStorageRead[] = [];
@@ -25,8 +25,8 @@ export class PublicExecutionResultBuilder {
25
25
  private _reverted = false;
26
26
  private _revertReason: SimulationError | undefined = undefined;
27
27
 
28
- constructor(execution: PublicExecution) {
29
- this._execution = execution;
28
+ constructor(executionRequest: PublicExecutionRequest) {
29
+ this._executionRequest = executionRequest;
30
30
  }
31
31
 
32
32
  static fromPublicCallRequest({
@@ -120,7 +120,7 @@ export class PublicExecutionResultBuilder {
120
120
 
121
121
  build(overrides: Partial<PublicExecutionResult> = {}): PublicExecutionResult {
122
122
  return {
123
- execution: this._execution,
123
+ executionRequest: this._executionRequest,
124
124
  nestedExecutions: this._nestedExecutions,
125
125
  noteHashReadRequests: [],
126
126
  nullifierReadRequests: [],
@@ -57,7 +57,7 @@ import { computeVarArgsHash } from '@aztec/circuits.js/hash';
57
57
  import { padArrayEnd } from '@aztec/foundation/collection';
58
58
  import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
59
59
  import {
60
- type PublicExecution,
60
+ type PublicExecutionRequest,
61
61
  type PublicExecutionResult,
62
62
  type PublicExecutor,
63
63
  accumulateReturnValues,
@@ -176,12 +176,14 @@ export abstract class AbstractPhaseManager {
176
176
  call => revertibleCallStack.find(p => p.equals(call)) || nonRevertibleCallStack.find(p => p.equals(call)),
177
177
  );
178
178
 
179
+ const teardownCallStack = tx.publicTeardownFunctionCall.isEmpty() ? [] : [tx.publicTeardownFunctionCall];
180
+
179
181
  if (callRequestsStack.length === 0) {
180
182
  return {
181
183
  [PublicKernelType.NON_PUBLIC]: [],
182
184
  [PublicKernelType.SETUP]: [],
183
185
  [PublicKernelType.APP_LOGIC]: [],
184
- [PublicKernelType.TEARDOWN]: [],
186
+ [PublicKernelType.TEARDOWN]: teardownCallStack,
185
187
  [PublicKernelType.TAIL]: [],
186
188
  };
187
189
  }
@@ -191,8 +193,6 @@ export abstract class AbstractPhaseManager {
191
193
  c => revertibleCallStack.findIndex(p => p.equals(c)) !== -1,
192
194
  );
193
195
 
194
- const teardownCallStack = tx.publicTeardownFunctionCall.isEmpty() ? [] : [tx.publicTeardownFunctionCall];
195
-
196
196
  if (firstRevertibleCallIndex === 0) {
197
197
  return {
198
198
  [PublicKernelType.NON_PUBLIC]: [],
@@ -256,7 +256,7 @@ export abstract class AbstractPhaseManager {
256
256
  const enqueuedCallResults = [];
257
257
 
258
258
  for (const enqueuedCall of enqueuedCalls) {
259
- const executionStack: (PublicExecution | PublicExecutionResult)[] = [enqueuedCall];
259
+ const executionStack: (PublicExecutionRequest | PublicExecutionResult)[] = [enqueuedCall];
260
260
 
261
261
  // Keep track of which result is for the top/enqueued call
262
262
  let enqueuedExecutionResult: PublicExecutionResult | undefined;
@@ -283,10 +283,10 @@ export abstract class AbstractPhaseManager {
283
283
 
284
284
  // Sanity check for a current upstream assumption.
285
285
  // Consumers of the result seem to expect "reverted <=> revertReason !== undefined".
286
- const functionSelector = result.execution.functionSelector.toString();
286
+ const functionSelector = result.executionRequest.functionSelector.toString();
287
287
  if (result.reverted && !result.revertReason) {
288
288
  throw new Error(
289
- `Simulation of ${result.execution.contractAddress.toString()}:${functionSelector}(${
289
+ `Simulation of ${result.executionRequest.contractAddress.toString()}:${functionSelector}(${
290
290
  result.functionName
291
291
  }) reverted with no reason.`,
292
292
  );
@@ -294,7 +294,7 @@ export abstract class AbstractPhaseManager {
294
294
 
295
295
  if (result.reverted && !PhaseIsRevertible[this.phase]) {
296
296
  this.log.debug(
297
- `Simulation error on ${result.execution.contractAddress.toString()}:${functionSelector}(${
297
+ `Simulation error on ${result.executionRequest.contractAddress.toString()}:${functionSelector}(${
298
298
  result.functionName
299
299
  }) with reason: ${result.revertReason}`,
300
300
  );
@@ -308,7 +308,7 @@ export abstract class AbstractPhaseManager {
308
308
 
309
309
  // Simulate the public kernel circuit.
310
310
  this.log.debug(
311
- `Running public kernel circuit for ${result.execution.contractAddress.toString()}:${functionSelector}(${
311
+ `Running public kernel circuit for ${result.executionRequest.contractAddress.toString()}:${functionSelector}(${
312
312
  result.functionName
313
313
  })`,
314
314
  );
@@ -331,7 +331,7 @@ export abstract class AbstractPhaseManager {
331
331
  // but the kernel carries the reverted flag forward. But if the simulator reverts, so should the kernel.
332
332
  if (result.reverted && kernelPublicOutput.revertCode.isOK()) {
333
333
  throw new Error(
334
- `Public kernel circuit did not revert on ${result.execution.contractAddress.toString()}:${functionSelector}(${
334
+ `Public kernel circuit did not revert on ${result.executionRequest.contractAddress.toString()}:${functionSelector}(${
335
335
  result.functionName
336
336
  }), but simulator did.`,
337
337
  );
@@ -341,7 +341,7 @@ export abstract class AbstractPhaseManager {
341
341
  // So safely return the revert reason and the kernel output (which has had its revertible side effects dropped)
342
342
  if (result.reverted) {
343
343
  this.log.debug(
344
- `Reverting on ${result.execution.contractAddress.toString()}:${functionSelector}(${
344
+ `Reverting on ${result.executionRequest.contractAddress.toString()}:${functionSelector}(${
345
345
  result.functionName
346
346
  }) with reason: ${result.revertReason}`,
347
347
  );
@@ -430,9 +430,9 @@ export abstract class AbstractPhaseManager {
430
430
  );
431
431
 
432
432
  const publicCircuitPublicInputs = PublicCircuitPublicInputs.from({
433
- callContext: result.execution.callContext,
433
+ callContext: result.executionRequest.callContext,
434
434
  proverAddress: AztecAddress.ZERO,
435
- argsHash: computeVarArgsHash(result.execution.args),
435
+ argsHash: computeVarArgsHash(result.executionRequest.args),
436
436
  newNoteHashes: padArrayEnd(result.newNoteHashes, NoteHash.empty(), MAX_NEW_NOTE_HASHES_PER_CALL),
437
437
  newNullifiers: padArrayEnd(result.newNullifiers, Nullifier.empty(), MAX_NEW_NULLIFIERS_PER_CALL),
438
438
  newL2ToL1Msgs: padArrayEnd(result.newL2ToL1Messages, L2ToL1Message.empty(), MAX_NEW_L2_TO_L1_MSGS_PER_CALL),
@@ -481,8 +481,8 @@ export abstract class AbstractPhaseManager {
481
481
  });
482
482
 
483
483
  return new PublicCallStackItem(
484
- result.execution.contractAddress,
485
- new FunctionData(result.execution.functionSelector, false),
484
+ result.executionRequest.contractAddress,
485
+ new FunctionData(result.executionRequest.functionSelector, false),
486
486
  publicCircuitPublicInputs,
487
487
  isExecutionRequest,
488
488
  );
@@ -18,8 +18,8 @@ import { type Gas } from '../avm/avm_gas.js';
18
18
  * The public function execution result.
19
19
  */
20
20
  export interface PublicExecutionResult {
21
- /** The execution that triggered this result. */
22
- execution: PublicExecution;
21
+ /** The execution request that triggered this result. */
22
+ executionRequest: PublicExecutionRequest;
23
23
 
24
24
  /** The side effect counter at the start of the function call. */
25
25
  startSideEffectCounter: Fr;
@@ -90,9 +90,13 @@ export interface PublicExecutionResult {
90
90
  }
91
91
 
92
92
  /**
93
- * The execution of a public function.
93
+ * The execution request of a public function.
94
+ * A subset of PublicCallRequest
94
95
  */
95
- export type PublicExecution = Pick<PublicCallRequest, 'contractAddress' | 'functionSelector' | 'callContext' | 'args'>;
96
+ export type PublicExecutionRequest = Pick<
97
+ PublicCallRequest,
98
+ 'contractAddress' | 'functionSelector' | 'callContext' | 'args'
99
+ >;
96
100
 
97
101
  /**
98
102
  * Returns if the input is a public execution result and not just a public execution.
@@ -100,9 +104,9 @@ export type PublicExecution = Pick<PublicCallRequest, 'contractAddress' | 'funct
100
104
  * @returns Whether the input is a public execution result and not just a public execution.
101
105
  */
102
106
  export function isPublicExecutionResult(
103
- input: PublicExecution | PublicExecutionResult,
107
+ input: PublicExecutionRequest | PublicExecutionResult,
104
108
  ): input is PublicExecutionResult {
105
- return 'execution' in input && input.execution !== undefined;
109
+ return 'executionRequest' in input && input.executionRequest !== undefined;
106
110
  }
107
111
 
108
112
  /**
@@ -4,21 +4,21 @@ import { createDebugLogger } from '@aztec/foundation/log';
4
4
  import { Timer } from '@aztec/foundation/timer';
5
5
 
6
6
  import { AvmContext } from '../avm/avm_context.js';
7
+ import { AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
7
8
  import { AvmMachineState } from '../avm/avm_machine_state.js';
8
9
  import { AvmSimulator } from '../avm/avm_simulator.js';
9
10
  import { HostStorage } from '../avm/journal/host_storage.js';
10
11
  import { AvmPersistableStateManager } from '../avm/journal/index.js';
11
12
  import { type CommitmentsDB, type PublicContractsDB, type PublicStateDB } from './db_interfaces.js';
12
- import { type PublicExecution, type PublicExecutionResult, checkValidStaticCall } from './execution.js';
13
+ import { type PublicExecutionRequest, type PublicExecutionResult } from './execution.js';
13
14
  import { PublicSideEffectTrace } from './side_effect_trace.js';
14
- import { createAvmExecutionEnvironment } from './transitional_adaptors.js';
15
15
 
16
16
  /**
17
17
  * Handles execution of public functions.
18
18
  */
19
19
  export class PublicExecutor {
20
20
  constructor(
21
- private readonly stateDb: PublicStateDB,
21
+ private readonly publicStorageDB: PublicStateDB,
22
22
  private readonly contractsDb: PublicContractsDB,
23
23
  private readonly commitmentsDb: CommitmentsDB,
24
24
  private readonly header: Header,
@@ -38,10 +38,10 @@ export class PublicExecutor {
38
38
  * @returns The result of execution, including the results of all nested calls.
39
39
  */
40
40
  public async simulate(
41
- executionRequest: PublicExecution,
41
+ executionRequest: PublicExecutionRequest,
42
42
  globalVariables: GlobalVariables,
43
43
  availableGas: Gas,
44
- txContext: TxContext,
44
+ _txContext: TxContext,
45
45
  pendingSiloedNullifiers: Nullifier[],
46
46
  transactionFee: Fr = Fr.ZERO,
47
47
  startSideEffectCounter: number = 0,
@@ -53,7 +53,7 @@ export class PublicExecutor {
53
53
  PublicExecutor.log.verbose(`[AVM] Executing public external function ${fnName}.`);
54
54
  const timer = new Timer();
55
55
 
56
- const hostStorage = new HostStorage(this.stateDb, this.contractsDb, this.commitmentsDb);
56
+ const hostStorage = new HostStorage(this.publicStorageDB, this.contractsDb, this.commitmentsDb);
57
57
  const trace = new PublicSideEffectTrace(startSideEffectCounter);
58
58
  const avmPersistableState = AvmPersistableStateManager.newWithPendingSiloedNullifiers(
59
59
  hostStorage,
@@ -65,7 +65,6 @@ export class PublicExecutor {
65
65
  executionRequest,
66
66
  this.header,
67
67
  globalVariables,
68
- txContext.gasSettings,
69
68
  transactionFee,
70
69
  );
71
70
 
@@ -75,7 +74,7 @@ export class PublicExecutor {
75
74
  const avmResult = await simulator.execute();
76
75
  const bytecode = simulator.getBytecode()!;
77
76
 
78
- // Commit the journals state to the DBs since this is a top-level execution.
77
+ // Commit the public storage state to the DBs since this is a top-level execution.
79
78
  // Observe that this will write all the state changes to the DBs, not only the latest for each slot.
80
79
  // However, the underlying DB keep a cache and will only write the latest state to disk.
81
80
  // TODO(dbanks12): this should be unnecessary here or should be exposed by state manager
@@ -105,18 +104,34 @@ export class PublicExecutor {
105
104
  // (which counts the request itself)
106
105
  );
107
106
 
108
- // TODO(https://github.com/AztecProtocol/aztec-packages/issues/5818): is this really needed?
109
- // should already be handled in simulation.
110
- if (executionRequest.callContext.isStaticCall) {
111
- checkValidStaticCall(
112
- publicExecutionResult.newNoteHashes,
113
- publicExecutionResult.newNullifiers,
114
- publicExecutionResult.contractStorageUpdateRequests,
115
- publicExecutionResult.newL2ToL1Messages,
116
- publicExecutionResult.unencryptedLogs,
117
- );
118
- }
119
-
120
107
  return publicExecutionResult;
121
108
  }
122
109
  }
110
+
111
+ /**
112
+ * Convert a PublicExecutionRequest object to an AvmExecutionEnvironment
113
+ *
114
+ * @param executionRequest
115
+ * @param globalVariables
116
+ * @returns
117
+ */
118
+ function createAvmExecutionEnvironment(
119
+ executionRequest: PublicExecutionRequest,
120
+ header: Header,
121
+ globalVariables: GlobalVariables,
122
+ transactionFee: Fr,
123
+ ): AvmExecutionEnvironment {
124
+ return new AvmExecutionEnvironment(
125
+ executionRequest.contractAddress,
126
+ executionRequest.callContext.storageContractAddress,
127
+ executionRequest.callContext.msgSender,
128
+ executionRequest.functionSelector,
129
+ /*contractCallDepth=*/ Fr.zero(),
130
+ transactionFee,
131
+ header,
132
+ globalVariables,
133
+ executionRequest.callContext.isStaticCall,
134
+ executionRequest.callContext.isDelegateCall,
135
+ executionRequest.args,
136
+ );
137
+ }
@@ -1,6 +1,6 @@
1
1
  export * from './abstract_phase_manager.js';
2
2
  export * from './db_interfaces.js';
3
- export { isPublicExecutionResult, type PublicExecution, type PublicExecutionResult } from './execution.js';
3
+ export { isPublicExecutionResult, type PublicExecutionRequest, type PublicExecutionResult } from './execution.js';
4
4
  export { PublicExecutor } from './executor.js';
5
5
  export * from './fee_payment.js';
6
6
  export { HintsBuilder } from './hints_builder.js';
@@ -21,8 +21,9 @@ import {
21
21
  convertSimulatedPublicTeardownInputsToWitnessMap,
22
22
  convertSimulatedPublicTeardownOutputFromWitnessMap,
23
23
  } from '@aztec/noir-protocol-circuits-types';
24
- import { type SimulationProvider, WASMSimulator } from '@aztec/simulator';
25
24
 
25
+ import { WASMSimulator } from '../providers/acvm_wasm.js';
26
+ import { type SimulationProvider } from '../providers/simulation_provider.js';
26
27
  import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
27
28
 
28
29
  /**