@aztec/simulator 0.56.0 → 0.58.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 (205) hide show
  1. package/dest/acvm/oracle/oracle.d.ts +2 -5
  2. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  3. package/dest/acvm/oracle/oracle.js +7 -38
  4. package/dest/acvm/oracle/typed_oracle.d.ts +4 -8
  5. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  6. package/dest/acvm/oracle/typed_oracle.js +1 -10
  7. package/dest/avm/avm_execution_environment.d.ts +2 -3
  8. package/dest/avm/avm_execution_environment.d.ts.map +1 -1
  9. package/dest/avm/avm_execution_environment.js +3 -4
  10. package/dest/avm/avm_gas.d.ts.map +1 -1
  11. package/dest/avm/avm_gas.js +2 -3
  12. package/dest/avm/avm_memory_types.d.ts +10 -5
  13. package/dest/avm/avm_memory_types.d.ts.map +1 -1
  14. package/dest/avm/avm_memory_types.js +31 -16
  15. package/dest/avm/avm_simulator.d.ts.map +1 -1
  16. package/dest/avm/avm_simulator.js +5 -2
  17. package/dest/avm/errors.d.ts +1 -1
  18. package/dest/avm/errors.d.ts.map +1 -1
  19. package/dest/avm/errors.js +12 -3
  20. package/dest/avm/fixtures/index.d.ts.map +1 -1
  21. package/dest/avm/fixtures/index.js +4 -4
  22. package/dest/avm/journal/journal.d.ts +2 -1
  23. package/dest/avm/journal/journal.d.ts.map +1 -1
  24. package/dest/avm/journal/journal.js +8 -8
  25. package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
  26. package/dest/avm/opcodes/accrued_substate.js +54 -47
  27. package/dest/avm/opcodes/addressing_mode.d.ts +3 -2
  28. package/dest/avm/opcodes/addressing_mode.d.ts.map +1 -1
  29. package/dest/avm/opcodes/addressing_mode.js +25 -21
  30. package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
  31. package/dest/avm/opcodes/arithmetic.js +7 -6
  32. package/dest/avm/opcodes/bitwise.d.ts +3 -3
  33. package/dest/avm/opcodes/bitwise.d.ts.map +1 -1
  34. package/dest/avm/opcodes/bitwise.js +19 -16
  35. package/dest/avm/opcodes/commitment.d.ts.map +1 -1
  36. package/dest/avm/opcodes/commitment.js +6 -5
  37. package/dest/avm/opcodes/comparators.d.ts.map +1 -1
  38. package/dest/avm/opcodes/comparators.js +7 -6
  39. package/dest/avm/opcodes/contract.d.ts.map +1 -1
  40. package/dest/avm/opcodes/contract.js +8 -6
  41. package/dest/avm/opcodes/control_flow.js +7 -7
  42. package/dest/avm/opcodes/conversion.d.ts.map +1 -1
  43. package/dest/avm/opcodes/conversion.js +11 -10
  44. package/dest/avm/opcodes/ec_add.d.ts.map +1 -1
  45. package/dest/avm/opcodes/ec_add.js +25 -15
  46. package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
  47. package/dest/avm/opcodes/environment_getters.js +6 -5
  48. package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
  49. package/dest/avm/opcodes/external_calls.js +37 -26
  50. package/dest/avm/opcodes/hashing.d.ts +1 -3
  51. package/dest/avm/opcodes/hashing.d.ts.map +1 -1
  52. package/dest/avm/opcodes/hashing.js +39 -48
  53. package/dest/avm/opcodes/instruction.d.ts +2 -6
  54. package/dest/avm/opcodes/instruction.d.ts.map +1 -1
  55. package/dest/avm/opcodes/instruction.js +3 -9
  56. package/dest/avm/opcodes/instruction_impl.d.ts +1 -2
  57. package/dest/avm/opcodes/instruction_impl.d.ts.map +1 -1
  58. package/dest/avm/opcodes/instruction_impl.js +2 -5
  59. package/dest/avm/opcodes/memory.d.ts +0 -12
  60. package/dest/avm/opcodes/memory.d.ts.map +1 -1
  61. package/dest/avm/opcodes/memory.js +24 -54
  62. package/dest/avm/opcodes/misc.d.ts.map +1 -1
  63. package/dest/avm/opcodes/misc.js +10 -9
  64. package/dest/avm/opcodes/multi_scalar_mul.d.ts.map +1 -1
  65. package/dest/avm/opcodes/multi_scalar_mul.js +35 -20
  66. package/dest/avm/opcodes/storage.d.ts.map +1 -1
  67. package/dest/avm/opcodes/storage.js +13 -11
  68. package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
  69. package/dest/avm/serialization/bytecode_serialization.js +2 -3
  70. package/dest/avm/serialization/instruction_serialization.d.ts +32 -34
  71. package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
  72. package/dest/avm/serialization/instruction_serialization.js +34 -37
  73. package/dest/avm/test_utils.d.ts +1 -2
  74. package/dest/avm/test_utils.d.ts.map +1 -1
  75. package/dest/avm/test_utils.js +1 -1
  76. package/dest/client/client_execution_context.d.ts +6 -30
  77. package/dest/client/client_execution_context.d.ts.map +1 -1
  78. package/dest/client/client_execution_context.js +36 -54
  79. package/dest/client/db_oracle.d.ts +1 -2
  80. package/dest/client/db_oracle.d.ts.map +1 -1
  81. package/dest/client/db_oracle.js +1 -1
  82. package/dest/client/index.d.ts +1 -1
  83. package/dest/client/index.d.ts.map +1 -1
  84. package/dest/client/index.js +2 -2
  85. package/dest/client/private_execution.d.ts +12 -3
  86. package/dest/client/private_execution.d.ts.map +1 -1
  87. package/dest/client/private_execution.js +29 -23
  88. package/dest/client/simulator.d.ts +2 -3
  89. package/dest/client/simulator.d.ts.map +1 -1
  90. package/dest/client/simulator.js +1 -1
  91. package/dest/client/view_data_oracle.d.ts +1 -2
  92. package/dest/client/view_data_oracle.d.ts.map +1 -1
  93. package/dest/client/view_data_oracle.js +1 -1
  94. package/dest/common/debug_fn_name.d.ts +4 -0
  95. package/dest/common/debug_fn_name.d.ts.map +1 -0
  96. package/dest/common/debug_fn_name.js +15 -0
  97. package/dest/common/index.d.ts +0 -1
  98. package/dest/common/index.d.ts.map +1 -1
  99. package/dest/common/index.js +1 -2
  100. package/dest/public/db_interfaces.d.ts +1 -2
  101. package/dest/public/db_interfaces.d.ts.map +1 -1
  102. package/dest/public/dual_side_effect_trace.d.ts +76 -0
  103. package/dest/public/dual_side_effect_trace.d.ts.map +1 -0
  104. package/dest/public/dual_side_effect_trace.js +109 -0
  105. package/dest/public/enqueued_call_side_effect_trace.d.ts +114 -0
  106. package/dest/public/enqueued_call_side_effect_trace.d.ts.map +1 -0
  107. package/dest/public/enqueued_call_side_effect_trace.js +314 -0
  108. package/dest/public/enqueued_call_simulator.d.ts +2 -2
  109. package/dest/public/enqueued_call_simulator.d.ts.map +1 -1
  110. package/dest/public/enqueued_call_simulator.js +20 -10
  111. package/dest/public/enqueued_calls_processor.d.ts +2 -2
  112. package/dest/public/enqueued_calls_processor.d.ts.map +1 -1
  113. package/dest/public/enqueued_calls_processor.js +3 -5
  114. package/dest/public/execution.d.ts +11 -5
  115. package/dest/public/execution.d.ts.map +1 -1
  116. package/dest/public/execution.js +13 -1
  117. package/dest/public/executor.d.ts +7 -6
  118. package/dest/public/executor.d.ts.map +1 -1
  119. package/dest/public/executor.js +24 -15
  120. package/dest/public/fee_payment.d.ts +1 -1
  121. package/dest/public/fee_payment.d.ts.map +1 -1
  122. package/dest/public/fee_payment.js +4 -7
  123. package/dest/public/hints_builder.d.ts +2 -2
  124. package/dest/public/hints_builder.d.ts.map +1 -1
  125. package/dest/public/hints_builder.js +2 -2
  126. package/dest/public/public_db_sources.d.ts +4 -5
  127. package/dest/public/public_db_sources.d.ts.map +1 -1
  128. package/dest/public/public_db_sources.js +15 -11
  129. package/dest/public/public_kernel_tail_simulator.d.ts +3 -3
  130. package/dest/public/public_kernel_tail_simulator.d.ts.map +1 -1
  131. package/dest/public/public_kernel_tail_simulator.js +1 -1
  132. package/dest/public/public_processor.d.ts +7 -10
  133. package/dest/public/public_processor.d.ts.map +1 -1
  134. package/dest/public/public_processor.js +9 -10
  135. package/dest/public/side_effect_errors.d.ts +4 -0
  136. package/dest/public/side_effect_errors.d.ts.map +1 -0
  137. package/dest/public/side_effect_errors.js +7 -0
  138. package/dest/public/side_effect_trace.d.ts +3 -4
  139. package/dest/public/side_effect_trace.d.ts.map +1 -1
  140. package/dest/public/side_effect_trace.js +54 -29
  141. package/dest/public/side_effect_trace_interface.d.ts +1 -1
  142. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  143. package/package.json +12 -9
  144. package/src/acvm/oracle/oracle.ts +8 -86
  145. package/src/acvm/oracle/typed_oracle.ts +8 -33
  146. package/src/avm/avm_execution_environment.ts +1 -3
  147. package/src/avm/avm_gas.ts +1 -2
  148. package/src/avm/avm_memory_types.ts +38 -16
  149. package/src/avm/avm_simulator.ts +7 -1
  150. package/src/avm/errors.ts +11 -3
  151. package/src/avm/fixtures/index.ts +2 -3
  152. package/src/avm/journal/journal.ts +14 -10
  153. package/src/avm/opcodes/accrued_substate.ts +53 -61
  154. package/src/avm/opcodes/addressing_mode.ts +27 -24
  155. package/src/avm/opcodes/arithmetic.ts +6 -8
  156. package/src/avm/opcodes/bitwise.ts +18 -18
  157. package/src/avm/opcodes/commitment.ts +6 -7
  158. package/src/avm/opcodes/comparators.ts +6 -8
  159. package/src/avm/opcodes/contract.ts +7 -8
  160. package/src/avm/opcodes/control_flow.ts +6 -6
  161. package/src/avm/opcodes/conversion.ts +10 -12
  162. package/src/avm/opcodes/ec_add.ts +29 -24
  163. package/src/avm/opcodes/environment_getters.ts +5 -4
  164. package/src/avm/opcodes/external_calls.ts +37 -30
  165. package/src/avm/opcodes/hashing.ts +38 -63
  166. package/src/avm/opcodes/instruction.ts +3 -10
  167. package/src/avm/opcodes/instruction_impl.ts +0 -3
  168. package/src/avm/opcodes/memory.ts +23 -67
  169. package/src/avm/opcodes/misc.ts +9 -11
  170. package/src/avm/opcodes/multi_scalar_mul.ts +31 -26
  171. package/src/avm/opcodes/storage.ts +12 -10
  172. package/src/avm/serialization/bytecode_serialization.ts +0 -2
  173. package/src/avm/serialization/instruction_serialization.ts +1 -4
  174. package/src/avm/test_utils.ts +1 -2
  175. package/src/client/client_execution_context.ts +46 -97
  176. package/src/client/db_oracle.ts +6 -2
  177. package/src/client/index.ts +1 -1
  178. package/src/client/private_execution.ts +45 -15
  179. package/src/client/simulator.ts +2 -3
  180. package/src/client/view_data_oracle.ts +1 -2
  181. package/src/common/debug_fn_name.ts +22 -0
  182. package/src/common/index.ts +0 -1
  183. package/src/public/db_interfaces.ts +5 -2
  184. package/src/public/dual_side_effect_trace.ts +173 -0
  185. package/src/public/enqueued_call_side_effect_trace.ts +552 -0
  186. package/src/public/enqueued_call_simulator.ts +35 -14
  187. package/src/public/enqueued_calls_processor.ts +4 -6
  188. package/src/public/execution.ts +15 -6
  189. package/src/public/executor.ts +42 -19
  190. package/src/public/fee_payment.ts +4 -6
  191. package/src/public/hints_builder.ts +9 -11
  192. package/src/public/public_db_sources.ts +31 -22
  193. package/src/public/public_kernel_tail_simulator.ts +3 -3
  194. package/src/public/public_processor.ts +17 -13
  195. package/src/public/side_effect_errors.ts +6 -0
  196. package/src/public/side_effect_trace.ts +74 -29
  197. package/src/public/side_effect_trace_interface.ts +2 -2
  198. package/dest/client/execution_result.d.ts +0 -104
  199. package/dest/client/execution_result.d.ts.map +0 -1
  200. package/dest/client/execution_result.js +0 -136
  201. package/dest/common/return_values.d.ts +0 -11
  202. package/dest/common/return_values.d.ts.map +0 -1
  203. package/dest/common/return_values.js +0 -13
  204. package/src/client/execution_result.ts +0 -228
  205. package/src/common/return_values.ts +0 -18
