@aztec/simulator 0.0.1-commit.0b941701 → 0.0.1-commit.0dc957cde

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 (149) hide show
  1. package/README.md +4 -4
  2. package/dest/private/acvm/acvm.d.ts +4 -2
  3. package/dest/private/acvm/acvm.d.ts.map +1 -1
  4. package/dest/private/acvm/acvm.js +4 -3
  5. package/dest/private/acvm_native.d.ts +5 -3
  6. package/dest/private/acvm_native.d.ts.map +1 -1
  7. package/dest/private/acvm_native.js +8 -6
  8. package/dest/private/acvm_wasm.d.ts +4 -3
  9. package/dest/private/acvm_wasm.d.ts.map +1 -1
  10. package/dest/private/acvm_wasm.js +4 -4
  11. package/dest/private/circuit_recording/circuit_recorder.d.ts +4 -3
  12. package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
  13. package/dest/private/circuit_recording/circuit_recorder.js +7 -5
  14. package/dest/private/circuit_recording/file_circuit_recorder.d.ts +3 -2
  15. package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
  16. package/dest/private/circuit_recording/file_circuit_recorder.js +2 -2
  17. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +7 -2
  18. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
  19. package/dest/private/circuit_recording/memory_circuit_recorder.js +4 -4
  20. package/dest/private/factory.d.ts +3 -3
  21. package/dest/private/factory.d.ts.map +1 -1
  22. package/dest/private/factory.js +7 -4
  23. package/dest/public/avm/avm_gas.js +3 -3
  24. package/dest/public/avm/avm_simulator.js +1 -1
  25. package/dest/public/avm/calldata.d.ts +1 -1
  26. package/dest/public/avm/calldata.d.ts.map +1 -1
  27. package/dest/public/avm/calldata.js +3 -2
  28. package/dest/public/avm/fixtures/account_proof_fetcher.d.ts +2 -0
  29. package/dest/public/avm/fixtures/account_proof_fetcher.d.ts.map +1 -0
  30. package/dest/public/avm/fixtures/account_proof_fetcher.js +152 -0
  31. package/dest/public/avm/opcodes/accrued_substate.d.ts +4 -5
  32. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
  33. package/dest/public/avm/opcodes/accrued_substate.js +11 -16
  34. package/dest/public/avm/serialization/bytecode_serialization.js +3 -3
  35. package/dest/public/avm/serialization/instruction_serialization.d.ts +2 -2
  36. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
  37. package/dest/public/avm/serialization/instruction_serialization.js +1 -1
  38. package/dest/public/contracts_db_checkpoint.d.ts +2 -2
  39. package/dest/public/contracts_db_checkpoint.d.ts.map +1 -1
  40. package/dest/public/contracts_db_checkpoint.js +1 -1
  41. package/dest/public/executor_metrics.d.ts +1 -1
  42. package/dest/public/executor_metrics.d.ts.map +1 -1
  43. package/dest/public/executor_metrics.js +7 -2
  44. package/dest/public/fixtures/amm_test.js +2 -2
  45. package/dest/public/fixtures/bulk_test.d.ts +1 -1
  46. package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
  47. package/dest/public/fixtures/bulk_test.js +4 -4
  48. package/dest/public/fixtures/custom_bytecode_tests.d.ts +3 -1
  49. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
  50. package/dest/public/fixtures/custom_bytecode_tests.js +61 -1
  51. package/dest/public/fixtures/opcode_spammer.d.ts +3 -4
  52. package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -1
  53. package/dest/public/fixtures/opcode_spammer.js +16 -56
  54. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +6 -5
  55. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  56. package/dest/public/fixtures/public_tx_simulation_tester.js +37 -10
  57. package/dest/public/fixtures/utils.d.ts +2 -2
  58. package/dest/public/fixtures/utils.d.ts.map +1 -1
  59. package/dest/public/fixtures/utils.js +10 -10
  60. package/dest/public/hinting_db_sources.d.ts +5 -5
  61. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  62. package/dest/public/hinting_db_sources.js +7 -6
  63. package/dest/public/public_db_sources.d.ts +6 -5
  64. package/dest/public/public_db_sources.d.ts.map +1 -1
  65. package/dest/public/public_db_sources.js +14 -14
  66. package/dest/public/public_processor/guarded_merkle_tree.d.ts +5 -5
  67. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  68. package/dest/public/public_processor/guarded_merkle_tree.js +5 -5
  69. package/dest/public/public_processor/public_processor.d.ts +8 -4
  70. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  71. package/dest/public/public_processor/public_processor.js +60 -47
  72. package/dest/public/public_processor/public_processor_metrics.d.ts +2 -2
  73. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  74. package/dest/public/public_processor/public_processor_metrics.js +20 -4
  75. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +3 -2
  76. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -1
  77. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +4 -3
  78. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +5 -5
  79. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
  80. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +10 -11
  81. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +4 -4
  82. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -1
  83. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +7 -7
  84. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +4 -4
  85. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -1
  86. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +6 -6
  87. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +3 -2
  88. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +1 -1
  89. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.js +2 -2
  90. package/dest/public/public_tx_simulator/factories.d.ts +3 -2
  91. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -1
  92. package/dest/public/public_tx_simulator/factories.js +4 -4
  93. package/dest/public/public_tx_simulator/public_tx_context.d.ts +10 -5
  94. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  95. package/dest/public/public_tx_simulator/public_tx_context.js +16 -18
  96. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +9 -4
  97. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  98. package/dest/public/public_tx_simulator/public_tx_simulator.js +19 -12
  99. package/dest/public/side_effect_trace.d.ts +4 -4
  100. package/dest/public/side_effect_trace.d.ts.map +1 -1
  101. package/dest/public/side_effect_trace.js +3 -3
  102. package/dest/public/state_manager/state_manager.d.ts +10 -4
  103. package/dest/public/state_manager/state_manager.d.ts.map +1 -1
  104. package/dest/public/state_manager/state_manager.js +12 -5
  105. package/dest/public/test_executor_metrics.d.ts +8 -2
  106. package/dest/public/test_executor_metrics.d.ts.map +1 -1
  107. package/dest/public/test_executor_metrics.js +24 -2
  108. package/package.json +15 -16
  109. package/src/private/acvm/acvm.ts +4 -3
  110. package/src/private/acvm_native.ts +11 -5
  111. package/src/private/acvm_wasm.ts +7 -3
  112. package/src/private/circuit_recording/circuit_recorder.ts +7 -5
  113. package/src/private/circuit_recording/file_circuit_recorder.ts +7 -2
  114. package/src/private/circuit_recording/memory_circuit_recorder.ts +6 -4
  115. package/src/private/factory.ts +7 -4
  116. package/src/public/avm/avm_gas.ts +2 -2
  117. package/src/public/avm/avm_simulator.ts +1 -1
  118. package/src/public/avm/calldata.ts +3 -2
  119. package/src/public/avm/fixtures/account_proof.json +553 -0
  120. package/src/public/avm/fixtures/account_proof_fetcher.ts +166 -0
  121. package/src/public/avm/opcodes/accrued_substate.ts +10 -19
  122. package/src/public/avm/opcodes/external_calls.ts +1 -1
  123. package/src/public/avm/serialization/bytecode_serialization.ts +2 -2
  124. package/src/public/avm/serialization/instruction_serialization.ts +1 -1
  125. package/src/public/contracts_db_checkpoint.ts +1 -1
  126. package/src/public/executor_metrics.ts +4 -1
  127. package/src/public/fixtures/amm_test.ts +2 -2
  128. package/src/public/fixtures/bulk_test.ts +2 -4
  129. package/src/public/fixtures/custom_bytecode_tests.ts +139 -1
  130. package/src/public/fixtures/opcode_spammer.ts +18 -55
  131. package/src/public/fixtures/public_tx_simulation_tester.ts +47 -6
  132. package/src/public/fixtures/utils.ts +17 -12
  133. package/src/public/fuzzing/avm_fuzzer_simulator.ts +1 -1
  134. package/src/public/hinting_db_sources.ts +9 -7
  135. package/src/public/public_db_sources.ts +27 -19
  136. package/src/public/public_processor/guarded_merkle_tree.ts +6 -6
  137. package/src/public/public_processor/public_processor.ts +86 -60
  138. package/src/public/public_processor/public_processor_metrics.ts +10 -4
  139. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +8 -4
  140. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +10 -8
  141. package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +7 -5
  142. package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +7 -5
  143. package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +3 -1
  144. package/src/public/public_tx_simulator/factories.ts +6 -3
  145. package/src/public/public_tx_simulator/public_tx_context.ts +21 -16
  146. package/src/public/public_tx_simulator/public_tx_simulator.ts +20 -12
  147. package/src/public/side_effect_trace.ts +5 -2
  148. package/src/public/state_manager/state_manager.ts +27 -4
  149. package/src/public/test_executor_metrics.ts +27 -3
