@aztec/simulator 0.86.0 → 0.87.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 (188) hide show
  1. package/dest/common/errors.d.ts +3 -6
  2. package/dest/common/errors.d.ts.map +1 -1
  3. package/dest/common/errors.js +50 -31
  4. package/dest/private/acvm/acvm.d.ts +0 -2
  5. package/dest/private/acvm/acvm.d.ts.map +1 -1
  6. package/dest/private/acvm/acvm.js +2 -2
  7. package/dest/private/acvm/deserialize.d.ts +0 -2
  8. package/dest/private/acvm/deserialize.d.ts.map +1 -1
  9. package/dest/private/acvm/oracle/oracle.d.ts +2 -2
  10. package/dest/private/acvm/oracle/oracle.d.ts.map +1 -1
  11. package/dest/private/acvm/oracle/oracle.js +30 -33
  12. package/dest/private/acvm/oracle/typed_oracle.d.ts +1 -3
  13. package/dest/private/acvm/oracle/typed_oracle.d.ts.map +1 -1
  14. package/dest/private/acvm/serialize.d.ts +8 -2
  15. package/dest/private/acvm/serialize.d.ts.map +1 -1
  16. package/dest/private/acvm/serialize.js +26 -0
  17. package/dest/private/index.d.ts +3 -0
  18. package/dest/private/index.d.ts.map +1 -1
  19. package/dest/private/index.js +3 -0
  20. package/dest/private/private_execution.d.ts.map +1 -1
  21. package/dest/private/private_execution.js +7 -1
  22. package/dest/private/providers/acvm_native.d.ts +0 -2
  23. package/dest/private/providers/acvm_native.d.ts.map +1 -1
  24. package/dest/private/providers/acvm_native.js +1 -1
  25. package/dest/private/providers/circuit_recording/circuit_recorder.d.ts +0 -2
  26. package/dest/private/providers/circuit_recording/circuit_recorder.d.ts.map +1 -1
  27. package/dest/private/providers/simulation_provider.d.ts.map +1 -1
  28. package/dest/private/providers/simulation_provider.js +14 -16
  29. package/dest/private/simulator.d.ts.map +1 -1
  30. package/dest/private/utility_execution_oracle.d.ts +0 -2
  31. package/dest/private/utility_execution_oracle.d.ts.map +1 -1
  32. package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
  33. package/dest/public/avm/avm_contract_call_result.js +2 -2
  34. package/dest/public/avm/avm_execution_environment.d.ts +2 -1
  35. package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
  36. package/dest/public/avm/avm_execution_environment.js +4 -2
  37. package/dest/public/avm/avm_gas.d.ts +0 -15
  38. package/dest/public/avm/avm_gas.d.ts.map +1 -1
  39. package/dest/public/avm/avm_gas.js +0 -18
  40. package/dest/public/avm/avm_memory_types.d.ts +84 -86
  41. package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
  42. package/dest/public/avm/avm_simulator.d.ts +1 -3
  43. package/dest/public/avm/avm_simulator.d.ts.map +1 -1
  44. package/dest/public/avm/avm_simulator.js +3 -3
  45. package/dest/public/avm/avm_simulator_interface.d.ts +0 -2
  46. package/dest/public/avm/avm_simulator_interface.d.ts.map +1 -1
  47. package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
  48. package/dest/public/avm/fixtures/initializers.js +1 -1
  49. package/dest/public/avm/fixtures/utils.d.ts +0 -10
  50. package/dest/public/avm/fixtures/utils.d.ts.map +1 -1
  51. package/dest/public/avm/fixtures/utils.js +0 -42
  52. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
  53. package/dest/public/avm/opcodes/accrued_substate.js +7 -7
  54. package/dest/public/avm/opcodes/addressing_mode.d.ts +7 -6
  55. package/dest/public/avm/opcodes/addressing_mode.d.ts.map +1 -1
  56. package/dest/public/avm/opcodes/addressing_mode.js +18 -15
  57. package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
  58. package/dest/public/avm/opcodes/arithmetic.js +1 -1
  59. package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
  60. package/dest/public/avm/opcodes/bitwise.js +2 -2
  61. package/dest/public/avm/opcodes/comparators.d.ts.map +1 -1
  62. package/dest/public/avm/opcodes/comparators.js +1 -1
  63. package/dest/public/avm/opcodes/contract.d.ts +1 -2
  64. package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
  65. package/dest/public/avm/opcodes/contract.js +8 -9
  66. package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
  67. package/dest/public/avm/opcodes/control_flow.js +1 -1
  68. package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
  69. package/dest/public/avm/opcodes/conversion.js +1 -1
  70. package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
  71. package/dest/public/avm/opcodes/ec_add.js +1 -1
  72. package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
  73. package/dest/public/avm/opcodes/environment_getters.js +1 -1
  74. package/dest/public/avm/opcodes/external_calls.d.ts +6 -6
  75. package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
  76. package/dest/public/avm/opcodes/external_calls.js +22 -22
  77. package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
  78. package/dest/public/avm/opcodes/hashing.js +3 -3
  79. package/dest/public/avm/opcodes/instruction.d.ts +0 -2
  80. package/dest/public/avm/opcodes/instruction.d.ts.map +1 -1
  81. package/dest/public/avm/opcodes/memory.d.ts +4 -4
  82. package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
  83. package/dest/public/avm/opcodes/memory.js +16 -16
  84. package/dest/public/avm/opcodes/misc.d.ts.map +1 -1
  85. package/dest/public/avm/opcodes/misc.js +18 -11
  86. package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
  87. package/dest/public/avm/opcodes/storage.js +2 -2
  88. package/dest/public/avm/serialization/buffer_cursor.d.ts +0 -2
  89. package/dest/public/avm/serialization/buffer_cursor.d.ts.map +1 -1
  90. package/dest/public/avm/serialization/bytecode_serialization.d.ts +0 -2
  91. package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -1
  92. package/dest/public/avm/serialization/instruction_serialization.d.ts +0 -2
  93. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
  94. package/dest/public/executor_metrics.d.ts +3 -3
  95. package/dest/public/executor_metrics.d.ts.map +1 -1
  96. package/dest/public/executor_metrics.js +6 -6
  97. package/dest/public/executor_metrics_interface.d.ts +1 -1
  98. package/dest/public/executor_metrics_interface.d.ts.map +1 -1
  99. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  100. package/dest/public/fixtures/public_tx_simulation_tester.js +3 -3
  101. package/dest/public/fixtures/utils.d.ts.map +1 -1
  102. package/dest/public/fixtures/utils.js +19 -26
  103. package/dest/public/hinting_db_sources.d.ts +0 -2
  104. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  105. package/dest/public/hinting_db_sources.js +9 -2
  106. package/dest/public/public_processor/public_processor.d.ts +5 -7
  107. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  108. package/dest/public/public_processor/public_processor.js +10 -7
  109. package/dest/public/public_tx_simulator/apps_tests/amm_test.js +5 -5
  110. package/dest/public/public_tx_simulator/apps_tests/token_test.js +6 -6
  111. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +1 -1
  112. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
  113. package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +3 -3
  114. package/dest/public/public_tx_simulator/public_tx_context.d.ts +1 -1
  115. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  116. package/dest/public/public_tx_simulator/public_tx_context.js +37 -34
  117. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +2 -1
  118. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  119. package/dest/public/public_tx_simulator/public_tx_simulator.js +15 -4
  120. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +1 -1
  121. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -1
  122. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +2 -2
  123. package/dest/public/side_effect_trace.d.ts +2 -39
  124. package/dest/public/side_effect_trace.d.ts.map +1 -1
  125. package/dest/public/side_effect_trace.js +8 -32
  126. package/dest/public/side_effect_trace_interface.d.ts +0 -4
  127. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  128. package/dest/public/state_manager/nullifiers.d.ts.map +1 -1
  129. package/dest/public/state_manager/public_storage.d.ts.map +1 -1
  130. package/dest/public/state_manager/state_manager.d.ts +6 -4
  131. package/dest/public/state_manager/state_manager.d.ts.map +1 -1
  132. package/dest/public/state_manager/state_manager.js +6 -3
  133. package/dest/public/test_executor_metrics.d.ts +5 -4
  134. package/dest/public/test_executor_metrics.d.ts.map +1 -1
  135. package/dest/public/test_executor_metrics.js +47 -11
  136. package/dest/public/unique_class_ids.d.ts.map +1 -1
  137. package/dest/test/utils.d.ts.map +1 -1
  138. package/package.json +18 -17
  139. package/src/common/errors.ts +77 -41
  140. package/src/private/acvm/acvm.ts +2 -2
  141. package/src/private/acvm/oracle/oracle.ts +38 -31
  142. package/src/private/acvm/oracle/typed_oracle.ts +1 -1
  143. package/src/private/acvm/serialize.ts +35 -0
  144. package/src/private/index.ts +3 -0
  145. package/src/private/pick_notes.ts +4 -4
  146. package/src/private/private_execution.ts +8 -0
  147. package/src/private/providers/acvm_native.ts +6 -2
  148. package/src/private/providers/simulation_provider.ts +14 -16
  149. package/src/private/simulator.ts +4 -1
  150. package/src/public/avm/avm_contract_call_result.ts +2 -2
  151. package/src/public/avm/avm_execution_environment.ts +7 -1
  152. package/src/public/avm/avm_gas.ts +0 -20
  153. package/src/public/avm/avm_simulator.ts +3 -1
  154. package/src/public/avm/fixtures/initializers.ts +1 -0
  155. package/src/public/avm/fixtures/utils.ts +0 -66
  156. package/src/public/avm/opcodes/accrued_substate.ts +31 -11
  157. package/src/public/avm/opcodes/addressing_mode.ts +23 -20
  158. package/src/public/avm/opcodes/arithmetic.ts +2 -1
  159. package/src/public/avm/opcodes/bitwise.ts +9 -3
  160. package/src/public/avm/opcodes/comparators.ts +2 -1
  161. package/src/public/avm/opcodes/contract.ts +7 -6
  162. package/src/public/avm/opcodes/control_flow.ts +7 -2
  163. package/src/public/avm/opcodes/conversion.ts +2 -1
  164. package/src/public/avm/opcodes/ec_add.ts +2 -1
  165. package/src/public/avm/opcodes/environment_getters.ts +7 -2
  166. package/src/public/avm/opcodes/external_calls.ts +26 -14
  167. package/src/public/avm/opcodes/hashing.ts +17 -5
  168. package/src/public/avm/opcodes/memory.ts +33 -15
  169. package/src/public/avm/opcodes/misc.ts +23 -15
  170. package/src/public/avm/opcodes/storage.ts +9 -3
  171. package/src/public/avm/serialization/buffer_cursor.ts +4 -1
  172. package/src/public/executor_metrics.ts +11 -6
  173. package/src/public/executor_metrics_interface.ts +1 -1
  174. package/src/public/fixtures/public_tx_simulation_tester.ts +3 -2
  175. package/src/public/fixtures/utils.ts +21 -28
  176. package/src/public/hinting_db_sources.ts +17 -4
  177. package/src/public/public_processor/public_processor.ts +11 -5
  178. package/src/public/public_tx_simulator/apps_tests/amm_test.ts +5 -5
  179. package/src/public/public_tx_simulator/apps_tests/token_test.ts +6 -6
  180. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +3 -2
  181. package/src/public/public_tx_simulator/public_tx_context.ts +96 -81
  182. package/src/public/public_tx_simulator/public_tx_simulator.ts +14 -3
  183. package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +10 -1
  184. package/src/public/side_effect_trace.ts +7 -111
  185. package/src/public/side_effect_trace_interface.ts +0 -4
  186. package/src/public/state_manager/state_manager.ts +13 -5
  187. package/src/public/test_executor_metrics.ts +60 -13
  188. package/src/public/avm/opcodes/.eslintrc.cjs +0 -8