@@ -1,5 +1,5 @@
1
1
  import {
2
- type MerkleTreeOperations,
2
+ type MerkleTreeReadOperations,
3
3
  type NestedProcessReturnValues,
4
4
  type ProcessedTx,
5
5
  ProvingRequestType,
@@ -28,7 +28,7 @@ import {
28
28
  } from '@aztec/circuits.js';
29
29
  import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
30
30
  import { Timer } from '@aztec/foundation/timer';
31
- import { ProtocolCircuitVks, getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types';
31
+ import { ProtocolCircuitVks, TubeVk, getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types';
32
32
 
33
33
  import { inspect } from 'util';
34
34
 
@@ -93,7 +93,7 @@ export class EnqueuedCallsProcessor {
93
93
  }
94
94
 
95
95
  static create(
96
- db: MerkleTreeOperations,
96
+ db: MerkleTreeReadOperations,
97
97
  publicExecutor: PublicExecutor,
98
98
  publicKernelSimulator: PublicKernelCircuitSimulator,
99
99
  globalVariables: GlobalVariables,
@@ -377,9 +377,7 @@ export class EnqueuedCallsProcessor {
377
377
  // The proof is not used in simulation.
378
378
  const proof = makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH);
379
379
 
380
- const vk = isFromPrivate
381
- ? ProtocolCircuitVks.PrivateKernelTailToPublicArtifact
382
- : ProtocolCircuitVks.PublicKernelMergeArtifact;
380
+ const vk = isFromPrivate ? TubeVk : ProtocolCircuitVks.PublicKernelMergeArtifact;
383
381
  const vkIndex = getVKIndex(vk);
384
382
  const siblingPath = getVKSiblingPath(vkIndex);
385
383
 
@@ -1,4 +1,5 @@
1
1
  import {
2
+ NestedProcessReturnValues,
2
3
  type PublicExecutionRequest,
3
4
  type SimulationError,
4
5
  type UnencryptedFunctionL2Logs,
@@ -21,8 +22,6 @@ import {
21
22
  } from '@aztec/circuits.js';
22
23
  import { computeVarArgsHash } from '@aztec/circuits.js/hash';
23
24
 
24
- import { type Gas as AvmGas } from '../avm/avm_gas.js';
25
-
26
25
  /**
27
26
  * The public function execution result.
28
27
  */
@@ -35,9 +34,9 @@ export interface PublicExecutionResult {
35
34
  /** The side effect counter after executing this function call */
36
35
  endSideEffectCounter: Fr;
37
36
  /** How much gas was available for this public execution. */
38
- startGasLeft: AvmGas;
37
+ startGasLeft: Gas;
39
38
  /** How much gas was left after this public execution. */
40
- endGasLeft: AvmGas;
39
+ endGasLeft: Gas;
41
40
  /** Transaction fee set for this tx. */
42
41
  transactionFee: Fr;
43
42
 
@@ -86,8 +85,6 @@ export interface PublicExecutionResult {
86
85
  */
87
86
  allUnencryptedLogs: UnencryptedFunctionL2Logs;
88
87
 
89
- // TODO(dbanks12): add contract instance read requests
90
-
91
88
  /** The requests to call public functions made by this call. */
92
89
  publicCallRequests: PublicInnerCallRequest[];
93
90
  /** The results of nested calls. */
@@ -100,6 +97,18 @@ export interface PublicExecutionResult {
100
97
  functionName: string;
101
98
  }
102
99
 
100
+ /**
101
+ * Recursively accummulate the return values of a call result and its nested executions,
102
+ * so they can be retrieved in order.
103
+ * @param executionResult
104
+ * @returns
105
+ */
106
+ export function accumulatePublicReturnValues(executionResult: PublicExecutionResult): NestedProcessReturnValues {
107
+ const acc = new NestedProcessReturnValues(executionResult.returnValues);
108
+ acc.nested = executionResult.nestedExecutions.map(nestedExecution => accumulatePublicReturnValues(nestedExecution));
109
+ return acc;
110
+ }
111
+
103
112
  export function collectExecutionResults(result: PublicExecutionResult): PublicExecutionResult[] {
104
113
  return [result, ...result.nestedExecutions.map(collectExecutionResults)].flat();
105
114
  }
@@ -1,6 +1,15 @@
1
1
  import { type PublicExecutionRequest } from '@aztec/circuit-types';
2
2
  import { type AvmSimulationStats } from '@aztec/circuit-types/stats';
3
- import { Fr, Gas, type GlobalVariables, type Header, type Nullifier, type TxContext } from '@aztec/circuits.js';
3
+ import {
4
+ type CombinedConstantData,
5
+ Fr,
6
+ Gas,
7
+ type GlobalVariables,
8
+ type Nullifier,
9
+ PublicAccumulatedDataArrayLengths,
10
+ PublicValidationRequestArrayLengths,
11
+ type TxContext,
12
+ } from '@aztec/circuits.js';
4
13
  import { createDebugLogger } from '@aztec/foundation/log';
5
14
  import { Timer } from '@aztec/foundation/timer';
6
15
  import { type TelemetryClient } from '@aztec/telemetry-client';
@@ -10,6 +19,9 @@ import { AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
10
19
  import { AvmMachineState } from '../avm/avm_machine_state.js';
11
20
  import { AvmSimulator } from '../avm/avm_simulator.js';
12
21
  import { AvmPersistableStateManager } from '../avm/journal/index.js';
22
+ import { getPublicFunctionDebugName } from '../common/debug_fn_name.js';
23
+ import { DualSideEffectTrace } from './dual_side_effect_trace.js';
24
+ import { PublicEnqueuedCallSideEffectTrace } from './enqueued_call_side_effect_trace.js';
13
25
  import { type PublicExecutionResult } from './execution.js';
14
26
  import { ExecutorMetrics } from './executor_metrics.js';
15
27
  import { type WorldStateDB } from './public_db_sources.js';
@@ -21,7 +33,7 @@ import { PublicSideEffectTrace } from './side_effect_trace.js';
21
33
  export class PublicExecutor {
22
34
  metrics: ExecutorMetrics;
23
35
 
24
- constructor(private readonly worldStateDB: WorldStateDB, private readonly header: Header, client: TelemetryClient) {
36
+ constructor(private readonly worldStateDB: WorldStateDB, client: TelemetryClient) {
25
37
  this.metrics = new ExecutorMetrics(client, 'PublicExecutor');
26
38
  }
27
39
 
@@ -30,45 +42,50 @@ export class PublicExecutor {
30
42
  /**
31
43
  * Executes a public execution request.
32
44
  * @param executionRequest - The execution to run.
33
- * @param globalVariables - The global variables to use.
34
- * @param availableGas - The gas available at the start of this enqueued call.
45
+ * @param constants - The constants (including global variables) to use.
46
+ * @param allocatedGas - The gas available at the start of this enqueued call.
35
47
  * @param txContext - Transaction context.
36
48
  * @param pendingSiloedNullifiers - The pending nullifier set from earlier parts of this TX.
37
49
  * @param transactionFee - Fee offered for this TX.
38
50
  * @param startSideEffectCounter - The counter of the first side-effect generated by this simulation.
51
+ * @param previousValidationRequestArrayLengths - Side effect array lengths from previous kernel
52
+ * @param previousAccumulatedDataArrayLengths - Side effect array lengths from previous kernel
39
53
  * @returns The result of execution, including the results of all nested calls.
40
54
  */
41
55
  public async simulate(
42
56
  executionRequest: PublicExecutionRequest,
43
- globalVariables: GlobalVariables,
44
- availableGas: Gas,
57
+ constants: CombinedConstantData,
58
+ allocatedGas: Gas,
45
59
  _txContext: TxContext,
46
60
  pendingSiloedNullifiers: Nullifier[],
47
61
  transactionFee: Fr = Fr.ZERO,
48
62
  startSideEffectCounter: number = 0,
63
+ previousValidationRequestArrayLengths: PublicValidationRequestArrayLengths = PublicValidationRequestArrayLengths.empty(),
64
+ previousAccumulatedDataArrayLengths: PublicAccumulatedDataArrayLengths = PublicAccumulatedDataArrayLengths.empty(),
49
65
  ): Promise<PublicExecutionResult> {
50
66
  const address = executionRequest.contractAddress;
51
67
  const selector = executionRequest.callContext.functionSelector;
52
- const fnName = (await this.worldStateDB.getDebugFunctionName(address, selector)) ?? `${address}:${selector}`;
68
+ const fnName = await getPublicFunctionDebugName(this.worldStateDB, address, selector, executionRequest.args);
53
69
 
54
- PublicExecutor.log.verbose(`[AVM] Executing public external function ${fnName}.`);
70
+ PublicExecutor.log.verbose(`[AVM] Executing public external function ${fnName}@${address}.`);
55
71
  const timer = new Timer();
56
72
 
57
- const trace = new PublicSideEffectTrace(startSideEffectCounter);
73
+ const innerCallTrace = new PublicSideEffectTrace(startSideEffectCounter);
74
+ const enqueuedCallTrace = new PublicEnqueuedCallSideEffectTrace(
75
+ startSideEffectCounter,
76
+ previousValidationRequestArrayLengths,
77
+ previousAccumulatedDataArrayLengths,
78
+ );
79
+ const trace = new DualSideEffectTrace(innerCallTrace, enqueuedCallTrace);
58
80
  const avmPersistableState = AvmPersistableStateManager.newWithPendingSiloedNullifiers(
59
81
  this.worldStateDB,
60
82
  trace,
61
83
  pendingSiloedNullifiers.map(n => n.value),
62
84
  );
63
85
 
64
- const avmExecutionEnv = createAvmExecutionEnvironment(
65
- executionRequest,
66
- this.header,
67
- globalVariables,
68
- transactionFee,
69
- );
86
+ const avmExecutionEnv = createAvmExecutionEnvironment(executionRequest, constants.globalVariables, transactionFee);
70
87
 
71
- const avmMachineState = new AvmMachineState(availableGas);
88
+ const avmMachineState = new AvmMachineState(allocatedGas);
72
89
  const avmContext = new AvmContext(avmPersistableState, avmExecutionEnv, avmMachineState);
73
90
  const simulator = new AvmSimulator(avmContext);
74
91
  const avmResult = await simulator.execute();
@@ -94,7 +111,7 @@ export class PublicExecutor {
94
111
 
95
112
  const publicExecutionResult = trace.toPublicExecutionResult(
96
113
  avmExecutionEnv,
97
- /*startGasLeft=*/ availableGas,
114
+ /*startGasLeft=*/ allocatedGas,
98
115
  /*endGasLeft=*/ Gas.from(avmContext.machineState.gasLeft),
99
116
  bytecode,
100
117
  avmResult,
@@ -107,6 +124,14 @@ export class PublicExecutor {
107
124
  this.metrics.recordFunctionSimulation(bytecode.length, timer.ms());
108
125
  }
109
126
 
127
+ const _vmCircuitPublicInputs = enqueuedCallTrace.toVMCircuitPublicInputs(
128
+ constants,
129
+ avmExecutionEnv,
130
+ /*startGasLeft=*/ allocatedGas,
131
+ /*endGasLeft=*/ Gas.from(avmContext.machineState.gasLeft),
132
+ avmResult,
133
+ );
134
+
110
135
  return publicExecutionResult;
111
136
  }
112
137
  }
@@ -120,7 +145,6 @@ export class PublicExecutor {
120
145
  */
121
146
  function createAvmExecutionEnvironment(
122
147
  executionRequest: PublicExecutionRequest,
123
- header: Header,
124
148
  globalVariables: GlobalVariables,
125
149
  transactionFee: Fr,
126
150
  ): AvmExecutionEnvironment {
@@ -131,7 +155,6 @@ function createAvmExecutionEnvironment(
131
155
  executionRequest.callContext.functionSelector,
132
156
  /*contractCallDepth=*/ Fr.zero(),
133
157
  transactionFee,
134
- header,
135
158
  globalVariables,
136
159
  executionRequest.callContext.isStaticCall,
137
160
  executionRequest.callContext.isDelegateCall,
@@ -1,14 +1,13 @@
1
- import { FEE_JUICE_ADDRESS } from '@aztec/circuits.js';
2
1
  import { computePublicDataTreeLeafSlot, deriveStorageSlotInMap } from '@aztec/circuits.js/hash';
3
- import { AztecAddress } from '@aztec/foundation/aztec-address';
2
+ import { type AztecAddress } from '@aztec/foundation/aztec-address';
4
3
  import { Fr } from '@aztec/foundation/fields';
5
- import { FeeJuiceArtifact } from '@aztec/protocol-contracts/fee-juice';
4
+ import { ProtocolContractAddress, ProtocolContractArtifact } from '@aztec/protocol-contracts';
6
5
 
7
6
  /**
8
7
  * Computes the storage slot within the Fee Juice contract for the balance of the fee payer.
9
8
  */
10
9
  export function computeFeePayerBalanceStorageSlot(feePayer: AztecAddress) {
11
- return deriveStorageSlotInMap(FeeJuiceArtifact.storageLayout.balances.slot, feePayer);
10
+ return deriveStorageSlotInMap(ProtocolContractArtifact.FeeJuice.storageLayout.balances.slot, feePayer);
12
11
  }
13
12
 
14
13
  /**
@@ -18,7 +17,6 @@ export function computeFeePayerBalanceLeafSlot(feePayer: AztecAddress): Fr {
18
17
  if (feePayer.isZero()) {
19
18
  return Fr.ZERO;
20
19
  }
21
- const feeJuice = AztecAddress.fromBigInt(FEE_JUICE_ADDRESS);
22
20
  const balanceSlot = computeFeePayerBalanceStorageSlot(feePayer);
23
- return computePublicDataTreeLeafSlot(feeJuice, balanceSlot);
21
+ return computePublicDataTreeLeafSlot(ProtocolContractAddress.FeeJuice, balanceSlot);
24
22
  }
@@ -29,10 +29,10 @@ import {
29
29
  import { makeTuple } from '@aztec/foundation/array';
30
30
  import { type Tuple } from '@aztec/foundation/serialize';
31
31
  import { type IndexedTreeLeafPreimage } from '@aztec/foundation/trees';
32
- import { type MerkleTreeOperations } from '@aztec/world-state';
32
+ import { type MerkleTreeReadOperations } from '@aztec/world-state';
33
33
 
34
34
  export class HintsBuilder {
35
- constructor(private db: MerkleTreeOperations) {}
35
+ constructor(private db: MerkleTreeReadOperations) {}
36
36
 
37
37
  async getNoteHashReadRequestsHints(
38
38
  readRequests: Tuple<TreeLeafReadRequest, typeof MAX_NOTE_HASH_READ_REQUESTS_PER_TX>,
@@ -49,15 +49,13 @@ export class HintsBuilder {
49
49
  nullifierReadRequests: Tuple<ScopedReadRequest, typeof MAX_NULLIFIER_READ_REQUESTS_PER_TX>,
50
50
  pendingNullifiers: Tuple<Nullifier, typeof MAX_NULLIFIERS_PER_TX>,
51
51
  ) {
52
- return (
53
- await buildSiloedNullifierReadRequestHints(
54
- this,
55
- nullifierReadRequests,
56
- pendingNullifiers,
57
- MAX_NULLIFIER_READ_REQUESTS_PER_TX,
58
- MAX_NULLIFIER_READ_REQUESTS_PER_TX,
59
- )
60
- ).hints;
52
+ return await buildSiloedNullifierReadRequestHints(
53
+ this,
54
+ nullifierReadRequests,
55
+ pendingNullifiers,
56
+ MAX_NULLIFIER_READ_REQUESTS_PER_TX,
57
+ MAX_NULLIFIER_READ_REQUESTS_PER_TX,
58
+ );
61
59
  }
62
60
 
63
61
  getNullifierNonExistentReadRequestHints(
@@ -1,9 +1,18 @@
1
- import { MerkleTreeId, NullifierMembershipWitness, type Tx } from '@aztec/circuit-types';
1
+ import {
2
+ MerkleTreeId,
3
+ type MerkleTreeReadOperations,
4
+ type MerkleTreeWriteOperations,
5
+ NullifierMembershipWitness,
6
+ type Tx,
7
+ } from '@aztec/circuit-types';
2
8
  import { type PublicDBAccessStats } from '@aztec/circuit-types/stats';
3
9
  import {
4
10
  type AztecAddress,
11
+ type ContractClassPublic,
5
12
  ContractClassRegisteredEvent,
13
+ type ContractDataSource,
6
14
  ContractInstanceDeployedEvent,
15
+ type ContractInstanceWithAddress,
7
16
  Fr,
8
17
  FunctionSelector,
9
18
  type L1_TO_L2_MSG_TREE_HEIGHT,
@@ -14,19 +23,13 @@ import {
14
23
  import { computeL1ToL2MessageNullifier, computePublicDataTreeLeafSlot } from '@aztec/circuits.js/hash';
15
24
  import { createDebugLogger } from '@aztec/foundation/log';
16
25
  import { Timer } from '@aztec/foundation/timer';
17
- import { ClassRegistererAddress } from '@aztec/protocol-contracts/class-registerer';
26
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
18
27
  import {
19
28
  type CommitmentsDB,
20
29
  MessageLoadOracleInputs,
21
30
  type PublicContractsDB,
22
31
  type PublicStateDB,
23
32
  } from '@aztec/simulator';
24
- import {
25
- type ContractClassPublic,
26
- type ContractDataSource,
27
- type ContractInstanceWithAddress,
28
- } from '@aztec/types/contracts';
29
- import { type MerkleTreeOperations } from '@aztec/world-state';
30
33
 
31
34
  /**
32
35
  * Implements the PublicContractsDB using a ContractDataSource.
@@ -47,7 +50,7 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
47
50
  public addNewContracts(tx: Tx): Promise<void> {
48
51
  // Extract contract class and instance data from logs and add to cache for this block
49
52
  const logs = tx.unencryptedLogs.unrollLogs();
50
- ContractClassRegisteredEvent.fromLogs(logs, ClassRegistererAddress).forEach(e => {
53
+ ContractClassRegisteredEvent.fromLogs(logs, ProtocolContractAddress.ContractClassRegisterer).forEach(e => {
51
54
  this.log.debug(`Adding class ${e.contractClassId.toString()} to public execution contract cache`);
52
55
  this.classCache.set(e.contractClassId.toString(), e.toContractClassPublic());
53
56
  });
@@ -70,7 +73,7 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
70
73
  // Let's say we have two txs adding the same contract on the same block. If the 2nd one reverts,
71
74
  // wouldn't that accidentally remove the contract added on the first one?
72
75
  const logs = tx.unencryptedLogs.unrollLogs();
73
- ContractClassRegisteredEvent.fromLogs(logs, ClassRegistererAddress).forEach(e =>
76
+ ContractClassRegisteredEvent.fromLogs(logs, ProtocolContractAddress.ContractClassRegisterer).forEach(e =>
74
77
  this.classCache.delete(e.contractClassId.toString()),
75
78
  );
76
79
  ContractInstanceDeployedEvent.fromLogs(logs).forEach(e => this.instanceCache.delete(e.address.toString()));
@@ -124,7 +127,7 @@ export class WorldStateDB extends ContractsDataSourcePublicDB implements PublicS
124
127
  private publicCheckpointedWriteCache: Map<bigint, Fr> = new Map();
125
128
  private publicUncommittedWriteCache: Map<bigint, Fr> = new Map();
126
129
 
127
- constructor(private db: MerkleTreeOperations, dataSource: ContractDataSource) {
130
+ constructor(private db: MerkleTreeWriteOperations, dataSource: ContractDataSource) {
128
131
  super(dataSource);
129
132
  }
130
133
 
@@ -149,17 +152,7 @@ export class WorldStateDB extends ContractsDataSourcePublicDB implements PublicS
149
152
  return committed;
150
153
  }
151
154
 
152
- const lowLeafResult = await this.db.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot);
153
- if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
154
- return Fr.ZERO;
155
- }
156
-
157
- const preimage = (await this.db.getLeafPreimage(
158
- MerkleTreeId.PUBLIC_DATA_TREE,
159
- lowLeafResult.index,
160
- )) as PublicDataTreeLeafPreimage;
161
-
162
- return preimage.value;
155
+ return await readPublicState(this.db, contract, slot);
163
156
  }
164
157
 
165
158
  /**
@@ -325,3 +318,19 @@ export class WorldStateDB extends ContractsDataSourcePublicDB implements PublicS
325
318
  return Promise.resolve();
326
319
  }
327
320
  }
321
+
322
+ export async function readPublicState(db: MerkleTreeReadOperations, contract: AztecAddress, slot: Fr): Promise<Fr> {
323
+ const leafSlot = computePublicDataTreeLeafSlot(contract, slot).toBigInt();
324
+
325
+ const lowLeafResult = await db.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot);
326
+ if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
327
+ return Fr.ZERO;
328
+ }
329
+
330
+ const preimage = (await db.getLeafPreimage(
331
+ MerkleTreeId.PUBLIC_DATA_TREE,
332
+ lowLeafResult.index,
333
+ )) as PublicDataTreeLeafPreimage;
334
+
335
+ return preimage.value;
336
+ }
@@ -11,19 +11,19 @@ import {
11
11
  mergeAccumulatedData,
12
12
  } from '@aztec/circuits.js';
13
13
  import { ProtocolCircuitVks, getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types';
14
- import { type MerkleTreeOperations } from '@aztec/world-state';
14
+ import { type MerkleTreeReadOperations } from '@aztec/world-state';
15
15
 
16
16
  import { HintsBuilder } from './hints_builder.js';
17
17
  import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
18
18
 
19
19
  export class PublicKernelTailSimulator {
20
20
  constructor(
21
- private db: MerkleTreeOperations,
21
+ private db: MerkleTreeReadOperations,
22
22
  private publicKernelSimulator: PublicKernelCircuitSimulator,
23
23
  private hintsBuilder: HintsBuilder,
24
24
  ) {}
25
25
 
26
- static create(db: MerkleTreeOperations, publicKernelSimulator: PublicKernelCircuitSimulator) {
26
+ static create(db: MerkleTreeReadOperations, publicKernelSimulator: PublicKernelCircuitSimulator) {
27
27
  const hintsBuilder = new HintsBuilder(db);
28
28
  return new PublicKernelTailSimulator(db, publicKernelSimulator, hintsBuilder);
29
29
  }
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  type FailedTx,
3
+ type MerkleTreeWriteOperations,
3
4
  NestedProcessReturnValues,
4
5
  type ProcessedTx,
5
6
  type ProcessedTxHandler,
@@ -9,9 +10,8 @@ import {
9
10
  validateProcessedTx,
10
11
  } from '@aztec/circuit-types';
11
12
  import {
12
- AztecAddress,
13
13
  ContractClassRegisteredEvent,
14
- FEE_JUICE_ADDRESS,
14
+ type ContractDataSource,
15
15
  type GlobalVariables,
16
16
  type Header,
17
17
  MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
@@ -21,10 +21,8 @@ import {
21
21
  import { times } from '@aztec/foundation/collection';
22
22
  import { createDebugLogger } from '@aztec/foundation/log';
23
23
  import { Timer } from '@aztec/foundation/timer';
24
- import { ClassRegistererAddress } from '@aztec/protocol-contracts/class-registerer';
24
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
25
25
  import { Attributes, type TelemetryClient, type Tracer, trackSpan } from '@aztec/telemetry-client';
26
- import { type ContractDataSource } from '@aztec/types/contracts';
27
- import { type MerkleTreeOperations } from '@aztec/world-state';
28
26
 
29
27
  import { type SimulationProvider } from '../providers/index.js';
30
28
  import { EnqueuedCallsProcessor } from './enqueued_calls_processor.js';
@@ -40,7 +38,6 @@ import { PublicProcessorMetrics } from './public_processor_metrics.js';
40
38
  */
41
39
  export class PublicProcessorFactory {
42
40
  constructor(
43
- private merkleTree: MerkleTreeOperations,
44
41
  private contractDataSource: ContractDataSource,
45
42
  private simulator: SimulationProvider,
46
43
  private telemetryClient: TelemetryClient,
@@ -52,12 +49,16 @@ export class PublicProcessorFactory {
52
49
  * @param globalVariables - The global variables for the block being processed.
53
50
  * @returns A new instance of a PublicProcessor.
54
51
  */
55
- public create(maybeHistoricalHeader: Header | undefined, globalVariables: GlobalVariables): PublicProcessor {
56
- const { merkleTree, telemetryClient } = this;
52
+ public create(
53
+ merkleTree: MerkleTreeWriteOperations,
54
+ maybeHistoricalHeader: Header | undefined,
55
+ globalVariables: GlobalVariables,
56
+ ): PublicProcessor {
57
+ const { telemetryClient } = this;
57
58
  const historicalHeader = maybeHistoricalHeader ?? merkleTree.getInitialHeader();
58
59
 
59
60
  const worldStateDB = new WorldStateDB(merkleTree, this.contractDataSource);
60
- const publicExecutor = new PublicExecutor(worldStateDB, historicalHeader, telemetryClient);
61
+ const publicExecutor = new PublicExecutor(worldStateDB, telemetryClient);
61
62
  const publicKernelSimulator = new RealPublicKernelCircuitSimulator(this.simulator);
62
63
 
63
64
  return PublicProcessor.create(
@@ -79,7 +80,7 @@ export class PublicProcessorFactory {
79
80
  export class PublicProcessor {
80
81
  private metrics: PublicProcessorMetrics;
81
82
  constructor(
82
- protected db: MerkleTreeOperations,
83
+ protected db: MerkleTreeWriteOperations,
83
84
  protected publicExecutor: PublicExecutor,
84
85
  protected publicKernel: PublicKernelCircuitSimulator,
85
86
  protected globalVariables: GlobalVariables,
@@ -93,7 +94,7 @@ export class PublicProcessor {
93
94
  }
94
95
 
95
96
  static create(
96
- db: MerkleTreeOperations,
97
+ db: MerkleTreeWriteOperations,
97
98
  publicExecutor: PublicExecutor,
98
99
  publicKernelSimulator: PublicKernelCircuitSimulator,
99
100
  globalVariables: GlobalVariables,
@@ -216,7 +217,7 @@ export class PublicProcessor {
216
217
  return finalPublicDataUpdateRequests;
217
218
  }
218
219
 
219
- const feeJuiceAddress = AztecAddress.fromBigInt(FEE_JUICE_ADDRESS);
220
+ const feeJuiceAddress = ProtocolContractAddress.FeeJuice;
220
221
  const balanceSlot = computeFeePayerBalanceStorageSlot(feePayer);
221
222
  const leafSlot = computeFeePayerBalanceLeafSlot(feePayer);
222
223
  const txFee = tx.data.getTransactionFee(this.globalVariables.gasFees);
@@ -269,7 +270,10 @@ export class PublicProcessor {
269
270
  });
270
271
 
271
272
  this.metrics.recordClassRegistration(
272
- ...ContractClassRegisteredEvent.fromLogs(tx.unencryptedLogs.unrollLogs(), ClassRegistererAddress),
273
+ ...ContractClassRegisteredEvent.fromLogs(
274
+ tx.unencryptedLogs.unrollLogs(),
275
+ ProtocolContractAddress.ContractClassRegisterer,
276
+ ),
273
277
  );
274
278
 
275
279
  const phaseCount = processedPhases.length;
@@ -0,0 +1,6 @@
1
+ export class SideEffectLimitReachedError extends Error {
2
+ constructor(sideEffectType: string, limit: number) {
3
+ super(`Reached the limit on number of '${sideEffectType}' side effects: ${limit}`);
4
+ this.name = 'SideEffectLimitReachedError';
5
+ }
6
+ }