@aztec/simulator 3.0.0-nightly.20251208 → 3.0.0-nightly.20251210

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 (185) hide show
  1. package/dest/common/errors.d.ts +2 -2
  2. package/dest/common/errors.d.ts.map +1 -1
  3. package/dest/private/acvm/deserialize.d.ts +2 -2
  4. package/dest/private/acvm/deserialize.d.ts.map +1 -1
  5. package/dest/private/acvm/deserialize.js +1 -1
  6. package/dest/private/acvm/serialize.d.ts +2 -2
  7. package/dest/private/acvm/serialize.d.ts.map +1 -1
  8. package/dest/private/acvm/serialize.js +1 -1
  9. package/dest/private/circuit_recording/circuit_recorder.js +1 -1
  10. package/dest/public/avm/avm_context.d.ts +2 -2
  11. package/dest/public/avm/avm_context.d.ts.map +1 -1
  12. package/dest/public/avm/avm_contract_call_result.d.ts +2 -2
  13. package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
  14. package/dest/public/avm/avm_execution_environment.d.ts +2 -2
  15. package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
  16. package/dest/public/avm/avm_execution_environment.js +1 -1
  17. package/dest/public/avm/avm_gas.d.ts +1 -1
  18. package/dest/public/avm/avm_gas.d.ts.map +1 -1
  19. package/dest/public/avm/avm_machine_state.d.ts +2 -2
  20. package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
  21. package/dest/public/avm/avm_memory_types.d.ts +2 -2
  22. package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
  23. package/dest/public/avm/avm_memory_types.js +1 -1
  24. package/dest/public/avm/avm_simulator.d.ts +2 -2
  25. package/dest/public/avm/avm_simulator.d.ts.map +1 -1
  26. package/dest/public/avm/avm_simulator.js +1 -1
  27. package/dest/public/avm/errors.d.ts +2 -2
  28. package/dest/public/avm/errors.d.ts.map +1 -1
  29. package/dest/public/avm/fixtures/avm_simulation_tester.js +1 -1
  30. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +2 -2
  31. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
  32. package/dest/public/avm/fixtures/base_avm_simulation_tester.js +1 -1
  33. package/dest/public/avm/fixtures/initializers.d.ts +2 -2
  34. package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
  35. package/dest/public/avm/fixtures/initializers.js +1 -1
  36. package/dest/public/avm/fixtures/utils.d.ts +2 -2
  37. package/dest/public/avm/fixtures/utils.d.ts.map +1 -1
  38. package/dest/public/avm/fixtures/utils.js +1 -1
  39. package/dest/public/avm/opcodes/arithmetic.d.ts +3 -1
  40. package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
  41. package/dest/public/avm/opcodes/arithmetic.js +11 -1
  42. package/dest/public/avm/opcodes/ec_add.js +2 -2
  43. package/dest/public/avm/opcodes/hashing.d.ts +1 -1
  44. package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
  45. package/dest/public/avm/opcodes/hashing.js +3 -1
  46. package/dest/public/avm/opcodes/memory.js +1 -1
  47. package/dest/public/avm/revert_reason.d.ts +2 -2
  48. package/dest/public/avm/revert_reason.d.ts.map +1 -1
  49. package/dest/public/avm/serialization/instruction_serialization.js +1 -1
  50. package/dest/public/avm/test_utils.d.ts +2 -2
  51. package/dest/public/avm/test_utils.d.ts.map +1 -1
  52. package/dest/public/avm/test_utils.js +1 -1
  53. package/dest/public/contracts_db_checkpoint.d.ts +2 -2
  54. package/dest/public/contracts_db_checkpoint.d.ts.map +1 -1
  55. package/dest/public/db_interfaces.d.ts +2 -2
  56. package/dest/public/db_interfaces.d.ts.map +1 -1
  57. package/dest/public/debug_fn_name.d.ts +2 -2
  58. package/dest/public/debug_fn_name.d.ts.map +1 -1
  59. package/dest/public/fixtures/amm_test.js +2 -2
  60. package/dest/public/fixtures/bulk_test.js +1 -1
  61. package/dest/public/fixtures/custom_bytecode_tests.d.ts +2 -1
  62. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
  63. package/dest/public/fixtures/custom_bytecode_tests.js +21 -0
  64. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +1 -1
  65. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  66. package/dest/public/fixtures/public_tx_simulation_tester.js +2 -1
  67. package/dest/public/fixtures/simple_contract_data_source.d.ts +10 -2
  68. package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -1
  69. package/dest/public/fixtures/simple_contract_data_source.js +35 -0
  70. package/dest/public/fixtures/token_test.js +1 -1
  71. package/dest/public/fixtures/utils.d.ts +2 -2
  72. package/dest/public/fixtures/utils.d.ts.map +1 -1
  73. package/dest/public/fixtures/utils.js +1 -1
  74. package/dest/public/fuzzing/avm_simulator_bin.d.ts +2 -0
  75. package/dest/public/fuzzing/avm_simulator_bin.d.ts.map +1 -0
  76. package/dest/public/fuzzing/avm_simulator_bin.js +123 -0
  77. package/dest/public/fuzzing/helpers.d.ts +14 -0
  78. package/dest/public/fuzzing/helpers.d.ts.map +1 -0
  79. package/dest/public/fuzzing/helpers.js +75 -0
  80. package/dest/public/hinting_db_sources.d.ts +2 -2
  81. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  82. package/dest/public/hinting_db_sources.js +2 -2
  83. package/dest/public/index.d.ts +2 -2
  84. package/dest/public/index.d.ts.map +1 -1
  85. package/dest/public/index.js +1 -1
  86. package/dest/public/public_db_sources.d.ts +2 -2
  87. package/dest/public/public_db_sources.d.ts.map +1 -1
  88. package/dest/public/public_db_sources.js +1 -1
  89. package/dest/public/public_processor/public_processor.d.ts +1 -1
  90. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  91. package/dest/public/public_processor/public_processor.js +5 -3
  92. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +1 -13
  93. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -1
  94. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +3 -42
  95. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +1 -1
  96. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -1
  97. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +4 -4
  98. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +22 -0
  99. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +1 -0
  100. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.js +52 -0
  101. package/dest/public/public_tx_simulator/factories.d.ts +13 -0
  102. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -0
  103. package/dest/public/public_tx_simulator/factories.js +28 -0
  104. package/dest/public/public_tx_simulator/index.d.ts +3 -1
  105. package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
  106. package/dest/public/public_tx_simulator/index.js +2 -0
  107. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +2 -2
  108. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
  109. package/dest/public/public_tx_simulator/public_tx_context.d.ts +2 -2
  110. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  111. package/dest/public/public_tx_simulator/public_tx_context.js +1 -1
  112. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +2 -2
  113. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  114. package/dest/public/public_tx_simulator/public_tx_simulator.js +5 -3
  115. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +2 -2
  116. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -1
  117. package/dest/public/side_effect_trace.d.ts +2 -2
  118. package/dest/public/side_effect_trace.d.ts.map +1 -1
  119. package/dest/public/side_effect_trace.js +1 -1
  120. package/dest/public/side_effect_trace_interface.d.ts +2 -2
  121. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  122. package/dest/public/state_manager/nullifiers.d.ts +2 -2
  123. package/dest/public/state_manager/nullifiers.d.ts.map +1 -1
  124. package/dest/public/state_manager/public_storage.d.ts +2 -2
  125. package/dest/public/state_manager/public_storage.d.ts.map +1 -1
  126. package/dest/public/state_manager/public_storage.js +1 -1
  127. package/dest/public/state_manager/state_manager.d.ts +2 -2
  128. package/dest/public/state_manager/state_manager.d.ts.map +1 -1
  129. package/dest/public/state_manager/state_manager.js +1 -1
  130. package/package.json +17 -17
  131. package/src/common/errors.ts +1 -1
  132. package/src/private/acvm/deserialize.ts +1 -1
  133. package/src/private/acvm/serialize.ts +1 -1
  134. package/src/private/circuit_recording/circuit_recorder.ts +1 -1
  135. package/src/public/avm/avm_context.ts +1 -1
  136. package/src/public/avm/avm_contract_call_result.ts +1 -1
  137. package/src/public/avm/avm_execution_environment.ts +1 -1
  138. package/src/public/avm/avm_gas.ts +3 -3
  139. package/src/public/avm/avm_machine_state.ts +1 -1
  140. package/src/public/avm/avm_memory_types.ts +1 -1
  141. package/src/public/avm/avm_simulator.ts +1 -1
  142. package/src/public/avm/errors.ts +1 -1
  143. package/src/public/avm/fixtures/avm_simulation_tester.ts +1 -1
  144. package/src/public/avm/fixtures/base_avm_simulation_tester.ts +1 -1
  145. package/src/public/avm/fixtures/initializers.ts +1 -1
  146. package/src/public/avm/fixtures/utils.ts +1 -1
  147. package/src/public/avm/opcodes/arithmetic.ts +13 -1
  148. package/src/public/avm/opcodes/ec_add.ts +2 -2
  149. package/src/public/avm/opcodes/hashing.ts +3 -1
  150. package/src/public/avm/opcodes/memory.ts +1 -1
  151. package/src/public/avm/revert_reason.ts +1 -1
  152. package/src/public/avm/serialization/instruction_serialization.ts +1 -1
  153. package/src/public/avm/test_utils.ts +1 -1
  154. package/src/public/contracts_db_checkpoint.ts +1 -1
  155. package/src/public/db_interfaces.ts +1 -1
  156. package/src/public/debug_fn_name.ts +1 -1
  157. package/src/public/fixtures/amm_test.ts +2 -2
  158. package/src/public/fixtures/bulk_test.ts +1 -1
  159. package/src/public/fixtures/custom_bytecode_tests.ts +24 -0
  160. package/src/public/fixtures/minimal_public_tx.ts +1 -1
  161. package/src/public/fixtures/public_tx_simulation_tester.ts +2 -1
  162. package/src/public/fixtures/simple_contract_data_source.ts +40 -1
  163. package/src/public/fixtures/token_test.ts +1 -1
  164. package/src/public/fixtures/utils.ts +1 -1
  165. package/src/public/fuzzing/avm_simulator_bin.ts +157 -0
  166. package/src/public/fuzzing/helpers.ts +154 -0
  167. package/src/public/hinting_db_sources.ts +2 -2
  168. package/src/public/index.ts +2 -0
  169. package/src/public/public_db_sources.ts +1 -1
  170. package/src/public/public_processor/public_processor.ts +8 -3
  171. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +3 -49
  172. package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +1 -1
  173. package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +4 -8
  174. package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +81 -0
  175. package/src/public/public_tx_simulator/factories.ts +41 -0
  176. package/src/public/public_tx_simulator/index.ts +2 -0
  177. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +1 -1
  178. package/src/public/public_tx_simulator/public_tx_context.ts +1 -1
  179. package/src/public/public_tx_simulator/public_tx_simulator.ts +14 -3
  180. package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +1 -1
  181. package/src/public/side_effect_trace.ts +1 -1
  182. package/src/public/side_effect_trace_interface.ts +1 -1
  183. package/src/public/state_manager/nullifiers.ts +1 -1
  184. package/src/public/state_manager/public_storage.ts +1 -1
  185. package/src/public/state_manager/state_manager.ts +2 -2
