@aztec/simulator 0.37.0 → 0.39.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 (181) hide show
  1. package/dest/acvm/acvm.d.ts +1 -1
  2. package/dest/acvm/acvm.d.ts.map +1 -1
  3. package/dest/acvm/acvm.js +2 -2
  4. package/dest/acvm/oracle/oracle.d.ts +6 -5
  5. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  6. package/dest/acvm/oracle/oracle.js +26 -30
  7. package/dest/acvm/oracle/typed_oracle.d.ts +5 -5
  8. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  9. package/dest/acvm/oracle/typed_oracle.js +9 -9
  10. package/dest/avm/avm_execution_environment.d.ts +4 -3
  11. package/dest/avm/avm_execution_environment.d.ts.map +1 -1
  12. package/dest/avm/avm_execution_environment.js +17 -11
  13. package/dest/avm/avm_gas.d.ts.map +1 -1
  14. package/dest/avm/avm_gas.js +4 -1
  15. package/dest/avm/avm_machine_state.d.ts +5 -8
  16. package/dest/avm/avm_machine_state.d.ts.map +1 -1
  17. package/dest/avm/avm_machine_state.js +10 -22
  18. package/dest/avm/avm_memory_types.d.ts +1 -1
  19. package/dest/avm/avm_memory_types.d.ts.map +1 -1
  20. package/dest/avm/avm_message_call_result.d.ts +5 -8
  21. package/dest/avm/avm_message_call_result.d.ts.map +1 -1
  22. package/dest/avm/avm_message_call_result.js +1 -4
  23. package/dest/avm/avm_simulator.d.ts.map +1 -1
  24. package/dest/avm/avm_simulator.js +19 -13
  25. package/dest/avm/errors.d.ts +43 -2
  26. package/dest/avm/errors.d.ts.map +1 -1
  27. package/dest/avm/errors.js +86 -4
  28. package/dest/avm/journal/journal.d.ts +20 -1
  29. package/dest/avm/journal/journal.d.ts.map +1 -1
  30. package/dest/avm/journal/journal.js +70 -9
  31. package/dest/avm/journal/nullifiers.d.ts +3 -1
  32. package/dest/avm/journal/nullifiers.d.ts.map +1 -1
  33. package/dest/avm/journal/nullifiers.js +14 -6
  34. package/dest/avm/journal/public_storage.d.ts +10 -1
  35. package/dest/avm/journal/public_storage.d.ts.map +1 -1
  36. package/dest/avm/journal/public_storage.js +17 -2
  37. package/dest/avm/journal/trace.d.ts +1 -4
  38. package/dest/avm/journal/trace.d.ts.map +1 -1
  39. package/dest/avm/journal/trace.js +4 -5
  40. package/dest/avm/journal/trace_types.d.ts +1 -0
  41. package/dest/avm/journal/trace_types.d.ts.map +1 -1
  42. package/dest/avm/journal/trace_types.js +1 -1
  43. package/dest/avm/opcodes/bitwise.d.ts +4 -1
  44. package/dest/avm/opcodes/bitwise.d.ts.map +1 -1
  45. package/dest/avm/opcodes/bitwise.js +14 -2
  46. package/dest/avm/opcodes/conversion.d.ts +16 -0
  47. package/dest/avm/opcodes/conversion.d.ts.map +1 -0
  48. package/dest/avm/opcodes/conversion.js +48 -0
  49. package/dest/avm/opcodes/environment_getters.d.ts +16 -12
  50. package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
  51. package/dest/avm/opcodes/environment_getters.js +19 -48
  52. package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
  53. package/dest/avm/opcodes/external_calls.js +24 -13
  54. package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
  55. package/dest/avm/serialization/bytecode_serialization.js +6 -2
  56. package/dest/avm/serialization/instruction_serialization.d.ts +40 -38
  57. package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
  58. package/dest/avm/serialization/instruction_serialization.js +42 -39
  59. package/dest/client/client_execution_context.d.ts +59 -19
  60. package/dest/client/client_execution_context.d.ts.map +1 -1
  61. package/dest/client/client_execution_context.js +97 -45
  62. package/dest/client/db_oracle.d.ts +4 -11
  63. package/dest/client/db_oracle.d.ts.map +1 -1
  64. package/dest/client/execution_result.d.ts +22 -15
  65. package/dest/client/execution_result.d.ts.map +1 -1
  66. package/dest/client/execution_result.js +59 -13
  67. package/dest/client/logs_cache.d.ts +33 -0
  68. package/dest/client/logs_cache.d.ts.map +1 -0
  69. package/dest/client/logs_cache.js +59 -0
  70. package/dest/client/private_execution.d.ts +2 -2
  71. package/dest/client/private_execution.d.ts.map +1 -1
  72. package/dest/client/private_execution.js +5 -7
  73. package/dest/client/simulator.d.ts +4 -34
  74. package/dest/client/simulator.d.ts.map +1 -1
  75. package/dest/client/simulator.js +5 -43
  76. package/dest/client/unconstrained_execution.d.ts +2 -2
  77. package/dest/client/unconstrained_execution.d.ts.map +1 -1
  78. package/dest/client/unconstrained_execution.js +1 -1
  79. package/dest/client/view_data_oracle.d.ts +0 -7
  80. package/dest/client/view_data_oracle.d.ts.map +1 -1
  81. package/dest/client/view_data_oracle.js +1 -10
  82. package/dest/common/errors.d.ts +5 -0
  83. package/dest/common/errors.d.ts.map +1 -1
  84. package/dest/common/errors.js +6 -1
  85. package/dest/index.d.ts +1 -0
  86. package/dest/index.d.ts.map +1 -1
  87. package/dest/index.js +2 -1
  88. package/dest/mocks/fixtures.d.ts.map +1 -1
  89. package/dest/mocks/fixtures.js +3 -1
  90. package/dest/public/abstract_phase_manager.d.ts +10 -4
  91. package/dest/public/abstract_phase_manager.d.ts.map +1 -1
  92. package/dest/public/abstract_phase_manager.js +50 -19
  93. package/dest/public/app_logic_phase_manager.d.ts +1 -0
  94. package/dest/public/app_logic_phase_manager.d.ts.map +1 -1
  95. package/dest/public/app_logic_phase_manager.js +3 -3
  96. package/dest/public/execution.d.ts +9 -0
  97. package/dest/public/execution.d.ts.map +1 -1
  98. package/dest/public/execution.js +1 -1
  99. package/dest/public/executor.d.ts +2 -2
  100. package/dest/public/executor.d.ts.map +1 -1
  101. package/dest/public/executor.js +34 -17
  102. package/dest/public/hints_builder.d.ts +3 -3
  103. package/dest/public/hints_builder.d.ts.map +1 -1
  104. package/dest/public/hints_builder.js +3 -3
  105. package/dest/public/public_execution_context.d.ts +10 -4
  106. package/dest/public/public_execution_context.d.ts.map +1 -1
  107. package/dest/public/public_execution_context.js +19 -6
  108. package/dest/public/public_processor.d.ts.map +1 -1
  109. package/dest/public/public_processor.js +5 -3
  110. package/dest/public/setup_phase_manager.d.ts +1 -0
  111. package/dest/public/setup_phase_manager.d.ts.map +1 -1
  112. package/dest/public/setup_phase_manager.js +3 -2
  113. package/dest/public/tail_phase_manager.d.ts +1 -1
  114. package/dest/public/tail_phase_manager.d.ts.map +1 -1
  115. package/dest/public/tail_phase_manager.js +4 -26
  116. package/dest/public/teardown_phase_manager.d.ts +1 -0
  117. package/dest/public/teardown_phase_manager.d.ts.map +1 -1
  118. package/dest/public/teardown_phase_manager.js +3 -2
  119. package/dest/public/transitional_adaptors.d.ts +4 -17
  120. package/dest/public/transitional_adaptors.d.ts.map +1 -1
  121. package/dest/public/transitional_adaptors.js +27 -119
  122. package/dest/rollup/index.d.ts +2 -0
  123. package/dest/rollup/index.d.ts.map +1 -0
  124. package/dest/rollup/index.js +2 -0
  125. package/dest/rollup/rollup.d.ts +77 -0
  126. package/dest/rollup/rollup.d.ts.map +1 -0
  127. package/dest/rollup/rollup.js +78 -0
  128. package/dest/stats/index.d.ts +2 -0
  129. package/dest/stats/index.d.ts.map +1 -0
  130. package/dest/stats/index.js +2 -0
  131. package/dest/stats/stats.d.ts +4 -0
  132. package/dest/stats/stats.d.ts.map +1 -0
  133. package/dest/stats/stats.js +11 -0
  134. package/package.json +8 -8
  135. package/src/acvm/acvm.ts +2 -2
  136. package/src/acvm/oracle/oracle.ts +62 -36
  137. package/src/acvm/oracle/typed_oracle.ts +19 -11
  138. package/src/avm/avm_execution_environment.ts +34 -42
  139. package/src/avm/avm_gas.ts +3 -0
  140. package/src/avm/avm_machine_state.ts +14 -25
  141. package/src/avm/avm_memory_types.ts +1 -1
  142. package/src/avm/avm_message_call_result.ts +3 -14
  143. package/src/avm/avm_simulator.ts +24 -12
  144. package/src/avm/errors.ts +94 -4
  145. package/src/avm/journal/journal.ts +134 -9
  146. package/src/avm/journal/nullifiers.ts +19 -8
  147. package/src/avm/journal/public_storage.ts +23 -2
  148. package/src/avm/journal/trace.ts +3 -4
  149. package/src/avm/journal/trace_types.ts +1 -0
  150. package/src/avm/opcodes/bitwise.ts +18 -7
  151. package/src/avm/opcodes/conversion.ts +59 -0
  152. package/src/avm/opcodes/environment_getters.ts +21 -65
  153. package/src/avm/opcodes/external_calls.ts +32 -16
  154. package/src/avm/serialization/bytecode_serialization.ts +5 -0
  155. package/src/avm/serialization/instruction_serialization.ts +3 -0
  156. package/src/client/client_execution_context.ts +142 -46
  157. package/src/client/db_oracle.ts +4 -18
  158. package/src/client/execution_result.ts +75 -25
  159. package/src/client/logs_cache.ts +65 -0
  160. package/src/client/private_execution.ts +6 -10
  161. package/src/client/simulator.ts +8 -84
  162. package/src/client/unconstrained_execution.ts +2 -2
  163. package/src/client/view_data_oracle.ts +0 -10
  164. package/src/common/errors.ts +5 -0
  165. package/src/index.ts +1 -0
  166. package/src/mocks/fixtures.ts +2 -0
  167. package/src/public/abstract_phase_manager.ts +59 -23
  168. package/src/public/app_logic_phase_manager.ts +2 -1
  169. package/src/public/execution.ts +9 -0
  170. package/src/public/executor.ts +47 -14
  171. package/src/public/hints_builder.ts +5 -5
  172. package/src/public/public_execution_context.ts +18 -4
  173. package/src/public/public_processor.ts +8 -2
  174. package/src/public/setup_phase_manager.ts +16 -8
  175. package/src/public/tail_phase_manager.ts +8 -35
  176. package/src/public/teardown_phase_manager.ts +16 -8
  177. package/src/public/transitional_adaptors.ts +39 -177
  178. package/src/rollup/index.ts +1 -0
  179. package/src/rollup/rollup.ts +160 -0
  180. package/src/stats/index.ts +1 -0
  181. package/src/stats/stats.ts +20 -0
