@aztec/simulator 0.40.1 → 0.42.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 (234) hide show
  1. package/dest/acvm/acvm.d.ts +2 -2
  2. package/dest/acvm/acvm.d.ts.map +1 -1
  3. package/dest/acvm/acvm.js +3 -3
  4. package/dest/acvm/oracle/oracle.d.ts +6 -2
  5. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  6. package/dest/acvm/oracle/oracle.js +31 -19
  7. package/dest/acvm/oracle/typed_oracle.d.ts +8 -11
  8. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  9. package/dest/acvm/oracle/typed_oracle.js +17 -5
  10. package/dest/acvm/serialize.js +2 -2
  11. package/dest/avm/avm_execution_environment.d.ts +4 -3
  12. package/dest/avm/avm_execution_environment.d.ts.map +1 -1
  13. package/dest/avm/avm_execution_environment.js +7 -5
  14. package/dest/avm/avm_gas.d.ts +1 -5
  15. package/dest/avm/avm_gas.d.ts.map +1 -1
  16. package/dest/avm/avm_gas.js +67 -73
  17. package/dest/avm/avm_simulator.d.ts +5 -0
  18. package/dest/avm/avm_simulator.d.ts.map +1 -1
  19. package/dest/avm/avm_simulator.js +12 -4
  20. package/dest/avm/errors.d.ts +6 -0
  21. package/dest/avm/errors.d.ts.map +1 -1
  22. package/dest/avm/errors.js +10 -1
  23. package/dest/avm/fixtures/index.d.ts +3 -0
  24. package/dest/avm/fixtures/index.d.ts.map +1 -1
  25. package/dest/avm/fixtures/index.js +15 -3
  26. package/dest/avm/index.d.ts +2 -0
  27. package/dest/avm/index.d.ts.map +1 -0
  28. package/dest/avm/index.js +2 -0
  29. package/dest/avm/journal/host_storage.d.ts +1 -1
  30. package/dest/avm/journal/host_storage.d.ts.map +1 -1
  31. package/dest/avm/journal/journal.d.ts +4 -3
  32. package/dest/avm/journal/journal.d.ts.map +1 -1
  33. package/dest/avm/journal/journal.js +10 -11
  34. package/dest/avm/journal/nullifiers.d.ts +17 -5
  35. package/dest/avm/journal/nullifiers.d.ts.map +1 -1
  36. package/dest/avm/journal/nullifiers.js +27 -10
  37. package/dest/avm/journal/public_storage.d.ts +19 -6
  38. package/dest/avm/journal/public_storage.d.ts.map +1 -1
  39. package/dest/avm/journal/public_storage.js +30 -12
  40. package/dest/avm/journal/trace.d.ts +2 -0
  41. package/dest/avm/journal/trace.d.ts.map +1 -1
  42. package/dest/avm/journal/trace.js +7 -1
  43. package/dest/avm/journal/trace_types.d.ts +1 -0
  44. package/dest/avm/journal/trace_types.d.ts.map +1 -1
  45. package/dest/avm/journal/trace_types.js +1 -1
  46. package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
  47. package/dest/avm/opcodes/accrued_substate.js +6 -7
  48. package/dest/avm/opcodes/arithmetic.d.ts +1 -7
  49. package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
  50. package/dest/avm/opcodes/arithmetic.js +1 -12
  51. package/dest/avm/opcodes/conversion.js +2 -2
  52. package/dest/avm/opcodes/external_calls.d.ts +2 -2
  53. package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
  54. package/dest/avm/opcodes/external_calls.js +25 -13
  55. package/dest/avm/opcodes/instruction.d.ts +1 -1
  56. package/dest/avm/opcodes/instruction.d.ts.map +1 -1
  57. package/dest/avm/opcodes/instruction.js +6 -4
  58. package/dest/avm/opcodes/memory.d.ts +0 -4
  59. package/dest/avm/opcodes/memory.d.ts.map +1 -1
  60. package/dest/avm/opcodes/memory.js +1 -7
  61. package/dest/avm/opcodes/storage.d.ts +0 -12
  62. package/dest/avm/opcodes/storage.d.ts.map +1 -1
  63. package/dest/avm/opcodes/storage.js +3 -18
  64. package/dest/avm/serialization/bytecode_serialization.js +2 -2
  65. package/dest/client/client_execution_context.d.ts +30 -20
  66. package/dest/client/client_execution_context.d.ts.map +1 -1
  67. package/dest/client/client_execution_context.js +59 -39
  68. package/dest/client/db_oracle.d.ts +17 -12
  69. package/dest/client/db_oracle.d.ts.map +1 -1
  70. package/dest/client/execution_note_cache.js +2 -2
  71. package/dest/client/execution_result.d.ts +17 -2
  72. package/dest/client/execution_result.d.ts.map +1 -1
  73. package/dest/client/execution_result.js +32 -4
  74. package/dest/client/private_execution.d.ts +2 -3
  75. package/dest/client/private_execution.d.ts.map +1 -1
  76. package/dest/client/private_execution.js +22 -8
  77. package/dest/client/simulator.d.ts +0 -16
  78. package/dest/client/simulator.d.ts.map +1 -1
  79. package/dest/client/simulator.js +13 -30
  80. package/dest/client/unconstrained_execution.d.ts +2 -3
  81. package/dest/client/unconstrained_execution.d.ts.map +1 -1
  82. package/dest/client/unconstrained_execution.js +5 -7
  83. package/dest/client/view_data_oracle.d.ts +12 -10
  84. package/dest/client/view_data_oracle.d.ts.map +1 -1
  85. package/dest/client/view_data_oracle.js +17 -11
  86. package/dest/common/index.d.ts +1 -0
  87. package/dest/common/index.d.ts.map +1 -1
  88. package/dest/common/index.js +2 -1
  89. package/dest/common/return_values.d.ts +11 -0
  90. package/dest/common/return_values.d.ts.map +1 -0
  91. package/dest/common/return_values.js +13 -0
  92. package/dest/index.d.ts +3 -1
  93. package/dest/index.d.ts.map +1 -1
  94. package/dest/index.js +4 -2
  95. package/dest/mocks/fixtures.d.ts +15 -10
  96. package/dest/mocks/fixtures.d.ts.map +1 -1
  97. package/dest/mocks/fixtures.js +22 -17
  98. package/dest/{simulator → providers}/acvm_native.d.ts.map +1 -1
  99. package/dest/{simulator → providers}/acvm_native.js +13 -14
  100. package/dest/providers/acvm_wasm.d.ts.map +1 -0
  101. package/dest/providers/acvm_wasm.js +15 -0
  102. package/dest/providers/index.d.ts.map +1 -0
  103. package/dest/{simulator → providers}/index.js +1 -1
  104. package/dest/{simulator → providers}/simulation_provider.d.ts.map +1 -1
  105. package/dest/{simulator → providers}/simulation_provider.js +1 -1
  106. package/dest/public/abstract_phase_manager.d.ts +43 -42
  107. package/dest/public/abstract_phase_manager.d.ts.map +1 -1
  108. package/dest/public/abstract_phase_manager.js +81 -103
  109. package/dest/public/app_logic_phase_manager.d.ts +7 -8
  110. package/dest/public/app_logic_phase_manager.d.ts.map +1 -1
  111. package/dest/public/app_logic_phase_manager.js +14 -14
  112. package/dest/public/{db.d.ts → db_interfaces.d.ts} +3 -3
  113. package/dest/public/db_interfaces.d.ts.map +1 -0
  114. package/dest/public/db_interfaces.js +2 -0
  115. package/dest/public/execution.d.ts +17 -14
  116. package/dest/public/execution.d.ts.map +1 -1
  117. package/dest/public/execution.js +1 -1
  118. package/dest/public/executor.d.ts +3 -30
  119. package/dest/public/executor.d.ts.map +1 -1
  120. package/dest/public/executor.js +32 -279
  121. package/dest/public/fee_payment.d.ts +11 -0
  122. package/dest/public/fee_payment.d.ts.map +1 -0
  123. package/dest/public/fee_payment.js +24 -0
  124. package/dest/public/hints_builder.d.ts +3 -2
  125. package/dest/public/hints_builder.d.ts.map +1 -1
  126. package/dest/public/hints_builder.js +8 -4
  127. package/dest/public/index.d.ts +4 -2
  128. package/dest/public/index.d.ts.map +1 -1
  129. package/dest/public/index.js +5 -3
  130. package/dest/public/phase_manager_factory.d.ts +1 -1
  131. package/dest/public/phase_manager_factory.d.ts.map +1 -1
  132. package/dest/public/{public_executor.d.ts → public_db_sources.d.ts} +3 -2
  133. package/dest/public/public_db_sources.d.ts.map +1 -0
  134. package/dest/public/public_db_sources.js +198 -0
  135. package/dest/public/public_kernel.js +14 -14
  136. package/dest/public/public_processor.d.ts +8 -6
  137. package/dest/public/public_processor.d.ts.map +1 -1
  138. package/dest/public/public_processor.js +48 -29
  139. package/dest/public/setup_phase_manager.d.ts +7 -9
  140. package/dest/public/setup_phase_manager.d.ts.map +1 -1
  141. package/dest/public/setup_phase_manager.js +11 -20
  142. package/dest/public/tail_phase_manager.d.ts +5 -11
  143. package/dest/public/tail_phase_manager.d.ts.map +1 -1
  144. package/dest/public/tail_phase_manager.js +16 -36
  145. package/dest/public/teardown_phase_manager.d.ts +7 -9
  146. package/dest/public/teardown_phase_manager.d.ts.map +1 -1
  147. package/dest/public/teardown_phase_manager.js +15 -21
  148. package/dest/public/transitional_adaptors.d.ts +3 -2
  149. package/dest/public/transitional_adaptors.d.ts.map +1 -1
  150. package/dest/public/transitional_adaptors.js +24 -8
  151. package/dest/public/utils.d.ts +2 -2
  152. package/dest/public/utils.d.ts.map +1 -1
  153. package/dest/public/utils.js +21 -14
  154. package/package.json +12 -9
  155. package/src/acvm/acvm.ts +0 -3
  156. package/src/acvm/oracle/oracle.ts +53 -27
  157. package/src/acvm/oracle/typed_oracle.ts +25 -16
  158. package/src/acvm/serialize.ts +1 -1
  159. package/src/avm/avm_execution_environment.ts +9 -5
  160. package/src/avm/avm_gas.ts +66 -73
  161. package/src/avm/avm_simulator.ts +14 -3
  162. package/src/avm/errors.ts +10 -0
  163. package/src/avm/fixtures/index.ts +22 -2
  164. package/src/avm/index.ts +1 -0
  165. package/src/avm/journal/host_storage.ts +1 -1
  166. package/src/avm/journal/journal.ts +15 -14
  167. package/src/avm/journal/nullifiers.ts +27 -14
  168. package/src/avm/journal/public_storage.ts +30 -16
  169. package/src/avm/journal/trace.ts +12 -0
  170. package/src/avm/journal/trace_types.ts +1 -0
  171. package/src/avm/opcodes/accrued_substate.ts +5 -6
  172. package/src/avm/opcodes/arithmetic.ts +1 -14
  173. package/src/avm/opcodes/conversion.ts +1 -1
  174. package/src/avm/opcodes/external_calls.ts +26 -10
  175. package/src/avm/opcodes/instruction.ts +5 -3
  176. package/src/avm/opcodes/memory.ts +1 -8
  177. package/src/avm/opcodes/storage.ts +3 -20
  178. package/src/avm/serialization/bytecode_serialization.ts +1 -1
  179. package/src/client/client_execution_context.ts +70 -44
  180. package/src/client/db_oracle.ts +18 -12
  181. package/src/client/execution_note_cache.ts +1 -1
  182. package/src/client/execution_result.ts +41 -3
  183. package/src/client/private_execution.ts +38 -20
  184. package/src/client/simulator.ts +11 -32
  185. package/src/client/unconstrained_execution.ts +9 -12
  186. package/src/client/view_data_oracle.ts +20 -12
  187. package/src/common/index.ts +1 -0
  188. package/src/common/return_values.ts +18 -0
  189. package/src/index.ts +3 -1
  190. package/src/mocks/fixtures.ts +31 -33
  191. package/src/{simulator → providers}/acvm_native.ts +21 -19
  192. package/src/{simulator → providers}/acvm_wasm.ts +2 -16
  193. package/src/public/abstract_phase_manager.ts +146 -207
  194. package/src/public/app_logic_phase_manager.ts +23 -39
  195. package/src/public/{db.ts → db_interfaces.ts} +2 -2
  196. package/src/public/execution.ts +17 -14
  197. package/src/public/executor.ts +51 -391
  198. package/src/public/fee_payment.ts +26 -0
  199. package/src/public/hints_builder.ts +17 -3
  200. package/src/public/index.ts +4 -2
  201. package/src/public/phase_manager_factory.ts +1 -1
  202. package/src/public/{public_executor.ts → public_db_sources.ts} +3 -2
  203. package/src/public/public_kernel.ts +24 -24
  204. package/src/public/public_processor.ts +82 -38
  205. package/src/public/setup_phase_manager.ts +20 -45
  206. package/src/public/tail_phase_manager.ts +18 -68
  207. package/src/public/teardown_phase_manager.ts +22 -41
  208. package/src/public/transitional_adaptors.ts +24 -13
  209. package/src/public/utils.ts +20 -14
  210. package/dest/client/logs_cache.d.ts +0 -33
  211. package/dest/client/logs_cache.d.ts.map +0 -1
  212. package/dest/client/logs_cache.js +0 -59
  213. package/dest/public/db.d.ts.map +0 -1
  214. package/dest/public/db.js +0 -2
  215. package/dest/public/public_execution_context.d.ts +0 -121
  216. package/dest/public/public_execution_context.d.ts.map +0 -1
  217. package/dest/public/public_execution_context.js +0 -214
  218. package/dest/public/public_executor.d.ts.map +0 -1
  219. package/dest/public/public_executor.js +0 -197
  220. package/dest/public/state_actions.d.ts +0 -39
  221. package/dest/public/state_actions.d.ts.map +0 -1
  222. package/dest/public/state_actions.js +0 -80
  223. package/dest/simulator/acvm_wasm.d.ts.map +0 -1
  224. package/dest/simulator/acvm_wasm.js +0 -22
  225. package/dest/simulator/index.d.ts.map +0 -1
  226. package/src/client/logs_cache.ts +0 -65
  227. package/src/public/public_execution_context.ts +0 -289
  228. package/src/public/state_actions.ts +0 -102
  229. /package/dest/{simulator → providers}/acvm_native.d.ts +0 -0
  230. /package/dest/{simulator → providers}/acvm_wasm.d.ts +0 -0
  231. /package/dest/{simulator → providers}/index.d.ts +0 -0
  232. /package/dest/{simulator → providers}/simulation_provider.d.ts +0 -0
  233. /package/src/{simulator → providers}/index.ts +0 -0
  234. /package/src/{simulator → providers}/simulation_provider.ts +0 -0