@@ -1,4 +1,4 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { hexToBuffer } from '@aztec/foundation/string';
3
3
 
4
4
  import type { ACVMField, ACVMWitness } from './acvm_types.js';
@@ -1,5 +1,5 @@
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
1
2
  import type { EthAddress } from '@aztec/foundation/eth-address';
2
- import { Fr } from '@aztec/foundation/fields';
3
3
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
 
5
5
  import type { ACVMField } from './acvm_types.js';
@@ -1,4 +1,4 @@
1
- import { sha512 } from '@aztec/foundation/crypto';
1
+ import { sha512 } from '@aztec/foundation/crypto/sha512';
2
2
  import { createLogger } from '@aztec/foundation/log';
3
3
  import { Timer } from '@aztec/foundation/timer';
4
4
  import type { ForeignCallHandler, ForeignCallInput, ForeignCallOutput } from '@aztec/noir-acvm_js';
@@ -1,4 +1,4 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
3
 
4
4
  import type { PublicPersistableStateManager } from '../state_manager/state_manager.js';
@@ -1,4 +1,4 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import type { SimulationError } from '@aztec/stdlib/errors';
3
3
  import { Gas } from '@aztec/stdlib/gas';
4
4
 
@@ -1,4 +1,4 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import type { PublicSimulatorConfig } from '@aztec/stdlib/avm';
3
3
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import type { GlobalVariables } from '@aztec/stdlib/tx';
@@ -26,9 +26,9 @@ export function makeGas(gasCost: Partial<Gas>) {
26
26
  }
