@aztec/simulator 0.32.0 → 0.33.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 (227) hide show
  1. package/README.md +5 -3
  2. package/dest/acvm/acvm.d.ts +5 -5
  3. package/dest/acvm/acvm.d.ts.map +1 -1
  4. package/dest/acvm/acvm_types.d.ts +1 -1
  5. package/dest/acvm/acvm_types.d.ts.map +1 -1
  6. package/dest/acvm/deserialize.d.ts +1 -1
  7. package/dest/acvm/deserialize.d.ts.map +1 -1
  8. package/dest/acvm/oracle/index.d.ts +1 -2
  9. package/dest/acvm/oracle/index.d.ts.map +1 -1
  10. package/dest/acvm/oracle/index.js +1 -2
  11. package/dest/acvm/oracle/oracle.d.ts +2 -2
  12. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  13. package/dest/acvm/oracle/oracle.js +2 -3
  14. package/dest/acvm/oracle/typed_oracle.d.ts +6 -6
  15. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  16. package/dest/acvm/serialize.d.ts +4 -4
  17. package/dest/acvm/serialize.d.ts.map +1 -1
  18. package/dest/acvm/serialize.js +1 -1
  19. package/dest/avm/avm_context.d.ts +8 -18
  20. package/dest/avm/avm_context.d.ts.map +1 -1
  21. package/dest/avm/avm_context.js +10 -22
  22. package/dest/avm/avm_execution_environment.d.ts +4 -4
  23. package/dest/avm/avm_execution_environment.d.ts.map +1 -1
  24. package/dest/avm/avm_execution_environment.js +1 -1
  25. package/dest/avm/avm_gas.d.ts +71 -0
  26. package/dest/avm/avm_gas.d.ts.map +1 -0
  27. package/dest/avm/avm_gas.js +161 -0
  28. package/dest/avm/avm_machine_state.d.ts +5 -3
  29. package/dest/avm/avm_machine_state.d.ts.map +1 -1
  30. package/dest/avm/avm_machine_state.js +8 -2
  31. package/dest/avm/avm_memory_types.d.ts +54 -2
  32. package/dest/avm/avm_memory_types.d.ts.map +1 -1
  33. package/dest/avm/avm_memory_types.js +95 -2
  34. package/dest/avm/avm_message_call_result.d.ts +1 -1
  35. package/dest/avm/avm_message_call_result.d.ts.map +1 -1
  36. package/dest/avm/avm_simulator.d.ts.map +1 -1
  37. package/dest/avm/avm_simulator.js +10 -8
  38. package/dest/avm/errors.d.ts +1 -1
  39. package/dest/avm/errors.d.ts.map +1 -1
  40. package/dest/avm/fixtures/index.d.ts +1 -1
  41. package/dest/avm/fixtures/index.d.ts.map +1 -1
  42. package/dest/avm/fixtures/index.js +2 -2
  43. package/dest/avm/journal/host_storage.d.ts +1 -1
  44. package/dest/avm/journal/host_storage.d.ts.map +1 -1
  45. package/dest/avm/journal/journal.d.ts +2 -2
  46. package/dest/avm/journal/journal.d.ts.map +1 -1
  47. package/dest/avm/journal/trace.d.ts +1 -1
  48. package/dest/avm/journal/trace.d.ts.map +1 -1
  49. package/dest/avm/journal/trace_types.d.ts +1 -1
  50. package/dest/avm/journal/trace_types.d.ts.map +1 -1
  51. package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
  52. package/dest/avm/opcodes/accrued_substate.js +44 -16
  53. package/dest/avm/opcodes/addressing_mode.d.ts +5 -3
  54. package/dest/avm/opcodes/addressing_mode.d.ts.map +1 -1
  55. package/dest/avm/opcodes/addressing_mode.js +5 -1
  56. package/dest/avm/opcodes/arithmetic.d.ts +7 -3
  57. package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
  58. package/dest/avm/opcodes/arithmetic.js +27 -16
  59. package/dest/avm/opcodes/bitwise.d.ts +21 -20
  60. package/dest/avm/opcodes/bitwise.d.ts.map +1 -1
  61. package/dest/avm/opcodes/bitwise.js +43 -65
  62. package/dest/avm/opcodes/comparators.d.ts +12 -9
  63. package/dest/avm/opcodes/comparators.d.ts.map +1 -1
  64. package/dest/avm/opcodes/comparators.js +22 -32
  65. package/dest/avm/opcodes/context_getters.d.ts +20 -0
  66. package/dest/avm/opcodes/context_getters.d.ts.map +1 -0
  67. package/dest/avm/opcodes/context_getters.js +26 -0
  68. package/dest/avm/opcodes/contract.d.ts +14 -0
  69. package/dest/avm/opcodes/contract.d.ts.map +1 -0
  70. package/dest/avm/opcodes/contract.js +49 -0
  71. package/dest/avm/opcodes/control_flow.d.ts.map +1 -1
  72. package/dest/avm/opcodes/control_flow.js +12 -2
  73. package/dest/avm/opcodes/environment_getters.d.ts +31 -34
  74. package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
  75. package/dest/avm/opcodes/environment_getters.js +34 -43
  76. package/dest/avm/opcodes/external_calls.d.ts +13 -19
  77. package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
  78. package/dest/avm/opcodes/external_calls.js +50 -68
  79. package/dest/avm/opcodes/hashing.d.ts +3 -2
  80. package/dest/avm/opcodes/hashing.d.ts.map +1 -1
  81. package/dest/avm/opcodes/hashing.js +37 -18
  82. package/dest/avm/opcodes/index.d.ts +1 -0
  83. package/dest/avm/opcodes/index.d.ts.map +1 -1
  84. package/dest/avm/opcodes/index.js +2 -1
  85. package/dest/avm/opcodes/instruction.d.ts +12 -17
  86. package/dest/avm/opcodes/instruction.d.ts.map +1 -1
  87. package/dest/avm/opcodes/instruction.js +12 -22
  88. package/dest/avm/opcodes/instruction_impl.d.ts +14 -0
  89. package/dest/avm/opcodes/instruction_impl.d.ts.map +1 -1
  90. package/dest/avm/opcodes/instruction_impl.js +37 -16
  91. package/dest/avm/opcodes/memory.d.ts +4 -3
  92. package/dest/avm/opcodes/memory.d.ts.map +1 -1
  93. package/dest/avm/opcodes/memory.js +38 -19
  94. package/dest/avm/opcodes/storage.d.ts +5 -0
  95. package/dest/avm/opcodes/storage.d.ts.map +1 -1
  96. package/dest/avm/opcodes/storage.js +21 -7
  97. package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
  98. package/dest/avm/serialization/bytecode_serialization.js +7 -5
  99. package/dest/avm/serialization/instruction_serialization.d.ts +12 -11
  100. package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
  101. package/dest/avm/serialization/instruction_serialization.js +13 -12
  102. package/dest/avm/temporary_executor_migration.d.ts +6 -4
  103. package/dest/avm/temporary_executor_migration.d.ts.map +1 -1
  104. package/dest/avm/temporary_executor_migration.js +14 -3
  105. package/dest/client/client_execution_context.d.ts +11 -11
  106. package/dest/client/client_execution_context.d.ts.map +1 -1
  107. package/dest/client/client_execution_context.js +1 -1
  108. package/dest/client/db_oracle.d.ts +9 -9
  109. package/dest/client/db_oracle.d.ts.map +1 -1
  110. package/dest/client/db_oracle.js +1 -1
  111. package/dest/client/execution_note_cache.d.ts +2 -2
  112. package/dest/client/execution_note_cache.d.ts.map +1 -1
  113. package/dest/client/execution_result.d.ts +5 -5
  114. package/dest/client/execution_result.d.ts.map +1 -1
  115. package/dest/client/execution_result.js +1 -1
  116. package/dest/client/pick_notes.d.ts +1 -1
  117. package/dest/client/pick_notes.d.ts.map +1 -1
  118. package/dest/client/pick_notes.js +1 -1
  119. package/dest/client/private_execution.d.ts +5 -5
  120. package/dest/client/private_execution.d.ts.map +1 -1
  121. package/dest/client/private_execution.js +6 -2
  122. package/dest/client/simulator.d.ts +6 -6
  123. package/dest/client/simulator.d.ts.map +1 -1
  124. package/dest/client/simulator.js +1 -1
  125. package/dest/client/unconstrained_execution.d.ts +5 -5
  126. package/dest/client/unconstrained_execution.d.ts.map +1 -1
  127. package/dest/client/unconstrained_execution.js +1 -1
  128. package/dest/client/view_data_oracle.d.ts +6 -6
  129. package/dest/client/view_data_oracle.d.ts.map +1 -1
  130. package/dest/client/view_data_oracle.js +1 -1
  131. package/dest/common/errors.d.ts +1 -1
  132. package/dest/common/errors.d.ts.map +1 -1
  133. package/dest/common/errors.js +1 -1
  134. package/dest/public/db.d.ts +6 -6
  135. package/dest/public/db.d.ts.map +1 -1
  136. package/dest/public/execution.d.ts +2 -2
  137. package/dest/public/execution.d.ts.map +1 -1
  138. package/dest/public/executor.d.ts +13 -5
  139. package/dest/public/executor.d.ts.map +1 -1
  140. package/dest/public/executor.js +59 -20
  141. package/dest/public/index.d.ts +1 -1
  142. package/dest/public/index.d.ts.map +1 -1
  143. package/dest/public/public_execution_context.d.ts +7 -7
  144. package/dest/public/public_execution_context.d.ts.map +1 -1
  145. package/dest/public/public_execution_context.js +3 -3
  146. package/dest/public/state_actions.d.ts +2 -2
  147. package/dest/public/state_actions.d.ts.map +1 -1
  148. package/dest/simulator/acvm_native.d.ts +3 -3
  149. package/dest/simulator/acvm_native.d.ts.map +1 -1
  150. package/dest/simulator/acvm_wasm.d.ts +3 -3
  151. package/dest/simulator/acvm_wasm.d.ts.map +1 -1
  152. package/dest/simulator/acvm_wasm.js +2 -2
  153. package/dest/simulator/simulation_provider.d.ts +2 -2
  154. package/dest/simulator/simulation_provider.d.ts.map +1 -1
  155. package/dest/test/utils.d.ts +1 -1
  156. package/dest/test/utils.d.ts.map +1 -1
  157. package/dest/test/utils.js +1 -1
  158. package/dest/utils.d.ts +1 -1
  159. package/dest/utils.d.ts.map +1 -1
  160. package/package.json +15 -9
  161. package/src/acvm/acvm.ts +8 -8
  162. package/src/acvm/acvm_types.ts +1 -1
  163. package/src/acvm/deserialize.ts +1 -1
  164. package/src/acvm/oracle/index.ts +1 -2
  165. package/src/acvm/oracle/oracle.ts +3 -4
  166. package/src/acvm/oracle/typed_oracle.ts +18 -18
  167. package/src/acvm/serialize.ts +4 -4
  168. package/src/avm/avm_context.ts +15 -37
  169. package/src/avm/avm_execution_environment.ts +4 -4
  170. package/src/avm/{avm_gas_cost.ts → avm_gas.ts} +75 -21
  171. package/src/avm/avm_machine_state.ts +10 -3
  172. package/src/avm/avm_memory_types.ts +131 -3
  173. package/src/avm/avm_message_call_result.ts +1 -1
  174. package/src/avm/avm_simulator.ts +10 -8
  175. package/src/avm/errors.ts +1 -1
  176. package/src/avm/fixtures/index.ts +6 -1
  177. package/src/avm/journal/host_storage.ts +1 -1
  178. package/src/avm/journal/journal.ts +2 -2
  179. package/src/avm/journal/trace.ts +1 -1
  180. package/src/avm/journal/trace_types.ts +1 -1
  181. package/src/avm/opcodes/accrued_substate.ts +57 -22
  182. package/src/avm/opcodes/addressing_mode.ts +8 -3
  183. package/src/avm/opcodes/arithmetic.ts +32 -22
  184. package/src/avm/opcodes/bitwise.ts +50 -84
  185. package/src/avm/opcodes/comparators.ts +28 -43
  186. package/src/avm/opcodes/context_getters.ts +32 -0
  187. package/src/avm/opcodes/contract.ts +58 -0
  188. package/src/avm/opcodes/control_flow.ts +24 -6
  189. package/src/avm/opcodes/environment_getters.ts +36 -45
  190. package/src/avm/opcodes/external_calls.ts +65 -84
  191. package/src/avm/opcodes/hashing.ts +46 -23
  192. package/src/avm/opcodes/index.ts +1 -0
  193. package/src/avm/opcodes/instruction.ts +16 -28
  194. package/src/avm/opcodes/instruction_impl.ts +45 -15
  195. package/src/avm/opcodes/memory.ts +48 -28
  196. package/src/avm/opcodes/storage.ts +26 -12
  197. package/src/avm/serialization/bytecode_serialization.ts +6 -3
  198. package/src/avm/serialization/instruction_serialization.ts +1 -0
  199. package/src/avm/temporary_executor_migration.ts +20 -6
  200. package/src/client/client_execution_context.ts +15 -15
  201. package/src/client/db_oracle.ts +16 -10
  202. package/src/client/execution_note_cache.ts +2 -2
  203. package/src/client/execution_result.ts +9 -5
  204. package/src/client/pick_notes.ts +1 -1
  205. package/src/client/private_execution.ts +12 -6
  206. package/src/client/simulator.ts +8 -8
  207. package/src/client/unconstrained_execution.ts +5 -5
  208. package/src/client/view_data_oracle.ts +11 -11
  209. package/src/common/errors.ts +1 -1
  210. package/src/public/db.ts +6 -6
  211. package/src/public/execution.ts +10 -10
  212. package/src/public/executor.ts +78 -25
  213. package/src/public/index.ts +2 -2
  214. package/src/public/public_execution_context.ts +17 -7
  215. package/src/public/state_actions.ts +2 -2
  216. package/src/simulator/acvm_native.ts +3 -3
  217. package/src/simulator/acvm_wasm.ts +8 -4
  218. package/src/simulator/simulation_provider.ts +2 -2
  219. package/src/test/utils.ts +1 -1
  220. package/src/utils.ts +1 -1
  221. package/dest/acvm/oracle/debug.d.ts +0 -19
  222. package/dest/acvm/oracle/debug.d.ts.map +0 -1
  223. package/dest/acvm/oracle/debug.js +0 -95
  224. package/dest/avm/avm_gas_cost.d.ts +0 -322
  225. package/dest/avm/avm_gas_cost.d.ts.map +0 -1
  226. package/dest/avm/avm_gas_cost.js +0 -118
  227. package/src/acvm/oracle/debug.ts +0 -109