@@ -2,7 +2,14 @@ import type { Fr } from '@aztec/foundation/fields';
2
2
  import { jsonStringify } from '@aztec/foundation/json-rpc';
3
3
  import type { RawAssertionPayload } from '@aztec/noir-acvm_js';
4
4
  import { abiDecodeError } from '@aztec/noir-noirc_abi';
5
- import type { BrilligFunctionId, FunctionAbi, FunctionDebugMetadata, OpcodeLocation } from '@aztec/stdlib/abi';
5
+ import type {
6
+ BrilligFunctionId,
7
+ DebugFileMap,
8
+ DebugInfo,
9
+ FunctionAbi,
10
+ LocationNodeDebugInfo,
11
+ OpcodeLocation,
12
+ } from '@aztec/stdlib/abi';
6
13
  import {
7
14
  type FailingFunction,
8
15
  type NoirCallStack,
@@ -76,38 +83,42 @@ export function createSimulationError(error: Error, revertData?: Fr[]): Simulati
76
83
  }
77
84
 
78
85
  /**
79
- * Extracts a brillig location from an opcode location.
80
- * @param opcodeLocation - The opcode location to extract from. It should be in the format `acirLocation.brilligLocation` or `acirLocation`.
81
- * @returns The brillig location if the opcode location contains one.
82
- */
83
- function extractBrilligLocation(opcodeLocation: string): string | undefined {
84
- const splitted = opcodeLocation.split('.');
85
- if (splitted.length === 2) {
86
- return splitted[1];
87
- }
88
- return undefined;
89
- }
90
-
91
- /**
92
- * Extracts the call stack from the location of a failing opcode and the debug metadata.
93
- * One opcode can point to multiple calls due to inlining.
86
+ * Resolves the source code locations from an array of opcode locations
94
87
  */
