@aztec/simulator 0.41.0 → 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 (204) 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 -4
  5. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  6. package/dest/acvm/oracle/oracle.js +20 -11
  7. package/dest/acvm/oracle/typed_oracle.d.ts +5 -3
  8. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  9. package/dest/acvm/oracle/typed_oracle.js +10 -4
  10. package/dest/acvm/serialize.js +2 -2
  11. package/dest/avm/avm_gas.d.ts +1 -5
  12. package/dest/avm/avm_gas.d.ts.map +1 -1
  13. package/dest/avm/avm_gas.js +67 -73
  14. package/dest/avm/avm_simulator.d.ts +5 -0
  15. package/dest/avm/avm_simulator.d.ts.map +1 -1
  16. package/dest/avm/avm_simulator.js +8 -1
  17. package/dest/avm/fixtures/index.d.ts +3 -0
  18. package/dest/avm/fixtures/index.d.ts.map +1 -1
  19. package/dest/avm/fixtures/index.js +13 -1
  20. package/dest/avm/index.d.ts +2 -0
  21. package/dest/avm/index.d.ts.map +1 -0
  22. package/dest/avm/index.js +2 -0
  23. package/dest/avm/journal/host_storage.d.ts +1 -1
  24. package/dest/avm/journal/host_storage.d.ts.map +1 -1
  25. package/dest/avm/journal/journal.d.ts +2 -0
  26. package/dest/avm/journal/journal.d.ts.map +1 -1
  27. package/dest/avm/journal/journal.js +6 -2
  28. package/dest/avm/journal/trace.d.ts +2 -0
  29. package/dest/avm/journal/trace.d.ts.map +1 -1
  30. package/dest/avm/journal/trace.js +7 -1
  31. package/dest/avm/journal/trace_types.d.ts +1 -0
  32. package/dest/avm/journal/trace_types.d.ts.map +1 -1
  33. package/dest/avm/journal/trace_types.js +1 -1
  34. package/dest/avm/opcodes/arithmetic.d.ts +1 -7
  35. package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
  36. package/dest/avm/opcodes/arithmetic.js +1 -12
  37. package/dest/avm/opcodes/conversion.js +2 -2
  38. package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
  39. package/dest/avm/opcodes/external_calls.js +4 -3
  40. package/dest/avm/opcodes/instruction.d.ts +1 -1
  41. package/dest/avm/opcodes/instruction.d.ts.map +1 -1
  42. package/dest/avm/opcodes/instruction.js +6 -4
  43. package/dest/avm/opcodes/memory.d.ts +0 -4
  44. package/dest/avm/opcodes/memory.d.ts.map +1 -1
  45. package/dest/avm/opcodes/memory.js +1 -7
  46. package/dest/avm/opcodes/storage.d.ts +0 -5
  47. package/dest/avm/opcodes/storage.d.ts.map +1 -1
  48. package/dest/avm/opcodes/storage.js +1 -7
  49. package/dest/avm/serialization/bytecode_serialization.js +2 -2
  50. package/dest/client/client_execution_context.d.ts +11 -19
  51. package/dest/client/client_execution_context.d.ts.map +1 -1
  52. package/dest/client/client_execution_context.js +26 -43
  53. package/dest/client/db_oracle.d.ts +7 -1
  54. package/dest/client/db_oracle.d.ts.map +1 -1
  55. package/dest/client/execution_note_cache.d.ts +0 -17
  56. package/dest/client/execution_note_cache.d.ts.map +1 -1
  57. package/dest/client/execution_note_cache.js +1 -24
  58. package/dest/client/execution_result.d.ts +8 -4
  59. package/dest/client/execution_result.d.ts.map +1 -1
  60. package/dest/client/execution_result.js +16 -6
  61. package/dest/client/private_execution.d.ts +2 -3
  62. package/dest/client/private_execution.d.ts.map +1 -1
  63. package/dest/client/private_execution.js +20 -9
  64. package/dest/client/simulator.d.ts +0 -16
  65. package/dest/client/simulator.d.ts.map +1 -1
  66. package/dest/client/simulator.js +8 -25
  67. package/dest/client/unconstrained_execution.d.ts +2 -3
  68. package/dest/client/unconstrained_execution.d.ts.map +1 -1
  69. package/dest/client/unconstrained_execution.js +5 -7
  70. package/dest/client/view_data_oracle.d.ts +2 -0
  71. package/dest/client/view_data_oracle.d.ts.map +1 -1
  72. package/dest/client/view_data_oracle.js +7 -1
  73. package/dest/index.d.ts +3 -1
  74. package/dest/index.d.ts.map +1 -1
  75. package/dest/index.js +4 -2
  76. package/dest/mocks/fixtures.d.ts +14 -10
  77. package/dest/mocks/fixtures.d.ts.map +1 -1
  78. package/dest/mocks/fixtures.js +22 -16
  79. package/dest/{simulator → providers}/acvm_native.d.ts.map +1 -1
  80. package/dest/{simulator → providers}/acvm_native.js +13 -14
  81. package/dest/providers/acvm_wasm.d.ts.map +1 -0
  82. package/dest/providers/acvm_wasm.js +15 -0
  83. package/dest/providers/index.d.ts.map +1 -0
  84. package/dest/{simulator → providers}/index.js +1 -1
  85. package/dest/{simulator → providers}/simulation_provider.d.ts.map +1 -1
  86. package/dest/{simulator → providers}/simulation_provider.js +1 -1
  87. package/dest/public/abstract_phase_manager.d.ts +43 -42
  88. package/dest/public/abstract_phase_manager.d.ts.map +1 -1
  89. package/dest/public/abstract_phase_manager.js +77 -106
  90. package/dest/public/app_logic_phase_manager.d.ts +6 -7
  91. package/dest/public/app_logic_phase_manager.d.ts.map +1 -1
  92. package/dest/public/app_logic_phase_manager.js +14 -14
  93. package/dest/public/{db.d.ts → db_interfaces.d.ts} +3 -3
  94. package/dest/public/db_interfaces.d.ts.map +1 -0
  95. package/dest/public/db_interfaces.js +2 -0
  96. package/dest/public/execution.d.ts +16 -9
  97. package/dest/public/execution.d.ts.map +1 -1
  98. package/dest/public/execution.js +1 -1
  99. package/dest/public/executor.d.ts +3 -30
  100. package/dest/public/executor.d.ts.map +1 -1
  101. package/dest/public/executor.js +32 -282
  102. package/dest/public/fee_payment.d.ts +11 -0
  103. package/dest/public/fee_payment.d.ts.map +1 -0
  104. package/dest/public/fee_payment.js +24 -0
  105. package/dest/public/hints_builder.d.ts +1 -0
  106. package/dest/public/hints_builder.d.ts.map +1 -1
  107. package/dest/public/hints_builder.js +6 -2
  108. package/dest/public/index.d.ts +4 -2
  109. package/dest/public/index.d.ts.map +1 -1
  110. package/dest/public/index.js +5 -3
  111. package/dest/public/phase_manager_factory.d.ts +1 -1
  112. package/dest/public/phase_manager_factory.d.ts.map +1 -1
  113. package/dest/public/{public_executor.d.ts → public_db_sources.d.ts} +3 -2
  114. package/dest/public/public_db_sources.d.ts.map +1 -0
  115. package/dest/public/public_db_sources.js +198 -0
  116. package/dest/public/public_kernel.js +14 -14
  117. package/dest/public/public_processor.d.ts +6 -4
  118. package/dest/public/public_processor.d.ts.map +1 -1
  119. package/dest/public/public_processor.js +46 -27
  120. package/dest/public/setup_phase_manager.d.ts +6 -8
  121. package/dest/public/setup_phase_manager.d.ts.map +1 -1
  122. package/dest/public/setup_phase_manager.js +11 -20
  123. package/dest/public/tail_phase_manager.d.ts +4 -10
  124. package/dest/public/tail_phase_manager.d.ts.map +1 -1
  125. package/dest/public/tail_phase_manager.js +15 -35
  126. package/dest/public/teardown_phase_manager.d.ts +6 -8
  127. package/dest/public/teardown_phase_manager.d.ts.map +1 -1
  128. package/dest/public/teardown_phase_manager.js +15 -21
  129. package/dest/public/transitional_adaptors.d.ts +1 -1
  130. package/dest/public/transitional_adaptors.d.ts.map +1 -1
  131. package/dest/public/transitional_adaptors.js +8 -6
  132. package/dest/public/utils.d.ts +2 -2
  133. package/dest/public/utils.d.ts.map +1 -1
  134. package/dest/public/utils.js +21 -14
  135. package/package.json +12 -9
  136. package/src/acvm/acvm.ts +0 -3
  137. package/src/acvm/oracle/oracle.ts +36 -13
  138. package/src/acvm/oracle/typed_oracle.ts +12 -3
  139. package/src/acvm/serialize.ts +1 -1
  140. package/src/avm/avm_gas.ts +66 -73
  141. package/src/avm/avm_simulator.ts +9 -0
  142. package/src/avm/fixtures/index.ts +20 -0
  143. package/src/avm/index.ts +1 -0
  144. package/src/avm/journal/host_storage.ts +1 -1
  145. package/src/avm/journal/journal.ts +6 -1
  146. package/src/avm/journal/trace.ts +12 -0
  147. package/src/avm/journal/trace_types.ts +1 -0
  148. package/src/avm/opcodes/arithmetic.ts +1 -14
  149. package/src/avm/opcodes/conversion.ts +1 -1
  150. package/src/avm/opcodes/external_calls.ts +3 -1
  151. package/src/avm/opcodes/instruction.ts +5 -3
  152. package/src/avm/opcodes/memory.ts +1 -8
  153. package/src/avm/opcodes/storage.ts +1 -8
  154. package/src/avm/serialization/bytecode_serialization.ts +1 -1
  155. package/src/client/client_execution_context.ts +33 -45
  156. package/src/client/db_oracle.ts +8 -1
  157. package/src/client/execution_note_cache.ts +0 -28
  158. package/src/client/execution_result.ts +21 -7
  159. package/src/client/private_execution.ts +36 -21
  160. package/src/client/simulator.ts +7 -27
  161. package/src/client/unconstrained_execution.ts +9 -12
  162. package/src/client/view_data_oracle.ts +8 -0
  163. package/src/index.ts +3 -1
  164. package/src/mocks/fixtures.ts +30 -32
  165. package/src/{simulator → providers}/acvm_native.ts +21 -19
  166. package/src/{simulator → providers}/acvm_wasm.ts +2 -16
  167. package/src/public/abstract_phase_manager.ts +138 -205
  168. package/src/public/app_logic_phase_manager.ts +23 -39
  169. package/src/public/{db.ts → db_interfaces.ts} +2 -2
  170. package/src/public/execution.ts +15 -8
  171. package/src/public/executor.ts +51 -398
  172. package/src/public/fee_payment.ts +26 -0
  173. package/src/public/hints_builder.ts +6 -0
  174. package/src/public/index.ts +4 -2
  175. package/src/public/phase_manager_factory.ts +1 -1
  176. package/src/public/{public_executor.ts → public_db_sources.ts} +3 -2
  177. package/src/public/public_kernel.ts +24 -24
  178. package/src/public/public_processor.ts +77 -33
  179. package/src/public/setup_phase_manager.ts +20 -45
  180. package/src/public/tail_phase_manager.ts +17 -65
  181. package/src/public/teardown_phase_manager.ts +22 -41
  182. package/src/public/transitional_adaptors.ts +7 -11
  183. package/src/public/utils.ts +20 -14
  184. package/dest/public/db.d.ts.map +0 -1
  185. package/dest/public/db.js +0 -2
  186. package/dest/public/public_execution_context.d.ts +0 -121
  187. package/dest/public/public_execution_context.d.ts.map +0 -1
  188. package/dest/public/public_execution_context.js +0 -214
  189. package/dest/public/public_executor.d.ts.map +0 -1
  190. package/dest/public/public_executor.js +0 -197
  191. package/dest/public/state_actions.d.ts +0 -39
  192. package/dest/public/state_actions.d.ts.map +0 -1
  193. package/dest/public/state_actions.js +0 -80
  194. package/dest/simulator/acvm_wasm.d.ts.map +0 -1
  195. package/dest/simulator/acvm_wasm.js +0 -22
  196. package/dest/simulator/index.d.ts.map +0 -1
  197. package/src/public/public_execution_context.ts +0 -289
  198. package/src/public/state_actions.ts +0 -102
  199. /package/dest/{simulator → providers}/acvm_native.d.ts +0 -0
  200. /package/dest/{simulator → providers}/acvm_wasm.d.ts +0 -0
  201. /package/dest/{simulator → providers}/index.d.ts +0 -0
  202. /package/dest/{simulator → providers}/simulation_provider.d.ts +0 -0
  203. /package/src/{simulator → providers}/index.ts +0 -0
  204. /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
@@ -34,6 +34,14 @@ 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
46
  * Retrieve keys associated with a specific master public key and app address.
39
47
  * @param pkMHash - The master public key hash.
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: [],
@@ -124,39 +142,19 @@ export class PublicExecutionResultBuilder {
124
142
  startGasLeft: Gas.test(),
125
143
  endGasLeft: Gas.test(),
126
144
  transactionFee: Fr.ZERO,
145
+ calldata: [],
146
+ avmHints: AvmExecutionHints.empty(),
127
147
  ...overrides,
128
148
  };
129
149
  }
130
150
  }
131
151
 
132
152
  export const makeFunctionCall = (
153
+ name = 'function',
133
154
  to = makeAztecAddress(30),
134
155
  selector = makeSelector(5),
156
+ type = FunctionType.PUBLIC,
135
157
  args = new Array(ARGS_LENGTH).fill(Fr.ZERO),
136
158
  isStatic = false,
137
- ) => ({ to, functionData: new FunctionData(selector, /*isPrivate=*/ false), args, isStatic });
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
- }
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