@@ -1,17 +1,15 @@
1
- import { type Fr } from '@aztec/circuits.js';
2
-
3
1
  import type { AvmContext } from '../avm_context.js';
4
2
  import type { AvmExecutionEnvironment } from '../avm_execution_environment.js';
5
- import { Field, type MemoryValue } from '../avm_memory_types.js';
3
+ import { Field, type MemoryValue, Uint64 } from '../avm_memory_types.js';
6
4
  import { Opcode } from '../serialization/instruction_serialization.js';
7
5
  import { GetterInstruction } from './instruction_impl.js';
8
6
 
9
7
  abstract class EnvironmentGetterInstruction extends GetterInstruction {
10
8
  protected getValue(context: AvmContext): MemoryValue {
11
- return new Field(this.getEnvironmentValue(context.environment));
9
+ return this.getEnvironmentValue(context.environment);
12
10
  }
13
11
 
14
- protected abstract getEnvironmentValue(env: AvmExecutionEnvironment): Fr | number | bigint;
12
+ protected abstract getEnvironmentValue(env: AvmExecutionEnvironment): MemoryValue;
15
13
  }
16
14
 
17
15
  export class Address extends EnvironmentGetterInstruction {
@@ -19,7 +17,7 @@ export class Address extends EnvironmentGetterInstruction {
19
17
  static readonly opcode: Opcode = Opcode.ADDRESS;
20
18
 
21
19
  protected getEnvironmentValue(env: AvmExecutionEnvironment) {
22
- return env.address;
20
+ return new Field(env.address.toField());
23
21
  }
24
22
  }
25
23
 
@@ -28,7 +26,7 @@ export class StorageAddress extends EnvironmentGetterInstruction {
28
26
  static readonly opcode: Opcode = Opcode.STORAGEADDRESS;
29
27
 
30
28
  protected getEnvironmentValue(env: AvmExecutionEnvironment) {
31
- return env.storageAddress;
29
+ return new Field(env.storageAddress.toField());
32
30
  }
33
31
  }
34
32
 
@@ -37,7 +35,7 @@ export class Sender extends EnvironmentGetterInstruction {
37
35
  static readonly opcode: Opcode = Opcode.SENDER;
38
36
 
39
37
  protected getEnvironmentValue(env: AvmExecutionEnvironment) {
40
- return env.sender;
38
+ return new Field(env.sender.toField());
41
39
  }
42
40
  }
43
41
 
@@ -46,7 +44,7 @@ export class FeePerL2Gas extends EnvironmentGetterInstruction {
46
44
  static readonly opcode: Opcode = Opcode.FEEPERL2GAS;
47
45
 
48
46
  protected getEnvironmentValue(env: AvmExecutionEnvironment) {
49
- return env.feePerL2Gas;
47
+ return new Field(env.feePerL2Gas);
50
48
  }
51
49
  }
52
50
 
@@ -55,7 +53,16 @@ export class FeePerDAGas extends EnvironmentGetterInstruction {
55
53
  static readonly opcode: Opcode = Opcode.FEEPERDAGAS;
56
54
 
57
55
  protected getEnvironmentValue(env: AvmExecutionEnvironment) {
58
- return env.feePerDaGas;
56
+ return new Field(env.feePerDaGas);
57
+ }
58
+ }
59
+
60
+ export class TransactionFee extends EnvironmentGetterInstruction {
61
+ static type: string = 'TRANSACTIONFEE';
62
+ static readonly opcode: Opcode = Opcode.TRANSACTIONFEE;
63
+
64
+ protected getEnvironmentValue(env: AvmExecutionEnvironment) {
65
+ return new Field(env.transactionFee);
59
66
  }
60
67
  }
61
68
 
@@ -64,7 +71,7 @@ export class ChainId extends EnvironmentGetterInstruction {
64
71
  static readonly opcode: Opcode = Opcode.CHAINID;
65
72
 
66
73
  protected getEnvironmentValue(env: AvmExecutionEnvironment) {
67
- return env.globals.chainId;
74
+ return new Field(env.globals.chainId);
68
75
  }
69
76
  }
70
77
 
@@ -73,7 +80,7 @@ export class Version extends EnvironmentGetterInstruction {
73
80
  static readonly opcode: Opcode = Opcode.VERSION;
74
81
 
75
82
  protected getEnvironmentValue(env: AvmExecutionEnvironment) {
76
- return env.globals.version;
83
+ return new Field(env.globals.version);
77
84
  }
78
85
  }
79
86
 
@@ -82,7 +89,7 @@ export class BlockNumber extends EnvironmentGetterInstruction {
82
89
  static readonly opcode: Opcode = Opcode.BLOCKNUMBER;
83
90
 
84
91
  protected getEnvironmentValue(env: AvmExecutionEnvironment) {
85
- return env.globals.blockNumber;
92
+ return new Field(env.globals.blockNumber);
86
93
  }
87
94
  }
88
95
 
@@ -91,57 +98,6 @@ export class Timestamp extends EnvironmentGetterInstruction {
91
98
  static readonly opcode: Opcode = Opcode.TIMESTAMP;
92
99
 
93
100
  protected getEnvironmentValue(env: AvmExecutionEnvironment) {
94
- return env.globals.timestamp;
101
+ return new Uint64(env.globals.timestamp.toBigInt());
95
102
  }
96
103
  }
97
-
98
- // export class Coinbase extends EnvironmentGetterInstruction {
99
- // static type: string = 'COINBASE';
100
- // static numberOfOperands = 1;
101
-
102
- // constructor(private destOffset: number) {
103
- // super();
104
- // }
105
-
106
- // async execute(machineState: AvmMachineState, _journal: AvmJournal): Promise<void> {
107
- // const {coinbase} = machineState.executionEnvironment.globals;
108
-
109
- // machineState.memory.set(this.destOffset, coinbase);
110
-
111
- // this.incrementPc(machineState);
112
- // }
113
- // }
114
-
115
- // export class BlockL2GasLimit extends EnvironmentGetterInstruction {
116
- // static type: string = 'BLOCKL2GASLIMIT';
117
- // static numberOfOperands = 1;
118
-
119
- // constructor(private destOffset: number) {
120
- // super();
121
- // }
122
-
123
- // async execute(machineState: AvmMachineState, _journal: AvmJournal): Promise<void> {
124
- // const {blockL2GasLimit} = machineState.executionEnvironment.globals;
125
-
126
- // machineState.memory.set(this.destOffset, blockL2GasLimit);
127
-
128
- // this.incrementPc(machineState);
129
- // }
130
- // }
131
-
132
- // export class BlockDAGasLimit extends EnvironmentGetterInstruction {
133
- // static type: string = 'BLOCKDAGASLIMIT';
134
- // static numberOfOperands = 1;
135
-
136
- // constructor(private destOffset: number) {
137
- // super();
138
- // }
139
-
140
- // async execute(machineState: AvmMachineState, _journal: AvmJournal): Promise<void> {
141
- // const {blockDAGasLimit} = machineState.executionEnvironment.globals;
142
-
143
- // machineState.memory.set(this.destOffset, blockDAGasLimit);
144
-
145
- // this.incrementPc(machineState);
146
- // }
147
- // }
@@ -1,16 +1,13 @@
1
- import { FunctionSelector } from '@aztec/circuits.js';
1
+ import { FunctionSelector, Gas } from '@aztec/circuits.js';
2
2
  import { padArrayEnd } from '@aztec/foundation/collection';
3
3
 
4
- import { executePublicFunction } from '../../public/executor.js';
5
- import {
6
- convertPublicExecutionResult,
7
- createPublicExecutionContext,
8
- updateAvmContextFromPublicExecutionResult,
9
- } from '../../public/transitional_adaptors.js';
4
+ import { convertAvmResultsToPxResult, createPublicExecution } from '../../public/transitional_adaptors.js';
10
5
  import type { AvmContext } from '../avm_context.js';
11
6
  import { gasLeftToGas, sumGas } from '../avm_gas.js';
12
7
  import { Field, Uint8 } from '../avm_memory_types.js';
13
8
  import { type AvmContractCallResults } from '../avm_message_call_result.js';
9
+ import { AvmSimulator } from '../avm_simulator.js';
10
+ import { RethrownError } from '../errors.js';
14
11
  import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
15
12
  import { Addressing } from './addressing_mode.js';
16
13
  import { Instruction } from './instruction.js';
@@ -69,7 +66,7 @@ abstract class ExternalCall extends Instruction {
69
66
  const totalGas = sumGas(this.gasCost(memoryOperations), allocatedGas);
70
67
  context.machineState.consumeGas(totalGas);
71
68
 
72
- // TRANSITIONAL: This should be removed once the AVM is fully operational and the public executor is gone.
69
+ // TRANSITIONAL: This should be removed once the kernel handles and entire enqueued call per circuit
73
70
  const nestedContext = context.createNestedContractCallContext(
74
71
  callAddress.toFr(),
75
72
  calldata,
@@ -77,11 +74,21 @@ abstract class ExternalCall extends Instruction {
77
74
  this.type,
78
75
  FunctionSelector.fromField(functionSelector),
79
76
  );
80
- const pxContext = createPublicExecutionContext(nestedContext, calldata);
81
- const pxResults = await executePublicFunction(pxContext, /*nested=*/ true);
82
- const nestedCallResults: AvmContractCallResults = convertPublicExecutionResult(pxResults);
83
- updateAvmContextFromPublicExecutionResult(nestedContext, pxResults);
84
- const nestedPersistableState = nestedContext.persistableState;
77
+ const startSideEffectCounter = nestedContext.persistableState.trace.accessCounter;
78
+
79
+ const oldStyleExecution = createPublicExecution(startSideEffectCounter, nestedContext.environment, calldata);
80
+ const nestedCallResults: AvmContractCallResults = await new AvmSimulator(nestedContext).execute();
81
+ const pxResults = convertAvmResultsToPxResult(
82
+ nestedCallResults,
83
+ startSideEffectCounter,
84
+ oldStyleExecution,
85
+ Gas.from(allocatedGas),
86
+ nestedContext,
87
+ );
88
+ // store the old PublicExecutionResult object to maintain a recursive data structure for the old kernel
89
+ context.persistableState.transitionalExecutionResult.nestedExecutions.push(pxResults);
90
+ // END TRANSITIONAL
91
+
85
92
  // const nestedContext = context.createNestedContractCallContext(
86
93
  // callAddress.toFr(),
87
94
  // calldata,
@@ -90,10 +97,19 @@ abstract class ExternalCall extends Instruction {
90
97
  // FunctionSelector.fromField(functionSelector),
91
98
  // );
92
99
  // const nestedCallResults: AvmContractCallResults = await new AvmSimulator(nestedContext).execute();
93
- // const nestedPersistableState = nestedContext.persistableState;
94
100
 
95
101
  const success = !nestedCallResults.reverted;
96
102
 
103
+ // TRANSITIONAL: We rethrow here so that the MESSAGE gets propagated.
104
+ // This means that for now, the caller cannot recover from errors.
105
+ if (!success) {
106
+ if (!nestedCallResults.revertReason) {
107
+ throw new Error('A reverted nested call should be assigned a revert reason in the AVM execution loop');
108
+ }
109
+ // The nested call's revertReason will be used to track the stack of error causes down to the root.
110
+ throw new RethrownError(nestedCallResults.revertReason.message, nestedCallResults.revertReason);
111
+ }
112
+
97
113
  // We only take as much data as was specified in the return size and pad with zeroes if the return data is smaller
98
114
  // than the specified size in order to prevent that memory to be left with garbage
99
115
  const returnData = nestedCallResults.output.slice(0, this.retSize);
@@ -112,9 +128,9 @@ abstract class ExternalCall extends Instruction {
112
128
 
113
129
  // TODO: Should we merge the changes from a nested call in the case of a STATIC call?
114
130
  if (success) {
115
- context.persistableState.acceptNestedCallState(nestedPersistableState);
131
+ context.persistableState.acceptNestedCallState(nestedContext.persistableState);
116
132
  } else {
117
- context.persistableState.rejectNestedCallState(nestedPersistableState);
133
+ context.persistableState.rejectNestedCallState(nestedContext.persistableState);
118
134
  }
119
135
 
120
136
  memory.assert(memoryOperations);
@@ -1,4 +1,5 @@
1
1
  import { DAGasLeft, L2GasLeft } from '../opcodes/context_getters.js';
2
+ import { ToRadixLE } from '../opcodes/conversion.js';
2
3
  import { Keccak, Pedersen, Poseidon2, Sha256 } from '../opcodes/hashing.js';
3
4
  import type { Instruction } from '../opcodes/index.js';
4
5
  import {
@@ -46,6 +47,7 @@ import {
46
47
  StorageAddress,
47
48
  Sub,
48
49
  Timestamp,
50
+ TransactionFee,
49
51
  Version,
50
52
  Xor,
51
53
  } from '../opcodes/index.js';
@@ -82,6 +84,7 @@ const INSTRUCTION_SET = () =>
82
84
  [Sender.opcode, Sender],
83
85
  [FeePerL2Gas.opcode, FeePerL2Gas],
84
86
  [FeePerDAGas.opcode, FeePerDAGas],
87
+ [TransactionFee.opcode, TransactionFee],
85
88
  //[Contractcalldepth.opcode, Contractcalldepth],
86
89
  // Execution Environment - Globals
87
90
  [ChainId.opcode, ChainId],
@@ -134,6 +137,8 @@ const INSTRUCTION_SET = () =>
134
137
  [Poseidon2.opcode, Poseidon2],
135
138
  [Sha256.opcode, Sha256],
136
139
  [Pedersen.opcode, Pedersen],
140
+ // Conversions
141
+ [ToRadixLE.opcode, ToRadixLE],
137
142
  ]);
138
143
 
139
144
  interface Serializable {
@@ -29,6 +29,7 @@ export enum Opcode {
29
29
  SENDER,
30
30
  FEEPERL2GAS,
31
31
  FEEPERDAGAS,
32
+ TRANSACTIONFEE,
32
33
  CONTRACTCALLDEPTH,
33
34
  CHAINID,
34
35
  VERSION,
@@ -73,6 +74,8 @@ export enum Opcode {
73
74
  POSEIDON2,
74
75
  SHA256, // temp - may be removed, but alot of contracts rely on it
75
76
  PEDERSEN, // temp - may be removed, but alot of contracts rely on it
77
+ // Conversion
78
+ TORADIXLE,
76
79
  }
77
80
 
78
81
  // Possible types for an instruction's operand in its wire format. (Keep in sync with CPP code.
@@ -15,10 +15,8 @@ import {
15
15
  FunctionData,
16
16
  FunctionSelector,
17
17
  type Header,
18
- NoteHashReadRequestMembershipWitness,
19
18
  PrivateContextInputs,
20
19
  PublicCallRequest,
21
- type SideEffect,
22
20
  type TxContext,
23
21
  } from '@aztec/circuits.js';
24
22
  import { Aes128 } from '@aztec/circuits.js/barretenberg';
@@ -32,7 +30,8 @@ import { type NoteData, toACVMWitness } from '../acvm/index.js';
32
30
  import { type PackedValuesCache } from '../common/packed_values_cache.js';
33
31
  import { type DBOracle } from './db_oracle.js';
34
32
  import { type ExecutionNoteCache } from './execution_note_cache.js';
35
- import { type ExecutionResult, type NoteAndSlot, type NullifiedNoteHashCounter } from './execution_result.js';
33
+ import { CountedLog, type ExecutionResult, type NoteAndSlot } from './execution_result.js';
34
+ import { type LogsCache } from './logs_cache.js';
36
35
  import { pickNotes } from './pick_notes.js';
37
36
  import { executePrivateFunction } from './private_execution.js';
38
37
  import { ViewDataOracle } from './view_data_oracle.js';
@@ -58,12 +57,13 @@ export class ClientExecutionContext extends ViewDataOracle {
58
57
  * because these notes are meant to be maintained on a per-call basis
59
58
  * They should act as references for the read requests output by an app circuit via public inputs.
60
59
  */
61
- private gotNotes: Map<bigint, bigint> = new Map();
62
- private nullifiedNoteHashCounters: NullifiedNoteHashCounter[] = [];
63
- private encryptedLogs: EncryptedL2Log[] = [];
64
- private unencryptedLogs: UnencryptedL2Log[] = [];
60
+ private noteHashLeafIndexMap: Map<bigint, bigint> = new Map();
61
+ private nullifiedNoteHashCounters: Map<number, number> = new Map();
62
+ private encryptedLogs: CountedLog<EncryptedL2Log>[] = [];
63
+ private unencryptedLogs: CountedLog<UnencryptedL2Log>[] = [];
65
64
  private nestedExecutions: ExecutionResult[] = [];
66
65
  private enqueuedPublicFunctionCalls: PublicCallRequest[] = [];
66
+ private publicTeardownFunctionCall: PublicCallRequest = PublicCallRequest.empty();
67
67
 
68
68
  constructor(
69
69
  contractAddress: AztecAddress,
@@ -76,6 +76,7 @@ export class ClientExecutionContext extends ViewDataOracle {
76
76
  authWitnesses: AuthWitness[],
77
77
  private readonly packedValuesCache: PackedValuesCache,
78
78
  private readonly noteCache: ExecutionNoteCache,
79
+ private readonly logsCache: LogsCache,
79
80
  db: DBOracle,
80
81
  private node: AztecNode,
81
82
  protected sideEffectCounter: number = 0,
@@ -112,23 +113,11 @@ export class ClientExecutionContext extends ViewDataOracle {
112
113
  }
113
114
 
114
115
  /**
115
- * This function will populate readRequestPartialWitnesses which
116
- * here is just used to flag reads as "transient" for new notes created during this execution
117
- * or to flag non-transient reads with their leafIndex.
118
- * The KernelProver will use this to fully populate witnesses and provide hints to
119
- * the kernel regarding which commitments each transient read request corresponds to.
120
- * @param noteHashReadRequests - SideEffect containing Note hashed of the notes being read and counter.
121
- * @returns An array of partially filled in read request membership witnesses.
116
+ * The KernelProver will use this to fully populate witnesses and provide hints to the kernel circuit
117
+ * regarding which note hash each settled read request corresponds to.
122
118
  */
123
- public getNoteHashReadRequestPartialWitnesses(noteHashReadRequests: SideEffect[]) {
124
- return noteHashReadRequests
125
- .filter(r => !r.isEmpty())
126
- .map(r => {
127
- const index = this.gotNotes.get(r.value.toBigInt());
128
- return index !== undefined
129
- ? NoteHashReadRequestMembershipWitness.empty(index)
130
- : NoteHashReadRequestMembershipWitness.emptyTransient();
131
- });
119
+ public getNoteHashLeafIndexMap() {
120
+ return this.noteHashLeafIndexMap;
132
121
  }
133
122
 
134
123
  /**
@@ -147,14 +136,28 @@ export class ClientExecutionContext extends ViewDataOracle {
147
136
  * Return the encrypted logs emitted during this execution.
148
137
  */
149
138
  public getEncryptedLogs() {
150
- return new EncryptedFunctionL2Logs(this.encryptedLogs);
139
+ return this.encryptedLogs;
140
+ }
141
+
142
+ /**
143
+ * Return the encrypted logs emitted during this execution and nested executions.
144
+ */
145
+ public getAllEncryptedLogs() {
146
+ return new EncryptedFunctionL2Logs(this.logsCache.getEncryptedLogs());
151
147
  }
152
148
 
153
149
  /**
154
150
  * Return the encrypted logs emitted during this execution.
155
151
  */
156
152
  public getUnencryptedLogs() {
157
- return new UnencryptedFunctionL2Logs(this.unencryptedLogs);
153
+ return this.unencryptedLogs;
154
+ }
155
+
156
+ /**
157
+ * Return the unencrypted logs emitted during this execution and nested executions.
158
+ */
159
+ public getAllUnencryptedLogs() {
160
+ return new UnencryptedFunctionL2Logs(this.logsCache.getUnencryptedLogs());
158
161
  }
159
162
 
160
163
  /**
@@ -171,6 +174,13 @@ export class ClientExecutionContext extends ViewDataOracle {
171
174
  return this.enqueuedPublicFunctionCalls;
172
175
  }
173
176
 
177
+ /**
178
+ * Return the public teardown function call set during this execution.
179
+ */
180
+ public getPublicTeardownFunctionCall() {
181
+ return this.publicTeardownFunctionCall;
182
+ }
183
+
174
184
  /**
175
185
  * Pack the given array of arguments.
176
186
  * @param args - Arguments to pack
@@ -260,12 +270,12 @@ export class ClientExecutionContext extends ViewDataOracle {
260
270
 
261
271
  notes.forEach(n => {
262
272
  if (n.index !== undefined) {
263
- const siloedNoteHash = siloNoteHash(n.contractAddress, n.innerNoteHash);
264
- const uniqueSiloedNoteHash = computeUniqueNoteHash(n.nonce, siloedNoteHash);
265
273
  // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386)
266
- // Should always be uniqueSiloedNoteHash when publicly created notes include nonces.
267
- const noteHashForReadRequest = n.nonce.isZero() ? siloedNoteHash : uniqueSiloedNoteHash;
268
- this.gotNotes.set(noteHashForReadRequest.value, n.index);
274
+ // Should always call computeUniqueNoteHash when publicly created notes include nonces.
275
+ const uniqueNoteHash = n.nonce.isZero() ? n.innerNoteHash : computeUniqueNoteHash(n.nonce, n.innerNoteHash);
276
+ const siloedNoteHash = siloNoteHash(n.contractAddress, uniqueNoteHash);
277
+ const noteHashForReadRequest = siloedNoteHash;
278
+ this.noteHashLeafIndexMap.set(noteHashForReadRequest.toBigInt(), n.index);
269
279
  }
270
280
  });
271
281
 
@@ -321,7 +331,7 @@ export class ClientExecutionContext extends ViewDataOracle {
321
331
  innerNoteHash,
322
332
  );
323
333
  if (nullifiedNoteHashCounter !== undefined) {
324
- this.nullifiedNoteHashCounters.push({ noteHashCounter: nullifiedNoteHashCounter, nullifierCounter: counter });
334
+ this.nullifiedNoteHashCounters.set(nullifiedNoteHashCounter, counter);
325
335
  }
326
336
  return Promise.resolve();
327
337
  }
@@ -340,24 +350,45 @@ export class ClientExecutionContext extends ViewDataOracle {
340
350
  noteTypeId: Fr,
341
351
  publicKey: Point,
342
352
  log: Fr[],
353
+ counter: number,
343
354
  ) {
344
355
  const note = new Note(log);
345
356
  const l1NotePayload = new L1NotePayload(note, contractAddress, storageSlot, noteTypeId);
346
357
  const taggedNote = new TaggedNote(l1NotePayload);
347
358
  const encryptedNote = taggedNote.toEncryptedBuffer(publicKey);
348
359
  const encryptedLog = new EncryptedL2Log(encryptedNote);
349
- this.encryptedLogs.push(encryptedLog);
350
- return Fr.fromBuffer(encryptedLog.hash());
360
+ this.encryptedLogs.push(new CountedLog(encryptedLog, counter));
361
+ this.logsCache.addEncryptedLog(encryptedLog);
362
+ return encryptedNote;
351
363
  }
352
364
 
353
365
  /**
354
366
  * Emit an unencrypted log.
355
367
  * @param log - The unencrypted log to be emitted.
356
368
  */
357
- public override emitUnencryptedLog(log: UnencryptedL2Log) {
358
- this.unencryptedLogs.push(log);
369
+ public override emitUnencryptedLog(log: UnencryptedL2Log, counter: number) {
370
+ this.unencryptedLogs.push(new CountedLog(log, counter));
371
+ this.logsCache.addUnencryptedLog(log);
359
372
  const text = log.toHumanReadable();
360
373
  this.log.verbose(`Emitted unencrypted log: "${text.length > 100 ? text.slice(0, 100) + '...' : text}"`);
374
+ }
375
+
376
+ /**
377
+ * Emit a contract class unencrypted log.
378
+ * This fn exists separately from emitUnencryptedLog because sha hashing the preimage
379
+ * is too large to compile (16,200 fields, 518,400 bytes) => the oracle hashes it.
380
+ * See private_context.nr
381
+ * @param log - The unencrypted log to be emitted.
382
+ */
383
+ public override emitContractClassUnencryptedLog(log: UnencryptedL2Log, counter: number) {
384
+ this.unencryptedLogs.push(new CountedLog(log, counter));
385
+ this.logsCache.addUnencryptedLog(log);
386
+ const text = log.toHumanReadable();
387
+ this.log.verbose(
388
+ `Emitted unencrypted log from ContractClassRegisterer: "${
389
+ text.length > 100 ? text.slice(0, 100) + '...' : text
390
+ }"`,
391
+ );
361
392
  return Fr.fromBuffer(log.hash());
362
393
  }
363
394
 
@@ -419,6 +450,7 @@ export class ClientExecutionContext extends ViewDataOracle {
419
450
  this.authWitnesses,
420
451
  this.packedValuesCache,
421
452
  this.noteCache,
453
+ this.logsCache,
422
454
  this.db,
423
455
  this.node,
424
456
  sideEffectCounter,
@@ -441,9 +473,7 @@ export class ClientExecutionContext extends ViewDataOracle {
441
473
  }
442
474
 
443
475
  /**
444
- * Creates a PublicCallStackItem object representing the request to call a public function. No function
445
- * is actually called, since that must happen on the sequencer side. All the fields related to the result
446
- * of the execution are empty.
476
+ * Creates a PublicCallStackItem object representing the request to call a public function.
447
477
  * @param targetContractAddress - The address of the contract to call.
448
478
  * @param functionSelector - The function selector of the function to call.
449
479
  * @param argsHash - The packed arguments to pass to the function.
@@ -451,7 +481,8 @@ export class ClientExecutionContext extends ViewDataOracle {
451
481
  * @param isStaticCall - Whether the call is a static call.
452
482
  * @returns The public call stack item with the request information.
453
483
  */
454
- public override async enqueuePublicFunctionCall(
484
+ protected async createPublicCallRequest(
485
+ callType: 'enqueued' | 'teardown',
455
486
  targetContractAddress: AztecAddress,
456
487
  functionSelector: FunctionSelector,
457
488
  argsHash: Fr,
@@ -470,20 +501,51 @@ export class ClientExecutionContext extends ViewDataOracle {
470
501
  isStaticCall,
471
502
  );
472
503
  const args = this.packedValuesCache.unpack(argsHash);
473
- const enqueuedRequest = PublicCallRequest.from({
504
+
505
+ // TODO($846): if enqueued public calls are associated with global
506
+ // side-effect counter, that will leak info about how many other private
507
+ // side-effects occurred in the TX. Ultimately the private kernel should
508
+ // just output everything in the proper order without any counters.
509
+ this.log.verbose(
510
+ `Created PublicCallRequest of type [${callType}], side-effect counter [${sideEffectCounter}] to ${targetContractAddress}:${functionSelector}(${targetArtifact.name})`,
511
+ );
512
+
513
+ return PublicCallRequest.from({
474
514
  args,
475
515
  callContext: derivedCallContext,
476
516
  parentCallContext: this.callContext,
477
517
  functionData: FunctionData.fromAbi(targetArtifact),
478
518
  contractAddress: targetContractAddress,
479
519
  });
520
+ }
480
521
 
481
- // TODO($846): if enqueued public calls are associated with global
482
- // side-effect counter, that will leak info about how many other private
483
- // side-effects occurred in the TX. Ultimately the private kernel should
484
- // just output everything in the proper order without any counters.
485
- this.log.verbose(
486
- `Enqueued call to public function (with side-effect counter #${sideEffectCounter}) ${targetContractAddress}:${functionSelector}(${targetArtifact.name})`,
522
+ /**
523
+ * Creates and enqueues a PublicCallStackItem object representing the request to call a public function. No function
524
+ * is actually called, since that must happen on the sequencer side. All the fields related to the result
525
+ * of the execution are empty.
526
+ * @param targetContractAddress - The address of the contract to call.
527
+ * @param functionSelector - The function selector of the function to call.
528
+ * @param argsHash - The packed arguments to pass to the function.
529
+ * @param sideEffectCounter - The side effect counter at the start of the call.
530
+ * @param isStaticCall - Whether the call is a static call.
531
+ * @returns The public call stack item with the request information.
532
+ */
533
+ public override async enqueuePublicFunctionCall(
534
+ targetContractAddress: AztecAddress,
535
+ functionSelector: FunctionSelector,
536
+ argsHash: Fr,
537
+ sideEffectCounter: number,
538
+ isStaticCall: boolean,
539
+ isDelegateCall: boolean,
540
+ ): Promise<PublicCallRequest> {
541
+ const enqueuedRequest = await this.createPublicCallRequest(
542
+ 'enqueued',
543
+ targetContractAddress,
544
+ functionSelector,
545
+ argsHash,
546
+ sideEffectCounter,
547
+ isStaticCall,
548
+ isDelegateCall,
487
549
  );
488
550
 
489
551
  this.enqueuedPublicFunctionCalls.push(enqueuedRequest);
@@ -491,6 +553,40 @@ export class ClientExecutionContext extends ViewDataOracle {
491
553
  return enqueuedRequest;
492
554
  }
493
555
 
556
+ /**
557
+ * Creates a PublicCallStackItem and sets it as the public teardown function. No function
558
+ * is actually called, since that must happen on the sequencer side. All the fields related to the result
559
+ * of the execution are empty.
560
+ * @param targetContractAddress - The address of the contract to call.
561
+ * @param functionSelector - The function selector of the function to call.
562
+ * @param argsHash - The packed arguments to pass to the function.
563
+ * @param sideEffectCounter - The side effect counter at the start of the call.
564
+ * @param isStaticCall - Whether the call is a static call.
565
+ * @returns The public call stack item with the request information.
566
+ */
567
+ public override async setPublicTeardownFunctionCall(
568
+ targetContractAddress: AztecAddress,
569
+ functionSelector: FunctionSelector,
570
+ argsHash: Fr,
571
+ sideEffectCounter: number,
572
+ isStaticCall: boolean,
573
+ isDelegateCall: boolean,
574
+ ): Promise<PublicCallRequest> {
575
+ const publicTeardownFunctionCall = await this.createPublicCallRequest(
576
+ 'teardown',
577
+ targetContractAddress,
578
+ functionSelector,
579
+ argsHash,
580
+ sideEffectCounter,
581
+ isStaticCall,
582
+ isDelegateCall,
583
+ );
584
+
585
+ this.publicTeardownFunctionCall = publicTeardownFunctionCall;
586
+
587
+ return publicTeardownFunctionCall;
588
+ }
589
+
494
590
  /**
495
591
  * Derives the call context for a nested execution.
496
592
  * @param targetContractAddress - The address of the contract being called.
@@ -6,9 +6,9 @@ import {
6
6
  type PublicDataWitness,
7
7
  } from '@aztec/circuit-types';
8
8
  import { type CompleteAddress, type Header } from '@aztec/circuits.js';
9
- import { type FunctionArtifactWithDebugMetadata, type FunctionSelector } from '@aztec/foundation/abi';
9
+ import { type FunctionArtifact, type FunctionSelector } from '@aztec/foundation/abi';
10
10
  import { type AztecAddress } from '@aztec/foundation/aztec-address';
11
- import { type Fr, type Point } from '@aztec/foundation/fields';
11
+ import { type Fr } from '@aztec/foundation/fields';
12
12
  import { type ContractInstance } from '@aztec/types/contracts';
13
13
 
14
14
  import { type NoteData, type NullifierKeys } from '../acvm/index.js';
@@ -64,14 +64,6 @@ export interface DBOracle extends CommitmentsDB {
64
64
  */
65
65
  popCapsule(): Promise<Fr[]>;
66
66
 
67
- /**
68
- * Gets public keys for an address.
69
- * @param The address to look up
70
- * @returns The public keys for a specific address
71
- * TODO(#5834): Replace with `getCompleteAddress`.
72
- */
73
- getPublicKeysForAddress(address: AztecAddress): Promise<Point[]>;
74
-
75
67
  /**
76
68
  * Retrieve nullifier keys associated with a specific account and app/contract address.
77
69
  *
@@ -102,10 +94,7 @@ export interface DBOracle extends CommitmentsDB {
102
94
  * @param selector - The corresponding function selector.
103
95
  * @returns A Promise that resolves to a FunctionArtifact object.
104
96
  */
105
- getFunctionArtifact(
106
- contractAddress: AztecAddress,
107
- selector: FunctionSelector,
108
- ): Promise<FunctionArtifactWithDebugMetadata>;
97
+ getFunctionArtifact(contractAddress: AztecAddress, selector: FunctionSelector): Promise<FunctionArtifact>;
109
98
 
110
99
  /**
111
100
  * Retrieves the artifact of a specified function within a given contract.
@@ -115,10 +104,7 @@ export interface DBOracle extends CommitmentsDB {
115
104
  * @param functionName - The name of the function.
116
105
  * @returns The corresponding function's artifact as an object.
117
106
  */
118
- getFunctionArtifactByName(
119
- contractAddress: AztecAddress,
120
- functionName: string,
121
- ): Promise<FunctionArtifactWithDebugMetadata | undefined>;
107
+ getFunctionArtifactByName(contractAddress: AztecAddress, functionName: string): Promise<FunctionArtifact | undefined>;
122
108
 
123
109
  /**
124
110
  * Gets the index of a nullifier in the nullifier tree.