95
- function getSourceCodeLocationsFromOpcodeLocation(
96
- opcodeLocation: string,
97
- debug: FunctionDebugMetadata,
88
+ export function resolveOpcodeLocations(
89
+ opcodeLocations: OpcodeLocation[],
90
+ debug: DebugInfo,
91
+ files: DebugFileMap,
98
92
  brilligFunctionId?: BrilligFunctionId,
99
93
  ): SourceCodeLocation[] {
100
- const { debugSymbols, files } = debug;
94
+ let locations = opcodeLocations.flatMap(opcodeLocation =>
95
+ getSourceCodeLocationsFromOpcodeLocation(opcodeLocation, debug, files, brilligFunctionId),
96
+ );
101
97
 
102
- let callStack = debugSymbols.locations[opcodeLocation] || [];
103
- if (callStack.length === 0) {
104
- const brilligLocation = extractBrilligLocation(opcodeLocation);
105
- if (brilligFunctionId !== undefined && brilligLocation !== undefined) {
106
- callStack = debugSymbols.brillig_locations[brilligFunctionId][brilligLocation] || [];
98
+ // Adds the acir call stack if the last location is a brillig opcode
99
+ if (locations.length > 0) {
100
+ const decomposedOpcodeLocation = opcodeLocations[opcodeLocations.length - 1].split('.');
101
+ if (decomposedOpcodeLocation.length === 2) {
102
+ const acirCallstackId = debug.acir_locations[decomposedOpcodeLocation[0]];
103
+ if (acirCallstackId !== undefined) {
104
+ const callStack = debug.location_tree.locations[acirCallstackId];
105
+ const acirCallstack = getCallStackFromLocationNode(callStack, debug.location_tree.locations, files);
106
+ locations = acirCallstack.concat(locations);
107
+ }
107
108
  }
108
109
  }
109
- return callStack.map(call => {
110
- const { file: fileId, span } = call;
110
+ return locations;
111
+ }
112
+
113
+ function getCallStackFromLocationNode(
114
+ callStack: LocationNodeDebugInfo,
115
+ locationTree: LocationNodeDebugInfo[],
116
+ files: DebugFileMap,
117
+ ): SourceCodeLocation[] {
118
+ const result: SourceCodeLocation[] = [];
119
+
120
+ while (callStack.parent !== null) {
121
+ const { file: fileId, span } = callStack.value;
111
122
 
112
123
  const { path, source } = files[fileId];
113
124
 
@@ -118,30 +129,55 @@ function getSourceCodeLocationsFromOpcodeLocation(
118
129
  const line = previousLines.length;
119
130
  const column = previousLines[previousLines.length - 1].length + 1;
120
131
 
121
- return {
132
+ // Unshift since we are exploring child nodes first
133
+ result.unshift({
122
134
  filePath: path,
123
135
  line,
124
136
  column,
125
137
  fileSource: source,
126
138
  locationText,
127
- };
128
- });
129
- }
139
+ });
130
140
 
141
+ callStack = locationTree[callStack.parent];
142
+ }
143
+
144
+ return result;
145
+ }
131
146
  /**
132
- * Extracts the source code locations for an array of opcode locations
133
- * @param opcodeLocations - The opcode locations that caused the error.
134
- * @param debug - The debug metadata of the function.
135
- * @returns The source code locations.
147
+ * Extracts the call stack from the location of a failing opcode and the debug metadata.
148
+ * One opcode can point to multiple calls due to inlining.
136
149
  */
137
- export function resolveOpcodeLocations(
138
- opcodeLocations: OpcodeLocation[],
139
- debug: FunctionDebugMetadata,
150
+ function getSourceCodeLocationsFromOpcodeLocation(
151
+ opcodeLocation: string,
152
+ debug: DebugInfo,
153
+ files: DebugFileMap,
140
154
  brilligFunctionId?: BrilligFunctionId,
141
155
  ): SourceCodeLocation[] {
142
- return opcodeLocations.flatMap(opcodeLocation =>
143
- getSourceCodeLocationsFromOpcodeLocation(opcodeLocation, debug, brilligFunctionId),
144
- );
156
+ let callStackID = debug.acir_locations[opcodeLocation];
157
+ const brilligLocation = extractBrilligLocation(opcodeLocation);
158
+ if (brilligFunctionId !== undefined && brilligLocation !== undefined) {
159
+ callStackID = debug.brillig_locations[brilligFunctionId][brilligLocation];
160
+ if (callStackID === undefined) {
161
+ return [];
162
+ }
163
+ }
164
+
165
+ if (callStackID === undefined) {
166
+ return [];
167
+ }
168
+ const callStack = debug.location_tree.locations[callStackID];
169
+ return getCallStackFromLocationNode(callStack, debug.location_tree.locations, files);
170
+ }
171
+
172
+ /**
173
+ * Extracts a brillig location from an opcode location.
174
+ */
175
+ function extractBrilligLocation(opcodeLocation: string): string | undefined {
176
+ const splitted = opcodeLocation.split('.');
177
+ if (splitted.length === 2) {
178
+ return splitted[1];
179
+ }
180
+ return undefined;
145
181
  }
146
182
 
147
183
  export function resolveAssertionMessage(errorPayload: RawAssertionPayload, abi: FunctionAbi): string | undefined {
@@ -103,8 +103,8 @@ export function extractCallStack(
103
103
  }
104
104
 
105
105
  try {
106
- return resolveOpcodeLocations(callStack, debug, brilligFunctionId);
107
- } catch (err) {
106
+ return resolveOpcodeLocations(callStack, debug.debugSymbols, debug.files, brilligFunctionId);
107
+ } catch {
108
108
  return callStack;
109
109
  }
110
110
  }
@@ -1,13 +1,18 @@
1
1
  import { Fr, Point } from '@aztec/foundation/fields';
2
2
  import { EventSelector, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
3
3
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
- import { ContractClassLog, LogWithTxData } from '@aztec/stdlib/logs';
4
+ import { ContractClassLog, ContractClassLogFields, LogWithTxData } from '@aztec/stdlib/logs';
5
5
  import { MerkleTreeId } from '@aztec/stdlib/trees';
6
6
  import { TxHash } from '@aztec/stdlib/tx';
7
7
 
8
8
  import type { ACVMField } from '../acvm_types.js';
9
9
  import { fromBoundedVec, fromUintArray, fromUintBoundedVec } from '../deserialize.js';
10
- import { bufferToBoundedVec, toACVMField, toACVMFieldSingleOrArray } from '../serialize.js';
10
+ import {
11
+ arrayOfArraysToBoundedVecOfArrays,
12
+ bufferToBoundedVec,
13
+ toACVMField,
14
+ toACVMFieldSingleOrArray,
15
+ } from '../serialize.js';
11
16
  import type { TypedOracle } from './typed_oracle.js';
12
17
 
13
18
  /**
@@ -169,8 +174,9 @@ export class Oracle {
169
174
  [limit]: ACVMField[],
170
175
  [offset]: ACVMField[],
171
176
  [status]: ACVMField[],
172
- [returnSize]: ACVMField[],
173
- ): Promise<ACVMField[][]> {
177
+ [maxNotes]: ACVMField[],
178
+ [packedRetrievedNoteLength]: ACVMField[],
179
+ ): Promise<(ACVMField | ACVMField[])[]> {
174
180
  const noteDatas = await this.typedOracle.getNotes(
175
181
  Fr.fromString(storageSlot),
176
182
  +numSelects,
@@ -188,32 +194,30 @@ export class Oracle {
188
194
  +status,
189
195
  );
190
196
 
191
- const noteLength = noteDatas?.[0]?.note.items.length ?? 0;
192
- if (!noteDatas.every(({ note }) => noteLength === note.items.length)) {
193
- throw new Error('Notes should all be the same length.');
197
+ if (noteDatas.length > 0) {
198
+ const noteLength = noteDatas[0].note.items.length;
199
+ if (!noteDatas.every(({ note }) => noteLength === note.items.length)) {
200
+ throw new Error('Notes should all be the same length.');
201
+ }
194
202
  }
195
203
 
196
- const contractAddress = noteDatas[0]?.contractAddress ?? Fr.ZERO;
197
-
198
- // Values indicates whether the note is settled or transient.
199
- const noteTypes = {
200
- isSettled: new Fr(0),
201
- isTransient: new Fr(1),
202
- };
203
- const flattenData = noteDatas.flatMap(({ nonce, note, index }) => [
204
- nonce,
205
- index === undefined ? noteTypes.isTransient : noteTypes.isSettled,
206
- ...note.items,
207
- ]);
208
-
209
- const returnFieldSize = +returnSize;
210
- const returnData = [noteDatas.length, contractAddress, ...flattenData].map(v => toACVMField(v));
211
- if (returnData.length > returnFieldSize) {
212
- throw new Error(`Return data size too big. Maximum ${returnFieldSize} fields. Got ${flattenData.length}.`);
213
- }
204
+ // The expected return type is a BoundedVec<[Field; packedRetrievedNoteLength], maxNotes> where each
205
+ // array is structured as [contract_address, nonce, nonzero_note_hash_counter, ...packed_note].
214
206
 
215
- const paddedZeros = Array(returnFieldSize - returnData.length).fill(toACVMField(0));
216
- return [returnData.concat(paddedZeros)];
207
+ const returnDataAsArrayOfArrays = noteDatas.map(({ contractAddress, nonce, index, note }) => {
208
+ // If index is undefined, the note is transient which implies that the nonzero_note_hash_counter has to be true
209
+ const noteIsTransient = index === undefined;
210
+ const nonzeroNoteHashCounter = noteIsTransient ? true : false;
211
+ // If you change the array on the next line you have to change the `unpack_retrieved_note` function in
212
+ // `aztec/src/note/retrieved_note.nr`
213
+ return [contractAddress, nonce, nonzeroNoteHashCounter, ...note.items];
214
+ });
215
+
216
+ // Now we convert each sub-array to an array of ACVMField
217
+ const returnDataAsArrayOfACVMFieldArrays = returnDataAsArrayOfArrays.map(subArray => subArray.map(toACVMField));
218
+
219
+ // At last we convert the array of arrays to a bounded vec of arrays
220
+ return arrayOfArraysToBoundedVecOfArrays(returnDataAsArrayOfACVMFieldArrays, +maxNotes, +packedRetrievedNoteLength);
217
221
  }
218
222
 
219
223
  notifyCreatedNote(
@@ -288,10 +292,11 @@ export class Oracle {
288
292
  notifyCreatedContractClassLog(
289
293
  [contractAddress]: ACVMField[],
290
294
  message: ACVMField[],
295
+ [length]: ACVMField[],
291
296
  [counter]: ACVMField[],
292
297
  ): Promise<ACVMField[]> {
293
- const logPayload = message.map(Fr.fromString);
294
- const log = new ContractClassLog(new AztecAddress(Fr.fromString(contractAddress)), logPayload);
298
+ const logFields = new ContractClassLogFields(message.map(Fr.fromString));
299
+ const log = new ContractClassLog(new AztecAddress(Fr.fromString(contractAddress)), logFields, +length);
295
300
 
296
301
  this.typedOracle.notifyCreatedContractClassLog(log, +counter);
297
302
  return Promise.resolve([]);
@@ -351,8 +356,10 @@ export class Oracle {
351
356
  return [];
352
357
  }
353
358
 
354
- notifySetMinRevertibleSideEffectCounter([minRevertibleSideEffectCounter]: ACVMField[]): Promise<ACVMField[]> {
355
- this.typedOracle.notifySetMinRevertibleSideEffectCounter(Fr.fromString(minRevertibleSideEffectCounter).toNumber());
359
+ async notifySetMinRevertibleSideEffectCounter([minRevertibleSideEffectCounter]: ACVMField[]): Promise<ACVMField[]> {
360
+ await this.typedOracle.notifySetMinRevertibleSideEffectCounter(
361
+ Fr.fromString(minRevertibleSideEffectCounter).toNumber(),
362
+ );
356
363
  return Promise.resolve([]);
357
364
  }
358
365
 
@@ -198,7 +198,7 @@ export abstract class TypedOracle {
198
198
  return Promise.reject(new OracleMethodNotAvailableError('notifySetPublicTeardownFunctionCall'));
199
199
  }
200
200
 
201
- notifySetMinRevertibleSideEffectCounter(_minRevertibleSideEffectCounter: number): void {
201
+ notifySetMinRevertibleSideEffectCounter(_minRevertibleSideEffectCounter: number): Promise<void> {
202
202
  throw new OracleMethodNotAvailableError('notifySetMinRevertibleSideEffectCounter');
203
203
  }
204
204
 
@@ -86,3 +86,38 @@ export function arrayToBoundedVec(bVecStorage: ACVMField[], maxLen: number): [AC
86
86
  const len = toACVMField(BigInt(bVecStorage.length));
87
87
  return [storage, len];
88
88
  }
89
+
90
+ /**
91
+ * Converts an array of arrays representing Noir BoundedVec of nested arrays into its Noir serialized form.
92
+ * @param bVecStorage - The array underlying the BoundedVec.
93
+ * @param maxLen - The max length of the BoundedVec (max num of the nested arrays in the BoundedVec).
94
+ * @param nestedArrayLength - The length of the nested arrays (each nested array has to have the same length).
95
+ * @returns Serialized BoundedVec following Noir intrinsic serialization.
96
+ */
97
+ export function arrayOfArraysToBoundedVecOfArrays(
98
+ bVecStorage: ACVMField[][],
99
+ maxLen: number,
100
+ nestedArrayLength: number,
101
+ ): [ACVMField[], ACVMField] {
102
+ if (bVecStorage.length > maxLen) {
103
+ throw new Error(`Array of length ${bVecStorage.length} larger than maxLen ${maxLen}`);
104
+ }
105
+
106
+ // Check that all nested arrays have length nestedArrayLength
107
+ if (!bVecStorage.every(nestedArray => nestedArray.length === nestedArrayLength)) {
108
+ throw new Error(
109
+ `Nested array length passed in from Noir does not correspond to the length obtained in TS: ${nestedArrayLength} !== ${bVecStorage[0].length}`,
110
+ );
111
+ }
112
+
113
+ // Flatten the array of arrays
114
+ const flattenedStorage = bVecStorage.flat();
115
+
116
+ // Calculate and add padding
117
+ const numFieldsToPad = maxLen * nestedArrayLength - flattenedStorage.length;
118
+ const flattenedStorageWithPadding = flattenedStorage.concat(Array(numFieldsToPad).fill(toACVMField(BigInt(0))));
119
+
120
+ // Return flattened array with padding and length
121
+ const len = toACVMField(BigInt(bVecStorage.length));
122
+ return [flattenedStorageWithPadding, len];
123
+ }
@@ -9,6 +9,9 @@ export { ExecutionNoteCache } from './execution_note_cache.js';
9
9
  export { extractPrivateCircuitPublicInputs, readCurrentClassId } from './private_execution.js';
10
10
  export { witnessMapToFields } from './acvm/deserialize.js';
11
11
  export { toACVMWitness } from './acvm/serialize.js';
12
+ export { executePrivateFunction } from './private_execution.js';
13
+ export { PrivateExecutionOracle } from './private_execution_oracle.js';
14
+ export { UtilityExecutionOracle } from './utility_execution_oracle.js';
12
15
  export { extractCallStack } from './acvm/acvm.js';
13
16
  export { type NoteData, TypedOracle } from './acvm/oracle/typed_oracle.js';
14
17
  export { Oracle } from './acvm/oracle/oracle.js';
@@ -113,19 +113,19 @@ const sortNotes = (a: Fr[], b: Fr[], sorts: Sort[], level = 0): number => {
113
113
  }
114
114
 
115
115
  const { selector, order } = sorts[level];
116
- if (order === 0) {
116
+ if (order === (0 as SortOrder)) {
117
117
  return 0;
118
118
  }
119
119
 
120
120
  const aValue = selectPropertyFromPackedNoteContent(a, selector);
121
121
  const bValue = selectPropertyFromPackedNoteContent(b, selector);
122
122
 
123
- const dir = order === 1 ? [-1, 1] : [1, -1];
123
+ const dir = order === (1 as SortOrder) ? [-1, 1] : [1, -1];
124
124
  return aValue.toBigInt() === bValue.toBigInt()
125
125
  ? sortNotes(a, b, sorts, level + 1)
126
126
  : aValue.toBigInt() > bValue.toBigInt()
127
- ? dir[0]
128
- : dir[1];
127
+ ? dir[0]
128
+ : dir[1];
129
129
  };
130
130
 
131
131
  /**
@@ -91,6 +91,14 @@ export async function executePrivateFunction(
91
91
  rawReturnValues,
92
92
  nestedExecutions,
93
93
  contractClassLogs,
94
+ {
95
+ timings: {
96
+ witgen:
97
+ // Due to the recursive nature of execution, we have to subtract the time taken by the first level of
98
+ // child executions
99
+ duration - nestedExecutions.reduce((acc, nested) => acc + (nested.profileResult?.timings.witgen ?? 0), 0),
100
+ },
101
+ },
94
102
  );
95
103
  }
96
104
 
@@ -78,7 +78,7 @@ export async function executeNativeCircuit(
78
78
  try {
79
79
  // Check that the directory exists
80
80
  await fs.access(workingDirectory);
81
- } catch (error) {
81
+ } catch {
82
82
  return { status: ACVM_RESULT.FAILURE, reason: `Working directory ${workingDirectory} does not exist` };
83
83
  }
84
84
 
@@ -138,7 +138,11 @@ export async function executeNativeCircuit(
138
138
  }
139
139
 
140
140
  export class NativeACVMSimulator implements SimulationProvider {
141
- constructor(private workingDirectory: string, private pathToAcvm: string, private witnessFilename?: string) {}
141
+ constructor(
142
+ private workingDirectory: string,
143
+ private pathToAcvm: string,
144
+ private witnessFilename?: string,
145
+ ) {}
142
146
 
143
147
  async executeProtocolCircuit(
144
148
  input: ACVMWitness,
@@ -46,25 +46,23 @@ export type DecodedError = ExecutionError & { decodedAssertionPayload?: any; noi
46
46
  // Payload parsing taken from noir/noir-repo/tooling/noir_js/src/witness_generation.ts.
47
47
  // TODO: import this in isolation without having to import noir_js in its entirety.
48
48
  export function enrichNoirError(artifact: NoirCompiledCircuit, originalError: ExecutionError): DecodedError {
49
- const payload = originalError.rawAssertionPayload;
50
- if (!payload) {
51
- return originalError;
52
- }
53
49
  const enrichedError = originalError as DecodedError;
54
50
 
55
- try {
56
- // Decode the payload
57
- const decodedPayload = abiDecodeError(artifact.abi, payload);
51
+ if (originalError.rawAssertionPayload) {
52
+ try {
53
+ // Decode the payload
54
+ const decodedPayload = abiDecodeError(artifact.abi, originalError.rawAssertionPayload);
58
55
 
59
- if (typeof decodedPayload === 'string') {
60
- // If it's a string, just add it to the error message
61
- enrichedError.message = `Circuit execution failed: ${decodedPayload}`;
62
- } else {
63
- // If not, attach the payload to the original error
64
- enrichedError.decodedAssertionPayload = decodedPayload;
56
+ if (typeof decodedPayload === 'string') {
57
+ // If it's a string, just add it to the error message
58
+ enrichedError.message = `Circuit execution failed: ${decodedPayload}`;
59
+ } else {
60
+ // If not, attach the payload to the original error
61
+ enrichedError.decodedAssertionPayload = decodedPayload;
62
+ }
63
+ } catch {
64
+ // Ignore errors decoding the payload
65
65
  }
66
- } catch (_errorDecoding) {
67
- // Ignore errors decoding the payload
68
66
  }
69
67
 
70
68
  try {
@@ -84,7 +82,7 @@ export function enrichNoirError(artifact: NoirCompiledCircuit, originalError: Ex
84
82
  return `at ${errorLocation.locationText} (${errorLocation.filePath}:${errorLocation.line}:${errorLocation.column})`;
85
83
  }
86
84
  });
87
- } catch (_errorResolving) {
85
+ } catch {
88
86
  // Ignore errors resolving the callstack
89
87
  }
90
88
 
@@ -22,7 +22,10 @@ import { UtilityExecutionOracle } from './utility_execution_oracle.js';
22
22
  export class AcirSimulator {
23
23
  private log: Logger;
24
24
 
25
- constructor(private executionDataProvider: ExecutionDataProvider, private simulationProvider: SimulationProvider) {
25
+ constructor(
26
+ private executionDataProvider: ExecutionDataProvider,
27
+ private simulationProvider: SimulationProvider,
28
+ ) {
26
29
  this.log = createLogger('simulator');
27
30
  }
28
31
 
@@ -25,7 +25,7 @@ export class AvmContractCallResult {
25
25
  this.gasLeft,
26
26
  )}, totalInstructions: ${this.totalInstructions}`;
27
27
  if (this.revertReason) {
28
- resultsStr += `, revertReason: ${this.revertReason}`;
28
+ resultsStr += `, revertReason: ${this.revertReason.message}`;
29
29
  }
30
30
  return resultsStr;
31
31
  }
@@ -60,7 +60,7 @@ export class AvmFinalizedCallResult {
60
60
  this.gasLeft,
61
61
  )}, totalInstructions: ${this.totalInstructions}`;
62
62
  if (this.revertReason) {
63
- resultsStr += `, revertReason: ${this.revertReason}`;
63
+ resultsStr += `, revertReason: ${this.revertReason.message}`;
64
64
  }
65
65
  return resultsStr;
66
66
  }
@@ -15,9 +15,14 @@ export class AvmExecutionEnvironment {
15
15
  public readonly globals: GlobalVariables,
16
16
  public readonly isStaticCall: boolean,
17
17
  public readonly calldata: Fr[],
18
+ public readonly clientInitiatedSimulation: boolean = false,
18
19
  ) {}
19
20
 
20
- private deriveEnvironmentForNestedCallInternal(targetAddress: AztecAddress, calldata: Fr[], isStaticCall: boolean) {
21
+ private deriveEnvironmentForNestedCallInternal(
22
+ targetAddress: AztecAddress,
23
+ calldata: Fr[],
24
+ isStaticCall: boolean,
25
+ ): AvmExecutionEnvironment {
21
26
  return new AvmExecutionEnvironment(
22
27
  /*address=*/ targetAddress,
23
28
  /*sender=*/ this.address,
@@ -26,6 +31,7 @@ export class AvmExecutionEnvironment {
26
31
  this.globals,
27
32
  isStaticCall,
28
33
  calldata,
34
+ /*clientInitiatedSimulation=*/ this.clientInitiatedSimulation,
29
35
  );
30
36
  }
31
37
 
@@ -2,7 +2,6 @@ import * as c from '@aztec/constants';
2
2
 
3
3
  import { TypeTag } from './avm_memory_types.js';
4
4
  import { InstructionExecutionError } from './errors.js';
5
- import { Addressing, AddressingMode } from './opcodes/addressing_mode.js';
6
5
  import { Opcode } from './serialization/instruction_serialization.js';
7
6
 
8
7
  /** Gas counters in L1, L2, and DA. */
@@ -136,7 +135,6 @@ const DYNAMIC_GAS_COSTS = new Map<Opcode, Gas>([
136
135
  [Opcode.RETURN, makeCost(c.AVM_RETURN_DYN_L2_GAS, 0)],
137
136
  [Opcode.REVERT_8, makeCost(c.AVM_REVERT_DYN_L2_GAS, 0)],
138
137
  [Opcode.REVERT_16, makeCost(c.AVM_REVERT_DYN_L2_GAS, 0)],
139
- [Opcode.DEBUGLOG, makeCost(c.AVM_DEBUGLOG_DYN_L2_GAS, 0)],
140
138
  [Opcode.TORADIXBE, makeCost(c.AVM_TORADIXBE_DYN_L2_GAS, 0)],
141
139
  ]);
142
140
 
@@ -149,24 +147,6 @@ export function getDynamicGasCost(opcode: Opcode): Gas {
149
147
  return DYNAMIC_GAS_COSTS.has(opcode) ? DYNAMIC_GAS_COSTS.get(opcode)! : makeCost(0, 0);
150
148
  }
151
149
 
152
- /** Returns the gas cost associated with the memory operations performed. */
153
- export function getMemoryGasCost(args: { reads?: number; writes?: number; indirect?: number }) {
154
- const { reads, writes, indirect } = args;
155
- const indirectCount = Addressing.fromWire(indirect ?? 0).count(AddressingMode.INDIRECT);
156
- const l2MemoryGasCost =
157
- (reads ?? 0) * GAS_COST_CONSTANTS.MEMORY_READ +
158
- (writes ?? 0) * GAS_COST_CONSTANTS.MEMORY_WRITE +
159
- indirectCount * GAS_COST_CONSTANTS.MEMORY_INDIRECT_READ_PENALTY;
160
- return makeGas({ l2Gas: l2MemoryGasCost });
161
- }
162
-
163
- /** Constants used in base cost calculations. */
164
- export const GAS_COST_CONSTANTS = {
165
- MEMORY_READ: 10,
166
- MEMORY_INDIRECT_READ_PENALTY: 10,
167
- MEMORY_WRITE: 100,
168
- };
169
-
170
150
  /** Returns gas cost for an operation on a given type tag based on the base cost per byte. */
171
151
  export function getGasCostForTypeTag(tag: TypeTag, baseCost: Gas) {
172
152
  return mulGas(baseCost, getGasCostMultiplierFromTypeTag(tag));
@@ -79,6 +79,7 @@ export class AvmSimulator implements AvmSimulatorInterface {
79
79
  isStaticCall: boolean,
80
80
  calldata: Fr[],
81
81
  allocatedGas: Gas,
82
+ clientInitiatedSimulation: boolean = false,
82
83
  ) {
83
84
  const avmExecutionEnv = new AvmExecutionEnvironment(
84
85
  address,
@@ -88,6 +89,7 @@ export class AvmSimulator implements AvmSimulatorInterface {
88
89
  globals,
89
90
  isStaticCall,
90
91
  calldata,
92
+ clientInitiatedSimulation,
91
93
  );
92
94
 
93
95
  const avmMachineState = new AvmMachineState(allocatedGas);
@@ -108,7 +110,7 @@ export class AvmSimulator implements AvmSimulatorInterface {
108
110
  throw err;
109
111
  }
110
112
  return await this.handleFailureToRetrieveBytecode(
111
- `Bytecode retrieval for contract '${this.context.environment.address}' failed with ${err}. Reverting...`,
113
+ `Bytecode retrieval for contract '${this.context.environment.address}' failed with ${err.message}. Reverting...`,
112
114
  );
113
115
  }
114
116
 
@@ -71,6 +71,7 @@ export function initExecutionEnvironment(overrides?: Partial<AvmExecutionEnviron
71
71
  overrides?.globals ?? GlobalVariables.empty(),
72
72
  overrides?.isStaticCall ?? false,
73
73
  overrides?.calldata ?? [],
74
+ overrides?.clientInitiatedSimulation ?? true, // default to true for testing even though internal default is false
74
75
  );
75
76
  }
76
77
 
@@ -1,7 +1,5 @@
1
1
  import { DEPLOYER_CONTRACT_ADDRESS } from '@aztec/constants';
2
2
  import { Fr } from '@aztec/foundation/fields';
3
- import { AvmGadgetsTestContract } from '@aztec/noir-contracts.js/AvmGadgetsTest';
4
- import { AvmTestContract } from '@aztec/noir-contracts.js/AvmTest';
5
3
  import {
6
4
  type ContractArtifact,
7
5
  type FunctionAbi,
@@ -98,70 +96,6 @@ export function resolveContractAssertionMessage(
98
96
  return resolveAssertionMessageFromRevertData(output, functionArtifact);
99
97
  }
100
98
 
101
- export function getAvmTestContractFunctionSelector(functionName: string): Promise<FunctionSelector> {
102
- return getFunctionSelector(functionName, AvmTestContract.artifactForPublic);
103
- }
104
-
105
- export function getAvmGadgetsTestContractFunctionSelector(functionName: string): Promise<FunctionSelector> {
106
- const artifact = getAllFunctionAbis(AvmGadgetsTestContract.artifactForPublic).find(f => f.name === functionName)!;
107
- assert(!!artifact, `Function ${functionName} not found in AvmGadgetsTestContractArtifact`);
108
- const params = artifact.parameters;
109
- return FunctionSelector.fromNameAndParameters(artifact.name, params);
110
- }
111
-
112
- export function getAvmTestContractArtifact(functionName: string): FunctionArtifact {
113
- const artifact = getContractFunctionArtifact(functionName, AvmTestContract.artifactForPublic) as FunctionArtifact;
114
- assert(
115
- !!artifact?.bytecode,
116
- `No bytecode found for function ${functionName}. Try re-running bootstrap.sh on the repository root.`,
117
- );
118
- return artifact;
119
- }
120
-
121
- export function getAvmGadgetsTestContractArtifact(functionName: string): FunctionArtifact {
122
- const artifact = AvmGadgetsTestContract.artifactForPublic.functions.find(f => f.name === functionName)!;
123
- assert(
124
- !!artifact?.bytecode,
125
- `No bytecode found for function ${functionName}. Try re-running bootstrap.sh on the repository root.`,
126
- );
127
- return artifact;
128
- }
129
-
130
- export function getAvmTestContractBytecode(functionName: string): Buffer {
131
- const artifact = getAvmTestContractArtifact(functionName);
132
- return artifact.bytecode;
133
- }
134
-
135
- export function getAvmGadgetsTestContractBytecode(functionName: string): Buffer {
136
- const artifact = getAvmGadgetsTestContractArtifact(functionName);
137
- return artifact.bytecode;
138
- }
139
-
140
- export function resolveAvmTestContractAssertionMessage(
141
- functionName: string,
142
- revertReason: AvmRevertReason,
143
- output: Fr[],
144
- ): string | undefined {
145
- return resolveContractAssertionMessage(functionName, revertReason, output, AvmTestContract.artifactForPublic);
146
- }
147
-
148
- export function resolveAvmGadgetsTestContractAssertionMessage(
149
- functionName: string,
150
- revertReason: AvmRevertReason,
151
- output: Fr[],
152
- ): string | undefined {
153
- traverseCauseChain(revertReason, cause => {
154
- revertReason = cause as AvmRevertReason;
155
- });
156
-
157
- const functionArtifact = AvmGadgetsTestContract.artifactForPublic.functions.find(f => f.name === functionName);
158
- if (!functionArtifact || !revertReason.noirCallStack || !isNoirCallStackUnresolved(revertReason.noirCallStack)) {
159
- return undefined;
160
- }
161
-
162
- return resolveAssertionMessageFromRevertData(output, functionArtifact);
163
- }
164
-
165
99
  /**
166
100
  * Create a contract class and instance given constructor args, artifact, etc.
167
101
  * NOTE: This is useful for testing real-ish contract class registration and instance deployment TXs (via logs)