@@ -1,21 +1,21 @@
1
1
  import {
2
- AuthWitness,
3
- AztecNode,
4
- CompleteAddress,
2
+ type AuthWitness,
3
+ type AztecNode,
4
+ type CompleteAddress,
5
5
  MerkleTreeId,
6
- NoteStatus,
7
- NullifierMembershipWitness,
8
- PublicDataWitness,
6
+ type NoteStatus,
7
+ type NullifierMembershipWitness,
8
+ type PublicDataWitness,
9
9
  } from '@aztec/circuit-types';
10
- import { Header } from '@aztec/circuits.js';
10
+ import { type Header } from '@aztec/circuits.js';
11
11
  import { siloNullifier } from '@aztec/circuits.js/hash';
12
- import { AztecAddress } from '@aztec/foundation/aztec-address';
12
+ import { type AztecAddress } from '@aztec/foundation/aztec-address';
13
13
  import { Fr } from '@aztec/foundation/fields';
14
14
  import { createDebugLogger } from '@aztec/foundation/log';
15
- import { ContractInstance } from '@aztec/types/contracts';
15
+ import { type ContractInstance } from '@aztec/types/contracts';
16
16
 
17
- import { NoteData, TypedOracle } from '../acvm/index.js';
18
- import { DBOracle } from './db_oracle.js';
17
+ import { type NoteData, TypedOracle } from '../acvm/index.js';
18
+ import { type DBOracle } from './db_oracle.js';
19
19
  import { pickNotes } from './pick_notes.js';