@@ -1,5 +1,5 @@
1
1
  import { sha512 } from '@aztec/foundation/crypto/sha512';
2
- import { createLogger } from '@aztec/foundation/log';
2
+ import { type Logger, type LoggerBindings, resolveLogger } from '@aztec/foundation/log';
3
3
  import { Timer } from '@aztec/foundation/timer';
4
4
  import type { ForeignCallHandler, ForeignCallInput, ForeignCallOutput } from '@aztec/noir-acvm_js';
5
5
 
@@ -89,14 +89,16 @@ export class CircuitRecording {
89
89
  * ```
90
90
  */
91
91
  export class CircuitRecorder {
92
- protected readonly logger = createLogger('simulator:acvm:recording');
92
+ protected readonly logger: Logger;
93
93
 
94
94
  protected recording?: CircuitRecording;
95
95
 
96
96
  private stackDepth: number = 0;
97
97
  private newCircuit: boolean = true;
98
98
 
99
- protected constructor() {}
99
+ protected constructor(loggerOrBindings?: Logger | LoggerBindings) {
100
+ this.logger = resolveLogger('simulator:acvm:recording', loggerOrBindings);
101
+ }
100
102
 
101
103
  /**
102
104
  * Initializes a new circuit recording session.
@@ -159,11 +161,11 @@ export class CircuitRecorder {
159
161
  throw new Error(`Oracle method ${name} not found when setting up recording callback`);
160
162
  }
161
163
 
162
- const isExternalCall = (name as keyof ACIRCallback) === 'privateCallPrivateFunction';
164
+ const isExternalCall = (name as keyof ACIRCallback) === 'aztec_prv_callPrivateFunction';
163
165
 
164
166
  recordingCallback[name as keyof ACIRCallback] = (...args: ForeignCallInput[]): ReturnType<typeof fn> => {
165
167
  const timer = new Timer();
166
- // If we're entering another circuit via `privateCallPrivateFunction`, we increase the stack depth and set the
168
+ // If we're entering another circuit via `aztec_prv_callPrivateFunction`, we increase the stack depth and set the
167
169
  // newCircuit variable to ensure we are creating a new recording object.
168
170
  if (isExternalCall) {
169
171
  this.stackDepth++;
@@ -1,3 +1,5 @@
1
+ import type { Logger } from '@aztec/foundation/log';
2
+
1
3
  import fs from 'fs/promises';
2
4
  import path from 'path';
3
5
 
@@ -7,8 +9,11 @@ import { CircuitRecorder, type CircuitRecording } from './circuit_recorder.js';
7
9
  export class FileCircuitRecorder extends CircuitRecorder {
8
10
  declare recording?: CircuitRecording & { filePath: string; isFirstCall: boolean };
9
11
 
10
- constructor(private readonly recordDir: string) {
11
- super();
12
+ constructor(
13
+ private readonly recordDir: string,
14
+ logger?: Logger,
15
+ ) {
16
+ super(logger);
12
17
  }
13
18
 
14
19
  override async start(
@@ -1,11 +1,13 @@
1
+ import type { Logger } from '@aztec/foundation/log';
2
+
1
3
  import { CircuitRecorder } from './circuit_recorder.js';
2
4
 
3
- /*
5
+ /**
4
6
  * In memory circuit recorder uses the default implementation. This is kept
5
- * while we decide the fate of the FileCircuitRecorder
7
+ * while we decide the fate of the FileCircuitRecorder.
6
8
  */
7
9
  export class MemoryCircuitRecorder extends CircuitRecorder {
8
- constructor() {
9
- super();
10
+ constructor(logger?: Logger) {
11
+ super(logger);
10
12
  }
11
13
  }
@@ -1,4 +1,4 @@
1
- import { type Logger, createLogger } from '@aztec/foundation/log';
1
+ import { type Logger, type LoggerBindings, resolveLogger } from '@aztec/foundation/log';
2
2
 
3
3
  import { promises as fs } from 'fs';
4
4
 
@@ -21,18 +21,21 @@ export function getSimulatorConfigFromEnv() {
21
21
 
22
22
  export async function createSimulator(
23
23
  config: SimulatorConfig,
24
- logger: Logger = createLogger('simulator'),
24
+ loggerOrBindings?: Logger | LoggerBindings,
25
25
  ): Promise<CircuitSimulator> {
26
+ const logger = resolveLogger('simulator', loggerOrBindings);
26
27
  if (config.acvmBinaryPath && config.acvmWorkingDirectory) {
27
28
  try {
28
29
  await fs.access(config.acvmBinaryPath, fs.constants.R_OK);
29
30
  await fs.mkdir(config.acvmWorkingDirectory, { recursive: true });
30
31
  logger.info(`Using native ACVM at ${config.acvmBinaryPath} and working directory ${config.acvmWorkingDirectory}`);
31
- return new NativeACVMSimulator(config.acvmWorkingDirectory, config.acvmBinaryPath);
32
+ const acvmLogger = logger.createChild('acvm-native');
33
+ return new NativeACVMSimulator(config.acvmWorkingDirectory, config.acvmBinaryPath, undefined, acvmLogger);
32
34
  } catch {
33
35
  logger.warn(`Failed to access ACVM at ${config.acvmBinaryPath}, falling back to WASM`);
34
36
  }
35
37
  }
36
38
  logger.info('Using WASM ACVM simulation');
37
- return new WASMSimulator();
39
+ const wasmLogger = logger.createChild('wasm');
40
+ return new WASMSimulator(wasmLogger);
38
41
  }
@@ -110,7 +110,7 @@ const BASE_GAS_COSTS: Record<Opcode, Gas> = {
110
110
  [Opcode.NULLIFIEREXISTS]: makeCost(c.AVM_NULLIFIEREXISTS_BASE_L2_GAS, 0),
111
111
  [Opcode.EMITNULLIFIER]: makeCost(c.AVM_EMITNULLIFIER_BASE_L2_GAS, c.AVM_EMITNULLIFIER_BASE_DA_GAS),
112
112
  [Opcode.L1TOL2MSGEXISTS]: makeCost(c.AVM_L1TOL2MSGEXISTS_BASE_L2_GAS, 0),
113
- [Opcode.EMITUNENCRYPTEDLOG]: makeCost(c.AVM_EMITUNENCRYPTEDLOG_BASE_L2_GAS, c.AVM_EMITUNENCRYPTEDLOG_BASE_DA_GAS),
113
+ [Opcode.EMITPUBLICLOG]: makeCost(c.AVM_EMITPUBLICLOG_BASE_L2_GAS, c.AVM_EMITPUBLICLOG_BASE_DA_GAS),
114
114
  [Opcode.SENDL2TOL1MSG]: makeCost(c.AVM_SENDL2TOL1MSG_BASE_L2_GAS, c.AVM_SENDL2TOL1MSG_BASE_DA_GAS),
115
115
  [Opcode.GETCONTRACTINSTANCE]: makeCost(c.AVM_GETCONTRACTINSTANCE_BASE_L2_GAS, 0),
116
116
  [Opcode.CALL]: makeCost(c.AVM_CALL_BASE_L2_GAS, 0),
@@ -130,7 +130,7 @@ const DYNAMIC_GAS_COSTS = new Map<Opcode, Gas>([
130
130
  [Opcode.CALLDATACOPY, makeCost(c.AVM_CALLDATACOPY_DYN_L2_GAS, 0)],
131
131
  [Opcode.RETURNDATACOPY, makeCost(c.AVM_RETURNDATACOPY_DYN_L2_GAS, 0)],
132
132
  // TODO: Call and static call based on bytecode length
133
- [Opcode.EMITUNENCRYPTEDLOG, makeCost(c.AVM_EMITUNENCRYPTEDLOG_DYN_L2_GAS, c.AVM_EMITUNENCRYPTEDLOG_DYN_DA_GAS)],
133
+ [Opcode.EMITPUBLICLOG, makeCost(c.AVM_EMITPUBLICLOG_DYN_L2_GAS, c.AVM_EMITPUBLICLOG_DYN_DA_GAS)],
134
134
  [Opcode.TORADIXBE, makeCost(c.AVM_TORADIXBE_DYN_L2_GAS, 0)],
135
135
  [Opcode.AND_8, makeCost(c.AVM_BITWISE_DYN_L2_GAS, 0)],
136
136
  [Opcode.AND_16, makeCost(c.AVM_BITWISE_DYN_L2_GAS, 0)],
@@ -63,7 +63,7 @@ export class AvmSimulator implements AvmSimulatorInterface {
63
63
  public static async build(context: AvmContext): Promise<AvmSimulator> {
64
64
  const simulator = new AvmSimulator(context);
65
65
  const fnName = await context.persistableState.getPublicFunctionDebugName(context.environment);
66
- simulator.log = createLogger(`simulator:avm(f:${fnName})`);
66
+ simulator.log = createLogger(`simulator:avm(f:${fnName.slice(0, 128)})`);
67
67
 
68
68
  return simulator;
69
69
  }
@@ -33,13 +33,14 @@ export class LazyReaderMemory implements LazyReader {
33
33
  }
34
34
 
35
35
  public slice(start: number, end: number): Fr[] {
36
- const clampedEnd = Math.min(end, this.size);
36
+ const clampedEnd = Math.min(end, this.size, TaggedMemory.MAX_MEMORY_SIZE - this.offset);
37
37
  const length = Math.max(0, clampedEnd - start);
38
38
  return this.memory.getSlice(this.offset + start, length).map(word => word.toFr());
39
39
  }
40
40
 
41
41
  public readAll(): Fr[] {
42
- return this.memory.getSlice(this.offset, this.size).map(word => word.toFr());
42
+ const size = Math.min(this.size, TaggedMemory.MAX_MEMORY_SIZE - this.offset);
43
+ return this.memory.getSlice(this.offset, size).map(word => word.toFr());
43
44
  }
44
45
 
45
46
  public length(): number {