27
27
 
28
28
  /** Sums together multiple instances of Gas. */
29
- export function sumGas(...gases: Partial<Gas>[]) {
30
- return gases.reduce(
31
- (acc: Gas, gas) => ({
29
+ export function sumGas(...gases: Partial<Gas>[]): Gas {
30
+ return gases.reduce<Gas>(
31
+ (acc, gas) => ({
32
32
  l2Gas: acc.l2Gas + (gas.l2Gas ?? 0),
33
33
  daGas: acc.daGas + (gas.daGas ?? 0),
34
34
  }),
@@ -1,4 +1,4 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
2
 
3
3
  import type { Gas } from './avm_gas.js';
4
4
  import { TaggedMemory } from './avm_memory_types.js';
@@ -8,7 +8,7 @@ import {
8
8
  MEM_TAG_U128,
9
9
  } from '@aztec/constants';
10
10
  import { toBufferBE } from '@aztec/foundation/bigint-buffer';
11
- import { Fr } from '@aztec/foundation/fields';
11
+ import { Fr } from '@aztec/foundation/curves/bn254';
12
12
  import { type Logger, createLogger } from '@aztec/foundation/log';
13
13
  import type { FunctionsOf } from '@aztec/foundation/types';
14
14
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
@@ -1,4 +1,4 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { type Logger, createLogger } from '@aztec/foundation/log';
3
3
  import { Timer } from '@aztec/foundation/timer';
4
4
  import type { PublicSimulatorConfig } from '@aztec/stdlib/avm';
@@ -1,4 +1,4 @@
1
- import type { Point } from '@aztec/foundation/fields';
1
+ import type { Point } from '@aztec/foundation/curves/grumpkin';
2
2
  import type { FailingFunction, NoirCallStack } from '@aztec/stdlib/errors';
3
3
 
4
4
  import { ExecutionError } from '../../common/errors.js';
@@ -1,4 +1,4 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { encodeArguments } from '@aztec/stdlib/abi';
3
3
  import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
4
4
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
@@ -1,5 +1,5 @@
1
1
  import { CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS } from '@aztec/constants';
2
- import { Fr } from '@aztec/foundation/fields';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import { createLogger } from '@aztec/foundation/log';
4
4
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
5
5
  import { getCanonicalAuthRegistry } from '@aztec/protocol-contracts/auth-registry';
@@ -1,7 +1,7 @@
1
1
  import { AVM_MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
2
2
  import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
4
  import { EthAddress } from '@aztec/foundation/eth-address';
4
- import { Fr } from '@aztec/foundation/fields';
5
5
  import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
6
6
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
7
7
  import { GasFees } from '@aztec/stdlib/gas';
@@ -1,6 +1,6 @@
1
1
  import { CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS } from '@aztec/constants';
2
2
  import { BlockNumber } from '@aztec/foundation/branded-types';
3
- import { Fr } from '@aztec/foundation/fields';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
4
  import {
5
5
  type ContractArtifact,
6
6
  type FunctionAbi,
@@ -88,7 +88,9 @@ export class FieldDiv extends ThreeOperandArithmeticInstruction {
88
88
  static readonly opcode = Opcode.FDIV_8; // FIXME: needed for gas.
89
89
 
90
90
  protected compute(a: Field, b: Field): Field {
91
- // return (a as Field).fdiv(b as Field);
91
+ if (b.toBigInt() === 0n) {
92
+ throw new ArithmeticError('Division by zero');
93
+ }
92
94
  return a.fdiv(b);
93
95
  }
94
96
 
@@ -105,6 +107,11 @@ export class Shl extends ThreeOperandArithmeticInstruction {
105
107
  protected override compute(a: IntegralValue, b: IntegralValue): IntegralValue {
106
108
  return a.shl(b);
107
109
  }
110
+
111
+ protected override checkTags(memory: TaggedMemoryInterface, aOffset: number, bOffset: number) {
112
+ memory.checkTagsAreSame(aOffset, bOffset);
113
+ TaggedMemory.checkIsIntegralTag(memory.getTag(aOffset)); // Follows that bOffset tag is also of integral type
114
+ }
108
115
  }
109
116
 
110
117
  export class Shr extends ThreeOperandArithmeticInstruction {
@@ -114,4 +121,9 @@ export class Shr extends ThreeOperandArithmeticInstruction {
114
121
  protected override compute(a: IntegralValue, b: IntegralValue): IntegralValue {
115
122
  return a.shr(b);
116
123
  }
124
+
125
+ protected override checkTags(memory: TaggedMemoryInterface, aOffset: number, bOffset: number) {
126
+ memory.checkTagsAreSame(aOffset, bOffset);
127
+ TaggedMemory.checkIsIntegralTag(memory.getTag(aOffset)); // Follows that bOffset tag is also of integral type
128
+ }
117
129
  }
@@ -1,5 +1,5 @@
1
- import { Grumpkin } from '@aztec/foundation/crypto';
2
- import { Point } from '@aztec/foundation/fields';
1
+ import { Grumpkin } from '@aztec/foundation/crypto/grumpkin';
2
+ import { Point } from '@aztec/foundation/curves/grumpkin';
3
3
 
4
4
  import type { AvmContext } from '../avm_context.js';
5
5
  import { Field, TypeTag, Uint1 } from '../avm_memory_types.js';
@@ -1,4 +1,6 @@
1
- import { keccakf1600, poseidon2Permutation, sha256Compression } from '@aztec/foundation/crypto';
1
+ import { keccakf1600 } from '@aztec/foundation/crypto/keccak';
2
+ import { poseidon2Permutation } from '@aztec/foundation/crypto/poseidon';
3
+ import { sha256Compression } from '@aztec/foundation/crypto/sha256';
2
4
 
3
5
  import type { AvmContext } from '../avm_context.js';
4
6
  import { Field, TypeTag, Uint32, Uint64 } from '../avm_memory_types.js';
@@ -1,4 +1,4 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
 
3
3
  import { strict as assert } from 'assert';
4
4
 
@@ -1,4 +1,4 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
2
 
3
3
  import type { AvmContext } from './avm_context.js';
4
4
  import { type AvmExecutionError, AvmRevertReason } from './errors.js';
@@ -1,4 +1,4 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
 
3
3
  import { strict as assert } from 'assert';
4
4
 
@@ -1,4 +1,4 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import type { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
3
3
 
4
4
  import type { jest } from '@jest/globals';
@@ -1,4 +1,4 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
3
  import type { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
4
4
 
@@ -1,4 +1,4 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import type { FunctionSelector } from '@aztec/stdlib/abi';
3
3
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import type { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
@@ -1,4 +1,4 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { FunctionSelector } from '@aztec/stdlib/abi';
3
3
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
 
@@ -1,6 +1,6 @@
1
1
  import { GeneratorIndex } from '@aztec/constants';
2
- import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto';
3
- import { Fr } from '@aztec/foundation/fields';
2
+ import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
4
  import type { Logger } from '@aztec/foundation/log';
5
5
  import { Timer } from '@aztec/foundation/timer';
6
6
  import type { ContractArtifact } from '@aztec/stdlib/abi';
@@ -1,4 +1,4 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import type { Logger } from '@aztec/foundation/log';
3
3
  import { Timer } from '@aztec/foundation/timer';
4
4
  import type { ContractArtifact } from '@aztec/stdlib/abi';
@@ -31,6 +31,30 @@ export async function addressingWithBaseTagIssueTest(isIndirect: boolean, tester
31
31
  return await testCustomBytecode(bytecode, tester, txLabel);
32
32
  }
33
33
 
34
+ // First instruction sets a value with tag U64 at offset 0. Then a CalldataCopy instruction
35
+ // uses INDIRECT addressing to read from offset 0, which should fail because the value at
36
+ // offset 0 has tag U64 (not U32), making it an invalid address tag.
37
+ export async function addressingWithIndirectTagIssueTest(tester: PublicTxSimulationTester) {
38
+ // Set a U64 value at offset 0 - this will be used as an indirect address
39
+ const addressingMode = Addressing.fromModes([
40
+ AddressingMode.INDIRECT, // First operand (cdOffset) uses indirect addressing
41
+ AddressingMode.DIRECT,
42
+ AddressingMode.DIRECT,
43
+ ]);
44
+
45
+ const bytecode = encodeToBytecode([
46
+ // Set a U64 value at offset 0 - this has the wrong tag for an address (should be U32)
47
+ new Set(/*indirect=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT64, /*value=*/ 100n).as(Opcode.SET_64, Set.wireFormat64),
48
+ // Try to use indirect addressing: read from offset 0, which contains a U64 value
49
+ // This should fail because U64 is not a valid address tag (must be U32)
50
+ new CalldataCopy(/*indirect=*/ addressingMode.toWire(), /*copySize=*/ 1, /*cdOffset=*/ 0, /*dstOffset=*/ 1),
51
+ new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
52
+ ]);
53
+
54
+ const txLabel = 'AddressingWithIndirectTagInvalid';
55
+ return await testCustomBytecode(bytecode, tester, txLabel);
56
+ }
57
+
34
58
  export async function pcOutOfRangeTest(tester: PublicTxSimulationTester) {
35
59
  const bytecode = encodeToBytecode([
36
60
  new Jump(/*jumpOffset=*/ 123), // Jump to out-of-range pc offset.
@@ -21,7 +21,7 @@ export async function executeAvmMinimalPublicTx(tester: PublicTxSimulationTester
21
21
 
22
22
  // Modify the protocol contracts to be all zeros
23
23
  result.hints!.protocolContracts = ProtocolContracts.empty();
24
- result.publicInputs.protocolContracts = ProtocolContracts.empty();
24
+ result.publicInputs!.protocolContracts = ProtocolContracts.empty();
25
25
 
26
26
  return result;
27
27
  }
@@ -1,7 +1,7 @@
1
1
  import { DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT } from '@aztec/constants';
2
2
  import { asyncMap } from '@aztec/foundation/async-map';
3
3
  import { BlockNumber } from '@aztec/foundation/branded-types';
4
- import { Fr } from '@aztec/foundation/fields';
4
+ import { Fr } from '@aztec/foundation/curves/bn254';
5
5
  import { type ContractArtifact, encodeArguments } from '@aztec/stdlib/abi';
6
6
  import { PublicSimulatorConfig, type PublicTxResult } from '@aztec/stdlib/avm';
7
7
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
@@ -42,6 +42,7 @@ const defaultConfig: PublicSimulatorConfig = PublicSimulatorConfig.from({
42
42
  collectCallMetadata: true,
43
43
  collectDebugLogs: true,
44
44
  collectHints: false,
45
+ collectPublicInputs: false,
45
46
  collectStatistics: false,
46
47
  });
47
48
 
@@ -1,9 +1,10 @@
1
1
  import type { BlockNumber } from '@aztec/foundation/branded-types';
2
- import type { Fr } from '@aztec/foundation/fields';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import { createLogger } from '@aztec/foundation/log';
4
4
  import type { ContractArtifact, FunctionSelector } from '@aztec/stdlib/abi';
5
5
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
6
6
  import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
7
+ import { PublicKeys } from '@aztec/stdlib/keys';
7
8
 
8
9
  import { getFunctionSelector } from '../avm/fixtures/utils.js';
9
10
 
@@ -119,4 +120,42 @@ export class SimpleContractDataSource implements ContractDataSource {
119
120
  this.contractInstances.set(contractInstance.address.toString(), contractInstance);
120
121
  return Promise.resolve();
121
122
  }
123
+
124
+ /**
125
+ * FIXME: This is temporary
126
+ * Helper method for fuzzer: registers a contract with raw bytecode at a given address.
127
+ * Creates a minimal ContractClassPublic and ContractInstanceWithAddress.
128
+ * @param address - The contract address
129
+ * @param bytecode - The raw AVM bytecode
130
+ */
131
+ async addContractWithBytecode(address: AztecAddress, bytecode: Buffer): Promise<void> {
132
+ // Generate a deterministic class ID from the bytecode
133
+ const classId = Fr.fromBufferReduce(bytecode.subarray(0, 32));
134
+
135
+ // Create minimal ContractClassPublic
136
+ const contractClass: ContractClassPublic = {
137
+ id: classId,
138
+ version: 1 as const,
139
+ artifactHash: Fr.ZERO,
140
+ privateFunctionsRoot: Fr.ZERO,
141
+ privateFunctions: [],
142
+ utilityFunctions: [],
143
+ packedBytecode: bytecode,
144
+ };
145
+
146
+ // Create minimal ContractInstanceWithAddress
147
+ const contractInstance: ContractInstanceWithAddress = {
148
+ address,
149
+ version: 1 as const,
150
+ salt: Fr.ZERO,
151
+ deployer: address, // Use the contract address as deployer
152
+ currentContractClassId: classId,
153
+ originalContractClassId: classId,
154
+ initializationHash: Fr.ZERO,
155
+ publicKeys: PublicKeys.default(),
156
+ };
157
+
158
+ await this.addContractClass(contractClass);
159
+ await this.addContractInstance(contractInstance);
160
+ }
122
161
  }
@@ -1,4 +1,4 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import type { Logger } from '@aztec/foundation/log';
3
3
  import { Timer } from '@aztec/foundation/timer';
4
4
  import type { ContractArtifact } from '@aztec/stdlib/abi';
@@ -9,7 +9,7 @@ import {
9
9
  PRIVATE_LOG_SIZE_IN_FIELDS,
10
10
  } from '@aztec/constants';
11
11
  import { padArrayEnd } from '@aztec/foundation/collection';
12
- import { Fr } from '@aztec/foundation/fields';
12
+ import { Fr } from '@aztec/foundation/curves/bn254';
13
13
  import { CONTRACT_INSTANCE_PUBLISHED_EVENT_TAG } from '@aztec/protocol-contracts';
14
14
  import { bufferAsFields } from '@aztec/stdlib/abi';
15
15
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
@@ -0,0 +1,157 @@
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { EthAddress } from '@aztec/foundation/eth-address';
3
+ import { AvmCircuitPublicInputs, AvmTxHint, deserializeFromMessagePack } from '@aztec/stdlib/avm';
4
+ import { GlobalVariables } from '@aztec/stdlib/tx';
5
+ import { NativeWorldStateService } from '@aztec/world-state';
6
+
7
+ import { writeSync } from 'fs';
8
+ import { createInterface } from 'readline';
9
+
10
+ import { SimpleContractDataSource } from '../fixtures/simple_contract_data_source.js';
11
+ import { PublicContractsDB } from '../public_db_sources.js';
12
+ import { PublicTxSimulator } from '../public_tx_simulator/public_tx_simulator.js';
13
+ import { createFuzzerTx, registerContract } from './helpers.js';
14
+
15
+ // This cache holds opened world states to avoid reopening them for each invocation.
16
+ // It's a map so that in the future we could support multiple world states (if we had multiple fuzzers).
17
+ const worldStateCache = new Map<string, NativeWorldStateService>();
18
+
19
+ async function openExistingWorldState(dataDir: string, mapSizeKb: number): Promise<NativeWorldStateService> {
20
+ const cached = worldStateCache.get(dataDir);
21
+ if (cached) {
22
+ return cached;
23
+ }
24
+
25
+ const ws = await NativeWorldStateService.new(EthAddress.ZERO, dataDir, {
26
+ archiveTreeMapSizeKb: mapSizeKb,
27
+ nullifierTreeMapSizeKb: mapSizeKb,
28
+ noteHashTreeMapSizeKb: mapSizeKb,
29
+ messageTreeMapSizeKb: mapSizeKb,
30
+ publicDataTreeMapSizeKb: mapSizeKb,
31
+ });
32
+
33
+ worldStateCache.set(dataDir, ws);
34
+ return ws;
35
+ }
36
+
37
+ async function simulateWithPublicTxSimulator(
38
+ dataDir: string,
39
+ mapSizeKb: number,
40
+ bytecode: Buffer,
41
+ cppTx: AvmTxHint,
42
+ cppGlobals: GlobalVariables,
43
+ ): Promise<{ reverted: boolean; output: Fr[]; revertReason?: string; publicInputs: AvmCircuitPublicInputs }> {
44
+ const worldStateService = await openExistingWorldState(dataDir, mapSizeKb);
45
+ const merkleTrees = await worldStateService.fork();
46
+
47
+ // todo(ilyas): enable this once we can handle multiple bytecodes across multiple enqueued calls
48
+ // Concat all the enqueued calls, extract the de-duplicated contract addresses so we can register them
49
+ //const teardownCalls = cppTx.teardownEnqueuedCall ? [cppTx.teardownEnqueuedCall] : [];
50
+ //const contractAddresses = new Set([...cppTx.setupEnqueuedCalls, ...cppTx.appLogicEnqueuedCalls, ...teardownCalls].map(
51
+ // call => call.request.contractAddress,
52
+ //));
53
+ //await Promise.all([...contractAddresses].map(addr => registerContract(merkleTrees, addr)));
54
+ //await Promise.all(
55
+ // [...contractAddresses].map(addr => contractDataSource.addContractWithBytecode(addr, bytecode)),
56
+ //);
57
+
58
+ const contractAddress = cppTx.appLogicEnqueuedCalls[0].request.contractAddress;
59
+ await registerContract(merkleTrees, contractAddress);
60
+ const contractDataSource = new SimpleContractDataSource();
61
+ await contractDataSource.addContractWithBytecode(contractAddress, bytecode);
62
+
63
+ const contractsDb = new PublicContractsDB(contractDataSource);
64
+
65
+ const publicTxSimulator = new PublicTxSimulator(merkleTrees, contractsDb, cppGlobals, {
66
+ skipFeeEnforcement: true,
67
+ collectDebugLogs: false,
68
+ collectHints: false,
69
+ collectStatistics: false,
70
+ collectCallMetadata: false,
71
+ });
72
+
73
+ const tx = await createFuzzerTx(cppTx);
74
+ const result = await publicTxSimulator.simulate(tx);
75
+
76
+ const output = result.getAppLogicReturnValues().flatMap(rv => rv?.values?.filter(v => v != null) ?? []);
77
+
78
+ return {
79
+ reverted: !result.revertCode.isOK(),
80
+ output,
81
+ revertReason: result.findRevertReason()?.message,
82
+ publicInputs: result.publicInputs!,
83
+ };
84
+ }
85
+
86
+ async function executeFromJson(jsonLine: string): Promise<void> {
87
+ try {
88
+ const input = JSON.parse(jsonLine.trim());
89
+ if (!input.bytecode || !input.ws_data_dir || !input.ws_map_size_kb || !input.tx || !input.globals) {
90
+ writeSync(
91
+ process.stdout.fd,
92
+ 'Error: JSON must contain "bytecode", "ws_data_dir", "ws_map_size_kb", "tx", and "globals" fields\n',
93
+ );
94
+ return;
95
+ }
96
+
97
+ const bytecode = Buffer.from(input.bytecode, 'base64');
98
+ const rawTx: object = deserializeFromMessagePack(Buffer.from(input.tx, 'base64'));
99
+ const tx = AvmTxHint.fromPlainObject(rawTx);
100
+ const rawGlobals = deserializeFromMessagePack(Buffer.from(input.globals, 'base64'));
101
+ const globals = GlobalVariables.fromPlainObject(rawGlobals);
102
+
103
+ const result = await simulateWithPublicTxSimulator(input.ws_data_dir, input.ws_map_size_kb, bytecode, tx, globals);
104
+
105
+ // todo(ilyas): Would be nice to serialize entire publicInputs for comparison, but it was extremely slow.
106
+ // Serialize endTreeSnapshots for comparison with C++ simulator
107
+ const endTreeSnapshots = {
108
+ l1ToL2MessageTree: {
109
+ root: result.publicInputs.endTreeSnapshots.l1ToL2MessageTree.root.toString(),
110
+ nextAvailableLeafIndex: result.publicInputs.endTreeSnapshots.l1ToL2MessageTree.nextAvailableLeafIndex,
111
+ },
112
+ noteHashTree: {
113
+ root: result.publicInputs.endTreeSnapshots.noteHashTree.root.toString(),
114
+ nextAvailableLeafIndex: result.publicInputs.endTreeSnapshots.noteHashTree.nextAvailableLeafIndex,
115
+ },
116
+ nullifierTree: {
117
+ root: result.publicInputs.endTreeSnapshots.nullifierTree.root.toString(),
118
+ nextAvailableLeafIndex: result.publicInputs.endTreeSnapshots.nullifierTree.nextAvailableLeafIndex,
119
+ },
120
+ publicDataTree: {
121
+ root: result.publicInputs.endTreeSnapshots.publicDataTree.root.toString(),
122
+ nextAvailableLeafIndex: result.publicInputs.endTreeSnapshots.publicDataTree.nextAvailableLeafIndex,
123
+ },
124
+ };
125
+
126
+ writeSync(
127
+ process.stdout.fd,
128
+ JSON.stringify({
129
+ reverted: result.reverted,
130
+ output: result.output.map(v => v?.toString() ?? '0'),
131
+ revertReason: result.revertReason,
132
+ endTreeSnapshots,
133
+ }) + '\n',
134
+ );
135
+ } catch (error: any) {
136
+ writeSync(
137
+ process.stdout.fd,
138
+ JSON.stringify({
139
+ reverted: true,
140
+ output: [],
141
+ revertReason: error.message,
142
+ }) + '\n',
143
+ );
144
+ }
145
+ }
146
+
147
+ function mainLoop() {
148
+ const rl = createInterface({ input: process.stdin, terminal: false });
149
+ rl.on('line', (line: string) => {
150
+ if (line.trim()) {
151
+ void executeFromJson(line);
152
+ }
153
+ });
154
+ rl.on('close', () => process.exit(0));
155
+ }
156
+
157
+ mainLoop();