@@ -1,5 +1,9 @@
1
- import { type FunctionData } from '@aztec/circuits.js';
2
- import { type DecodedReturn, type FunctionArtifact, decodeReturnValues } from '@aztec/foundation/abi';
1
+ import {
2
+ type DecodedReturn,
3
+ type FunctionArtifact,
4
+ type FunctionSelector,
5
+ decodeReturnValues,
6
+ } from '@aztec/foundation/abi';
3
7
  import { type AztecAddress } from '@aztec/foundation/aztec-address';
4
8
  import { type Fr } from '@aztec/foundation/fields';
5
9
  import { createDebugLogger } from '@aztec/foundation/log';
@@ -7,7 +11,6 @@ import { createDebugLogger } from '@aztec/foundation/log';
7
11
  import { witnessMapToFields } from '../acvm/deserialize.js';
8
12
  import { Oracle, acvm, extractCallStack, toACVMWitness } from '../acvm/index.js';
9
13
  import { ExecutionError } from '../common/errors.js';
10
- import { AcirSimulator } from './simulator.js';
11
14
  import { type ViewDataOracle } from './view_data_oracle.js';
12
15
 
13
16
  // docs:start:execute_unconstrained_function
@@ -18,21 +21,15 @@ export async function executeUnconstrainedFunction(
18
21
  oracle: ViewDataOracle,
19
22
  artifact: FunctionArtifact,
20
23
  contractAddress: AztecAddress,
21
- functionData: FunctionData,
24
+ functionSelector: FunctionSelector,
22
25
  args: Fr[],
23
26
  log = createDebugLogger('aztec:simulator:unconstrained_execution'),
24
27
  ): Promise<DecodedReturn> {
25
- const functionSelector = functionData.selector;
26
28
  log.verbose(`Executing unconstrained function ${contractAddress}:${functionSelector}(${artifact.name})`);
27
29
 
28
30
  const acir = artifact.bytecode;
29
31
  const initialWitness = toACVMWitness(0, args);
30
- const acirExecutionResult = await acvm(
31
- await AcirSimulator.getSolver(),
32
- acir,
33
- initialWitness,
34
- new Oracle(oracle),
35
- ).catch((err: Error) => {
32
+ const acirExecutionResult = await acvm(acir, initialWitness, new Oracle(oracle)).catch((err: Error) => {
36
33
  throw new ExecutionError(
37
34
  err.message,
38
35
  {
@@ -45,6 +42,6 @@ export async function executeUnconstrainedFunction(
45
42
  });
46
43
 
47
44
  const returnWitness = witnessMapToFields(acirExecutionResult.returnWitness);
48
- return decodeReturnValues(artifact, returnWitness);
45
+ return decodeReturnValues(artifact.returnTypes, returnWitness);
49
46
  }
50
47
  // docs:end:execute_unconstrained_function
@@ -7,14 +7,14 @@ import {
7
7
  type NullifierMembershipWitness,
8
8
  type PublicDataWitness,
9
9
  } from '@aztec/circuit-types';
10
- import { type Header } from '@aztec/circuits.js';
10
+ import { type Header, type KeyValidationRequest } from '@aztec/circuits.js';
11
11
  import { siloNullifier } from '@aztec/circuits.js/hash';
12
12
  import { type AztecAddress } from '@aztec/foundation/aztec-address';
13
13
  import { Fr } from '@aztec/foundation/fields';
14
14
  import { applyStringFormatting, createDebugLogger } from '@aztec/foundation/log';
15
15
  import { type ContractInstance } from '@aztec/types/contracts';
16
16
 
17
- import { type NoteData, type NullifierKeys, TypedOracle } from '../acvm/index.js';
17
+ import { type NoteData, TypedOracle } from '../acvm/index.js';
18
18
  import { type DBOracle } from './db_oracle.js';
19
19
  import { pickNotes } from './pick_notes.js';
20
20
 
@@ -34,15 +34,22 @@ export class ViewDataOracle extends TypedOracle {
34
34
  super();
35
35
  }
36
36
 
37
+ public override getBlockNumber(): Promise<number> {
38
+ return this.aztecNode.getBlockNumber();
39
+ }
40
+
41
+ public override getContractAddress(): Promise<AztecAddress> {
42
+ return Promise.resolve(this.contractAddress);
43
+ }
44
+
37
45
  /**
38
- * Retrieve nullifier keys associated with a specific account and app/contract address.
39
- *
40
- * @param accountAddress - The account address.
41
- * @returns A Promise that resolves to nullifier keys of a requested account and contract.
42
- * @throws An error if the account is not registered in the database.
46
+ * Retrieve keys associated with a specific master public key and app address.
47
+ * @param pkMHash - The master public key hash.
48
+ * @returns A Promise that resolves to nullifier keys.
49
+ * @throws If the keys are not registered in the key store.
43
50
  */
44
- public override getNullifierKeys(account: AztecAddress): Promise<NullifierKeys> {
45
- return this.db.getNullifierKeys(account, this.contractAddress);
51
+ public override getKeyValidationRequest(pkMHash: Fr): Promise<KeyValidationRequest> {
52
+ return this.db.getKeyValidationRequest(pkMHash, this.contractAddress);
46
53
  }
47
54
 
48
55
  /**
@@ -129,11 +136,12 @@ export class ViewDataOracle extends TypedOracle {
129
136
 
130
137
  /**
131
138
  * Retrieve the complete address associated to a given address.
132
- * @param address - Address to fetch the complete address for.
139
+ * @param account - The account address.
133
140
  * @returns A complete address associated with the input address.
141
+ * @throws An error if the account is not registered in the database.
134
142
  */
135
- public override getCompleteAddress(address: AztecAddress): Promise<CompleteAddress> {
136
- return this.db.getCompleteAddress(address);
143
+ public override getCompleteAddress(account: AztecAddress): Promise<CompleteAddress> {
144
+ return this.db.getCompleteAddress(account);
137
145
  }
138
146
 
139
147
  /**
@@ -1,3 +1,4 @@
1
1
  export * from './packed_values_cache.js';
2
2
  export * from './errors.js';
3
3
  export * from './side_effect_counter.js';
4
+ export * from './return_values.js';
@@ -0,0 +1,18 @@
1
+ import { NestedProcessReturnValues } from '@aztec/circuit-types';
2
+
3
+ import type { ExecutionResult } from '../client/execution_result.js';
4
+ import type { PublicExecutionResult } from '../public/execution.js';
5
+
6
+ /**
7
+ * Recursively accummulate the return values of a call result and its nested executions,
8
+ * so they can be retrieved in order.
9
+ * @param executionResult
10
+ * @returns
11
+ */
12
+ export function accumulateReturnValues(
13
+ executionResult: PublicExecutionResult | ExecutionResult,
14
+ ): NestedProcessReturnValues {
15
+ const acc = new NestedProcessReturnValues(executionResult.returnValues);
16
+ acc.nested = executionResult.nestedExecutions.map(nestedExecution => accumulateReturnValues(nestedExecution));
17
+ return acc;
18
+ }
package/src/index.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  export * from './acvm/index.js';
2
+ export * from './avm/index.js';
2
3
  export * from './client/index.js';
3
4
  export * from './common/index.js';
4
5
  export * from './public/index.js';
5
- export * from './simulator/index.js';
6
+ export * from './providers/index.js';
6
7
  export * from './mocks/index.js';
7
8
  export * from './stats/index.js';
9
+ export * from './utils.js';
@@ -1,18 +1,17 @@
1
1
  import { type FunctionCall, type SimulationError, UnencryptedFunctionL2Logs } from '@aztec/circuit-types';
2
2
  import {
3
3
  ARGS_LENGTH,
4
+ AvmExecutionHints,
4
5
  type AztecAddress,
5
6
  CallContext,
6
- CallRequest,
7
+ type ContractStorageRead,
7
8
  type ContractStorageUpdateRequest,
8
9
  Fr,
9
- FunctionData,
10
10
  Gas,
11
- MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
12
- type PrivateKernelTailCircuitPublicInputs,
13
11
  type PublicCallRequest,
14
12
  } from '@aztec/circuits.js';
15
13
  import { makeAztecAddress, makeSelector } from '@aztec/circuits.js/testing';
14
+ import { FunctionType } from '@aztec/foundation/abi';
16
15
  import { padArrayEnd } from '@aztec/foundation/collection';
17
16
 
18
17
  import { type PublicExecution, type PublicExecutionResult } from '../public/execution.js';
@@ -21,6 +20,7 @@ export class PublicExecutionResultBuilder {
21
20
  private _execution: PublicExecution;
22
21
  private _nestedExecutions: PublicExecutionResult[] = [];
23
22
  private _contractStorageUpdateRequests: ContractStorageUpdateRequest[] = [];
23
+ private _contractStorageReads: ContractStorageRead[] = [];
24
24
  private _returnValues: Fr[] = [];
25
25
  private _reverted = false;
26
26
  private _revertReason: SimulationError | undefined = undefined;
@@ -34,17 +34,25 @@ export class PublicExecutionResultBuilder {
34
34
  returnValues = [new Fr(1n)],
35
35
  nestedExecutions = [],
36
36
  contractStorageUpdateRequests = [],
37
+ contractStorageReads = [],
38
+ revertReason = undefined,
37
39
  }: {
38
40
  request: PublicCallRequest;
39
41
  returnValues?: Fr[];
40
42
  nestedExecutions?: PublicExecutionResult[];
41
43
  contractStorageUpdateRequests?: ContractStorageUpdateRequest[];
44
+ contractStorageReads?: ContractStorageRead[];
45
+ revertReason?: SimulationError;
42
46
  }): PublicExecutionResultBuilder {
43
47
  const builder = new PublicExecutionResultBuilder(request);
44
48
 
45
49
  builder.withNestedExecutions(...nestedExecutions);
46
50
  builder.withContractStorageUpdateRequest(...contractStorageUpdateRequests);
51
+ builder.withContractStorageRead(...contractStorageReads);
47
52
  builder.withReturnValues(...returnValues);
53
+ if (revertReason) {
54
+ builder.withReverted(revertReason);
55
+ }
48
56
 
49
57
  return builder;
50
58
  }
@@ -55,6 +63,7 @@ export class PublicExecutionResultBuilder {
55
63
  returnValues = [new Fr(1n)],
56
64
  nestedExecutions = [],
57
65
  contractStorageUpdateRequests = [],
66
+ contractStorageReads = [],
58
67
  revertReason,
59
68
  }: {
60
69
  from: AztecAddress;
@@ -62,17 +71,19 @@ export class PublicExecutionResultBuilder {
62
71
  returnValues?: Fr[];
63
72
  nestedExecutions?: PublicExecutionResult[];
64
73
  contractStorageUpdateRequests?: ContractStorageUpdateRequest[];
74
+ contractStorageReads?: ContractStorageRead[];
65
75
  revertReason?: SimulationError;
66
76
  }) {
67
77
  const builder = new PublicExecutionResultBuilder({
68
- callContext: new CallContext(from, tx.to, tx.functionData.selector, false, false, 0),
78
+ callContext: new CallContext(from, tx.to, tx.selector, false, false, 0),
69
79
  contractAddress: tx.to,
70
- functionData: tx.functionData,
80
+ functionSelector: tx.selector,
71
81
  args: tx.args,
72
82
  });
73
83
 
74
84
  builder.withNestedExecutions(...nestedExecutions);
75
85
  builder.withContractStorageUpdateRequest(...contractStorageUpdateRequests);
86
+ builder.withContractStorageRead(...contractStorageReads);
76
87
  builder.withReturnValues(...returnValues);
77
88
  if (revertReason) {
78
89
  builder.withReverted(revertReason);
@@ -91,6 +102,11 @@ export class PublicExecutionResultBuilder {
91
102
  return this;
92
103
  }
93
104
 
105
+ withContractStorageRead(...reads: ContractStorageRead[]): PublicExecutionResultBuilder {
106
+ this._contractStorageReads.push(...reads);
107
+ return this;
108
+ }
109
+
94
110
  withReturnValues(...values: Fr[]): PublicExecutionResultBuilder {
95
111
  this._returnValues.push(...values);
96
112
  return this;
@@ -106,8 +122,10 @@ export class PublicExecutionResultBuilder {
106
122
  return {
107
123
  execution: this._execution,
108
124
  nestedExecutions: this._nestedExecutions,
125
+ noteHashReadRequests: [],
109
126
  nullifierReadRequests: [],
110
127
  nullifierNonExistentReadRequests: [],
128
+ l1ToL2MsgReadRequests: [],
111
129
  contractStorageUpdateRequests: this._contractStorageUpdateRequests,
112
130
  returnValues: padArrayEnd(this._returnValues, Fr.ZERO, 4), // TODO(#5450) Need to use the proper return values here
113
131
  newNoteHashes: [],
@@ -116,7 +134,6 @@ export class PublicExecutionResultBuilder {
116
134
  contractStorageReads: [],
117
135
  unencryptedLogsHashes: [],
118
136
  unencryptedLogs: UnencryptedFunctionL2Logs.empty(),
119
- unencryptedLogPreimagesLength: new Fr(4n), // empty logs have len 4
120
137
  allUnencryptedLogs: UnencryptedFunctionL2Logs.empty(),
121
138
  startSideEffectCounter: Fr.ZERO,
122
139
  endSideEffectCounter: Fr.ZERO,
@@ -125,38 +142,19 @@ export class PublicExecutionResultBuilder {
125
142
  startGasLeft: Gas.test(),
126
143
  endGasLeft: Gas.test(),
127
144
  transactionFee: Fr.ZERO,
145
+ calldata: [],
146
+ avmHints: AvmExecutionHints.empty(),
128
147
  ...overrides,
129
148
  };
130
149
  }
131
150
  }
132
151
 
133
152
  export const makeFunctionCall = (
153
+ name = 'function',
134
154
  to = makeAztecAddress(30),
135
155
  selector = makeSelector(5),
156
+ type = FunctionType.PUBLIC,
136
157
  args = new Array(ARGS_LENGTH).fill(Fr.ZERO),
137
- ) => ({ to, functionData: new FunctionData(selector, false), args });
138
-
139
- export function addKernelPublicCallStack(
140
- kernelOutput: PrivateKernelTailCircuitPublicInputs,
141
- calls: {
142
- setupCalls: PublicCallRequest[];
143
- appLogicCalls: PublicCallRequest[];
144
- teardownCall: PublicCallRequest;
145
- },
146
- ) {
147
- // the first two calls are non-revertible
148
- // the first is for setup, the second is for teardown
149
- kernelOutput.forPublic!.endNonRevertibleData.publicCallStack = padArrayEnd(
150
- // this is a stack, so the first item is the last call
151
- // and callRequests is in the order of the calls
152
- [calls.teardownCall.toCallRequest(), ...calls.setupCalls.map(c => c.toCallRequest())],
153
- CallRequest.empty(),
154
- MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
155
- );
156
-
157
- kernelOutput.forPublic!.end.publicCallStack = padArrayEnd(
158
- calls.appLogicCalls.map(c => c.toCallRequest()),
159
- CallRequest.empty(),
160
- MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
161
- );
162
- }
158
+ isStatic = false,
159
+ returnTypes = [],
160
+ ) => ({ name, to, selector, type, args, isStatic, returnTypes });
@@ -1,4 +1,4 @@
1
- import { randomBytes } from '@aztec/foundation/crypto';
1
+ import { runInDirectory } from '@aztec/foundation/fs';
2
2
  import { createDebugLogger } from '@aztec/foundation/log';
3
3
  import { Timer } from '@aztec/foundation/timer';
4
4
  import { type NoirCompiledCircuit } from '@aztec/types/noir';
@@ -137,23 +137,25 @@ export class NativeACVMSimulator implements SimulationProvider {
137
137
  async simulateCircuit(input: WitnessMap, compiledCircuit: NoirCompiledCircuit): Promise<WitnessMap> {
138
138
  // Execute the circuit on those initial witness values
139
139
 
140
- // Decode the bytecode from base64 since the acvm does not know about base64 encoding
141
- const decodedBytecode = Buffer.from(compiledCircuit.bytecode, 'base64');
142
-
143
- // Provide a unique working directory so we don't get clashes with parallel executions
144
- const directory = `${this.workingDirectory}/${randomBytes(8).toString('hex')}`;
145
-
146
- await fs.mkdir(directory, { recursive: true });
147
-
148
- // Execute the circuit
149
- const result = await executeNativeCircuit(input, decodedBytecode, directory, this.pathToAcvm, this.witnessFilename);
150
-
151
- await fs.rm(directory, { force: true, recursive: true });
152
-
153
- if (result.status == ACVM_RESULT.FAILURE) {
154
- throw new Error(`Failed to generate witness: ${result.reason}`);
155
- }
156
-
157
- return result.witness;
140
+ const operation = async (directory: string) => {
141
+ // Decode the bytecode from base64 since the acvm does not know about base64 encoding
142
+ const decodedBytecode = Buffer.from(compiledCircuit.bytecode, 'base64');
143
+ // Execute the circuit
144
+ const result = await executeNativeCircuit(
145
+ input,
146
+ decodedBytecode,
147
+ directory,
148
+ this.pathToAcvm,
149
+ this.witnessFilename,
150
+ );
151
+
152
+ if (result.status == ACVM_RESULT.FAILURE) {
153
+ throw new Error(`Failed to generate witness: ${result.reason}`);
154
+ }
155
+
156
+ return result.witness;
157
+ };
158
+
159
+ return await runInDirectory(this.workingDirectory, operation);
158
160
  }
159
161
  }
@@ -1,24 +1,11 @@
1
1
  import { foreignCallHandler } from '@aztec/noir-protocol-circuits-types';
2
2
  import { type NoirCompiledCircuit } from '@aztec/types/noir';
3
3
 
4
- import {
5
- type WasmBlackBoxFunctionSolver,
6
- createBlackBoxSolver,
7
- executeCircuitWithBlackBoxSolver,
8
- } from '@noir-lang/acvm_js';
4
+ import { executeCircuit } from '@noir-lang/acvm_js';
9
5
  import { type WitnessMap } from '@noir-lang/types';
10
6
 
11
7
  import { type SimulationProvider } from './simulation_provider.js';
12
8
 
13
- let solver: Promise<WasmBlackBoxFunctionSolver>;
14
-
15
- const getSolver = (): Promise<WasmBlackBoxFunctionSolver> => {
16
- if (!solver) {
17
- solver = createBlackBoxSolver();
18
- }
19
- return solver;
20
- };
21
-
22
9
  export class WASMSimulator implements SimulationProvider {
23
10
  async simulateCircuit(input: WitnessMap, compiledCircuit: NoirCompiledCircuit): Promise<WitnessMap> {
24
11
  // Execute the circuit on those initial witness values
@@ -27,8 +14,7 @@ export class WASMSimulator implements SimulationProvider {
27
14
  const decodedBytecode = Buffer.from(compiledCircuit.bytecode, 'base64');
28
15
  //
29
16
  // Execute the circuit
30
- const _witnessMap = await executeCircuitWithBlackBoxSolver(
31
- await getSolver(),
17
+ const _witnessMap = await executeCircuit(
32
18
  decodedBytecode,
33
19
  input,
34
20
  foreignCallHandler, // handle calls to debug_log