@aztec/simulator 0.0.1-commit.d3ec352c → 0.0.1-commit.d6f2b3f94
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 +2 -0
- package/dest/common/errors.d.ts +8 -2
- package/dest/common/errors.d.ts.map +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/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/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 +4 -4
- 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 +21 -18
- 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/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/avm_context.d.ts +3 -3
- package/dest/public/avm/avm_context.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.d.ts +6 -6
- package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.js +3 -3
- package/dest/public/avm/avm_execution_environment.d.ts +7 -6
- package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/public/avm/avm_execution_environment.js +1 -1
- package/dest/public/avm/avm_gas.d.ts +1 -1
- package/dest/public/avm/avm_gas.d.ts.map +1 -1
- package/dest/public/avm/avm_machine_state.d.ts +7 -6
- package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/public/avm/avm_machine_state.js +3 -2
- package/dest/public/avm/avm_memory_types.d.ts +2 -2
- package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/public/avm/avm_memory_types.js +4 -1
- package/dest/public/avm/avm_simulator.d.ts +4 -3
- package/dest/public/avm/avm_simulator.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.js +6 -5
- package/dest/public/avm/calldata.d.ts +51 -0
- package/dest/public/avm/calldata.d.ts.map +1 -0
- package/dest/public/avm/calldata.js +63 -0
- package/dest/public/avm/errors.d.ts +2 -2
- package/dest/public/avm/errors.d.ts.map +1 -1
- package/dest/public/avm/fixtures/account_proof_fetcher.d.ts +2 -0
- package/dest/public/avm/fixtures/account_proof_fetcher.d.ts.map +1 -0
- package/dest/public/avm/fixtures/account_proof_fetcher.js +152 -0
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.js +4 -3
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +2 -2
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.js +1 -1
- package/dest/public/avm/fixtures/initializers.d.ts +2 -2
- package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
- package/dest/public/avm/fixtures/initializers.js +3 -2
- package/dest/public/avm/fixtures/utils.d.ts +2 -2
- package/dest/public/avm/fixtures/utils.d.ts.map +1 -1
- package/dest/public/avm/fixtures/utils.js +1 -1
- package/dest/public/avm/opcodes/accrued_substate.d.ts +16 -17
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/accrued_substate.js +39 -39
- package/dest/public/avm/opcodes/arithmetic.d.ts +10 -8
- package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/public/avm/opcodes/arithmetic.js +12 -2
- package/dest/public/avm/opcodes/bitwise.d.ts +7 -7
- package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/public/avm/opcodes/bitwise.js +5 -5
- package/dest/public/avm/opcodes/comparators.d.ts +4 -4
- package/dest/public/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/public/avm/opcodes/comparators.js +1 -1
- package/dest/public/avm/opcodes/contract.d.ts +3 -3
- package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/public/avm/opcodes/contract.js +8 -8
- package/dest/public/avm/opcodes/control_flow.d.ts +3 -3
- package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
- package/dest/public/avm/opcodes/control_flow.js +4 -4
- package/dest/public/avm/opcodes/conversion.d.ts +3 -3
- package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/public/avm/opcodes/conversion.js +4 -4
- package/dest/public/avm/opcodes/ec_add.d.ts +4 -4
- package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/public/avm/opcodes/ec_add.js +17 -8
- package/dest/public/avm/opcodes/environment_getters.d.ts +5 -5
- package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/public/avm/opcodes/environment_getters.js +6 -6
- package/dest/public/avm/opcodes/external_calls.d.ts +9 -9
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.js +23 -22
- package/dest/public/avm/opcodes/hashing.d.ts +8 -8
- package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/public/avm/opcodes/hashing.js +21 -16
- package/dest/public/avm/opcodes/instruction_impl.d.ts +4 -4
- package/dest/public/avm/opcodes/instruction_impl.d.ts.map +1 -1
- package/dest/public/avm/opcodes/instruction_impl.js +4 -4
- package/dest/public/avm/opcodes/memory.d.ts +14 -14
- package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.js +26 -26
- package/dest/public/avm/opcodes/misc.d.ts +3 -3
- package/dest/public/avm/opcodes/misc.d.ts.map +1 -1
- package/dest/public/avm/opcodes/misc.js +4 -4
- package/dest/public/avm/opcodes/storage.d.ts +16 -15
- package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/public/avm/opcodes/storage.js +34 -24
- package/dest/public/avm/revert_reason.d.ts +2 -2
- package/dest/public/avm/revert_reason.d.ts.map +1 -1
- package/dest/public/avm/serialization/instruction_serialization.js +1 -1
- package/dest/public/avm/test_utils.d.ts +2 -2
- package/dest/public/avm/test_utils.d.ts.map +1 -1
- package/dest/public/avm/test_utils.js +1 -1
- package/dest/public/contracts_db_checkpoint.d.ts +2 -2
- package/dest/public/contracts_db_checkpoint.d.ts.map +1 -1
- package/dest/public/db_interfaces.d.ts +2 -2
- package/dest/public/db_interfaces.d.ts.map +1 -1
- package/dest/public/debug_fn_name.d.ts +4 -4
- package/dest/public/debug_fn_name.d.ts.map +1 -1
- package/dest/public/debug_fn_name.js +14 -5
- package/dest/public/executor_metrics.d.ts +1 -1
- package/dest/public/executor_metrics.d.ts.map +1 -1
- package/dest/public/executor_metrics.js +12 -33
- package/dest/public/fixtures/amm_test.js +2 -2
- 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 +5 -69
- package/dest/public/fixtures/custom_bytecode_tester.d.ts +28 -6
- 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/custom_bytecode_tests.d.ts +11 -8
- package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
- package/dest/public/fixtures/custom_bytecode_tests.js +83 -18
- package/dest/public/fixtures/index.d.ts +4 -2
- package/dest/public/fixtures/index.d.ts.map +1 -1
- package/dest/public/fixtures/index.js +3 -1
- package/dest/public/fixtures/minimal_public_tx.d.ts +2 -7
- package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -1
- package/dest/public/fixtures/minimal_public_tx.js +4 -14
- package/dest/public/fixtures/opcode_spammer.d.ts +122 -0
- package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -0
- package/dest/public/fixtures/opcode_spammer.js +1653 -0
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +15 -2
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +36 -8
- package/dest/public/fixtures/simple_contract_data_source.d.ts +2 -2
- package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -1
- package/dest/public/fixtures/token_test.js +1 -1
- package/dest/public/fixtures/utils.d.ts +2 -2
- package/dest/public/fixtures/utils.d.ts.map +1 -1
- package/dest/public/fixtures/utils.js +4 -3
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +60 -0
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -0
- package/dest/public/fuzzing/avm_fuzzer_simulator.js +171 -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/hinting_db_sources.d.ts +3 -2
- package/dest/public/hinting_db_sources.d.ts.map +1 -1
- package/dest/public/hinting_db_sources.js +7 -2
- package/dest/public/index.d.ts +2 -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 +5 -4
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +5 -5
- package/dest/public/public_processor/guarded_merkle_tree.d.ts +2 -1
- package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
- package/dest/public/public_processor/guarded_merkle_tree.js +5 -0
- package/dest/public/public_processor/public_processor.d.ts +6 -4
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +433 -37
- package/dest/public/public_processor/public_processor_metrics.d.ts +2 -2
- package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor_metrics.js +28 -45
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +3 -14
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +20 -55
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +20 -5
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +50 -11
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +4 -4
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +5 -5
- package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +4 -4
- package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +12 -11
- package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +23 -0
- package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/dumping_cpp_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 +3 -1
- package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/index.js +2 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +3 -3
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +5 -4
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +9 -9
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +7 -5
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +17 -10
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +24 -1
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +2 -2
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +395 -19
- package/dest/public/side_effect_trace.d.ts +6 -5
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +4 -4
- package/dest/public/side_effect_trace_interface.d.ts +2 -2
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/dest/public/state_manager/nullifiers.d.ts +2 -2
- package/dest/public/state_manager/nullifiers.d.ts.map +1 -1
- package/dest/public/state_manager/public_storage.d.ts +2 -2
- package/dest/public/state_manager/public_storage.d.ts.map +1 -1
- package/dest/public/state_manager/public_storage.js +1 -1
- package/dest/public/state_manager/state_manager.d.ts +11 -5
- package/dest/public/state_manager/state_manager.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.js +15 -8
- package/dest/public/test_executor_metrics.d.ts +3 -2
- package/dest/public/test_executor_metrics.d.ts.map +1 -1
- package/dest/public/test_executor_metrics.js +2 -2
- package/package.json +18 -18
- 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 +7 -3
- package/src/private/circuit_recording/circuit_recorder.ts +22 -19
- 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/avm_context.ts +2 -2
- package/src/public/avm/avm_contract_call_result.ts +8 -6
- package/src/public/avm/avm_execution_environment.ts +10 -5
- package/src/public/avm/avm_gas.ts +3 -3
- package/src/public/avm/avm_machine_state.ts +7 -6
- package/src/public/avm/avm_memory_types.ts +5 -1
- package/src/public/avm/avm_simulator.ts +9 -6
- package/src/public/avm/calldata.ts +100 -0
- package/src/public/avm/errors.ts +1 -1
- package/src/public/avm/fixtures/account_proof.json +553 -0
- package/src/public/avm/fixtures/account_proof_fetcher.ts +166 -0
- package/src/public/avm/fixtures/avm_simulation_tester.ts +9 -3
- package/src/public/avm/fixtures/base_avm_simulation_tester.ts +1 -1
- package/src/public/avm/fixtures/initializers.ts +3 -2
- package/src/public/avm/fixtures/utils.ts +1 -1
- package/src/public/avm/opcodes/accrued_substate.ts +28 -30
- package/src/public/avm/opcodes/arithmetic.ts +14 -2
- package/src/public/avm/opcodes/bitwise.ts +3 -3
- package/src/public/avm/opcodes/comparators.ts +1 -1
- package/src/public/avm/opcodes/contract.ts +4 -7
- package/src/public/avm/opcodes/control_flow.ts +2 -2
- package/src/public/avm/opcodes/conversion.ts +3 -3
- package/src/public/avm/opcodes/ec_add.ts +15 -6
- package/src/public/avm/opcodes/environment_getters.ts +7 -7
- package/src/public/avm/opcodes/external_calls.ts +17 -15
- package/src/public/avm/opcodes/hashing.ts +16 -10
- package/src/public/avm/opcodes/instruction_impl.ts +2 -2
- package/src/public/avm/opcodes/memory.ts +20 -20
- package/src/public/avm/opcodes/misc.ts +2 -2
- package/src/public/avm/opcodes/storage.ts +30 -22
- package/src/public/avm/revert_reason.ts +1 -1
- package/src/public/avm/serialization/instruction_serialization.ts +1 -1
- package/src/public/avm/test_utils.ts +1 -1
- package/src/public/contracts_db_checkpoint.ts +1 -1
- package/src/public/db_interfaces.ts +1 -1
- package/src/public/debug_fn_name.ts +17 -8
- package/src/public/executor_metrics.ts +9 -33
- package/src/public/fixtures/amm_test.ts +2 -2
- package/src/public/fixtures/bulk_test.ts +9 -9
- package/src/public/fixtures/custom_bytecode_tester.ts +53 -19
- package/src/public/fixtures/custom_bytecode_tests.ts +111 -18
- package/src/public/fixtures/index.ts +7 -1
- package/src/public/fixtures/minimal_public_tx.ts +6 -15
- package/src/public/fixtures/opcode_spammer.ts +1721 -0
- package/src/public/fixtures/public_tx_simulation_tester.ts +40 -6
- package/src/public/fixtures/simple_contract_data_source.ts +1 -1
- package/src/public/fixtures/token_test.ts +1 -1
- package/src/public/fixtures/utils.ts +2 -3
- package/src/public/fuzzing/avm_fuzzer_simulator.ts +288 -0
- package/src/public/fuzzing/avm_simulator_bin.ts +175 -0
- package/src/public/hinting_db_sources.ts +6 -2
- package/src/public/index.ts +2 -0
- package/src/public/public_db_sources.ts +16 -6
- package/src/public/public_processor/guarded_merkle_tree.ts +4 -0
- package/src/public/public_processor/public_processor.ts +49 -19
- package/src/public/public_processor/public_processor_metrics.ts +16 -44
- package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +25 -63
- package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +65 -9
- package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +7 -5
- package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +13 -14
- package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +83 -0
- package/src/public/public_tx_simulator/factories.ts +43 -0
- package/src/public/public_tx_simulator/index.ts +2 -0
- package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +1 -1
- package/src/public/public_tx_simulator/public_tx_context.ts +14 -7
- package/src/public/public_tx_simulator/public_tx_simulator.ts +32 -10
- package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +23 -0
- package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +1 -1
- package/src/public/side_effect_trace.ts +6 -3
- package/src/public/side_effect_trace_interface.ts +1 -1
- package/src/public/state_manager/nullifiers.ts +1 -1
- package/src/public/state_manager/public_storage.ts +1 -1
- package/src/public/state_manager/state_manager.ts +31 -22
- package/src/public/test_executor_metrics.ts +3 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NULLIFIER_SUBTREE_HEIGHT } from '@aztec/constants';
|
|
2
2
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
3
|
-
import { Fr } from '@aztec/foundation/
|
|
4
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
5
5
|
import { sleep } from '@aztec/foundation/sleep';
|
|
6
6
|
import { DateProvider, Timer, elapsed, executeTimeout } from '@aztec/foundation/timer';
|
|
7
7
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
@@ -62,11 +62,15 @@ import { PublicProcessorMetrics } from './public_processor_metrics.js';
|
|
|
62
62
|
* Creates new instances of PublicProcessor given the provided merkle tree db and contract data source.
|
|
63
63
|
*/
|
|
64
64
|
export class PublicProcessorFactory {
|
|
65
|
+
private log: Logger;
|
|
65
66
|
constructor(
|
|
66
67
|
private contractDataSource: ContractDataSource,
|
|
67
68
|
private dateProvider: DateProvider = new DateProvider(),
|
|
68
69
|
protected telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
69
|
-
|
|
70
|
+
bindings?: LoggerBindings,
|
|
71
|
+
) {
|
|
72
|
+
this.log = createLogger('simulator:public-processor-factory', bindings);
|
|
73
|
+
}
|
|
70
74
|
|
|
71
75
|
/**
|
|
72
76
|
* Creates a new instance of a PublicProcessor.
|
|
@@ -79,7 +83,8 @@ export class PublicProcessorFactory {
|
|
|
79
83
|
globalVariables: GlobalVariables,
|
|
80
84
|
config: PublicSimulatorConfig,
|
|
81
85
|
): PublicProcessor {
|
|
82
|
-
const
|
|
86
|
+
const bindings = this.log.getBindings();
|
|
87
|
+
const contractsDB = new PublicContractsDB(this.contractDataSource, bindings);
|
|
83
88
|
|
|
84
89
|
const guardedFork = new GuardedMerkleTreeOperations(merkleTree);
|
|
85
90
|
const publicTxSimulator = this.createPublicTxSimulator(guardedFork, contractsDB, globalVariables, config);
|
|
@@ -91,6 +96,7 @@ export class PublicProcessorFactory {
|
|
|
91
96
|
publicTxSimulator,
|
|
92
97
|
this.dateProvider,
|
|
93
98
|
this.telemetryClient,
|
|
99
|
+
createLogger('simulator:public-processor', bindings),
|
|
94
100
|
);
|
|
95
101
|
}
|
|
96
102
|
|
|
@@ -100,7 +106,14 @@ export class PublicProcessorFactory {
|
|
|
100
106
|
globalVariables: GlobalVariables,
|
|
101
107
|
config?: Partial<PublicTxSimulatorConfig>,
|
|
102
108
|
): PublicTxSimulatorInterface {
|
|
103
|
-
return new TelemetryCppPublicTxSimulator(
|
|
109
|
+
return new TelemetryCppPublicTxSimulator(
|
|
110
|
+
merkleTree,
|
|
111
|
+
contractsDB,
|
|
112
|
+
globalVariables,
|
|
113
|
+
this.telemetryClient,
|
|
114
|
+
config,
|
|
115
|
+
this.log.getBindings(),
|
|
116
|
+
);
|
|
104
117
|
}
|
|
105
118
|
}
|
|
106
119
|
|
|
@@ -125,8 +138,8 @@ export class PublicProcessor implements Traceable {
|
|
|
125
138
|
protected publicTxSimulator: PublicTxSimulatorInterface,
|
|
126
139
|
private dateProvider: DateProvider,
|
|
127
140
|
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
128
|
-
private log
|
|
129
|
-
private opts: Pick<SequencerConfig, 'fakeProcessingDelayPerTxMs'> = {},
|
|
141
|
+
private log: Logger,
|
|
142
|
+
private opts: Pick<SequencerConfig, 'fakeProcessingDelayPerTxMs' | 'fakeThrowAfterProcessingTxCount'> = {},
|
|
130
143
|
) {
|
|
131
144
|
this.metrics = new PublicProcessorMetrics(telemetryClient, 'PublicProcessor');
|
|
132
145
|
}
|
|
@@ -146,7 +159,7 @@ export class PublicProcessor implements Traceable {
|
|
|
146
159
|
txs: Iterable<Tx> | AsyncIterable<Tx>,
|
|
147
160
|
limits: PublicProcessorLimits = {},
|
|
148
161
|
validator: PublicProcessorValidator = {},
|
|
149
|
-
): Promise<[ProcessedTx[], FailedTx[], Tx[], NestedProcessReturnValues[]]> {
|
|
162
|
+
): Promise<[ProcessedTx[], FailedTx[], Tx[], NestedProcessReturnValues[], number]> {
|
|
150
163
|
const { maxTransactions, maxBlockSize, deadline, maxBlockGas, maxBlobFields } = limits;
|
|
151
164
|
const { preprocessValidator, nullifierCache } = validator;
|
|
152
165
|
const result: ProcessedTx[] = [];
|
|
@@ -160,7 +173,7 @@ export class PublicProcessor implements Traceable {
|
|
|
160
173
|
let totalBlockGas = new Gas(0, 0);
|
|
161
174
|
let totalBlobFields = 0;
|
|
162
175
|
|
|
163
|
-
for await (const
|
|
176
|
+
for await (const tx of txs) {
|
|
164
177
|
// Only process up to the max tx limit
|
|
165
178
|
if (maxTransactions !== undefined && result.length >= maxTransactions) {
|
|
166
179
|
this.log.debug(`Stopping tx processing due to reaching the max tx limit.`);
|
|
@@ -174,8 +187,8 @@ export class PublicProcessor implements Traceable {
|
|
|
174
187
|
}
|
|
175
188
|
|
|
176
189
|
// Skip this tx if it'd exceed max block size
|
|
177
|
-
const txHash =
|
|
178
|
-
const preTxSizeInBytes =
|
|
190
|
+
const txHash = tx.getTxHash().toString();
|
|
191
|
+
const preTxSizeInBytes = tx.getEstimatedPrivateTxEffectsSize();
|
|
179
192
|
if (maxBlockSize !== undefined && totalSizeInBytes + preTxSizeInBytes > maxBlockSize) {
|
|
180
193
|
this.log.warn(`Skipping processing of tx ${txHash} sized ${preTxSizeInBytes} bytes due to block size limit`, {
|
|
181
194
|
txHash,
|
|
@@ -187,7 +200,7 @@ export class PublicProcessor implements Traceable {
|
|
|
187
200
|
}
|
|
188
201
|
|
|
189
202
|
// Skip this tx if its gas limit would exceed the block gas limit
|
|
190
|
-
const txGasLimit =
|
|
203
|
+
const txGasLimit = tx.data.constants.txContext.gasSettings.gasLimits;
|
|
191
204
|
if (maxBlockGas !== undefined && totalBlockGas.add(txGasLimit).gtAny(maxBlockGas)) {
|
|
192
205
|
this.log.warn(`Skipping processing of tx ${txHash} due to block gas limit`, {
|
|
193
206
|
txHash,
|
|
@@ -198,9 +211,6 @@ export class PublicProcessor implements Traceable {
|
|
|
198
211
|
continue;
|
|
199
212
|
}
|
|
200
213
|
|
|
201
|
-
// The processor modifies the tx objects in place, so we need to clone them.
|
|
202
|
-
const tx = Tx.clone(origTx);
|
|
203
|
-
|
|
204
214
|
// We validate the tx before processing it, to avoid unnecessary work.
|
|
205
215
|
if (preprocessValidator) {
|
|
206
216
|
const result = await preprocessValidator.validateTx(tx);
|
|
@@ -233,6 +243,12 @@ export class PublicProcessor implements Traceable {
|
|
|
233
243
|
try {
|
|
234
244
|
const [processedTx, returnValues] = await this.processTx(tx, deadline);
|
|
235
245
|
|
|
246
|
+
// Inject a fake processing failure after N txs if requested
|
|
247
|
+
const fakeThrowAfter = this.opts.fakeThrowAfterProcessingTxCount;
|
|
248
|
+
if (fakeThrowAfter !== undefined && result.length + failed.length + 1 >= fakeThrowAfter) {
|
|
249
|
+
throw new Error(`Fake error after processing ${fakeThrowAfter} txs`);
|
|
250
|
+
}
|
|
251
|
+
|
|
236
252
|
const txBlobFields = processedTx.txEffect.getNumBlobFields();
|
|
237
253
|
|
|
238
254
|
// If the actual size of this tx would exceed block size, skip it
|
|
@@ -251,6 +267,7 @@ export class PublicProcessor implements Traceable {
|
|
|
251
267
|
}
|
|
252
268
|
|
|
253
269
|
// If the actual blob fields of this tx would exceed the limit, skip it
|
|
270
|
+
// Note: maxBlobFields already accounts for block end blob fields and previous blocks in checkpoint.
|
|
254
271
|
if (maxBlobFields !== undefined && totalBlobFields + txBlobFields > maxBlobFields) {
|
|
255
272
|
this.log.debug(
|
|
256
273
|
`Skipping processed tx ${txHash} with ${txBlobFields} blob fields due to max blob fields limit.`,
|
|
@@ -282,7 +299,15 @@ export class PublicProcessor implements Traceable {
|
|
|
282
299
|
if (err?.name === 'PublicProcessorTimeoutError') {
|
|
283
300
|
this.log.warn(`Stopping tx processing due to timeout.`);
|
|
284
301
|
// We hit the transaction execution deadline.
|
|
285
|
-
// There may still be a transaction executing
|
|
302
|
+
// There may still be a transaction executing on a worker thread (C++ via NAPI).
|
|
303
|
+
// Signal cancellation AND WAIT for the simulation to actually stop.
|
|
304
|
+
// This is critical because C++ might be in the middle of a slow operation (e.g., pad_trees)
|
|
305
|
+
// and won't check the cancellation flag until that operation completes.
|
|
306
|
+
// Without waiting, we'd proceed to revert checkpoints while C++ is still writing to state.
|
|
307
|
+
// Wait for C++ to stop gracefully.
|
|
308
|
+
await this.publicTxSimulator.cancel?.();
|
|
309
|
+
|
|
310
|
+
// Now stop the guarded fork to prevent any further TS-side access to the world state.
|
|
286
311
|
await this.guardedMerkleTree.stop();
|
|
287
312
|
|
|
288
313
|
// We now know there can't be any further access to world state. The fork is in a state where there is:
|
|
@@ -338,7 +363,7 @@ export class PublicProcessor implements Traceable {
|
|
|
338
363
|
totalSizeInBytes,
|
|
339
364
|
});
|
|
340
365
|
|
|
341
|
-
return [result, failed, usedTxs, returns];
|
|
366
|
+
return [result, failed, usedTxs, returns, totalBlobFields];
|
|
342
367
|
}
|
|
343
368
|
|
|
344
369
|
private async checkWorldStateUnchanged(
|
|
@@ -523,7 +548,7 @@ export class PublicProcessor implements Traceable {
|
|
|
523
548
|
|
|
524
549
|
const result = await this.publicTxSimulator.simulate(tx);
|
|
525
550
|
// TODO: use the callStackMetadata here to extract more data about public execution
|
|
526
|
-
const { hints, publicInputs, gasUsed, revertCode /*callStackMetadata*/ } = result;
|
|
551
|
+
const { hints, publicInputs, publicTxEffect, gasUsed, revertCode /*callStackMetadata*/ } = result;
|
|
527
552
|
|
|
528
553
|
const contractClassLogs = revertCode.isOK()
|
|
529
554
|
? tx.getContractClassLogs()
|
|
@@ -542,10 +567,15 @@ export class PublicProcessor implements Traceable {
|
|
|
542
567
|
const appLogicReturnValues: NestedProcessReturnValues[] = result.getAppLogicReturnValues();
|
|
543
568
|
// Extract the revert reason from the call stack metadata.
|
|
544
569
|
const revertReason = result.findRevertReason();
|
|
570
|
+
// Create proving request if we have hints and public inputs.
|
|
571
|
+
const avmProvingRequest =
|
|
572
|
+
hints && publicInputs ? PublicProcessor.generateProvingRequest(publicInputs, hints) : undefined;
|
|
545
573
|
|
|
546
574
|
const processedTx = makeProcessedTxFromTxWithPublicCalls(
|
|
547
575
|
tx,
|
|
548
|
-
|
|
576
|
+
this.globalVariables,
|
|
577
|
+
avmProvingRequest,
|
|
578
|
+
publicTxEffect,
|
|
549
579
|
gasUsed,
|
|
550
580
|
revertCode,
|
|
551
581
|
revertReason,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-registry';
|
|
2
2
|
import type { Gas } from '@aztec/stdlib/gas';
|
|
3
|
-
import
|
|
3
|
+
import { TxExecutionPhase } from '@aztec/stdlib/tx';
|
|
4
4
|
import {
|
|
5
5
|
Attributes,
|
|
6
6
|
type Gauge,
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
type TelemetryClient,
|
|
10
10
|
type Tracer,
|
|
11
11
|
type UpDownCounter,
|
|
12
|
-
|
|
12
|
+
createUpDownCounterWithDefault,
|
|
13
13
|
} from '@aztec/telemetry-client';
|
|
14
14
|
|
|
15
15
|
export class PublicProcessorMetrics {
|
|
@@ -34,60 +34,32 @@ export class PublicProcessorMetrics {
|
|
|
34
34
|
this.tracer = client.getTracer(name);
|
|
35
35
|
const meter = client.getMeter(name);
|
|
36
36
|
|
|
37
|
-
this.txDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TX_DURATION
|
|
38
|
-
description: 'How long it takes to process a transaction',
|
|
39
|
-
unit: 'ms',
|
|
40
|
-
valueType: ValueType.INT,
|
|
41
|
-
});
|
|
37
|
+
this.txDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TX_DURATION);
|
|
42
38
|
|
|
43
|
-
this.txCount = meter
|
|
44
|
-
|
|
39
|
+
this.txCount = createUpDownCounterWithDefault(meter, Metrics.PUBLIC_PROCESSOR_TX_COUNT, {
|
|
40
|
+
[Attributes.OK]: [true, false],
|
|
45
41
|
});
|
|
46
42
|
|
|
47
|
-
this.txPhaseCount = meter
|
|
48
|
-
description: 'Number of phases processed',
|
|
49
|
-
});
|
|
43
|
+
this.txPhaseCount = createUpDownCounterWithDefault(meter, Metrics.PUBLIC_PROCESSOR_TX_PHASE_COUNT);
|
|
50
44
|
|
|
51
|
-
this.phaseDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_PHASE_DURATION
|
|
52
|
-
description: 'How long it takes to process a phase',
|
|
53
|
-
unit: 'ms',
|
|
54
|
-
valueType: ValueType.INT,
|
|
55
|
-
});
|
|
45
|
+
this.phaseDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_PHASE_DURATION);
|
|
56
46
|
|
|
57
|
-
this.phaseCount = meter
|
|
58
|
-
|
|
47
|
+
this.phaseCount = createUpDownCounterWithDefault(meter, Metrics.PUBLIC_PROCESSOR_PHASE_COUNT, {
|
|
48
|
+
[Attributes.TX_PHASE_NAME]: [TxExecutionPhase.SETUP, TxExecutionPhase.APP_LOGIC, TxExecutionPhase.TEARDOWN],
|
|
49
|
+
[Attributes.OK]: [true, false],
|
|
59
50
|
});
|
|
60
51
|
|
|
61
|
-
this.bytecodeDeployed = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_DEPLOY_BYTECODE_SIZE
|
|
62
|
-
description: 'Size of deployed bytecode',
|
|
63
|
-
unit: 'By',
|
|
64
|
-
});
|
|
52
|
+
this.bytecodeDeployed = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_DEPLOY_BYTECODE_SIZE);
|
|
65
53
|
|
|
66
|
-
this.totalGas = meter.createGauge(Metrics.PUBLIC_PROCESSOR_TOTAL_GAS
|
|
67
|
-
description: 'Total gas used in block',
|
|
68
|
-
unit: 'gas',
|
|
69
|
-
});
|
|
54
|
+
this.totalGas = meter.createGauge(Metrics.PUBLIC_PROCESSOR_TOTAL_GAS);
|
|
70
55
|
|
|
71
|
-
this.totalGasHistogram = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TOTAL_GAS_HISTOGRAM
|
|
72
|
-
description: 'Total gas used in block as histogram',
|
|
73
|
-
unit: 'gas/block',
|
|
74
|
-
});
|
|
56
|
+
this.totalGasHistogram = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TOTAL_GAS_HISTOGRAM);
|
|
75
57
|
|
|
76
|
-
this.txGas = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TX_GAS
|
|
77
|
-
description: 'Gas used in transaction',
|
|
78
|
-
unit: 'gas/tx',
|
|
79
|
-
});
|
|
58
|
+
this.txGas = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TX_GAS);
|
|
80
59
|
|
|
81
|
-
this.gasRate = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_GAS_RATE
|
|
82
|
-
description: 'L2 gas per second for complete block',
|
|
83
|
-
unit: 'gas/s',
|
|
84
|
-
});
|
|
60
|
+
this.gasRate = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_GAS_RATE);
|
|
85
61
|
|
|
86
|
-
this.treeInsertionDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TREE_INSERTION
|
|
87
|
-
description: 'How long it takes for tree insertion',
|
|
88
|
-
unit: 'us',
|
|
89
|
-
valueType: ValueType.INT,
|
|
90
|
-
});
|
|
62
|
+
this.treeInsertionDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TREE_INSERTION);
|
|
91
63
|
}
|
|
92
64
|
|
|
93
65
|
recordPhaseDuration(phaseName: TxExecutionPhase, durationMs: number) {
|
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
2
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import type { ContractProvider } from '@aztec/native';
|
|
4
4
|
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
5
5
|
import { deserializeFromMessagePack, serializeWithMessagePack } from '@aztec/stdlib/avm';
|
|
6
6
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
7
7
|
import { ContractDeploymentData } from '@aztec/stdlib/contract';
|
|
8
|
-
import { ContractClassLog, ContractClassLogFields, PrivateLog } from '@aztec/stdlib/logs';
|
|
9
8
|
import type { GlobalVariables } from '@aztec/stdlib/tx';
|
|
10
9
|
|
|
11
10
|
import type { PublicContractsDB } from '../public_db_sources.js';
|
|
12
11
|
|
|
13
12
|
export class ContractProviderForCpp implements ContractProvider {
|
|
14
|
-
private log: Logger
|
|
13
|
+
private log: Logger;
|
|
15
14
|
|
|
16
15
|
constructor(
|
|
17
16
|
private contractsDB: PublicContractsDB,
|
|
18
17
|
private globalVariables: GlobalVariables,
|
|
19
|
-
|
|
18
|
+
bindings?: LoggerBindings,
|
|
19
|
+
) {
|
|
20
|
+
this.log = createLogger('simulator:contract_provider_for_cpp', bindings);
|
|
21
|
+
}
|
|
20
22
|
|
|
21
23
|
public getContractInstance = async (address: string): Promise<Buffer | undefined> => {
|
|
22
|
-
this.log.
|
|
24
|
+
this.log.trace(`Contract provider callback: getContractInstance(${address})`);
|
|
23
25
|
|
|
24
26
|
const aztecAddr = AztecAddress.fromString(address);
|
|
25
27
|
|
|
@@ -34,7 +36,7 @@ export class ContractProviderForCpp implements ContractProvider {
|
|
|
34
36
|
};
|
|
35
37
|
|
|
36
38
|
public getContractClass = async (classId: string): Promise<Buffer | undefined> => {
|
|
37
|
-
this.log.
|
|
39
|
+
this.log.trace(`Contract provider callback: getContractClass(${classId})`);
|
|
38
40
|
|
|
39
41
|
// Parse classId string to Fr
|
|
40
42
|
const classIdFr = Fr.fromString(classId);
|
|
@@ -51,20 +53,20 @@ export class ContractProviderForCpp implements ContractProvider {
|
|
|
51
53
|
};
|
|
52
54
|
|
|
53
55
|
public addContracts = async (contractDeploymentDataBuffer: Buffer): Promise<void> => {
|
|
54
|
-
this.log.
|
|
56
|
+
this.log.trace(`Contract provider callback: addContracts`);
|
|
55
57
|
|
|
56
58
|
const rawData: any = deserializeFromMessagePack(contractDeploymentDataBuffer);
|
|
57
59
|
|
|
58
|
-
// Construct
|
|
59
|
-
const contractDeploymentData =
|
|
60
|
+
// Construct ContractDeploymentData from plain object.
|
|
61
|
+
const contractDeploymentData = ContractDeploymentData.fromPlainObject(rawData);
|
|
60
62
|
|
|
61
63
|
// Add contracts to the contracts DB
|
|
62
|
-
this.log.
|
|
64
|
+
this.log.trace(`Calling contractsDB.addContracts`);
|
|
63
65
|
await this.contractsDB.addContracts(contractDeploymentData);
|
|
64
66
|
};
|
|
65
67
|
|
|
66
68
|
public getBytecodeCommitment = async (classId: string): Promise<Buffer | undefined> => {
|
|
67
|
-
this.log.
|
|
69
|
+
this.log.trace(`Contract provider callback: getBytecodeCommitment(${classId})`);
|
|
68
70
|
|
|
69
71
|
// Parse classId string to Fr
|
|
70
72
|
const classIdFr = Fr.fromString(classId);
|
|
@@ -82,18 +84,23 @@ export class ContractProviderForCpp implements ContractProvider {
|
|
|
82
84
|
};
|
|
83
85
|
|
|
84
86
|
public getDebugFunctionName = async (address: string, selector: string): Promise<string | undefined> => {
|
|
85
|
-
this.log.
|
|
87
|
+
this.log.trace(`Contract provider callback: getDebugFunctionName(${address}, ${selector})`);
|
|
86
88
|
|
|
87
89
|
// Parse address and selector strings
|
|
88
90
|
const aztecAddr = AztecAddress.fromString(address);
|
|
89
91
|
const selectorFr = Fr.fromString(selector);
|
|
90
|
-
const functionSelector = FunctionSelector.
|
|
92
|
+
const functionSelector = FunctionSelector.fromFieldOrUndefined(selectorFr);
|
|
93
|
+
|
|
94
|
+
if (!functionSelector) {
|
|
95
|
+
this.log.trace(`calldata[0] is not a function selector: ${selector}`);
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
91
98
|
|
|
92
99
|
// Fetch debug function name from the contracts DB
|
|
93
100
|
const name = await this.contractsDB.getDebugFunctionName(aztecAddr, functionSelector);
|
|
94
101
|
|
|
95
102
|
if (!name) {
|
|
96
|
-
this.log.
|
|
103
|
+
this.log.trace(`Debug function name not found for ${address}:${selector}`);
|
|
97
104
|
return undefined;
|
|
98
105
|
}
|
|
99
106
|
|
|
@@ -101,62 +108,17 @@ export class ContractProviderForCpp implements ContractProvider {
|
|
|
101
108
|
};
|
|
102
109
|
|
|
103
110
|
public createCheckpoint = (): Promise<void> => {
|
|
104
|
-
this.log.
|
|
111
|
+
this.log.trace(`Contract provider callback: createCheckpoint`);
|
|
105
112
|
return Promise.resolve(this.contractsDB.createCheckpoint());
|
|
106
113
|
};
|
|
107
114
|
|
|
108
115
|
public commitCheckpoint = (): Promise<void> => {
|
|
109
|
-
this.log.
|
|
116
|
+
this.log.trace(`Contract provider callback: commitCheckpoint`);
|
|
110
117
|
return Promise.resolve(this.contractsDB.commitCheckpoint());
|
|
111
118
|
};
|
|
112
119
|
|
|
113
120
|
public revertCheckpoint = (): Promise<void> => {
|
|
114
|
-
this.log.
|
|
121
|
+
this.log.trace(`Contract provider callback: revertCheckpoint`);
|
|
115
122
|
return Promise.resolve(this.contractsDB.revertCheckpoint());
|
|
116
123
|
};
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Reconstruct ContractDeploymentData from plain msgpack-deserialized objects.
|
|
120
|
-
*
|
|
121
|
-
* msgpackr does not automatically apply extensions to nested fields, so we need to
|
|
122
|
-
* manually reconstruct ContractClassLog and PrivateLog instances with proper types.
|
|
123
|
-
*
|
|
124
|
-
* TODO(dbanks12): we really shouldn't have to do this.... We need to for now because
|
|
125
|
-
* msgpack deserialization doesn't give us actual typed objects, but rather just JSON.
|
|
126
|
-
* It would be easier if all types matched between languages (like AztecAddress which is just
|
|
127
|
-
* FF in C++).
|
|
128
|
-
*/
|
|
129
|
-
private reconstructContractDeploymentData(rawData: any): ContractDeploymentData {
|
|
130
|
-
// Helper to ensure a value is an Fr instance
|
|
131
|
-
const toFr = (value: any): Fr => {
|
|
132
|
-
if (value instanceof Fr) {
|
|
133
|
-
return value;
|
|
134
|
-
}
|
|
135
|
-
if (Buffer.isBuffer(value)) {
|
|
136
|
-
return Fr.fromBuffer(value);
|
|
137
|
-
}
|
|
138
|
-
return new Fr(value);
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
// Reconstruct ContractClassLogs
|
|
142
|
-
const contractClassLogs = (rawData.contractClassLogs || []).map((log: any) => {
|
|
143
|
-
// Convert contractAddress to TS AztecAddress
|
|
144
|
-
const addressFr = toFr(log.contractAddress);
|
|
145
|
-
const address = AztecAddress.fromField(addressFr);
|
|
146
|
-
|
|
147
|
-
// Ensure all fields are Fr instances
|
|
148
|
-
const fields = (log.fields.fields || []).map((field: any) => toFr(field));
|
|
149
|
-
|
|
150
|
-
// Create proper ContractClassLog instance
|
|
151
|
-
return new ContractClassLog(address, new ContractClassLogFields(fields), log.emittedLength);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
// Reconstruct PrivateLogs - ensure fields are Fr instances
|
|
155
|
-
const privateLogs = (rawData.privateLogs || []).map((log: any) => {
|
|
156
|
-
const fields = (log.fields || []).map((field: any) => toFr(field));
|
|
157
|
-
return new PrivateLog(fields as any, log.emittedLength);
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
return new ContractDeploymentData(contractClassLogs, privateLogs);
|
|
161
|
-
}
|
|
162
124
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { type Logger, createLogger, logLevel } from '@aztec/foundation/log';
|
|
2
|
-
import {
|
|
1
|
+
import { type Logger, type LoggerBindings, createLogger, logLevel } from '@aztec/foundation/log';
|
|
2
|
+
import { sleep } from '@aztec/foundation/sleep';
|
|
3
|
+
import { type CancellationToken, avmSimulate, cancelSimulation, createCancellationToken } from '@aztec/native';
|
|
3
4
|
import { ProtocolContractsList } from '@aztec/protocol-contracts';
|
|
4
5
|
import {
|
|
5
6
|
AvmFastSimulationInputs,
|
|
@@ -33,15 +34,20 @@ import type {
|
|
|
33
34
|
*/
|
|
34
35
|
export class CppPublicTxSimulator extends PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
35
36
|
protected override log: Logger;
|
|
37
|
+
/** Current cancellation token for in-flight simulation. */
|
|
38
|
+
private cancellationToken?: CancellationToken;
|
|
39
|
+
/** Current simulation promise, used to wait for completion after cancellation. */
|
|
40
|
+
private simulationPromise?: Promise<Buffer>;
|
|
36
41
|
|
|
37
42
|
constructor(
|
|
38
43
|
merkleTree: MerkleTreeWriteOperations,
|
|
39
44
|
contractsDB: PublicContractsDB,
|
|
40
45
|
globalVariables: GlobalVariables,
|
|
41
46
|
config?: Partial<PublicSimulatorConfig>,
|
|
47
|
+
bindings?: LoggerBindings,
|
|
42
48
|
) {
|
|
43
|
-
super(merkleTree, contractsDB, globalVariables, config);
|
|
44
|
-
this.log = createLogger(`simulator:cpp_public_tx_simulator
|
|
49
|
+
super(merkleTree, contractsDB, globalVariables, config, undefined, bindings);
|
|
50
|
+
this.log = createLogger(`simulator:cpp_public_tx_simulator`, bindings);
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
/**
|
|
@@ -79,18 +85,39 @@ export class CppPublicTxSimulator extends PublicTxSimulator implements PublicTxS
|
|
|
79
85
|
);
|
|
80
86
|
|
|
81
87
|
// Create contract provider for callbacks to TypeScript PublicContractsDB from C++
|
|
82
|
-
const contractProvider = new ContractProviderForCpp(this.contractsDB, this.globalVariables);
|
|
88
|
+
const contractProvider = new ContractProviderForCpp(this.contractsDB, this.globalVariables, this.bindings);
|
|
83
89
|
|
|
84
90
|
// Serialize to msgpack and call the C++ simulator
|
|
85
91
|
this.log.trace(`Serializing fast simulation inputs to msgpack...`);
|
|
86
92
|
const inputBuffer = fastSimInputs.serializeWithMessagePack();
|
|
87
93
|
|
|
94
|
+
// Create cancellation token for this simulation
|
|
95
|
+
this.cancellationToken = createCancellationToken();
|
|
96
|
+
|
|
97
|
+
// Store the promise so cancel() can wait for it
|
|
98
|
+
this.log.debug(`Calling C++ simulator for tx ${txHash}`);
|
|
99
|
+
this.simulationPromise = avmSimulate(
|
|
100
|
+
inputBuffer,
|
|
101
|
+
contractProvider,
|
|
102
|
+
wsCppHandle,
|
|
103
|
+
logLevel,
|
|
104
|
+
// TODO: re-enable logging
|
|
105
|
+
undefined,
|
|
106
|
+
this.cancellationToken,
|
|
107
|
+
);
|
|
108
|
+
|
|
88
109
|
let resultBuffer: Buffer;
|
|
89
110
|
try {
|
|
90
|
-
|
|
91
|
-
resultBuffer = await avmSimulate(inputBuffer, contractProvider, wsCppHandle, logLevel);
|
|
111
|
+
resultBuffer = await this.simulationPromise;
|
|
92
112
|
} catch (error: any) {
|
|
113
|
+
// Check if this was a cancellation
|
|
114
|
+
if (error.message?.includes('Simulation cancelled')) {
|
|
115
|
+
throw new SimulationError(`C++ simulation cancelled`, []);
|
|
116
|
+
}
|
|
93
117
|
throw new SimulationError(`C++ simulation failed: ${error.message}`, []);
|
|
118
|
+
} finally {
|
|
119
|
+
this.cancellationToken = undefined;
|
|
120
|
+
this.simulationPromise = undefined;
|
|
94
121
|
}
|
|
95
122
|
|
|
96
123
|
// If we've reached this point, C++ succeeded during simulation,
|
|
@@ -109,6 +136,33 @@ export class CppPublicTxSimulator extends PublicTxSimulator implements PublicTxS
|
|
|
109
136
|
|
|
110
137
|
return cppResult;
|
|
111
138
|
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Cancel the current simulation if one is in progress.
|
|
142
|
+
* This signals the C++ simulator to stop at the next opcode or before the next WorldState write.
|
|
143
|
+
* Safe to call even if no simulation is in progress.
|
|
144
|
+
*
|
|
145
|
+
* @param waitTimeoutMs - If provided, wait up to this many ms for the simulation to actually stop.
|
|
146
|
+
* This is important because C++ might be in the middle of a slow operation
|
|
147
|
+
* (e.g., pad_trees) and won't check the cancellation flag until it completes.
|
|
148
|
+
* Default timeout of 100ms after cancellation.
|
|
149
|
+
*/
|
|
150
|
+
public async cancel(waitTimeoutMs: number = 100): Promise<void> {
|
|
151
|
+
if (this.cancellationToken) {
|
|
152
|
+
this.log.debug('Cancelling C++ simulation');
|
|
153
|
+
cancelSimulation(this.cancellationToken);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Wait for the simulation to actually complete if not already done
|
|
157
|
+
if (this.simulationPromise) {
|
|
158
|
+
this.log.debug(`Waiting up to ${waitTimeoutMs}ms for C++ simulation to stop`);
|
|
159
|
+
await Promise.race([
|
|
160
|
+
this.simulationPromise.catch(() => {}), // Ignore rejection, just wait for completion
|
|
161
|
+
sleep(waitTimeoutMs),
|
|
162
|
+
]);
|
|
163
|
+
this.log.debug('C++ simulation stopped or wait timed out');
|
|
164
|
+
}
|
|
165
|
+
}
|
|
112
166
|
}
|
|
113
167
|
|
|
114
168
|
export class MeasuredCppPublicTxSimulator extends CppPublicTxSimulator implements MeasuredPublicTxSimulatorInterface {
|
|
@@ -118,8 +172,9 @@ export class MeasuredCppPublicTxSimulator extends CppPublicTxSimulator implement
|
|
|
118
172
|
globalVariables: GlobalVariables,
|
|
119
173
|
protected readonly metrics: ExecutorMetricsInterface,
|
|
120
174
|
config?: Partial<PublicSimulatorConfig>,
|
|
175
|
+
bindings?: LoggerBindings,
|
|
121
176
|
) {
|
|
122
|
-
super(merkleTree, contractsDB, globalVariables, config);
|
|
177
|
+
super(merkleTree, contractsDB, globalVariables, config, bindings);
|
|
123
178
|
}
|
|
124
179
|
|
|
125
180
|
public override async simulate(tx: Tx, txLabel: string = 'unlabeledTx'): Promise<PublicTxResult> {
|
|
@@ -147,9 +202,10 @@ export class TelemetryCppPublicTxSimulator extends MeasuredCppPublicTxSimulator
|
|
|
147
202
|
globalVariables: GlobalVariables,
|
|
148
203
|
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
149
204
|
config?: Partial<PublicSimulatorConfig>,
|
|
205
|
+
bindings?: LoggerBindings,
|
|
150
206
|
) {
|
|
151
207
|
const metrics = new ExecutorMetrics(telemetryClient, 'CppPublicTxSimulator');
|
|
152
|
-
super(merkleTree, contractsDB, globalVariables, metrics, config);
|
|
208
|
+
super(merkleTree, contractsDB, globalVariables, metrics, config, bindings);
|
|
153
209
|
this.tracer = metrics.tracer;
|
|
154
210
|
}
|
|
155
211
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Logger, createLogger, logLevel } from '@aztec/foundation/log';
|
|
1
|
+
import { type Logger, type LoggerBindings, createLogger, logLevel } from '@aztec/foundation/log';
|
|
2
2
|
import { avmSimulateWithHintedDbs } from '@aztec/native';
|
|
3
3
|
import {
|
|
4
4
|
AvmCircuitInputs,
|
|
@@ -34,9 +34,10 @@ export class CppPublicTxSimulatorHintedDbs extends PublicTxSimulator implements
|
|
|
34
34
|
contractsDB: PublicContractsDB,
|
|
35
35
|
globalVariables: GlobalVariables,
|
|
36
36
|
config?: Partial<PublicSimulatorConfig>,
|
|
37
|
+
bindings?: LoggerBindings,
|
|
37
38
|
) {
|
|
38
|
-
super(merkleTree, contractsDB, globalVariables, config);
|
|
39
|
-
this.log = createLogger(`simulator:cpp_public_tx_simulator_hinted_dbs
|
|
39
|
+
super(merkleTree, contractsDB, globalVariables, config, undefined, bindings);
|
|
40
|
+
this.log = createLogger(`simulator:cpp_public_tx_simulator_hinted_dbs`, bindings);
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
/**
|
|
@@ -64,7 +65,7 @@ export class CppPublicTxSimulatorHintedDbs extends PublicTxSimulator implements
|
|
|
64
65
|
this.log.debug(`TS simulation succeeded for tx ${txHash}`);
|
|
65
66
|
|
|
66
67
|
// Extract the full AvmCircuitInputs from the TS result
|
|
67
|
-
const avmCircuitInputs = new AvmCircuitInputs(tsResult.hints!, tsResult.publicInputs);
|
|
68
|
+
const avmCircuitInputs = new AvmCircuitInputs(tsResult.hints!, tsResult.publicInputs!);
|
|
68
69
|
|
|
69
70
|
// Second, run C++ simulation with hinted DBs
|
|
70
71
|
this.log.debug(`Running C++ simulation with hinted DBs for tx ${txHash}`);
|
|
@@ -115,8 +116,9 @@ export class MeasuredCppPublicTxSimulatorHintedDbs
|
|
|
115
116
|
globalVariables: GlobalVariables,
|
|
116
117
|
protected readonly metrics: ExecutorMetricsInterface,
|
|
117
118
|
config?: Partial<PublicSimulatorConfig>,
|
|
119
|
+
bindings?: LoggerBindings,
|
|
118
120
|
) {
|
|
119
|
-
super(merkleTree, contractsDB, globalVariables, config);
|
|
121
|
+
super(merkleTree, contractsDB, globalVariables, config, bindings);
|
|
120
122
|
}
|
|
121
123
|
|
|
122
124
|
public override async simulate(tx: Tx, txLabel: string = 'unlabeledTx'): Promise<PublicTxResult> {
|