@aztec/simulator 0.0.1-commit.b655e406 → 0.0.1-commit.b9865e97
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.
- package/README.md +6 -4
- package/dest/client.d.ts +1 -1
- package/dest/common/errors.d.ts +2 -2
- package/dest/common/errors.d.ts.map +1 -1
- package/dest/common/index.d.ts +1 -1
- package/dest/common/stats/index.d.ts +1 -1
- package/dest/common/stats/stats.d.ts +1 -1
- package/dest/private/acvm/acvm.d.ts +4 -2
- package/dest/private/acvm/acvm.d.ts.map +1 -1
- package/dest/private/acvm/acvm.js +4 -3
- package/dest/private/acvm/acvm_types.d.ts +1 -1
- package/dest/private/acvm/deserialize.d.ts +2 -2
- package/dest/private/acvm/deserialize.d.ts.map +1 -1
- package/dest/private/acvm/deserialize.js +1 -1
- package/dest/private/acvm/index.d.ts +1 -1
- package/dest/private/acvm/serialize.d.ts +2 -2
- package/dest/private/acvm/serialize.d.ts.map +1 -1
- package/dest/private/acvm/serialize.js +1 -1
- package/dest/private/acvm_native.d.ts +5 -3
- package/dest/private/acvm_native.d.ts.map +1 -1
- package/dest/private/acvm_native.js +8 -6
- package/dest/private/acvm_wasm.d.ts +4 -3
- package/dest/private/acvm_wasm.d.ts.map +1 -1
- package/dest/private/acvm_wasm.js +7 -5
- package/dest/private/acvm_wasm_with_blobs.d.ts +1 -1
- package/dest/private/acvm_wasm_with_blobs.d.ts.map +1 -1
- package/dest/private/circuit_recording/circuit_recorder.d.ts +4 -3
- package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/circuit_recorder.js +23 -20
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts +3 -2
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/file_circuit_recorder.js +2 -2
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +7 -2
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/memory_circuit_recorder.js +4 -4
- package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +1 -1
- package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -1
- package/dest/private/circuit_simulator.d.ts +1 -1
- package/dest/private/factory.d.ts +3 -3
- package/dest/private/factory.d.ts.map +1 -1
- package/dest/private/factory.js +7 -4
- package/dest/public/avm/testing/account_proof_fetcher.d.ts +2 -0
- package/dest/public/avm/testing/account_proof_fetcher.d.ts.map +1 -0
- package/dest/public/avm/testing/account_proof_fetcher.js +152 -0
- package/dest/public/avm/{fixtures → testing}/base_avm_simulation_tester.d.ts +3 -2
- package/dest/public/avm/testing/base_avm_simulation_tester.d.ts.map +1 -0
- package/dest/public/avm/{fixtures → testing}/base_avm_simulation_tester.js +18 -3
- package/dest/public/avm/{fixtures → testing}/utils.d.ts +4 -10
- package/dest/public/avm/testing/utils.d.ts.map +1 -0
- package/dest/public/avm/{fixtures → testing}/utils.js +6 -35
- package/dest/public/contracts_db_checkpoint.d.ts +16 -0
- package/dest/public/contracts_db_checkpoint.d.ts.map +1 -0
- package/dest/public/contracts_db_checkpoint.js +30 -0
- package/dest/public/db_interfaces.d.ts +14 -2
- package/dest/public/db_interfaces.d.ts.map +1 -1
- package/dest/public/executor_metrics.d.ts +3 -2
- package/dest/public/executor_metrics.d.ts.map +1 -1
- package/dest/public/executor_metrics.js +13 -34
- package/dest/public/executor_metrics_interface.d.ts +3 -2
- package/dest/public/executor_metrics_interface.d.ts.map +1 -1
- package/dest/public/fixtures/amm_test.d.ts +1 -1
- package/dest/public/fixtures/amm_test.js +4 -4
- package/dest/public/fixtures/bulk_test.d.ts +3 -3
- package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
- package/dest/public/fixtures/bulk_test.js +36 -73
- package/dest/public/fixtures/custom_bytecode_tester.d.ts +29 -7
- package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
- package/dest/public/fixtures/custom_bytecode_tester.js +36 -12
- package/dest/public/fixtures/index.d.ts +2 -3
- package/dest/public/fixtures/index.d.ts.map +1 -1
- package/dest/public/fixtures/index.js +1 -2
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +30 -11
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +98 -31
- package/dest/public/fixtures/simple_contract_data_source.d.ts +5 -4
- package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -1
- package/dest/public/fixtures/simple_contract_data_source.js +5 -5
- package/dest/public/fixtures/token_test.d.ts +6 -2
- package/dest/public/fixtures/token_test.d.ts.map +1 -1
- package/dest/public/fixtures/token_test.js +13 -12
- package/dest/public/fixtures/utils.d.ts +3 -3
- package/dest/public/fixtures/utils.d.ts.map +1 -1
- package/dest/public/fixtures/utils.js +23 -23
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +62 -0
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -0
- package/dest/public/fuzzing/avm_fuzzer_simulator.js +176 -0
- package/dest/public/fuzzing/avm_simulator_bin.d.ts +2 -0
- package/dest/public/fuzzing/avm_simulator_bin.d.ts.map +1 -0
- package/dest/public/fuzzing/avm_simulator_bin.js +118 -0
- package/dest/public/index.d.ts +3 -2
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +1 -1
- package/dest/public/public_db_sources.d.ts +29 -66
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +83 -134
- package/dest/public/public_errors.d.ts +1 -1
- package/dest/public/public_errors.d.ts.map +1 -1
- package/dest/public/public_processor/guarded_merkle_tree.d.ts +8 -5
- package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
- package/dest/public/public_processor/guarded_merkle_tree.js +12 -4
- package/dest/public/public_processor/public_processor.d.ts +19 -21
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +553 -123
- package/dest/public/public_processor/public_processor_metrics.d.ts +5 -2
- package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor_metrics.js +36 -45
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +19 -0
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +99 -0
- package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts +23 -0
- package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/dumping_public_tx_simulator.js +52 -0
- package/dest/public/public_tx_simulator/factories.d.ts +14 -0
- package/dest/public/public_tx_simulator/factories.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/factories.js +28 -0
- package/dest/public/public_tx_simulator/index.d.ts +5 -3
- package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/index.js +3 -2
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +42 -89
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +101 -334
- package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts +22 -0
- package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/public_tx_simulator_base.js +28 -0
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +25 -2
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -1
- package/dest/public/side_effect_errors.d.ts +1 -1
- package/dest/public/side_effect_errors.d.ts.map +1 -1
- package/dest/public/test_executor_metrics.d.ts +11 -4
- package/dest/public/test_executor_metrics.d.ts.map +1 -1
- package/dest/public/test_executor_metrics.js +29 -6
- package/dest/public/unique_class_ids.d.ts +1 -1
- package/dest/public/unique_class_ids.d.ts.map +1 -1
- package/dest/public/utils.d.ts +1 -1
- package/dest/server.d.ts +1 -1
- package/dest/testing.d.ts +1 -1
- package/package.json +22 -22
- package/src/common/errors.ts +1 -1
- package/src/private/acvm/acvm.ts +4 -3
- package/src/private/acvm/deserialize.ts +1 -1
- package/src/private/acvm/serialize.ts +1 -1
- package/src/private/acvm_native.ts +11 -5
- package/src/private/acvm_wasm.ts +11 -4
- package/src/private/circuit_recording/circuit_recorder.ts +24 -21
- package/src/private/circuit_recording/file_circuit_recorder.ts +7 -2
- package/src/private/circuit_recording/memory_circuit_recorder.ts +6 -4
- package/src/private/factory.ts +7 -4
- package/src/public/avm/testing/account_proof.json +553 -0
- package/src/public/avm/testing/account_proof_fetcher.ts +166 -0
- package/src/public/avm/{fixtures → testing}/base_avm_simulation_tester.ts +23 -3
- package/src/public/avm/{fixtures → testing}/utils.ts +6 -41
- package/src/public/contracts_db_checkpoint.ts +41 -0
- package/src/public/db_interfaces.ts +16 -1
- package/src/public/executor_metrics.ts +11 -34
- package/src/public/executor_metrics_interface.ts +2 -1
- package/src/public/fixtures/amm_test.ts +4 -4
- package/src/public/fixtures/bulk_test.ts +38 -13
- package/src/public/fixtures/custom_bytecode_tester.ts +54 -20
- package/src/public/fixtures/index.ts +5 -2
- package/src/public/fixtures/public_tx_simulation_tester.ts +129 -27
- package/src/public/fixtures/simple_contract_data_source.ts +9 -10
- package/src/public/fixtures/token_test.ts +18 -10
- package/src/public/fixtures/utils.ts +28 -25
- package/src/public/fuzzing/avm_fuzzer_simulator.ts +285 -0
- package/src/public/fuzzing/avm_simulator_bin.ts +173 -0
- package/src/public/index.ts +4 -2
- package/src/public/public_db_sources.ts +112 -174
- package/src/public/public_processor/guarded_merkle_tree.ts +14 -6
- package/src/public/public_processor/public_processor.ts +225 -136
- package/src/public/public_processor/public_processor_metrics.ts +28 -44
- package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +125 -0
- package/src/public/public_tx_simulator/dumping_public_tx_simulator.ts +83 -0
- package/src/public/public_tx_simulator/factories.ts +44 -0
- package/src/public/public_tx_simulator/index.ts +4 -2
- package/src/public/public_tx_simulator/public_tx_simulator.ts +153 -500
- package/src/public/public_tx_simulator/public_tx_simulator_base.ts +35 -0
- package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +24 -2
- package/src/public/test_executor_metrics.ts +34 -8
- package/dest/public/avm/avm_context.d.ts +0 -41
- package/dest/public/avm/avm_context.d.ts.map +0 -1
- package/dest/public/avm/avm_context.js +0 -44
- package/dest/public/avm/avm_contract_call_result.d.ts +0 -32
- package/dest/public/avm/avm_contract_call_result.d.ts.map +0 -1
- package/dest/public/avm/avm_contract_call_result.js +0 -54
- package/dest/public/avm/avm_execution_environment.d.ts +0 -23
- package/dest/public/avm/avm_execution_environment.d.ts.map +0 -1
- package/dest/public/avm/avm_execution_environment.js +0 -36
- package/dest/public/avm/avm_gas.d.ts +0 -44
- package/dest/public/avm/avm_gas.d.ts.map +0 -1
- package/dest/public/avm/avm_gas.js +0 -195
- package/dest/public/avm/avm_machine_state.d.ts +0 -97
- package/dest/public/avm/avm_machine_state.d.ts.map +0 -1
- package/dest/public/avm/avm_machine_state.js +0 -109
- package/dest/public/avm/avm_memory_types.d.ts +0 -275
- package/dest/public/avm/avm_memory_types.d.ts.map +0 -1
- package/dest/public/avm/avm_memory_types.js +0 -351
- package/dest/public/avm/avm_simulator.d.ts +0 -39
- package/dest/public/avm/avm_simulator.d.ts.map +0 -1
- package/dest/public/avm/avm_simulator.js +0 -190
- package/dest/public/avm/avm_simulator_interface.d.ts +0 -9
- package/dest/public/avm/avm_simulator_interface.d.ts.map +0 -1
- package/dest/public/avm/avm_simulator_interface.js +0 -3
- package/dest/public/avm/errors.d.ts +0 -98
- package/dest/public/avm/errors.d.ts.map +0 -1
- package/dest/public/avm/errors.js +0 -129
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +0 -22
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +0 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.js +0 -74
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +0 -1
- package/dest/public/avm/fixtures/initializers.d.ts +0 -43
- package/dest/public/avm/fixtures/initializers.d.ts.map +0 -1
- package/dest/public/avm/fixtures/initializers.js +0 -42
- package/dest/public/avm/fixtures/utils.d.ts.map +0 -1
- package/dest/public/avm/index.d.ts +0 -2
- package/dest/public/avm/index.d.ts.map +0 -1
- package/dest/public/avm/index.js +0 -1
- package/dest/public/avm/opcodes/accrued_substate.d.ts +0 -75
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +0 -1
- package/dest/public/avm/opcodes/accrued_substate.js +0 -255
- package/dest/public/avm/opcodes/addressing_mode.d.ts +0 -31
- package/dest/public/avm/opcodes/addressing_mode.d.ts.map +0 -1
- package/dest/public/avm/opcodes/addressing_mode.js +0 -94
- package/dest/public/avm/opcodes/arithmetic.d.ts +0 -47
- package/dest/public/avm/opcodes/arithmetic.d.ts.map +0 -1
- package/dest/public/avm/opcodes/arithmetic.js +0 -87
- package/dest/public/avm/opcodes/bitwise.d.ts +0 -42
- package/dest/public/avm/opcodes/bitwise.d.ts.map +0 -1
- package/dest/public/avm/opcodes/bitwise.js +0 -99
- package/dest/public/avm/opcodes/comparators.d.ts +0 -25
- package/dest/public/avm/opcodes/comparators.d.ts.map +0 -1
- package/dest/public/avm/opcodes/comparators.js +0 -43
- package/dest/public/avm/opcodes/contract.d.ts +0 -20
- package/dest/public/avm/opcodes/contract.d.ts.map +0 -1
- package/dest/public/avm/opcodes/contract.js +0 -65
- package/dest/public/avm/opcodes/control_flow.d.ts +0 -41
- package/dest/public/avm/opcodes/control_flow.d.ts.map +0 -1
- package/dest/public/avm/opcodes/control_flow.js +0 -107
- package/dest/public/avm/opcodes/conversion.d.ts +0 -18
- package/dest/public/avm/opcodes/conversion.d.ts.map +0 -1
- package/dest/public/avm/opcodes/conversion.js +0 -333
- package/dest/public/avm/opcodes/ec_add.d.ts +0 -19
- package/dest/public/avm/opcodes/ec_add.d.ts.map +0 -1
- package/dest/public/avm/opcodes/ec_add.js +0 -84
- package/dest/public/avm/opcodes/environment_getters.d.ts +0 -28
- package/dest/public/avm/opcodes/environment_getters.d.ts.map +0 -1
- package/dest/public/avm/opcodes/environment_getters.js +0 -77
- package/dest/public/avm/opcodes/external_calls.d.ts +0 -59
- package/dest/public/avm/opcodes/external_calls.d.ts.map +0 -1
- package/dest/public/avm/opcodes/external_calls.js +0 -209
- package/dest/public/avm/opcodes/hashing.d.ts +0 -36
- package/dest/public/avm/opcodes/hashing.d.ts.map +0 -1
- package/dest/public/avm/opcodes/hashing.js +0 -114
- package/dest/public/avm/opcodes/index.d.ts +0 -16
- package/dest/public/avm/opcodes/index.d.ts.map +0 -1
- package/dest/public/avm/opcodes/index.js +0 -15
- package/dest/public/avm/opcodes/instruction.d.ts +0 -74
- package/dest/public/avm/opcodes/instruction.d.ts.map +0 -1
- package/dest/public/avm/opcodes/instruction.js +0 -95
- package/dest/public/avm/opcodes/instruction_impl.d.ts +0 -19
- package/dest/public/avm/opcodes/instruction_impl.d.ts.map +0 -1
- package/dest/public/avm/opcodes/instruction_impl.js +0 -30
- package/dest/public/avm/opcodes/memory.d.ts +0 -74
- package/dest/public/avm/opcodes/memory.d.ts.map +0 -1
- package/dest/public/avm/opcodes/memory.js +0 -257
- package/dest/public/avm/opcodes/misc.d.ts +0 -18
- package/dest/public/avm/opcodes/misc.d.ts.map +0 -1
- package/dest/public/avm/opcodes/misc.js +0 -73
- package/dest/public/avm/opcodes/storage.d.ts +0 -24
- package/dest/public/avm/opcodes/storage.d.ts.map +0 -1
- package/dest/public/avm/opcodes/storage.js +0 -68
- package/dest/public/avm/revert_reason.d.ts +0 -18
- package/dest/public/avm/revert_reason.d.ts.map +0 -1
- package/dest/public/avm/revert_reason.js +0 -38
- package/dest/public/avm/serialization/buffer_cursor.d.ts +0 -26
- package/dest/public/avm/serialization/buffer_cursor.d.ts.map +0 -1
- package/dest/public/avm/serialization/buffer_cursor.js +0 -99
- package/dest/public/avm/serialization/bytecode_serialization.d.ts +0 -17
- package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +0 -1
- package/dest/public/avm/serialization/bytecode_serialization.js +0 -333
- package/dest/public/avm/serialization/instruction_serialization.d.ts +0 -114
- package/dest/public/avm/serialization/instruction_serialization.d.ts.map +0 -1
- package/dest/public/avm/serialization/instruction_serialization.js +0 -261
- package/dest/public/avm/test_utils.d.ts +0 -15
- package/dest/public/avm/test_utils.d.ts.map +0 -1
- package/dest/public/avm/test_utils.js +0 -44
- package/dest/public/debug_fn_name.d.ts +0 -5
- package/dest/public/debug_fn_name.d.ts.map +0 -1
- package/dest/public/debug_fn_name.js +0 -9
- package/dest/public/fixtures/custom_bytecode_tests.d.ts +0 -9
- package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +0 -1
- package/dest/public/fixtures/custom_bytecode_tests.js +0 -109
- package/dest/public/fixtures/minimal_public_tx.d.ts +0 -10
- package/dest/public/fixtures/minimal_public_tx.d.ts.map +0 -1
- package/dest/public/fixtures/minimal_public_tx.js +0 -29
- package/dest/public/hinting_db_sources.d.ts +0 -70
- package/dest/public/hinting_db_sources.d.ts.map +0 -1
- package/dest/public/hinting_db_sources.js +0 -297
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +0 -41
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +0 -1
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +0 -89
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +0 -24
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +0 -1
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +0 -51
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +0 -127
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +0 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +0 -292
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +0 -21
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +0 -1
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +0 -39
- package/dest/public/side_effect_trace.d.ts +0 -87
- package/dest/public/side_effect_trace.d.ts.map +0 -1
- package/dest/public/side_effect_trace.js +0 -199
- package/dest/public/side_effect_trace_interface.d.ts +0 -23
- package/dest/public/side_effect_trace_interface.d.ts.map +0 -1
- package/dest/public/side_effect_trace_interface.js +0 -1
- package/dest/public/state_manager/index.d.ts +0 -2
- package/dest/public/state_manager/index.d.ts.map +0 -1
- package/dest/public/state_manager/index.js +0 -1
- package/dest/public/state_manager/nullifiers.d.ts +0 -61
- package/dest/public/state_manager/nullifiers.d.ts.map +0 -1
- package/dest/public/state_manager/nullifiers.js +0 -92
- package/dest/public/state_manager/public_storage.d.ts +0 -66
- package/dest/public/state_manager/public_storage.d.ts.map +0 -1
- package/dest/public/state_manager/public_storage.js +0 -145
- package/dest/public/state_manager/state_manager.d.ts +0 -166
- package/dest/public/state_manager/state_manager.d.ts.map +0 -1
- package/dest/public/state_manager/state_manager.js +0 -391
- package/dest/public/tx_contract_cache.d.ts +0 -41
- package/dest/public/tx_contract_cache.d.ts.map +0 -1
- package/dest/public/tx_contract_cache.js +0 -49
- package/src/public/avm/avm_context.ts +0 -61
- package/src/public/avm/avm_contract_call_result.ts +0 -67
- package/src/public/avm/avm_execution_environment.ts +0 -48
- package/src/public/avm/avm_gas.ts +0 -183
- package/src/public/avm/avm_machine_state.ts +0 -169
- package/src/public/avm/avm_memory_types.ts +0 -436
- package/src/public/avm/avm_simulator.ts +0 -274
- package/src/public/avm/avm_simulator_interface.ts +0 -8
- package/src/public/avm/errors.ts +0 -163
- package/src/public/avm/fixtures/avm_simulation_tester.ts +0 -108
- package/src/public/avm/fixtures/initializers.ts +0 -104
- package/src/public/avm/index.ts +0 -1
- package/src/public/avm/opcodes/accrued_substate.ts +0 -288
- package/src/public/avm/opcodes/addressing_mode.ts +0 -111
- package/src/public/avm/opcodes/arithmetic.ts +0 -117
- package/src/public/avm/opcodes/bitwise.ts +0 -113
- package/src/public/avm/opcodes/comparators.ts +0 -55
- package/src/public/avm/opcodes/contract.ts +0 -75
- package/src/public/avm/opcodes/control_flow.ts +0 -123
- package/src/public/avm/opcodes/conversion.ts +0 -104
- package/src/public/avm/opcodes/ec_add.ts +0 -96
- package/src/public/avm/opcodes/environment_getters.ts +0 -87
- package/src/public/avm/opcodes/external_calls.ts +0 -260
- package/src/public/avm/opcodes/hashing.ts +0 -145
- package/src/public/avm/opcodes/index.ts +0 -15
- package/src/public/avm/opcodes/instruction.ts +0 -136
- package/src/public/avm/opcodes/instruction_impl.ts +0 -36
- package/src/public/avm/opcodes/memory.ts +0 -293
- package/src/public/avm/opcodes/misc.ts +0 -102
- package/src/public/avm/opcodes/storage.ts +0 -87
- package/src/public/avm/revert_reason.ts +0 -55
- package/src/public/avm/serialization/buffer_cursor.ts +0 -118
- package/src/public/avm/serialization/bytecode_serialization.ts +0 -204
- package/src/public/avm/serialization/instruction_serialization.ts +0 -249
- package/src/public/avm/test_utils.ts +0 -64
- package/src/public/debug_fn_name.ts +0 -18
- package/src/public/fixtures/custom_bytecode_tests.ts +0 -135
- package/src/public/fixtures/minimal_public_tx.ts +0 -36
- package/src/public/hinting_db_sources.ts +0 -505
- package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +0 -128
- package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +0 -109
- package/src/public/public_tx_simulator/public_tx_context.ts +0 -471
- package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +0 -63
- package/src/public/side_effect_trace.ts +0 -290
- package/src/public/side_effect_trace_interface.ts +0 -28
- package/src/public/state_manager/index.ts +0 -1
- package/src/public/state_manager/nullifiers.ts +0 -103
- package/src/public/state_manager/public_storage.ts +0 -174
- package/src/public/state_manager/state_manager.ts +0 -560
- package/src/public/tx_contract_cache.ts +0 -69
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
3
|
-
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
-
|
|
5
|
-
import type { PublicContractsDBInterface } from './db_interfaces.js';
|
|
6
|
-
|
|
7
|
-
export async function getPublicFunctionDebugName(
|
|
8
|
-
db: PublicContractsDBInterface,
|
|
9
|
-
contractAddress: AztecAddress,
|
|
10
|
-
calldata: Fr[],
|
|
11
|
-
): Promise<string> {
|
|
12
|
-
// Public function is dispatched and therefore the target function is passed in the first argument.
|
|
13
|
-
if (!calldata[0]) {
|
|
14
|
-
return `<calldata[0] undefined> (Contract Address: ${contractAddress})`;
|
|
15
|
-
}
|
|
16
|
-
const selector = FunctionSelector.fromField(calldata[0]);
|
|
17
|
-
return (await db.getDebugFunctionName(contractAddress, selector)) ?? selector.toString();
|
|
18
|
-
}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { strict as assert } from 'assert';
|
|
2
|
-
|
|
3
|
-
import { TypeTag } from '../avm/avm_memory_types.js';
|
|
4
|
-
import { Addressing, AddressingMode } from '../avm/opcodes/addressing_mode.js';
|
|
5
|
-
import { CalldataCopy, Jump, Return, Set } from '../avm/opcodes/index.js';
|
|
6
|
-
import { encodeToBytecode } from '../avm/serialization/bytecode_serialization.js';
|
|
7
|
-
import {
|
|
8
|
-
MAX_OPCODE_VALUE,
|
|
9
|
-
Opcode,
|
|
10
|
-
OperandType,
|
|
11
|
-
getOperandSize,
|
|
12
|
-
} from '../avm/serialization/instruction_serialization.js';
|
|
13
|
-
import { testCustomBytecode } from './custom_bytecode_tester.js';
|
|
14
|
-
import { PublicTxSimulationTester } from './public_tx_simulation_tester.js';
|
|
15
|
-
|
|
16
|
-
// First instruction resolved a base address (offset 0) which is uninitialized and therefore
|
|
17
|
-
// of invalid tag (FF). This will trigger an exceptional halt.
|
|
18
|
-
export async function addressingWithBaseTagIssueTest(isIndirect: boolean, tester: PublicTxSimulationTester) {
|
|
19
|
-
const addressingMode = Addressing.fromModes([
|
|
20
|
-
isIndirect ? AddressingMode.INDIRECT_RELATIVE : AddressingMode.RELATIVE,
|
|
21
|
-
AddressingMode.DIRECT,
|
|
22
|
-
AddressingMode.DIRECT,
|
|
23
|
-
]);
|
|
24
|
-
|
|
25
|
-
const bytecode = encodeToBytecode([
|
|
26
|
-
new CalldataCopy(/*indirect=*/ addressingMode.toWire(), /*copySize=*/ 1, /*cdOffset=*/ 0, /*dstOffset=*/ 0),
|
|
27
|
-
new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
|
|
28
|
-
]);
|
|
29
|
-
|
|
30
|
-
const txLabel = isIndirect ? 'AddressingWithBaseTagInvalidIndirect' : 'AddressingWithBaseTagInvalidDirect';
|
|
31
|
-
return await testCustomBytecode(bytecode, tester, txLabel);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export async function pcOutOfRangeTest(tester: PublicTxSimulationTester) {
|
|
35
|
-
const bytecode = encodeToBytecode([
|
|
36
|
-
new Jump(/*jumpOffset=*/ 123), // Jump to out-of-range pc offset.
|
|
37
|
-
new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
|
|
38
|
-
]);
|
|
39
|
-
|
|
40
|
-
const txLabel = 'PcOutOfRange';
|
|
41
|
-
return await testCustomBytecode(bytecode, tester, txLabel);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export async function invalidOpcodeTest(tester: PublicTxSimulationTester) {
|
|
45
|
-
let bytecode = encodeToBytecode([
|
|
46
|
-
new Set(/*indirect=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
|
|
47
|
-
]);
|
|
48
|
-
|
|
49
|
-
const offsetReturnOpcodeByte = bytecode.length;
|
|
50
|
-
|
|
51
|
-
bytecode = Buffer.concat([
|
|
52
|
-
bytecode,
|
|
53
|
-
encodeToBytecode([new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0)]),
|
|
54
|
-
]);
|
|
55
|
-
|
|
56
|
-
// Manipulate the Return opcode to make the opcode invalid (out of range).
|
|
57
|
-
bytecode[offsetReturnOpcodeByte] = MAX_OPCODE_VALUE + 1; // opcode is invalid.
|
|
58
|
-
|
|
59
|
-
const txLabel = 'InvalidOpcode';
|
|
60
|
-
return await testCustomBytecode(bytecode, tester, txLabel);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Single invalid byte in the bytecode.
|
|
64
|
-
export async function invalidByteTest(tester: PublicTxSimulationTester) {
|
|
65
|
-
const invalidOpcode = MAX_OPCODE_VALUE + 7;
|
|
66
|
-
assert(invalidOpcode < 256, 'Invalid opcode must fit in a single byte');
|
|
67
|
-
const bytecode = Buffer.from([invalidOpcode]);
|
|
68
|
-
|
|
69
|
-
const txLabel = 'InvalidByte';
|
|
70
|
-
return await testCustomBytecode(bytecode, tester, txLabel);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Truncate the last instruction in the bytecode.
|
|
74
|
-
export async function instructionTruncatedTest(tester: PublicTxSimulationTester) {
|
|
75
|
-
let bytecode = encodeToBytecode([
|
|
76
|
-
new Set(/*indirect=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
|
|
77
|
-
]);
|
|
78
|
-
|
|
79
|
-
// Truncate the bytecode.
|
|
80
|
-
bytecode = bytecode.subarray(0, -1);
|
|
81
|
-
|
|
82
|
-
const txLabel = 'InstructionTruncated';
|
|
83
|
-
return await testCustomBytecode(bytecode, tester, txLabel);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Invalid tag value byte in an instruction.
|
|
87
|
-
export async function invalidTagValueTest(tester: PublicTxSimulationTester) {
|
|
88
|
-
const bytecode = encodeToBytecode([
|
|
89
|
-
new Set(/*indirect=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
|
|
90
|
-
new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
|
|
91
|
-
]);
|
|
92
|
-
|
|
93
|
-
const tagOffset = getTagOffsetInInstruction(Set.wireFormat8);
|
|
94
|
-
assert(bytecode[tagOffset].valueOf() == TypeTag.UINT32.valueOf(), 'Set instruction tag should be UINT32 in test');
|
|
95
|
-
bytecode[tagOffset] = TypeTag.INVALID;
|
|
96
|
-
|
|
97
|
-
const txLabel = 'InvalidTagValue';
|
|
98
|
-
return await testCustomBytecode(bytecode, tester, txLabel);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Combine an invalid tag in the last instruction that is truncated.
|
|
102
|
-
export async function invalidTagValueAndInstructionTruncatedTest(tester: PublicTxSimulationTester) {
|
|
103
|
-
let bytecode = encodeToBytecode([
|
|
104
|
-
// Important: value argument must be a bigint otherwise a type error will be thrown.
|
|
105
|
-
new Set(/*indirect=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT128, /*value=*/ 0n).as(Opcode.SET_128, Set.wireFormat128),
|
|
106
|
-
]);
|
|
107
|
-
|
|
108
|
-
// Truncate the bytecode.
|
|
109
|
-
bytecode = bytecode.subarray(0, -5);
|
|
110
|
-
const tagOffset = getTagOffsetInInstruction(Set.wireFormat128);
|
|
111
|
-
assert(bytecode[tagOffset].valueOf() == TypeTag.UINT128.valueOf(), 'Set instruction tag should be UINT128 in test');
|
|
112
|
-
bytecode[tagOffset] = 0x6f; // Invalid tag value.
|
|
113
|
-
|
|
114
|
-
const txLabel = 'InvalidTagValueAndInstructionTruncated';
|
|
115
|
-
return await testCustomBytecode(bytecode, tester, txLabel);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Returns the offset of the tag in an instruction.
|
|
120
|
-
* @details Loops over the wire format operand type entries until it finds the tag.
|
|
121
|
-
* Returns the byte offset of the tag based on each operand size that is passed.
|
|
122
|
-
*
|
|
123
|
-
* @param wireFormat array of operand types
|
|
124
|
-
* @returns byte offset of the tag
|
|
125
|
-
*/
|
|
126
|
-
function getTagOffsetInInstruction(wireFormat: OperandType[]): number {
|
|
127
|
-
let offset = 0;
|
|
128
|
-
for (const operand of wireFormat) {
|
|
129
|
-
if (operand === OperandType.TAG) {
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
offset += getOperandSize(operand);
|
|
133
|
-
}
|
|
134
|
-
return offset;
|
|
135
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { AvmCircuitInputs } from '@aztec/stdlib/avm';
|
|
2
|
-
import { ProtocolContracts } from '@aztec/stdlib/tx';
|
|
3
|
-
|
|
4
|
-
import avmMinimalCircuitInputsJson from '../../../artifacts/avm_minimal_inputs.json' with { type: 'json' };
|
|
5
|
-
import { TypeTag } from '../avm/avm_memory_types.js';
|
|
6
|
-
import { Add, Return, Set } from '../avm/opcodes/index.js';
|
|
7
|
-
import { encodeToBytecode } from '../avm/serialization/bytecode_serialization.js';
|
|
8
|
-
import { Opcode } from '../avm/serialization/instruction_serialization.js';
|
|
9
|
-
import type { PublicTxResult } from '../public_tx_simulator/public_tx_simulator.js';
|
|
10
|
-
import { testCustomBytecode } from './custom_bytecode_tester.js';
|
|
11
|
-
import { PublicTxSimulationTester } from './public_tx_simulation_tester.js';
|
|
12
|
-
|
|
13
|
-
export async function executeAvmMinimalPublicTx(tester: PublicTxSimulationTester): Promise<PublicTxResult> {
|
|
14
|
-
const minimalBytecode = encodeToBytecode([
|
|
15
|
-
new Set(/*indirect*/ 0, /*dstOffset*/ 0, TypeTag.UINT32, /*value*/ 1).as(Opcode.SET_8, Set.wireFormat8),
|
|
16
|
-
new Set(/*indirect*/ 0, /*dstOffset*/ 1, TypeTag.UINT32, /*value*/ 2).as(Opcode.SET_8, Set.wireFormat8),
|
|
17
|
-
new Add(/*indirect=*/ 0, /*aOffset=*/ 0, /*bOffset=*/ 1, /*dstOffset=*/ 2).as(Opcode.ADD_8, Add.wireFormat8),
|
|
18
|
-
new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 2),
|
|
19
|
-
]);
|
|
20
|
-
|
|
21
|
-
const result = await testCustomBytecode(minimalBytecode, tester, 'MinimalTx', 'AvmMinimalContract');
|
|
22
|
-
|
|
23
|
-
// Modify the protocol contracts to be all zeros
|
|
24
|
-
result.avmProvingRequest.inputs.hints.protocolContracts = ProtocolContracts.empty();
|
|
25
|
-
result.avmProvingRequest.inputs.publicInputs.protocolContracts = ProtocolContracts.empty();
|
|
26
|
-
|
|
27
|
-
return result;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Reads the AVM circuit inputs for the minimal public tx from a pre-generated JSON file.
|
|
32
|
-
* @returns The AvmCircuitInputs for the minimal public tx.
|
|
33
|
-
*/
|
|
34
|
-
export function readAvmMinimalPublicTxInputsFromFile(): AvmCircuitInputs {
|
|
35
|
-
return AvmCircuitInputs.schema.parse(avmMinimalCircuitInputsJson);
|
|
36
|
-
}
|
|
@@ -1,505 +0,0 @@
|
|
|
1
|
-
import { sha256Trunc } from '@aztec/foundation/crypto';
|
|
2
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import type { IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/trees';
|
|
5
|
-
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
6
|
-
import {
|
|
7
|
-
AvmAppendLeavesHint,
|
|
8
|
-
AvmBytecodeCommitmentHint,
|
|
9
|
-
AvmCommitCheckpointHint,
|
|
10
|
-
AvmContractClassHint,
|
|
11
|
-
AvmContractInstanceHint,
|
|
12
|
-
AvmCreateCheckpointHint,
|
|
13
|
-
type AvmExecutionHints,
|
|
14
|
-
AvmGetLeafPreimageHintNullifierTree,
|
|
15
|
-
AvmGetLeafPreimageHintPublicDataTree,
|
|
16
|
-
AvmGetLeafValueHint,
|
|
17
|
-
AvmGetPreviousValueIndexHint,
|
|
18
|
-
AvmGetSiblingPathHint,
|
|
19
|
-
AvmRevertCheckpointHint,
|
|
20
|
-
AvmSequentialInsertHintNullifierTree,
|
|
21
|
-
AvmSequentialInsertHintPublicDataTree,
|
|
22
|
-
} from '@aztec/stdlib/avm';
|
|
23
|
-
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
24
|
-
import type { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
25
|
-
import {
|
|
26
|
-
AppendOnlyTreeSnapshot,
|
|
27
|
-
type BatchInsertionResult,
|
|
28
|
-
type IndexedTreeId,
|
|
29
|
-
MerkleTreeId,
|
|
30
|
-
type MerkleTreeLeafType,
|
|
31
|
-
type MerkleTreeWriteOperations,
|
|
32
|
-
NullifierLeaf,
|
|
33
|
-
NullifierLeafPreimage,
|
|
34
|
-
PublicDataTreeLeaf,
|
|
35
|
-
PublicDataTreeLeafPreimage,
|
|
36
|
-
type SequentialInsertionResult,
|
|
37
|
-
type TreeHeights,
|
|
38
|
-
getTreeName,
|
|
39
|
-
merkleTreeIds,
|
|
40
|
-
} from '@aztec/stdlib/trees';
|
|
41
|
-
import { TreeSnapshots } from '@aztec/stdlib/tx';
|
|
42
|
-
import type { UInt64 } from '@aztec/stdlib/types';
|
|
43
|
-
import type { WorldStateRevision } from '@aztec/stdlib/world-state';
|
|
44
|
-
|
|
45
|
-
import { strict as assert } from 'assert';
|
|
46
|
-
|
|
47
|
-
import type { PublicContractsDBInterface } from './db_interfaces.js';
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* A public contracts database that forwards requests and collects AVM hints.
|
|
51
|
-
*/
|
|
52
|
-
export class HintingPublicContractsDB implements PublicContractsDBInterface {
|
|
53
|
-
// We deduplicate contract classes because they include the whole bytecode.
|
|
54
|
-
private contractClassIds: Set<bigint> = new Set();
|
|
55
|
-
|
|
56
|
-
constructor(
|
|
57
|
-
private readonly db: PublicContractsDBInterface,
|
|
58
|
-
private hints: AvmExecutionHints,
|
|
59
|
-
) {}
|
|
60
|
-
|
|
61
|
-
public async getContractInstance(
|
|
62
|
-
address: AztecAddress,
|
|
63
|
-
timestamp: UInt64,
|
|
64
|
-
): Promise<ContractInstanceWithAddress | undefined> {
|
|
65
|
-
const instance = await this.db.getContractInstance(address, timestamp);
|
|
66
|
-
if (instance) {
|
|
67
|
-
// We don't need to hint the block number because it doesn't change.
|
|
68
|
-
this.hints.contractInstances.push(
|
|
69
|
-
new AvmContractInstanceHint(
|
|
70
|
-
instance.address,
|
|
71
|
-
instance.salt,
|
|
72
|
-
instance.deployer,
|
|
73
|
-
instance.currentContractClassId,
|
|
74
|
-
instance.originalContractClassId,
|
|
75
|
-
instance.initializationHash,
|
|
76
|
-
instance.publicKeys,
|
|
77
|
-
),
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
return instance;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
public async getContractClass(contractClassId: Fr): Promise<ContractClassPublic | undefined> {
|
|
84
|
-
const contractClass = await this.db.getContractClass(contractClassId);
|
|
85
|
-
if (contractClass && !this.contractClassIds.has(contractClassId.toBigInt())) {
|
|
86
|
-
this.contractClassIds.add(contractClassId.toBigInt());
|
|
87
|
-
this.hints.contractClasses.push(
|
|
88
|
-
new AvmContractClassHint(
|
|
89
|
-
contractClass.id,
|
|
90
|
-
contractClass.artifactHash,
|
|
91
|
-
contractClass.privateFunctionsRoot,
|
|
92
|
-
contractClass.packedBytecode,
|
|
93
|
-
),
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
return contractClass;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
public async getBytecodeCommitment(contractClassId: Fr): Promise<Fr | undefined> {
|
|
100
|
-
const commitment = await this.db.getBytecodeCommitment(contractClassId);
|
|
101
|
-
if (commitment) {
|
|
102
|
-
this.hints.bytecodeCommitments.push(new AvmBytecodeCommitmentHint(contractClassId, commitment));
|
|
103
|
-
}
|
|
104
|
-
return commitment;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
public async getDebugFunctionName(
|
|
108
|
-
contractAddress: AztecAddress,
|
|
109
|
-
selector: FunctionSelector,
|
|
110
|
-
): Promise<string | undefined> {
|
|
111
|
-
return await this.db.getDebugFunctionName(contractAddress, selector);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* A low-level merkle DB that collects hints.
|
|
117
|
-
*/
|
|
118
|
-
export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
|
|
119
|
-
private static readonly log: Logger = createLogger('simulator:hinting-merkle-db');
|
|
120
|
-
// This stack is only for debugging purposes.
|
|
121
|
-
// The top of the stack is the current checkpoint id.
|
|
122
|
-
// We need the stack to be non-empty and use 0 as an arbitrary initial checkpoint id.
|
|
123
|
-
// This is not necessarily a checkpoint that happened, but whatever tree state we start with.
|
|
124
|
-
private checkpointStack: number[] = [0];
|
|
125
|
-
private nextCheckpointId: number = 1;
|
|
126
|
-
private checkpointActionCounter: number = 0; // yes, a side-effect counter.
|
|
127
|
-
|
|
128
|
-
public static async create(db: MerkleTreeWriteOperations, hints: AvmExecutionHints) {
|
|
129
|
-
const hintingTreesDB = new HintingMerkleWriteOperations(db, hints);
|
|
130
|
-
const startStateReference = await db.getStateReference();
|
|
131
|
-
hints.startingTreeRoots = new TreeSnapshots(
|
|
132
|
-
startStateReference.l1ToL2MessageTree,
|
|
133
|
-
startStateReference.partial.noteHashTree,
|
|
134
|
-
startStateReference.partial.nullifierTree,
|
|
135
|
-
startStateReference.partial.publicDataTree,
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
return hintingTreesDB;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Use create() to instantiate.
|
|
142
|
-
private constructor(
|
|
143
|
-
private db: MerkleTreeWriteOperations,
|
|
144
|
-
private hints: AvmExecutionHints,
|
|
145
|
-
) {}
|
|
146
|
-
|
|
147
|
-
// Getters.
|
|
148
|
-
public async getSiblingPath<ID extends MerkleTreeId>(
|
|
149
|
-
treeId: ID,
|
|
150
|
-
index: bigint,
|
|
151
|
-
): Promise<SiblingPath<TreeHeights[ID]>> {
|
|
152
|
-
const path = await this.db.getSiblingPath(treeId, index);
|
|
153
|
-
const key = await this.getHintKey(treeId);
|
|
154
|
-
this.hints.getSiblingPathHints.push(new AvmGetSiblingPathHint(key, treeId, index, path.toFields()));
|
|
155
|
-
return Promise.resolve(path);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
public async getPreviousValueIndex<ID extends IndexedTreeId>(
|
|
159
|
-
treeId: ID,
|
|
160
|
-
value: bigint,
|
|
161
|
-
): Promise<
|
|
162
|
-
| {
|
|
163
|
-
index: bigint;
|
|
164
|
-
alreadyPresent: boolean;
|
|
165
|
-
}
|
|
166
|
-
| undefined
|
|
167
|
-
> {
|
|
168
|
-
const result = await this.db.getPreviousValueIndex(treeId, value);
|
|
169
|
-
if (result === undefined) {
|
|
170
|
-
throw new Error(
|
|
171
|
-
`getPreviousValueIndex(${getTreeName(
|
|
172
|
-
treeId,
|
|
173
|
-
)}, ${value}}) returned undefined. Possible wrong tree setup or corrupted state.`,
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
const key = await this.getHintKey(treeId);
|
|
177
|
-
this.hints.getPreviousValueIndexHints.push(
|
|
178
|
-
new AvmGetPreviousValueIndexHint(key, treeId, new Fr(value), result.index, result.alreadyPresent),
|
|
179
|
-
);
|
|
180
|
-
return result;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
public async getLeafPreimage<ID extends IndexedTreeId>(
|
|
184
|
-
treeId: ID,
|
|
185
|
-
index: bigint,
|
|
186
|
-
): Promise<IndexedTreeLeafPreimage | undefined> {
|
|
187
|
-
const preimage = await this.db.getLeafPreimage<ID>(treeId, index);
|
|
188
|
-
if (preimage) {
|
|
189
|
-
const key = await this.getHintKey(treeId);
|
|
190
|
-
|
|
191
|
-
switch (treeId) {
|
|
192
|
-
case MerkleTreeId.PUBLIC_DATA_TREE:
|
|
193
|
-
this.hints.getLeafPreimageHintsPublicDataTree.push(
|
|
194
|
-
new AvmGetLeafPreimageHintPublicDataTree(key, index, preimage as PublicDataTreeLeafPreimage),
|
|
195
|
-
);
|
|
196
|
-
break;
|
|
197
|
-
case MerkleTreeId.NULLIFIER_TREE:
|
|
198
|
-
this.hints.getLeafPreimageHintsNullifierTree.push(
|
|
199
|
-
new AvmGetLeafPreimageHintNullifierTree(key, index, preimage as NullifierLeafPreimage),
|
|
200
|
-
);
|
|
201
|
-
break;
|
|
202
|
-
default:
|
|
203
|
-
// Use getLeafValue for the other trees.
|
|
204
|
-
throw new Error('getLeafPreimage only supported for PublicDataTree and NullifierTree!');
|
|
205
|
-
break;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return preimage;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
public async getLeafValue<ID extends MerkleTreeId>(
|
|
213
|
-
treeId: ID,
|
|
214
|
-
index: bigint,
|
|
215
|
-
): Promise<MerkleTreeLeafType<typeof treeId> | undefined> {
|
|
216
|
-
// Use getLeafPreimage for PublicDataTree and NullifierTree.
|
|
217
|
-
assert(treeId == MerkleTreeId.NOTE_HASH_TREE || treeId == MerkleTreeId.L1_TO_L2_MESSAGE_TREE);
|
|
218
|
-
|
|
219
|
-
const value = await this.db.getLeafValue<ID>(treeId, index);
|
|
220
|
-
if (value) {
|
|
221
|
-
const key = await this.getHintKey(treeId);
|
|
222
|
-
// We can cast to Fr because we know the type of the tree.
|
|
223
|
-
this.hints.getLeafValueHints.push(new AvmGetLeafValueHint(key, treeId, index, value as Fr));
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return value;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// State modification.
|
|
230
|
-
// FIXME(fcarreiro): This is a horrible interface (in the merkle ops). It's receiving the leaves as buffers,
|
|
231
|
-
// from a leaf class that is NOT the one that will be used to write. Make this type safe.
|
|
232
|
-
public async sequentialInsert<TreeHeight extends number, ID extends IndexedTreeId>(
|
|
233
|
-
treeId: ID,
|
|
234
|
-
leaves: Buffer[],
|
|
235
|
-
): Promise<SequentialInsertionResult<TreeHeight>> {
|
|
236
|
-
// Use appendLeaf for NoteHashTree and L1ToL2MessageTree.
|
|
237
|
-
assert(treeId == MerkleTreeId.PUBLIC_DATA_TREE || treeId == MerkleTreeId.NULLIFIER_TREE);
|
|
238
|
-
// We only support 1 leaf at a time for now. Can easily be extended.
|
|
239
|
-
assert(leaves.length === 1, 'sequentialInsert supports only one leaf at a time!');
|
|
240
|
-
|
|
241
|
-
const beforeState = await this.getHintKey(treeId);
|
|
242
|
-
|
|
243
|
-
const result = await this.db.sequentialInsert<TreeHeight, ID>(treeId, leaves);
|
|
244
|
-
|
|
245
|
-
const afterState = await this.getHintKey(treeId);
|
|
246
|
-
HintingMerkleWriteOperations.logTreeChange('sequentialInsert', beforeState, afterState, treeId);
|
|
247
|
-
|
|
248
|
-
switch (treeId) {
|
|
249
|
-
case MerkleTreeId.PUBLIC_DATA_TREE:
|
|
250
|
-
this.hints.sequentialInsertHintsPublicDataTree.push(
|
|
251
|
-
new AvmSequentialInsertHintPublicDataTree(
|
|
252
|
-
beforeState,
|
|
253
|
-
afterState,
|
|
254
|
-
treeId,
|
|
255
|
-
PublicDataTreeLeaf.fromBuffer(leaves[0]),
|
|
256
|
-
{
|
|
257
|
-
leaf: result.lowLeavesWitnessData[0].leafPreimage as PublicDataTreeLeafPreimage,
|
|
258
|
-
index: result.lowLeavesWitnessData[0].index,
|
|
259
|
-
path: result.lowLeavesWitnessData[0].siblingPath.toFields(),
|
|
260
|
-
},
|
|
261
|
-
{
|
|
262
|
-
leaf: result.insertionWitnessData[0].leafPreimage as PublicDataTreeLeafPreimage,
|
|
263
|
-
index: result.insertionWitnessData[0].index,
|
|
264
|
-
path: result.insertionWitnessData[0].siblingPath.toFields(),
|
|
265
|
-
},
|
|
266
|
-
),
|
|
267
|
-
);
|
|
268
|
-
break;
|
|
269
|
-
case MerkleTreeId.NULLIFIER_TREE:
|
|
270
|
-
this.hints.sequentialInsertHintsNullifierTree.push(
|
|
271
|
-
new AvmSequentialInsertHintNullifierTree(
|
|
272
|
-
beforeState,
|
|
273
|
-
afterState,
|
|
274
|
-
treeId,
|
|
275
|
-
NullifierLeaf.fromBuffer(leaves[0]),
|
|
276
|
-
{
|
|
277
|
-
leaf: result.lowLeavesWitnessData[0].leafPreimage as NullifierLeafPreimage,
|
|
278
|
-
index: result.lowLeavesWitnessData[0].index,
|
|
279
|
-
path: result.lowLeavesWitnessData[0].siblingPath.toFields(),
|
|
280
|
-
},
|
|
281
|
-
{
|
|
282
|
-
leaf: result.insertionWitnessData[0].leafPreimage as NullifierLeafPreimage,
|
|
283
|
-
index: result.insertionWitnessData[0].index,
|
|
284
|
-
path: result.insertionWitnessData[0].siblingPath.toFields(),
|
|
285
|
-
},
|
|
286
|
-
),
|
|
287
|
-
);
|
|
288
|
-
break;
|
|
289
|
-
default:
|
|
290
|
-
throw new Error('sequentialInsert only supported for PublicDataTree and NullifierTree!');
|
|
291
|
-
break;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
return result;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
public async appendLeaves<ID extends MerkleTreeId>(treeId: ID, leaves: MerkleTreeLeafType<ID>[]): Promise<void> {
|
|
298
|
-
// Use sequentialInsert for PublicDataTree and NullifierTree.
|
|
299
|
-
assert(treeId == MerkleTreeId.NOTE_HASH_TREE || treeId == MerkleTreeId.L1_TO_L2_MESSAGE_TREE);
|
|
300
|
-
|
|
301
|
-
// We need to process each leaf individually because we need the sibling path after insertion, to be able to constraint the insertion.
|
|
302
|
-
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/13380): This can be changed if the world state appendLeaves returns the sibling paths.
|
|
303
|
-
if (leaves.length === 1) {
|
|
304
|
-
await this.appendLeafInternal(treeId, leaves[0]);
|
|
305
|
-
return;
|
|
306
|
-
} else {
|
|
307
|
-
// TODO(dbanks12): NON-HINTING! We skip hinting here for now because:
|
|
308
|
-
// 1. We only ever append multiple leaves (for now) when padding (all empty leaves).
|
|
309
|
-
// 2. We don't need hints per-item when padding.
|
|
310
|
-
// 3. In order to get per-item hints today, you need to append one-at-a-time (mentioned above), which is VERY slow.
|
|
311
|
-
await this.db.appendLeaves<ID>(treeId, leaves);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
public async createCheckpoint(): Promise<void> {
|
|
316
|
-
const actionCounter = this.checkpointActionCounter++;
|
|
317
|
-
const oldCheckpointId = this.getCurrentCheckpointId();
|
|
318
|
-
const treesStateHash = await this.getTreesStateHash();
|
|
319
|
-
|
|
320
|
-
await this.db.createCheckpoint();
|
|
321
|
-
this.checkpointStack.push(this.nextCheckpointId++);
|
|
322
|
-
const newCheckpointId = this.getCurrentCheckpointId();
|
|
323
|
-
|
|
324
|
-
this.hints.createCheckpointHints.push(new AvmCreateCheckpointHint(actionCounter, oldCheckpointId, newCheckpointId));
|
|
325
|
-
|
|
326
|
-
HintingMerkleWriteOperations.log.trace(
|
|
327
|
-
`[createCheckpoint:${actionCounter}] Checkpoint evolved ${oldCheckpointId} -> ${newCheckpointId} at trees state ${treesStateHash}.`,
|
|
328
|
-
);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
public commitAllCheckpoints(): Promise<void> {
|
|
332
|
-
throw new Error('commitAllCheckpoints is not supported in HintingMerkleWriteOperations.');
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
public revertAllCheckpoints(): Promise<void> {
|
|
336
|
-
throw new Error('revertAllCheckpoints is not supported in HintingMerkleWriteOperations.');
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
public async commitCheckpoint(): Promise<void> {
|
|
340
|
-
const actionCounter = this.checkpointActionCounter++;
|
|
341
|
-
const oldCheckpointId = this.getCurrentCheckpointId();
|
|
342
|
-
const treesStateHash = await this.getTreesStateHash();
|
|
343
|
-
|
|
344
|
-
await this.db.commitCheckpoint();
|
|
345
|
-
this.checkpointStack.pop();
|
|
346
|
-
const newCheckpointId = this.getCurrentCheckpointId();
|
|
347
|
-
|
|
348
|
-
this.hints.commitCheckpointHints.push(new AvmCommitCheckpointHint(actionCounter, oldCheckpointId, newCheckpointId));
|
|
349
|
-
|
|
350
|
-
HintingMerkleWriteOperations.log.trace(
|
|
351
|
-
`[commitCheckpoint:${actionCounter}] Checkpoint evolved ${oldCheckpointId} -> ${newCheckpointId} at trees state ${treesStateHash}.`,
|
|
352
|
-
);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
public async revertCheckpoint(): Promise<void> {
|
|
356
|
-
const actionCounter = this.checkpointActionCounter++;
|
|
357
|
-
const oldCheckpointId = this.getCurrentCheckpointId();
|
|
358
|
-
const treesStateHash = await this.getTreesStateHash();
|
|
359
|
-
|
|
360
|
-
const beforeState: Record<MerkleTreeId, AppendOnlyTreeSnapshot> = {
|
|
361
|
-
[MerkleTreeId.PUBLIC_DATA_TREE]: await this.getHintKey(MerkleTreeId.PUBLIC_DATA_TREE),
|
|
362
|
-
[MerkleTreeId.NULLIFIER_TREE]: await this.getHintKey(MerkleTreeId.NULLIFIER_TREE),
|
|
363
|
-
[MerkleTreeId.NOTE_HASH_TREE]: await this.getHintKey(MerkleTreeId.NOTE_HASH_TREE),
|
|
364
|
-
[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: await this.getHintKey(MerkleTreeId.L1_TO_L2_MESSAGE_TREE),
|
|
365
|
-
[MerkleTreeId.ARCHIVE]: await this.getHintKey(MerkleTreeId.ARCHIVE),
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
await this.db.revertCheckpoint();
|
|
369
|
-
this.checkpointStack.pop();
|
|
370
|
-
const newCheckpointId = this.getCurrentCheckpointId();
|
|
371
|
-
|
|
372
|
-
const afterState: Record<MerkleTreeId, AppendOnlyTreeSnapshot> = {
|
|
373
|
-
[MerkleTreeId.PUBLIC_DATA_TREE]: await this.getHintKey(MerkleTreeId.PUBLIC_DATA_TREE),
|
|
374
|
-
[MerkleTreeId.NULLIFIER_TREE]: await this.getHintKey(MerkleTreeId.NULLIFIER_TREE),
|
|
375
|
-
[MerkleTreeId.NOTE_HASH_TREE]: await this.getHintKey(MerkleTreeId.NOTE_HASH_TREE),
|
|
376
|
-
[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: await this.getHintKey(MerkleTreeId.L1_TO_L2_MESSAGE_TREE),
|
|
377
|
-
[MerkleTreeId.ARCHIVE]: await this.getHintKey(MerkleTreeId.ARCHIVE),
|
|
378
|
-
};
|
|
379
|
-
|
|
380
|
-
this.hints.revertCheckpointHints.push(
|
|
381
|
-
AvmRevertCheckpointHint.create(actionCounter, oldCheckpointId, newCheckpointId, beforeState, afterState),
|
|
382
|
-
);
|
|
383
|
-
|
|
384
|
-
HintingMerkleWriteOperations.log.trace(
|
|
385
|
-
`[revertCheckpoint:${actionCounter}] Checkpoint evolved ${oldCheckpointId} -> ${newCheckpointId} at trees state ${treesStateHash}.`,
|
|
386
|
-
);
|
|
387
|
-
for (const treeId of merkleTreeIds()) {
|
|
388
|
-
HintingMerkleWriteOperations.logTreeChange('revertCheckpoint', beforeState[treeId], afterState[treeId], treeId);
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// Private methods.
|
|
393
|
-
private async getHintKey(treeId: MerkleTreeId): Promise<AppendOnlyTreeSnapshot> {
|
|
394
|
-
const treeInfo = await this.db.getTreeInfo(treeId);
|
|
395
|
-
return new AppendOnlyTreeSnapshot(Fr.fromBuffer(treeInfo.root), Number(treeInfo.size));
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
private getCurrentCheckpointId(): number {
|
|
399
|
-
return this.checkpointStack[this.checkpointStack.length - 1];
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
// For logging/debugging purposes.
|
|
403
|
-
private async getTreesStateHash(): Promise<Fr> {
|
|
404
|
-
const stateReferenceFields = (await this.db.getStateReference()).toFields();
|
|
405
|
-
return Fr.fromBuffer(sha256Trunc(Buffer.concat(stateReferenceFields.map(field => field.toBuffer()))));
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
private static logTreeChange(
|
|
409
|
-
action: string,
|
|
410
|
-
beforeState: AppendOnlyTreeSnapshot,
|
|
411
|
-
afterState: AppendOnlyTreeSnapshot,
|
|
412
|
-
treeId: MerkleTreeId,
|
|
413
|
-
) {
|
|
414
|
-
const treeName = getTreeName(treeId);
|
|
415
|
-
HintingMerkleWriteOperations.log.trace(
|
|
416
|
-
`[${action}] ${treeName} tree state: ${beforeState.root}, ${beforeState.nextAvailableLeafIndex} -> ${afterState.root}, ${afterState.nextAvailableLeafIndex}.`,
|
|
417
|
-
);
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
private async appendLeafInternal<ID extends MerkleTreeId>(
|
|
421
|
-
treeId: ID,
|
|
422
|
-
leaf: MerkleTreeLeafType<ID>,
|
|
423
|
-
): Promise<SiblingPath<TreeHeights[ID]>> {
|
|
424
|
-
// Use sequentialInsert for PublicDataTree and NullifierTree.
|
|
425
|
-
assert(treeId == MerkleTreeId.NOTE_HASH_TREE || treeId == MerkleTreeId.L1_TO_L2_MESSAGE_TREE);
|
|
426
|
-
|
|
427
|
-
const beforeState = await this.getHintKey(treeId);
|
|
428
|
-
|
|
429
|
-
await this.db.appendLeaves<ID>(treeId, [leaf]);
|
|
430
|
-
|
|
431
|
-
const afterState = await this.getHintKey(treeId);
|
|
432
|
-
|
|
433
|
-
HintingMerkleWriteOperations.logTreeChange('appendLeaves', beforeState, afterState, treeId);
|
|
434
|
-
|
|
435
|
-
this.hints.appendLeavesHints.push(new AvmAppendLeavesHint(beforeState, afterState, treeId, [leaf as Fr]));
|
|
436
|
-
|
|
437
|
-
return await this.getSiblingPath(treeId, BigInt(beforeState.nextAvailableLeafIndex));
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
// Non-hinted required methods from MerkleTreeWriteOperations interface
|
|
441
|
-
public async getTreeInfo(treeId: MerkleTreeId) {
|
|
442
|
-
return await this.db.getTreeInfo(treeId);
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
public async getStateReference() {
|
|
446
|
-
return await this.db.getStateReference();
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
public getInitialHeader() {
|
|
450
|
-
return this.db.getInitialHeader();
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
public getRevision(): WorldStateRevision {
|
|
454
|
-
return this.db.getRevision();
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
public async updateArchive(header: any): Promise<void> {
|
|
458
|
-
return await this.db.updateArchive(header);
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
public async batchInsert<
|
|
462
|
-
TreeHeight extends number,
|
|
463
|
-
SubtreeSiblingPathHeight extends number,
|
|
464
|
-
ID extends IndexedTreeId,
|
|
465
|
-
>(
|
|
466
|
-
treeId: ID,
|
|
467
|
-
leaves: Buffer[],
|
|
468
|
-
subtreeHeight: number,
|
|
469
|
-
): Promise<BatchInsertionResult<TreeHeight, SubtreeSiblingPathHeight>> {
|
|
470
|
-
return await this.db.batchInsert<TreeHeight, SubtreeSiblingPathHeight, ID>(treeId, leaves, subtreeHeight);
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
public async close(): Promise<void> {
|
|
474
|
-
return await this.db.close();
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
public async findLeafIndices<ID extends MerkleTreeId>(
|
|
478
|
-
treeId: ID,
|
|
479
|
-
values: MerkleTreeLeafType<ID>[],
|
|
480
|
-
): Promise<(bigint | undefined)[]> {
|
|
481
|
-
return await this.db.findLeafIndices(treeId, values);
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
public findSiblingPaths<ID extends MerkleTreeId>(
|
|
485
|
-
treeId: ID,
|
|
486
|
-
values: MerkleTreeLeafType<ID>[],
|
|
487
|
-
): Promise<({ path: SiblingPath<TreeHeights[ID]>; index: bigint } | undefined)[]> {
|
|
488
|
-
return this.db.findSiblingPaths(treeId, values);
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
public async findLeafIndicesAfter<ID extends MerkleTreeId>(
|
|
492
|
-
treeId: ID,
|
|
493
|
-
values: MerkleTreeLeafType<ID>[],
|
|
494
|
-
startIndex: bigint,
|
|
495
|
-
): Promise<(bigint | undefined)[]> {
|
|
496
|
-
return await this.db.findLeafIndicesAfter(treeId, values, startIndex);
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
public async getBlockNumbersForLeafIndices<ID extends MerkleTreeId>(
|
|
500
|
-
treeId: ID,
|
|
501
|
-
leafIndices: bigint[],
|
|
502
|
-
): Promise<(bigint | undefined)[]> {
|
|
503
|
-
return await this.db.getBlockNumbersForLeafIndices(treeId, leafIndices);
|
|
504
|
-
}
|
|
505
|
-
}
|