@aztec/simulator 0.43.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 (155) hide show
  1. package/dest/acvm/oracle/oracle.d.ts +3 -1
  2. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  3. package/dest/acvm/oracle/oracle.js +12 -6
  4. package/dest/acvm/oracle/typed_oracle.d.ts +6 -4
  5. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  6. package/dest/acvm/oracle/typed_oracle.js +8 -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 +8 -10
  14. package/dest/avm/avm_execution_environment.d.ts.map +1 -1
  15. package/dest/avm/avm_execution_environment.js +15 -19
  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 -8
  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 +10 -6
  25. package/dest/avm/fixtures/index.d.ts.map +1 -1
  26. package/dest/avm/fixtures/index.js +10 -17
  27. package/dest/avm/journal/journal.d.ts +56 -65
  28. package/dest/avm/journal/journal.d.ts.map +1 -1
  29. package/dest/avm/journal/journal.js +80 -117
  30. package/dest/avm/journal/nullifiers.d.ts +21 -8
  31. package/dest/avm/journal/nullifiers.d.ts.map +1 -1
  32. package/dest/avm/journal/nullifiers.js +26 -8
  33. package/dest/avm/journal/public_storage.d.ts +5 -1
  34. package/dest/avm/journal/public_storage.d.ts.map +1 -1
  35. package/dest/avm/journal/public_storage.js +11 -2
  36. package/dest/avm/opcodes/accrued_substate.d.ts +1 -2
  37. package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
  38. package/dest/avm/opcodes/accrued_substate.js +8 -17
  39. package/dest/avm/opcodes/environment_getters.d.ts +13 -8
  40. package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
  41. package/dest/avm/opcodes/environment_getters.js +20 -13
  42. package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
  43. package/dest/avm/opcodes/external_calls.js +11 -27
  44. package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
  45. package/dest/avm/serialization/bytecode_serialization.js +5 -5
  46. package/dest/avm/serialization/instruction_serialization.d.ts +9 -9
  47. package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
  48. package/dest/avm/serialization/instruction_serialization.js +10 -10
  49. package/dest/avm/test_utils.d.ts +14 -0
  50. package/dest/avm/test_utils.d.ts.map +1 -0
  51. package/dest/avm/test_utils.js +36 -0
  52. package/dest/client/client_execution_context.d.ts +6 -4
  53. package/dest/client/client_execution_context.d.ts.map +1 -1
  54. package/dest/client/client_execution_context.js +8 -6
  55. package/dest/client/execution_note_cache.d.ts.map +1 -1
  56. package/dest/client/execution_note_cache.js +1 -1
  57. package/dest/client/execution_result.d.ts +2 -1
  58. package/dest/client/execution_result.d.ts.map +1 -1
  59. package/dest/client/execution_result.js +1 -1
  60. package/dest/client/index.d.ts +2 -0
  61. package/dest/client/index.d.ts.map +1 -1
  62. package/dest/client/index.js +3 -1
  63. package/dest/client/simulator.d.ts +3 -3
  64. package/dest/client/simulator.d.ts.map +1 -1
  65. package/dest/client/simulator.js +1 -1
  66. package/dest/client/view_data_oracle.d.ts +5 -1
  67. package/dest/client/view_data_oracle.d.ts.map +1 -1
  68. package/dest/client/view_data_oracle.js +12 -4
  69. package/dest/mocks/fixtures.d.ts +3 -3
  70. package/dest/mocks/fixtures.d.ts.map +1 -1
  71. package/dest/mocks/fixtures.js +6 -5
  72. package/dest/public/abstract_phase_manager.d.ts +1 -0
  73. package/dest/public/abstract_phase_manager.d.ts.map +1 -1
  74. package/dest/public/abstract_phase_manager.js +17 -14
  75. package/dest/public/app_logic_phase_manager.d.ts.map +1 -1
  76. package/dest/public/app_logic_phase_manager.js +2 -1
  77. package/dest/public/execution.d.ts +33 -30
  78. package/dest/public/execution.d.ts.map +1 -1
  79. package/dest/public/execution.js +2 -2
  80. package/dest/public/executor.d.ts +12 -7
  81. package/dest/public/executor.d.ts.map +1 -1
  82. package/dest/public/executor.js +42 -33
  83. package/dest/public/hints_builder.d.ts +1 -1
  84. package/dest/public/index.d.ts +1 -1
  85. package/dest/public/index.d.ts.map +1 -1
  86. package/dest/public/index.js +1 -1
  87. package/dest/public/public_kernel.d.ts +1 -1
  88. package/dest/public/public_kernel.d.ts.map +1 -1
  89. package/dest/public/public_kernel.js +2 -2
  90. package/dest/public/public_processor.d.ts +5 -2
  91. package/dest/public/public_processor.d.ts.map +1 -1
  92. package/dest/public/public_processor.js +142 -123
  93. package/dest/public/side_effect_trace.d.ts +87 -0
  94. package/dest/public/side_effect_trace.d.ts.map +1 -0
  95. package/dest/public/side_effect_trace.js +236 -0
  96. package/dest/public/side_effect_trace_interface.d.ts +36 -0
  97. package/dest/public/side_effect_trace_interface.d.ts.map +1 -0
  98. package/dest/public/side_effect_trace_interface.js +2 -0
  99. package/dest/public/teardown_phase_manager.d.ts.map +1 -1
  100. package/dest/public/teardown_phase_manager.js +2 -1
  101. package/dest/rollup/rollup.d.ts +1 -1
  102. package/dest/rollup/rollup.d.ts.map +1 -1
  103. package/dest/rollup/rollup.js +2 -2
  104. package/package.json +18 -9
  105. package/src/acvm/oracle/oracle.ts +23 -5
  106. package/src/acvm/oracle/typed_oracle.ts +23 -4
  107. package/src/avm/avm_context.ts +2 -2
  108. package/src/avm/{avm_message_call_result.ts → avm_contract_call_result.ts} +1 -1
  109. package/src/avm/avm_execution_environment.ts +16 -26
  110. package/src/avm/avm_gas.ts +1 -1
  111. package/src/avm/avm_simulator.ts +10 -13
  112. package/src/avm/bytecode_utils.ts +32 -0
  113. package/src/avm/errors.ts +1 -1
  114. package/src/avm/fixtures/index.ts +21 -23
  115. package/src/avm/journal/journal.ts +118 -224
  116. package/src/avm/journal/nullifiers.ts +30 -13
  117. package/src/avm/journal/public_storage.ts +12 -2
  118. package/src/avm/opcodes/accrued_substate.ts +12 -21
  119. package/src/avm/opcodes/environment_getters.ts +23 -14
  120. package/src/avm/opcodes/external_calls.ts +13 -36
  121. package/src/avm/serialization/bytecode_serialization.ts +4 -3
  122. package/src/avm/serialization/instruction_serialization.ts +3 -3
  123. package/src/avm/test_utils.ts +53 -0
  124. package/src/client/client_execution_context.ts +22 -7
  125. package/src/client/execution_note_cache.ts +0 -1
  126. package/src/client/execution_result.ts +2 -1
  127. package/src/client/index.ts +2 -0
  128. package/src/client/simulator.ts +8 -2
  129. package/src/client/view_data_oracle.ts +20 -3
  130. package/src/mocks/fixtures.ts +7 -6
  131. package/src/public/abstract_phase_manager.ts +32 -21
  132. package/src/public/app_logic_phase_manager.ts +1 -0
  133. package/src/public/execution.ts +45 -31
  134. package/src/public/executor.ts +71 -49
  135. package/src/public/index.ts +1 -1
  136. package/src/public/public_kernel.ts +2 -1
  137. package/src/public/public_processor.ts +11 -2
  138. package/src/public/side_effect_trace.ts +341 -0
  139. package/src/public/side_effect_trace_interface.ts +41 -0
  140. package/src/public/teardown_phase_manager.ts +1 -0
  141. package/src/rollup/rollup.ts +3 -1
  142. package/dest/avm/avm_message_call_result.d.ts.map +0 -1
  143. package/dest/avm/avm_message_call_result.js +0 -18
  144. package/dest/avm/journal/trace.d.ts +0 -33
  145. package/dest/avm/journal/trace.d.ts.map +0 -1
  146. package/dest/avm/journal/trace.js +0 -152
  147. package/dest/avm/journal/trace_types.d.ts +0 -55
  148. package/dest/avm/journal/trace_types.d.ts.map +0 -1
  149. package/dest/avm/journal/trace_types.js +0 -2
  150. package/dest/public/transitional_adaptors.d.ts +0 -21
  151. package/dest/public/transitional_adaptors.d.ts.map +0 -1
  152. package/dest/public/transitional_adaptors.js +0 -90
  153. package/src/avm/journal/trace.ts +0 -181
  154. package/src/avm/journal/trace_types.ts +0 -91
  155. package/src/public/transitional_adaptors.ts +0 -168