20
20
 
21
21
  /**
@@ -1,4 +1,4 @@
1
- import { FailingFunction, NoirCallStack, SimulationError } from '@aztec/circuit-types';
1
+ import { type FailingFunction, type NoirCallStack, SimulationError } from '@aztec/circuit-types';
2
2
 
3
3
  /**
4
4
  * An error that occurred during the execution of a function.
package/src/public/db.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { NullifierMembershipWitness } from '@aztec/circuit-types';
2
- import { EthAddress, FunctionSelector, L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/circuits.js';
3
- import { AztecAddress } from '@aztec/foundation/aztec-address';
4
- import { Fr } from '@aztec/foundation/fields';
5
- import { ContractInstanceWithAddress } from '@aztec/types/contracts';
1
+ import { type NullifierMembershipWitness } from '@aztec/circuit-types';
2
+ import { type EthAddress, type FunctionSelector, type L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/circuits.js';
3
+ import { type AztecAddress } from '@aztec/foundation/aztec-address';
4
+ import { type Fr } from '@aztec/foundation/fields';
5
+ import { type ContractInstanceWithAddress } from '@aztec/types/contracts';
6
6
 
7
- import { MessageLoadOracleInputs } from '../acvm/index.js';
7
+ import { type MessageLoadOracleInputs } from '../acvm/index.js';
8
8
 
9
9
  /**
10
10
  * Database interface for providing access to public state.
@@ -1,16 +1,16 @@
1
- import { SimulationError, UnencryptedFunctionL2Logs } from '@aztec/circuit-types';
1
+ import { type SimulationError, type UnencryptedFunctionL2Logs } from '@aztec/circuit-types';
2
2
  import {
3
- AztecAddress,
4
- ContractStorageRead,
5
- ContractStorageUpdateRequest,
6
- Fr,
7
- L2ToL1Message,
8
- PublicCallRequest,
3
+ type AztecAddress,
4
+ type ContractStorageRead,
5
+ type ContractStorageUpdateRequest,
6
+ type Fr,
7
+ type L2ToL1Message,
8
+ type PublicCallRequest,
9
9
  PublicDataRead,
10
10
  PublicDataUpdateRequest,
11
- ReadRequest,
12
- SideEffect,
13
- SideEffectLinkedToNoteHash,
11
+ type ReadRequest,
12
+ type SideEffect,
13
+ type SideEffectLinkedToNoteHash,
14
14
  } from '@aztec/circuits.js';
15
15
  import { computePublicDataTreeLeafSlot, computePublicDataTreeValue } from '@aztec/circuits.js/hash';
16
16
 
@@ -1,5 +1,5 @@
1
1
  import { UnencryptedFunctionL2Logs } from '@aztec/circuit-types';
2
- import { Fr, GlobalVariables, Header, PublicCircuitPublicInputs } from '@aztec/circuits.js';
2
+ import { Fr, type GlobalVariables, type Header, PublicCircuitPublicInputs } from '@aztec/circuits.js';
3
3
  import { createDebugLogger } from '@aztec/foundation/log';
4
4
 
5
5
  import { spawn } from 'child_process';
@@ -13,6 +13,7 @@ import { AvmSimulator } from '../avm/avm_simulator.js';
13
13
  import { HostStorage } from '../avm/journal/host_storage.js';
14
14
  import { AvmPersistableStateManager } from '../avm/journal/index.js';
15
15
  import {
16
+ isAvmBytecode,
16
17
  temporaryConvertAvmResults,
17
18
  temporaryCreateAvmExecutionEnvironment,
18
19
  } from '../avm/temporary_executor_migration.js';
@@ -20,8 +21,8 @@ import { AcirSimulator } from '../client/simulator.js';
20
21
  import { ExecutionError, createSimulationError } from '../common/errors.js';
21
22
  import { SideEffectCounter } from '../common/index.js';
22
23
  import { PackedArgsCache } from '../common/packed_args_cache.js';
23
- import { CommitmentsDB, PublicContractsDB, PublicStateDB } from './db.js';
24
- import { PublicExecution, PublicExecutionResult, checkValidStaticCall } from './execution.js';
24
+ import { type CommitmentsDB, type PublicContractsDB, type PublicStateDB } from './db.js';
25
+ import { type PublicExecution, type PublicExecutionResult, checkValidStaticCall } from './execution.js';
25
26
  import { PublicExecutionContext } from './public_execution_context.js';
26
27
 
27
28
  /**
@@ -166,6 +167,7 @@ export class PublicExecutor {
166
167
  private readonly header: Header,
167
168
  ) {}
168
169
 
170
+ private readonly log = createDebugLogger('aztec:simulator:public_executor');
169
171
  /**
170
172
  * Executes a public execution request.
171
173
  * @param execution - The execution to run.
@@ -176,6 +178,30 @@ export class PublicExecutor {
176
178
  execution: PublicExecution,
177
179
  globalVariables: GlobalVariables,
178
180
  sideEffectCounter: number = 0,
181
+ ): Promise<PublicExecutionResult> {
182
+ const selector = execution.functionData.selector;
183
+ const bytecode = await this.contractsDb.getBytecode(execution.contractAddress, selector);
184
+ if (!bytecode) {
185
+ throw new Error(`Bytecode not found for ${execution.contractAddress}:${selector}`);
186
+ }
187
+
188
+ if (isAvmBytecode(bytecode)) {
189
+ return await this.simulateAvm(execution, globalVariables, sideEffectCounter);
190
+ } else {
191
+ return await this.simulateAcvm(execution, globalVariables, sideEffectCounter);
192
+ }
193
+ }
194
+
195
+ /**
196
+ * Executes a public execution request with the ACVM.
197
+ * @param execution - The execution to run.
198
+ * @param globalVariables - The global variables to use.
199
+ * @returns The result of the run plus all nested runs.
200
+ */
201
+ private async simulateAcvm(
202
+ execution: PublicExecution,
203
+ globalVariables: GlobalVariables,
204
+ sideEffectCounter: number = 0,
179
205
  ): Promise<PublicExecutionResult> {
180
206
  const selector = execution.functionData.selector;
181
207
  const acir = await this.contractsDb.getBytecode(execution.contractAddress, selector);
@@ -214,12 +240,12 @@ export class PublicExecutor {
214
240
  }
215
241
 
216
242
  /**
217
- * Executes a public execution request in the avm.
243
+ * Executes a public execution request in the AVM.
218
244
  * @param execution - The execution to run.
219
245
  * @param globalVariables - The global variables to use.
220
246
  * @returns The result of the run plus all nested runs.
221
247
  */
222
- public async simulateAvm(
248
+ private async simulateAvm(
223
249
  execution: PublicExecution,
224
250
  globalVariables: GlobalVariables,
225
251
  _sideEffectCounter = 0,
@@ -230,13 +256,14 @@ export class PublicExecutor {
230
256
  const worldStateJournal = new AvmPersistableStateManager(hostStorage);
231
257
  const executionEnv = temporaryCreateAvmExecutionEnvironment(execution, globalVariables);
232
258
  // TODO(@spalladino) Load initial gas from the public execution request
233
- const machineState = new AvmMachineState(100_000, 100_000, 100_000);
259
+ const machineState = new AvmMachineState(1e10, 1e10, 1e10);
234
260
 
235
261
  const context = new AvmContext(worldStateJournal, executionEnv, machineState);
236
262
  const simulator = new AvmSimulator(context);
237
263
 
238
264
  const result = await simulator.execute();
239
265
  const newWorldState = context.persistableState.flush();
266
+
240
267
  // TODO(@spalladino) Read gas left from machineState and return it
241
268
  return temporaryConvertAvmResults(execution, newWorldState, result);
242
269
  }
@@ -260,6 +287,7 @@ export class PublicExecutor {
260
287
  const artifactsPath = path.resolve('target');
261
288
 
262
289
  // Create the directory if it does not exist
290
+ await fs.rm(artifactsPath, { recursive: true, force: true });
263
291
  await fs.mkdir(artifactsPath, { recursive: true });
264
292
 
265
293
  const calldataPath = path.join(artifactsPath, 'calldata.bin');
@@ -269,34 +297,54 @@ export class PublicExecutor {
269
297
  const { args, functionData, contractAddress } = avmExecution;
270
298
  const bytecode = await this.contractsDb.getBytecode(contractAddress, functionData.selector);
271
299
  // Write call data and bytecode to files.
272
- await Promise.all([
273
- fs.writeFile(
274
- calldataPath,
275
- args.map(c => c.toBuffer()),
276
- ),
277
- fs.writeFile(bytecodePath, bytecode!),
278
- ]);
279
-
280
- const bbBinary = spawn(path.join(bbPath, 'build', 'bin', 'bb'), [
281
- 'avm_prove',
282
- '-b',
283
- bytecodePath,
284
- '-d',
300
+ await fs.writeFile(
285
301
  calldataPath,
286
- '-o',
287
- proofPath,
288
- ]);
302
+ args.map(c => c.toBuffer()),
303
+ );
304
+ await fs.writeFile(bytecodePath, bytecode!);
305
+
306
+ const bbExec = path.join(bbPath, 'build', 'bin', 'bb');
307
+ const bbArgs = ['avm_prove', '-b', bytecodePath, '-d', calldataPath, '-o', proofPath];
308
+ this.log(`calling '${bbExec} ${bbArgs.join(' ')}'`);
309
+ const bbBinary = spawn(bbExec, bbArgs);
310
+
289
311
  // The binary writes the proof and the verification key to the write path.
290
312
  return new Promise((resolve, reject) => {
313
+ let stdout: string = '';
314
+ let stderr: string = '';
315
+
291
316
  bbBinary.on('close', () => {
292
- resolve(Promise.all([fs.readFile(proofPath), fs.readFile(path.join(artifactsPath, 'vk'))]));
317
+ this.log(`Proof generation complete. Reading proof and vk from ${proofPath}.`);
318
+ return resolve(Promise.all([fs.readFile(proofPath), fs.readFile(path.join(artifactsPath, 'vk'))]));
319
+ });
320
+
321
+ // Catch stdout.
322
+ bbBinary.stdout.on('data', (data: Buffer) => {
323
+ stdout += data.toString();
293
324
  });
325
+ bbBinary.stdout.on('end', () => {
326
+ if (stdout.length > 0) {
327
+ this.log(`stdout: ${stdout}`);
328
+ }
329
+ });
330
+
331
+ // Catch stderr.
332
+ bbBinary.stderr.on('data', (data: Buffer) => {
333
+ stderr += data.toString();
334
+ });
335
+ bbBinary.stderr.on('end', () => {
336
+ if (stderr.length > 0) {
337
+ this.log(`stderr: ${stderr}`);
338
+ }
339
+ });
340
+
294
341
  // Catch and propagate errors from spawning
295
342
  bbBinary.on('error', err => {
296
343
  reject(err);
297
344
  });
298
345
  });
299
346
  }
347
+
300
348
  /**
301
349
  * Verifies an AVM proof. This function is currently only used for testing purposes, as verification
302
350
  * is not fully complete in the AVM yet.
@@ -313,9 +361,14 @@ export class PublicExecutor {
313
361
  const proofPath = path.join(artifactsPath, 'proof');
314
362
 
315
363
  // Write the verification key and the proof to files.
316
- await Promise.all([fs.writeFile(vkPath, vk), fs.writeFile(proofPath, proof)]);
364
+ await fs.writeFile(vkPath, vk);
365
+ await fs.writeFile(proofPath, proof);
366
+
367
+ const bbExec = path.join(bbPath, 'build', 'bin', 'bb');
368
+ const bbArgs = ['avm_verify', '-p', proofPath];
369
+ this.log(`calling '${bbPath} ${bbArgs.join(' ')}'`);
370
+ const bbBinary = spawn(bbExec, bbArgs);
317
371
 
318
- const bbBinary = spawn(path.join(bbPath, 'build', 'bin', 'bb'), ['avm_verify', '-p', proofPath]);
319
372
  // The binary prints to stdout 1 if the proof is valid and 0 if it is not.
320
373
  return new Promise((resolve, reject) => {
321
374
  let result = Buffer.alloc(0);
@@ -1,7 +1,7 @@
1
1
  export * from './db.js';
2
2
  export {
3
- PublicExecution,
4
- PublicExecutionResult,
3
+ type PublicExecution,
4
+ type PublicExecutionResult,
5
5
  isPublicExecutionResult,
6
6
  collectPublicDataReads,
7
7
  collectPublicDataUpdateRequests,
@@ -1,15 +1,25 @@
1
- import { NullifierMembershipWitness, UnencryptedFunctionL2Logs, UnencryptedL2Log } from '@aztec/circuit-types';
2
- import { CallContext, FunctionData, FunctionSelector, GlobalVariables, Header } from '@aztec/circuits.js';
3
- import { AztecAddress } from '@aztec/foundation/aztec-address';
1
+ import {
2
+ type NullifierMembershipWitness,
3
+ UnencryptedFunctionL2Logs,
4
+ type UnencryptedL2Log,
5
+ } from '@aztec/circuit-types';
6
+ import {
7
+ CallContext,
8
+ FunctionData,
9
+ type FunctionSelector,
10
+ type GlobalVariables,
11
+ type Header,
12
+ } from '@aztec/circuits.js';
13
+ import { type AztecAddress } from '@aztec/foundation/aztec-address';
4
14
  import { EthAddress } from '@aztec/foundation/eth-address';
5
15
  import { Fr } from '@aztec/foundation/fields';
6
16
  import { createDebugLogger } from '@aztec/foundation/log';
7
- import { ContractInstance } from '@aztec/types/contracts';
17
+ import { type ContractInstance } from '@aztec/types/contracts';
8
18
 
9
19
  import { TypedOracle, toACVMWitness } from '../acvm/index.js';
10
- import { PackedArgsCache, SideEffectCounter } from '../common/index.js';
11
- import { CommitmentsDB, PublicContractsDB, PublicStateDB } from './db.js';
12
- import { PublicExecution, PublicExecutionResult, checkValidStaticCall } from './execution.js';
20
+ import { type PackedArgsCache, type SideEffectCounter } from '../common/index.js';
21
+ import { type CommitmentsDB, type PublicContractsDB, type PublicStateDB } from './db.js';
22
+ import { type PublicExecution, type PublicExecutionResult, checkValidStaticCall } from './execution.js';
13
23
  import { executePublicFunction } from './executor.js';
14
24
  import { ContractStorageActionsCollector } from './state_actions.js';
15
25
 
@@ -1,8 +1,8 @@
1
1
  import { ContractStorageRead, ContractStorageUpdateRequest } from '@aztec/circuits.js';
2
- import { AztecAddress } from '@aztec/foundation/aztec-address';
2
+ import { type AztecAddress } from '@aztec/foundation/aztec-address';
3
3
  import { Fr } from '@aztec/foundation/fields';
4
4
 
5
- import { PublicStateDB } from './db.js';
5
+ import { type PublicStateDB } from './db.js';
6
6
 
7
7
  /**
8
8
  * Implements read/write operations on a contract public storage, collecting
@@ -1,11 +1,11 @@
1
1
  import { randomBytes } from '@aztec/foundation/crypto';
2
- import { NoirCompiledCircuit } from '@aztec/types/noir';
2
+ import { type NoirCompiledCircuit } from '@aztec/types/noir';
3
3
 
4
- import { WitnessMap } from '@noir-lang/types';
4
+ import { type WitnessMap } from '@noir-lang/types';
5
5
  import * as proc from 'child_process';
6
6
  import fs from 'fs/promises';
7
7
 
8
- import { SimulationProvider } from './simulation_provider.js';
8
+ import { type SimulationProvider } from './simulation_provider.js';
9
9
 
10
10
  /**
11
11
  * Parses a TOML format witness map string into a Map structure
@@ -1,9 +1,13 @@
1
- import { NoirCompiledCircuit } from '@aztec/types/noir';
1
+ import { type NoirCompiledCircuit } from '@aztec/types/noir';
2
2
 
3
- import { WasmBlackBoxFunctionSolver, createBlackBoxSolver, executeCircuitWithBlackBoxSolver } from '@noir-lang/acvm_js';
4
- import { WitnessMap } from '@noir-lang/types';
3
+ import {
4
+ type WasmBlackBoxFunctionSolver,
5
+ createBlackBoxSolver,
6
+ executeCircuitWithBlackBoxSolver,
7
+ } from '@noir-lang/acvm_js';
8
+ import { type WitnessMap } from '@noir-lang/types';
5
9
 
6
- import { SimulationProvider } from './simulation_provider.js';
10
+ import { type SimulationProvider } from './simulation_provider.js';
7
11
 
8
12
  let solver: Promise<WasmBlackBoxFunctionSolver>;
9
13
 
@@ -1,6 +1,6 @@
1
- import { NoirCompiledCircuit } from '@aztec/types/noir';
1
+ import { type NoirCompiledCircuit } from '@aztec/types/noir';
2
2
 
3
- import { WitnessMap } from '@noir-lang/types';
3
+ import { type WitnessMap } from '@noir-lang/types';
4
4
 
5
5
  /**
6
6
  * Low level simulation interface
package/src/test/utils.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { L1Actor, L1ToL2Message, L2Actor } from '@aztec/circuit-types';
2
- import { AztecAddress, EthAddress, Fr } from '@aztec/circuits.js';
2
+ import { type AztecAddress, EthAddress, type Fr } from '@aztec/circuits.js';
3
3
  import { computeMessageSecretHash } from '@aztec/circuits.js/hash';
4
4
  import { sha256ToField } from '@aztec/foundation/crypto';
5
5
 
package/src/utils.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { pedersenHash } from '@aztec/foundation/crypto';
2
- import { Fr } from '@aztec/foundation/fields';
2
+ import { type Fr } from '@aztec/foundation/fields';
3
3
 
4
4
  /**
5
5
  * Computes the resulting storage slot for an entry in a mapping.
@@ -1,19 +0,0 @@
1
- import { ForeignCallInput } from '@noir-lang/acvm_js';
2
- import { ACVMField } from '../acvm_types.js';
3
- /**
4
- * Convert an array of ACVMFields to a string.
5
- *
6
- * @param msg - array of ACVMFields where each represents a single ascii character
7
- * @returns string representation of the message
8
- */
9
- export declare function acvmFieldMessageToString(msg: ACVMField[]): string;
10
- /**
11
- * Convert an array of ACVMFields from ACVM to a formatted string.
12
- *
13
- * @param parameters - either one parameter representing a simple field or array, or two parameters when
14
- * It's a message without args or three parameters when it's a message with arguments.
15
- *
16
- * @returns formatted string
17
- */
18
- export declare function oracleDebugCallToFormattedStr(parameters: ForeignCallInput[]): string;
19
- //# sourceMappingURL=debug.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../../src/acvm/oracle/debug.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,MAAM,CAajE;AAyBD;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAAC,UAAU,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAcpF"}
@@ -1,95 +0,0 @@
1
- /**
2
- * Convert an array of ACVMFields to a string.
3
- *
4
- * @param msg - array of ACVMFields where each represents a single ascii character
5
- * @returns string representation of the message
6
- */
7
- export function acvmFieldMessageToString(msg) {
8
- let msgStr = '';
9
- for (const msgChar of msg) {
10
- const asciiCode = Number(msgChar);
11
- const asciiChar = String.fromCharCode(asciiCode);
12
- msgStr = msgStr.concat(asciiChar);
13
- }
14
- // cut off string in case of preemptive null termination
15
- const nullCharIndex = msgStr.indexOf('\\0');
16
- if (nullCharIndex >= 0) {
17
- msgStr = msgStr.substring(0, nullCharIndex);
18
- }
19
- return msgStr.replaceAll('\\n', '\n').replaceAll('\\t', '\t');
20
- }
21
- /**
22
- * Format a debug string for Aztec.nr filling in `'{0}'` entries with their
23
- * corresponding values from the args array.
24
- *
25
- * @param formatStr - str of form `'this is a string with some entries like {0} and {1}'`
26
- * @param args - array of fields to fill in the string format entries with
27
- * @returns formatted string
28
- */
29
- function applyStringFormatting(formatStr, args) {
30
- const matches = formatStr.match(/{\d+}/g);
31
- if (matches == null) {
32
- return formatStr;
33
- }
34
- // Get the numeric values within the curly braces, convert them to numbers,
35
- // and find the maximum value.
36
- const maxIndex = Math.max(...matches.map(match => Number(match.slice(1, -1))));
37
- const argsPadded = args.concat(Array.from({ length: Math.max(0, maxIndex - args.length) }, () => '0xBAD'));
38
- return formatStr.replace(/{(\d+)}/g, function (match, index) {
39
- return typeof args[index] != 'undefined' ? argsPadded[index] : match;
40
- });
41
- }
42
- /**
43
- * Convert an array of ACVMFields from ACVM to a formatted string.
44
- *
45
- * @param parameters - either one parameter representing a simple field or array, or two parameters when
46
- * It's a message without args or three parameters when it's a message with arguments.
47
- *
48
- * @returns formatted string
49
- */
50
- export function oracleDebugCallToFormattedStr(parameters) {
51
- if (parameters.length === 1) {
52
- return processFieldOrArray(parameters[0]);
53
- }
54
- let formatArgs = [];
55
- if (parameters.length > 2) {
56
- formatArgs = parameters[1];
57
- }
58
- const formattedMsg = applyStringFormatting(acvmFieldMessageToString(parameters[0]), formatArgs);
59
- return formattedMsg;
60
- }
61
- /**
62
- * Processes a field or an array and returns a string representation.
63
- * @param fieldOrArray - The field or array to be processed.
64
- * @returns Returns the processed string representation of the field or array.
65
- */
66
- function processFieldOrArray(fieldOrArray) {
67
- if (fieldOrArray.length === 1) {
68
- return `${fieldOrArray[0]}`;
69
- }
70
- // Check if all the elements start with 63 zero bytes
71
- // --> if yes, we have an array of bytes and we print as hex
72
- if (onlyBytes(fieldOrArray)) {
73
- const decimalArray = fieldOrArray.map(element => parseInt(element, 16));
74
- return '0x' + Buffer.from(decimalArray).toString('hex');
75
- }
76
- return '[' + fieldOrArray.join(', ') + ']';
77
- }
78
- /**
79
- * Checks if all elements in the array are valid byte representations.
80
- * @param array - The array to be checked.
81
- * @returns Returns `true` if all elements are valid byte representations, `false` otherwise.
82
- * @throws Throws an error if any element has an invalid length.
83
- */
84
- function onlyBytes(array) {
85
- for (const element of array) {
86
- if (element.length != 66) {
87
- throw new Error('Invalid element length. Expected 66 chars, got ' + element.length + ' chars.');
88
- }
89
- if (!element.startsWith('0x00000000000000000000000000000000000000000000000000000000000000')) {
90
- return false;
91
- }
92
- }
93
- return true;
94
- }
95
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVidWcuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYWN2bS9vcmFjbGUvZGVidWcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBSUE7Ozs7O0dBS0c7QUFDSCxNQUFNLFVBQVUsd0JBQXdCLENBQUMsR0FBZ0I7SUFDdkQsSUFBSSxNQUFNLEdBQUcsRUFBRSxDQUFDO0lBQ2hCLEtBQUssTUFBTSxPQUFPLElBQUksR0FBRyxFQUFFLENBQUM7UUFDMUIsTUFBTSxTQUFTLEdBQUcsTUFBTSxDQUFDLE9BQU8sQ0FBQyxDQUFDO1FBQ2xDLE1BQU0sU0FBUyxHQUFHLE1BQU0sQ0FBQyxZQUFZLENBQUMsU0FBUyxDQUFDLENBQUM7UUFDakQsTUFBTSxHQUFHLE1BQU0sQ0FBQyxNQUFNLENBQUMsU0FBUyxDQUFDLENBQUM7SUFDcEMsQ0FBQztJQUNELHdEQUF3RDtJQUN4RCxNQUFNLGFBQWEsR0FBRyxNQUFNLENBQUMsT0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFDO0lBQzVDLElBQUksYUFBYSxJQUFJLENBQUMsRUFBRSxDQUFDO1FBQ3ZCLE1BQU0sR0FBRyxNQUFNLENBQUMsU0FBUyxDQUFDLENBQUMsRUFBRSxhQUFhLENBQUM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