@@ -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
+ }
@@ -1,11 +1,10 @@
1
1
  import { FunctionSelector, Gas } from '@aztec/circuits.js';
2
2
  import { padArrayEnd } from '@aztec/foundation/collection';
3
3
 
4
- import { convertAvmResultsToPxResult, createPublicExecution } from '../../public/transitional_adaptors.js';
5
4
  import type { AvmContext } from '../avm_context.js';
5
+ import { type AvmContractCallResult } from '../avm_contract_call_result.js';
6
6
  import { gasLeftToGas } from '../avm_gas.js';
7
7
  import { Field, TypeTag, Uint8 } from '../avm_memory_types.js';
8
- import { type AvmContractCallResults } from '../avm_message_call_result.js';
9
8
  import { AvmSimulator } from '../avm_simulator.js';
10
9
  import { RethrownError } from '../errors.js';
11
10
  import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
@@ -24,7 +23,6 @@ abstract class ExternalCall extends Instruction {
24
23
  OperandType.UINT32,
25
24
  OperandType.UINT32,
26
25
  OperandType.UINT32,
27
- /* temporary function selector */
28
26
  OperandType.UINT32,
29
27
  ];
30
28
 
@@ -37,8 +35,8 @@ abstract class ExternalCall extends Instruction {
37
35
  private retOffset: number,
38
36
  private retSize: number,
39
37
  private successOffset: number,
40
- // Function selector is temporary since eventually public contract bytecode will be one blob
41
- // containing all functions, and function selector will become an application-level mechanism
38
+ // NOTE: Function selector is likely temporary since eventually public contract bytecode will be one
39
+ // blob containing all functions, and function selector will become an application-level mechanism
42
40
  // (e.g. first few bytes of calldata + compiler-generated jump table)
43
41
  private functionSelectorOffset: number,
44
42
  ) {
@@ -81,7 +79,6 @@ abstract class ExternalCall extends Instruction {
81
79
  const allocatedGas = { l2Gas: allocatedL2Gas, daGas: allocatedDaGas };
82
80
  context.machineState.consumeGas(allocatedGas);
83
81
 
84
- // TRANSITIONAL: This should be removed once the kernel handles and entire enqueued call per circuit
85
82
  const nestedContext = context.createNestedContractCallContext(
86
83
  callAddress.toFr(),
87
84
  calldata,
@@ -89,32 +86,9 @@ abstract class ExternalCall extends Instruction {
89
86
  callType,
90
87
  FunctionSelector.fromField(functionSelector),
91
88
  );
92
- const startSideEffectCounter = nestedContext.persistableState.trace.accessCounter;
93
89
 
94
- const oldStyleExecution = createPublicExecution(startSideEffectCounter, nestedContext.environment, calldata);
95
90
  const simulator = new AvmSimulator(nestedContext);
96
- const nestedCallResults: AvmContractCallResults = await simulator.execute();
97
- const pxResults = convertAvmResultsToPxResult(
98
- nestedCallResults,
99
- startSideEffectCounter,
100
- oldStyleExecution,
101
- Gas.from(allocatedGas),
102
- nestedContext,
103
- simulator.getBytecode(),
104
- );
105
- // store the old PublicExecutionResult object to maintain a recursive data structure for the old kernel
106
- context.persistableState.transitionalExecutionResult.nestedExecutions.push(pxResults);
107
- // END TRANSITIONAL
108
-
109
- // const nestedContext = context.createNestedContractCallContext(
110
- // callAddress.toFr(),
111
- // calldata,
112
- // allocatedGas,
113
- // this.type,
114
- // FunctionSelector.fromField(functionSelector),
115
- // );
116
- // const nestedCallResults: AvmContractCallResults = await new AvmSimulator(nestedContext).execute();
117
-
91
+ const nestedCallResults: AvmContractCallResult = await simulator.execute();
118
92
  const success = !nestedCallResults.reverted;
119
93
 
120
94
  // TRANSITIONAL: We rethrow here so that the MESSAGE gets propagated.
@@ -143,12 +117,15 @@ abstract class ExternalCall extends Instruction {
143
117
  // Refund unused gas
144
118
  context.machineState.refundGas(gasLeftToGas(nestedContext.machineState));
145
119
 
146
- // TODO: Should we merge the changes from a nested call in the case of a STATIC call?
147
- if (success) {
148
- context.persistableState.acceptNestedCallState(nestedContext.persistableState);
149
- } else {
150
- context.persistableState.rejectNestedCallState(nestedContext.persistableState);
151
- }
120
+ // Accept the nested call's state and trace the nested call
121
+ await context.persistableState.processNestedCall(
122
+ /*nestedState=*/ nestedContext.persistableState,
123
+ /*nestedEnvironment=*/ nestedContext.environment,
124
+ /*startGasLeft=*/ Gas.from(allocatedGas),
125
+ /*endGasLeft=*/ Gas.from(nestedContext.machineState.gasLeft),
126
+ /*bytecode=*/ simulator.getBytecode()!,
127
+ /*avmCallResults=*/ nestedCallResults,
128
+ );
152
129
 
153
130
  memory.assert(memoryOperations);
154
131
  context.machineState.incrementPc();
@@ -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,
@@ -0,0 +1,53 @@
1
+ import { Fr } from '@aztec/circuits.js';
2
+ import { type ContractInstanceWithAddress } from '@aztec/types/contracts';
3
+
4
+ import { type jest } from '@jest/globals';
5
+ import { mock } from 'jest-mock-extended';
6
+
7
+ import { type CommitmentsDB, type PublicContractsDB, type PublicStateDB } from '../public/db_interfaces.js';
8
+ import { type PublicSideEffectTraceInterface } from '../public/side_effect_trace_interface.js';
9
+ import { type HostStorage } from './journal/host_storage.js';
10
+
11
+ export function mockGetBytecode(hs: HostStorage, bytecode: Buffer) {
12
+ (hs as jest.Mocked<HostStorage>).contractsDb.getBytecode.mockResolvedValue(bytecode);
13
+ }
14
+
15
+ export function mockTraceFork(trace: PublicSideEffectTraceInterface, nestedTrace?: PublicSideEffectTraceInterface) {
16
+ (trace as jest.Mocked<PublicSideEffectTraceInterface>).fork.mockReturnValue(
17
+ nestedTrace ?? mock<PublicSideEffectTraceInterface>(),
18
+ );
19
+ }
20
+
21
+ export function mockStorageRead(hs: HostStorage, value: Fr) {
22
+ (hs.publicStateDb as jest.Mocked<PublicStateDB>).storageRead.mockResolvedValue(value);
23
+ }
24
+
25
+ export function mockStorageReadWithMap(hs: HostStorage, mockedStorage: Map<bigint, Fr>) {
26
+ (hs.publicStateDb as jest.Mocked<PublicStateDB>).storageRead.mockImplementation((_address, slot) =>
27
+ Promise.resolve(mockedStorage.get(slot.toBigInt()) ?? Fr.ZERO),
28
+ );
29
+ }
30
+
31
+ export function mockNoteHashExists(hs: HostStorage, leafIndex: Fr, _value?: Fr) {
32
+ (hs.commitmentsDb as jest.Mocked<CommitmentsDB>).getCommitmentIndex.mockResolvedValue(leafIndex.toBigInt());
33
+ }
34
+
35
+ export function mockNullifierExists(hs: HostStorage, leafIndex: Fr, _value?: Fr) {
36
+ (hs.commitmentsDb as jest.Mocked<CommitmentsDB>).getNullifierIndex.mockResolvedValue(leafIndex.toBigInt());
37
+ }
38
+
39
+ export function mockL1ToL2MessageExists(hs: HostStorage, leafIndex: Fr, value: Fr, valueAtOtherIndices?: Fr) {
40
+ (hs.commitmentsDb as jest.Mocked<CommitmentsDB>).getL1ToL2LeafValue.mockImplementation((index: bigint) => {
41
+ if (index == leafIndex.toBigInt()) {
42
+ return Promise.resolve(value);
43
+ } else {
44
+ // any indices other than mockAtLeafIndex will return a different value
45
+ // (or undefined if no value is specified for other indices)
46
+ return Promise.resolve(valueAtOtherIndices!);
47
+ }
48
+ });
49
+ }
50
+
51
+ export function mockGetContractInstance(hs: HostStorage, contractInstance: ContractInstanceWithAddress) {
52
+ (hs.contractsDb as jest.Mocked<PublicContractsDB>).getContractInstance.mockResolvedValue(contractInstance);
53
+ }
@@ -22,7 +22,13 @@ import {
22
22
  } from '@aztec/circuits.js';
23
23
  import { Aes128 } from '@aztec/circuits.js/barretenberg';
24
24
  import { computeUniqueNoteHash, siloNoteHash } from '@aztec/circuits.js/hash';
25
- import { type FunctionAbi, type FunctionArtifact, countArgumentsSize } from '@aztec/foundation/abi';
25
+ import {
26
+ EventSelector,
27
+ type FunctionAbi,
28
+ type FunctionArtifact,
29
+ type NoteSelector,
30
+ countArgumentsSize,
31
+ } from '@aztec/foundation/abi';
26
32
  import { AztecAddress } from '@aztec/foundation/aztec-address';
27
33
  import { pedersenHash } from '@aztec/foundation/crypto';
28
34
  import { Fr, GrumpkinScalar, type Point } from '@aztec/foundation/fields';
@@ -288,7 +294,7 @@ export class ClientExecutionContext extends ViewDataOracle {
288
294
  */
289
295
  public override notifyCreatedNote(
290
296
  storageSlot: Fr,
291
- noteTypeId: Fr,
297
+ noteTypeId: NoteSelector,
292
298
  noteItems: Fr[],
293
299
  innerNoteHash: Fr,
294
300
  counter: number,
@@ -382,7 +388,7 @@ export class ClientExecutionContext extends ViewDataOracle {
382
388
  preimage: Fr[],
383
389
  ) {
384
390
  const event = new Event(preimage);
385
- const l1EventPayload = new L1EventPayload(event, contractAddress, randomness, eventTypeId);
391
+ const l1EventPayload = new L1EventPayload(event, contractAddress, randomness, EventSelector.fromField(eventTypeId));
386
392
  const taggedEvent = new TaggedLog(l1EventPayload);
387
393
 
388
394
  const ephSk = GrumpkinScalar.random();
@@ -404,7 +410,7 @@ export class ClientExecutionContext extends ViewDataOracle {
404
410
  public override computeEncryptedNoteLog(
405
411
  contractAddress: AztecAddress,
406
412
  storageSlot: Fr,
407
- noteTypeId: Fr,
413
+ noteTypeId: NoteSelector,
408
414
  ovKeys: KeyValidationRequest,
409
415
  ivpkM: Point,
410
416
  preimage: Fr[],
@@ -672,16 +678,25 @@ export class ClientExecutionContext extends ViewDataOracle {
672
678
 
673
679
  /**
674
680
  * Read the public storage data.
681
+ * @param contractAddress - The address to read storage from.
675
682
  * @param startStorageSlot - The starting storage slot.
683
+ * @param blockNumber - The block number to read storage at.
676
684
  * @param numberOfElements - Number of elements to read from the starting storage slot.
677
685
  */
678
- 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[]> {
679
692
  const values = [];
680
693
  for (let i = 0n; i < numberOfElements; i++) {
681
694
  const storageSlot = new Fr(startStorageSlot.value + i);
682
695
 
683
- const value = await this.aztecNode.getPublicStorageAt(this.callContext.storageContractAddress, storageSlot);
684
- 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
+ );
685
700
 
686
701
  values.push(value);
687
702
  }
@@ -63,7 +63,6 @@ export class ExecutionNoteCache {
63
63
  nullifiedNoteHashCounter = note.counter;
64
64
  this.newNotes.set(contractAddress.toBigInt(), notes);
65
65
  }
66
-
67
66
  return nullifiedNoteHashCounter;
68
67
  }
69
68
 
@@ -8,6 +8,7 @@ import {
8
8
  type UnencryptedL2Log,
9
9
  } from '@aztec/circuit-types';
10
10
  import { type IsEmpty, type PrivateCallStackItem, PublicCallRequest, sortByCounter } from '@aztec/circuits.js';
11
+ import { type NoteSelector } from '@aztec/foundation/abi';
11
12
  import { type Fr } from '@aztec/foundation/fields';
12
13
 
13
14
  import { type ACVMField } from '../acvm/index.js';
@@ -21,7 +22,7 @@ export interface NoteAndSlot {
21
22
  /** The storage slot of the note. */
22
23
  storageSlot: Fr;
23
24
  /** The note type identifier. */
24
- noteTypeId: Fr;
25
+ noteTypeId: NoteSelector;
25
26
  }
26
27
 
27
28
  export class CountedLog<TLog extends UnencryptedL2Log | EncryptedL2NoteLog | EncryptedL2Log> implements IsEmpty {
@@ -1,3 +1,5 @@
1
1
  export * from './simulator.js';
2
2
  export * from './db_oracle.js';
3
3
  export * from './execution_result.js';
4
+ export * from './pick_notes.js';
5
+ export * from './execution_note_cache.js';
@@ -5,6 +5,7 @@ import {
5
5
  type FunctionArtifact,
6
6
  FunctionSelector,
7
7
  FunctionType,
8
+ type NoteSelector,
8
9
  encodeArguments,
9
10
  } from '@aztec/foundation/abi';
10
11
  import { AztecAddress } from '@aztec/foundation/aztec-address';
@@ -140,7 +141,7 @@ export class AcirSimulator {
140
141
  contractAddress: AztecAddress,
141
142
  nonce: Fr,
142
143
  storageSlot: Fr,
143
- noteTypeId: Fr,
144
+ noteTypeId: NoteSelector,
144
145
  computeNullifier: boolean,
145
146
  note: Note,
146
147
  ) {
@@ -210,7 +211,12 @@ export class AcirSimulator {
210
211
  * @param note - The note.
211
212
  * @returns The note hash.
212
213
  */
213
- public async computeInnerNoteHash(contractAddress: AztecAddress, storageSlot: Fr, noteTypeId: Fr, note: Note) {
214
+ public async computeInnerNoteHash(
215
+ contractAddress: AztecAddress,
216
+ storageSlot: Fr,
217
+ noteTypeId: NoteSelector,
218
+ note: Note,
219
+ ) {
214
220
  const { innerNoteHash } = await this.computeNoteHashAndOptionallyANullifier(
215
221
  contractAddress,
216
222
  Fr.ZERO,
@@ -42,6 +42,14 @@ export class ViewDataOracle extends TypedOracle {
42
42
  return Promise.resolve(this.contractAddress);
43
43
  }
44
44
 
45
+ public override getChainId(): Promise<Fr> {
46
+ return Promise.resolve(this.aztecNode.getChainId().then(id => new Fr(id)));
47
+ }
48
+
49
+ public override getVersion(): Promise<Fr> {
50
+ return Promise.resolve(this.aztecNode.getVersion().then(v => new Fr(v)));
51
+ }
52
+
45
53
  /**
46
54
  * Retrieve keys associated with a specific master public key and app address.
47
55
  * @param pkMHash - The master public key hash.
@@ -252,16 +260,25 @@ export class ViewDataOracle extends TypedOracle {
252
260
 
253
261
  /**
254
262
  * Read the public storage data.
263
+ * @param contractAddress - The address to read storage from.
255
264
  * @param startStorageSlot - The starting storage slot.
265
+ * @param blockNumber - The block number to read storage at.
256
266
  * @param numberOfElements - Number of elements to read from the starting storage slot.
257
267
  */
258
- 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
+ ) {
259
274
  const values = [];
260
275
  for (let i = 0n; i < numberOfElements; i++) {
261
276
  const storageSlot = new Fr(startStorageSlot.value + i);
262
- const value = await this.aztecNode.getPublicStorageAt(this.contractAddress, storageSlot);
277
+ const value = await this.aztecNode.getPublicStorageAt(contractAddress, storageSlot, blockNumber);
263
278
 
264
- 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
+ );
265
282
  values.push(value);
266
283
  }
267
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: [],
@@ -143,7 +143,8 @@ export class PublicExecutionResultBuilder {
143
143
  endGasLeft: Gas.test(),
144
144
  transactionFee: Fr.ZERO,
145
145
  calldata: [],
146
- avmHints: AvmExecutionHints.empty(),
146
+ avmCircuitHints: AvmExecutionHints.empty(),
147
+ functionName: 'unknown',
147
148
  ...overrides,
148
149
  };
149
150
  }
@@ -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,
@@ -77,6 +77,7 @@ export const PhaseIsRevertible: Record<PublicKernelType, boolean> = {
77
77
  };
78
78
 
79
79
  export type PublicProvingInformation = {
80
+ functionName: string; // informational only
80
81
  calldata: Fr[];
81
82
  bytecode: Buffer;
82
83
  inputs: PublicKernelCircuitPrivateInputs;
@@ -89,6 +90,7 @@ export function makeAvmProvingRequest(
89
90
  ): AvmProvingRequest {
90
91
  return {
91
92
  type: AVM_REQUEST,
93
+ functionName: info.functionName,
92
94
  bytecode: info.bytecode,
93
95
  calldata: info.calldata,
94
96
  avmHints: info.avmHints,
@@ -174,12 +176,14 @@ export abstract class AbstractPhaseManager {
174
176
  call => revertibleCallStack.find(p => p.equals(call)) || nonRevertibleCallStack.find(p => p.equals(call)),
175
177
  );
176
178
 
179
+ const teardownCallStack = tx.publicTeardownFunctionCall.isEmpty() ? [] : [tx.publicTeardownFunctionCall];
180
+
177
181
  if (callRequestsStack.length === 0) {
178
182
  return {
179
183
  [PublicKernelType.NON_PUBLIC]: [],
180
184
  [PublicKernelType.SETUP]: [],
181
185
  [PublicKernelType.APP_LOGIC]: [],
182
- [PublicKernelType.TEARDOWN]: [],
186
+ [PublicKernelType.TEARDOWN]: teardownCallStack,
183
187
  [PublicKernelType.TAIL]: [],
184
188
  };
185
189
  }
@@ -189,8 +193,6 @@ export abstract class AbstractPhaseManager {
189
193
  c => revertibleCallStack.findIndex(p => p.equals(c)) !== -1,
190
194
  );
191
195
 
192
- const teardownCallStack = tx.publicTeardownFunctionCall.isEmpty() ? [] : [tx.publicTeardownFunctionCall];
193
-
194
196
  if (firstRevertibleCallIndex === 0) {
195
197
  return {
196
198
  [PublicKernelType.NON_PUBLIC]: [],
@@ -254,7 +256,7 @@ export abstract class AbstractPhaseManager {
254
256
  const enqueuedCallResults = [];
255
257
 
256
258
  for (const enqueuedCall of enqueuedCalls) {
257
- const executionStack: (PublicExecution | PublicExecutionResult)[] = [enqueuedCall];
259
+ const executionStack: (PublicExecutionRequest | PublicExecutionResult)[] = [enqueuedCall];
258
260
 
259
261
  // Keep track of which result is for the top/enqueued call
260
262
  let enqueuedExecutionResult: PublicExecutionResult | undefined;
@@ -264,13 +266,15 @@ export abstract class AbstractPhaseManager {
264
266
  const isExecutionRequest = !isPublicExecutionResult(current);
265
267
  const result = isExecutionRequest
266
268
  ? await this.publicExecutor.simulate(
267
- current,
269
+ /*executionRequest=*/ current,
268
270
  this.globalVariables,
269
271
  /*availableGas=*/ this.getAvailableGas(tx, kernelPublicOutput),
270
272
  tx.data.constants.txContext,
271
273
  /*pendingNullifiers=*/ this.getSiloedPendingNullifiers(kernelPublicOutput),
272
274
  transactionFee,
273
275
  /*startSideEffectCounter=*/ AbstractPhaseManager.getMaxSideEffectCounter(kernelPublicOutput) + 1,
276
+ // NOTE: startSideEffectCounter is not the same as the executionRequest's sideEffectCounter
277
+ // (which counts the request itself)
274
278
  )
275
279
  : current;
276
280
 
@@ -279,18 +283,20 @@ export abstract class AbstractPhaseManager {
279
283
 
280
284
  // Sanity check for a current upstream assumption.
281
285
  // Consumers of the result seem to expect "reverted <=> revertReason !== undefined".
282
- const functionSelector = result.execution.functionSelector.toString();
286
+ const functionSelector = result.executionRequest.functionSelector.toString();
283
287
  if (result.reverted && !result.revertReason) {
284
288
  throw new Error(
285
- `Simulation of ${result.execution.contractAddress.toString()}:${functionSelector} reverted with no reason.`,
289
+ `Simulation of ${result.executionRequest.contractAddress.toString()}:${functionSelector}(${
290
+ result.functionName
291
+ }) reverted with no reason.`,
286
292
  );
287
293
  }
288
294
 
289
295
  if (result.reverted && !PhaseIsRevertible[this.phase]) {
290
296
  this.log.debug(
291
- `Simulation error on ${result.execution.contractAddress.toString()}:${functionSelector} with reason: ${
292
- result.revertReason
293
- }`,
297
+ `Simulation error on ${result.executionRequest.contractAddress.toString()}:${functionSelector}(${
298
+ result.functionName
299
+ }) with reason: ${result.revertReason}`,
294
300
  );
295
301
  throw result.revertReason;
296
302
  }
@@ -302,7 +308,9 @@ export abstract class AbstractPhaseManager {
302
308
 
303
309
  // Simulate the public kernel circuit.
304
310
  this.log.debug(
305
- `Running public kernel circuit for ${result.execution.contractAddress.toString()}:${functionSelector}`,
311
+ `Running public kernel circuit for ${result.executionRequest.contractAddress.toString()}:${functionSelector}(${
312
+ result.functionName
313
+ })`,
306
314
  );
307
315
  const callData = await this.getPublicCallData(result, isExecutionRequest);
308
316
  const [privateInputs, publicInputs] = await this.runKernelCircuit(kernelPublicOutput, callData);
@@ -310,10 +318,11 @@ export abstract class AbstractPhaseManager {
310
318
 
311
319
  // Capture the inputs for later proving in the AVM and kernel.
312
320
  const publicProvingInformation: PublicProvingInformation = {
321
+ functionName: result.functionName,
313
322
  calldata: result.calldata,
314
323
  bytecode: result.bytecode!,
315
324
  inputs: privateInputs,
316
- avmHints: result.avmHints,
325
+ avmHints: result.avmCircuitHints,
317
326
  };
318
327
  provingInformationList.push(publicProvingInformation);
319
328
 
@@ -322,7 +331,9 @@ export abstract class AbstractPhaseManager {
322
331
  // but the kernel carries the reverted flag forward. But if the simulator reverts, so should the kernel.
323
332
  if (result.reverted && kernelPublicOutput.revertCode.isOK()) {
324
333
  throw new Error(
325
- `Public kernel circuit did not revert on ${result.execution.contractAddress.toString()}:${functionSelector}, but simulator did.`,
334
+ `Public kernel circuit did not revert on ${result.executionRequest.contractAddress.toString()}:${functionSelector}(${
335
+ result.functionName
336
+ }), but simulator did.`,
326
337
  );
327
338
  }
328
339
 
@@ -330,9 +341,9 @@ export abstract class AbstractPhaseManager {
330
341
  // So safely return the revert reason and the kernel output (which has had its revertible side effects dropped)
331
342
  if (result.reverted) {
332
343
  this.log.debug(
333
- `Reverting on ${result.execution.contractAddress.toString()}:${functionSelector} with reason: ${
334
- result.revertReason
335
- }`,
344
+ `Reverting on ${result.executionRequest.contractAddress.toString()}:${functionSelector}(${
345
+ result.functionName
346
+ }) with reason: ${result.revertReason}`,
336
347
  );
337
348
  // TODO(@spalladino): Check gasUsed is correct. The AVM should take care of setting gasLeft to zero upon a revert.
338
349
  return {
@@ -419,9 +430,9 @@ export abstract class AbstractPhaseManager {
419
430
  );
420
431
 
421
432
  const publicCircuitPublicInputs = PublicCircuitPublicInputs.from({
422
- callContext: result.execution.callContext,
433
+ callContext: result.executionRequest.callContext,
423
434
  proverAddress: AztecAddress.ZERO,
424
- argsHash: computeVarArgsHash(result.execution.args),
435
+ argsHash: computeVarArgsHash(result.executionRequest.args),
425
436
  newNoteHashes: padArrayEnd(result.newNoteHashes, NoteHash.empty(), MAX_NEW_NOTE_HASHES_PER_CALL),
426
437
  newNullifiers: padArrayEnd(result.newNullifiers, Nullifier.empty(), MAX_NEW_NULLIFIERS_PER_CALL),
427
438
  newL2ToL1Msgs: padArrayEnd(result.newL2ToL1Messages, L2ToL1Message.empty(), MAX_NEW_L2_TO_L1_MSGS_PER_CALL),
@@ -470,8 +481,8 @@ export abstract class AbstractPhaseManager {
470
481
  });
471
482
 
472
483
  return new PublicCallStackItem(
473
- result.execution.contractAddress,
474
- new FunctionData(result.execution.functionSelector, false),
484
+ result.executionRequest.contractAddress,
485
+ new FunctionData(result.executionRequest.functionSelector, false),
475
486
  publicCircuitPublicInputs,
476
487
  isExecutionRequest,
477
488
  );
@@ -47,6 +47,7 @@ export class AppLogicPhaseManager extends AbstractPhaseManager {
47
47
  // if so, this is removing contracts deployed in private setup
48
48
  await this.publicContractsDB.removeNewContracts(tx);
49
49
  await this.publicStateDB.rollbackToCheckpoint();
50
+ tx.filterRevertedLogs(kernelOutput);
50
51
  } else {
51
52
  tx.unencryptedLogs.addFunctionLogs(newUnencryptedLogs);
52
53
  // TODO(#6470): we should be adding contracts deployed in those logs to the publicContractsDB