@aztec/simulator 3.0.0-devnet.2 → 3.0.0-devnet.2-patch.1
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/dest/client.d.ts +1 -1
- package/dest/common/errors.d.ts +2 -8
- 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 +1 -1
- 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 +1 -1
- package/dest/private/acvm_native.d.ts.map +1 -1
- package/dest/private/acvm_native.js +15 -13
- package/dest/private/acvm_wasm.d.ts +1 -1
- package/dest/private/acvm_wasm.d.ts.map +1 -1
- 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 +1 -1
- package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/circuit_recorder.js +1 -1
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts +1 -1
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +1 -1
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
- 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 +1 -1
- package/dest/public/avm/avm_context.d.ts +2 -2
- package/dest/public/avm/avm_context.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.d.ts +2 -2
- package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
- package/dest/public/avm/avm_execution_environment.d.ts +5 -5
- package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/public/avm/avm_execution_environment.js +5 -8
- package/dest/public/avm/avm_gas.d.ts +2 -2
- package/dest/public/avm/avm_gas.d.ts.map +1 -1
- package/dest/public/avm/avm_machine_state.d.ts +2 -2
- package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/public/avm/avm_memory_types.d.ts +14 -14
- package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/public/avm/avm_memory_types.js +1 -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 +8 -7
- package/dest/public/avm/avm_simulator_interface.d.ts +1 -1
- package/dest/public/avm/errors.d.ts +8 -2
- package/dest/public/avm/errors.d.ts.map +1 -1
- package/dest/public/avm/errors.js +14 -2
- 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 +12 -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 -3
- package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
- package/dest/public/avm/fixtures/initializers.js +7 -5
- package/dest/public/avm/fixtures/utils.d.ts +4 -3
- package/dest/public/avm/fixtures/utils.d.ts.map +1 -1
- package/dest/public/avm/fixtures/utils.js +3 -2
- package/dest/public/avm/index.d.ts +1 -1
- package/dest/public/avm/opcodes/accrued_substate.d.ts +1 -1
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/addressing_mode.d.ts +1 -1
- package/dest/public/avm/opcodes/addressing_mode.d.ts.map +1 -1
- package/dest/public/avm/opcodes/addressing_mode.js +2 -2
- 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 +11 -1
- package/dest/public/avm/opcodes/bitwise.d.ts +5 -5
- package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
- 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/contract.d.ts +1 -1
- package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/public/avm/opcodes/control_flow.d.ts +1 -1
- package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
- package/dest/public/avm/opcodes/conversion.d.ts +1 -1
- package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/public/avm/opcodes/ec_add.d.ts +2 -2
- package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/public/avm/opcodes/ec_add.js +3 -4
- package/dest/public/avm/opcodes/environment_getters.d.ts +1 -1
- package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.d.ts +1 -1
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.js +0 -1
- package/dest/public/avm/opcodes/hashing.d.ts +2 -2
- package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/public/avm/opcodes/hashing.js +3 -1
- package/dest/public/avm/opcodes/index.d.ts +1 -1
- package/dest/public/avm/opcodes/instruction.d.ts +2 -2
- package/dest/public/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/public/avm/opcodes/instruction_impl.d.ts +1 -1
- package/dest/public/avm/opcodes/instruction_impl.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.d.ts +2 -2
- package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.js +1 -1
- package/dest/public/avm/opcodes/misc.d.ts +1 -1
- 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 +3 -3
- package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
- 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/revert_reason.js +3 -2
- package/dest/public/avm/serialization/buffer_cursor.d.ts +1 -1
- package/dest/public/avm/serialization/buffer_cursor.d.ts.map +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.d.ts +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.js +9 -6
- package/dest/public/avm/serialization/instruction_serialization.d.ts +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 +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/debug_fn_name.d.ts +15 -2
- package/dest/public/debug_fn_name.d.ts.map +1 -1
- package/dest/public/debug_fn_name.js +19 -0
- 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 +1 -1
- 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 +2 -2
- package/dest/public/fixtures/bulk_test.d.ts +1 -1
- package/dest/public/fixtures/bulk_test.js +1 -1
- package/dest/public/fixtures/custom_bytecode_tester.d.ts +2 -2
- package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
- package/dest/public/fixtures/custom_bytecode_tests.d.ts +2 -1
- package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
- package/dest/public/fixtures/custom_bytecode_tests.js +21 -0
- package/dest/public/fixtures/index.d.ts +1 -1
- package/dest/public/fixtures/minimal_public_tx.d.ts +2 -3
- package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -1
- package/dest/public/fixtures/minimal_public_tx.js +2 -2
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +10 -5
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +28 -14
- 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 +4 -4
- 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 +2 -2
- package/dest/public/fixtures/utils.d.ts.map +1 -1
- package/dest/public/fixtures/utils.js +4 -4
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +46 -0
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -0
- package/dest/public/fuzzing/avm_fuzzer_simulator.js +136 -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 +84 -0
- package/dest/public/hinting_db_sources.d.ts +13 -4
- package/dest/public/hinting_db_sources.d.ts.map +1 -1
- package/dest/public/hinting_db_sources.js +66 -13
- 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 +22 -63
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +74 -131
- 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 +5 -4
- package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.d.ts +11 -18
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +37 -36
- package/dest/public/public_processor/public_processor_metrics.d.ts +1 -1
- package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +18 -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 +94 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +19 -22
- 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 +54 -50
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +42 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +86 -0
- package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +30 -0
- package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +170 -0
- package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +22 -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 +13 -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 -1
- package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/index.js +3 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +14 -7
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +5 -5
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +6 -3
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +13 -5
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +11 -31
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +109 -126
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +2 -2
- 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 +4 -4
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.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/side_effect_trace.d.ts +2 -3
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +1 -1
- package/dest/public/side_effect_trace_interface.d.ts +3 -4
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/dest/public/state_manager/index.d.ts +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 +9 -11
- package/dest/public/state_manager/state_manager.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.js +10 -6
- package/dest/public/test_executor_metrics.d.ts +4 -3
- package/dest/public/test_executor_metrics.d.ts.map +1 -1
- package/dest/public/test_executor_metrics.js +5 -4
- 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 +21 -20
- package/src/common/errors.ts +1 -1
- package/src/private/acvm/deserialize.ts +1 -1
- package/src/private/acvm/serialize.ts +1 -1
- package/src/private/acvm_native.ts +17 -9
- package/src/private/circuit_recording/circuit_recorder.ts +1 -1
- package/src/public/avm/avm_context.ts +1 -1
- package/src/public/avm/avm_contract_call_result.ts +1 -1
- package/src/public/avm/avm_execution_environment.ts +4 -6
- package/src/public/avm/avm_gas.ts +3 -3
- package/src/public/avm/avm_machine_state.ts +1 -1
- package/src/public/avm/avm_memory_types.ts +1 -1
- package/src/public/avm/avm_simulator.ts +11 -9
- package/src/public/avm/errors.ts +17 -3
- package/src/public/avm/fixtures/avm_simulation_tester.ts +10 -2
- package/src/public/avm/fixtures/base_avm_simulation_tester.ts +1 -1
- package/src/public/avm/fixtures/initializers.ts +8 -10
- package/src/public/avm/fixtures/utils.ts +3 -2
- package/src/public/avm/opcodes/addressing_mode.ts +2 -2
- package/src/public/avm/opcodes/arithmetic.ts +13 -1
- package/src/public/avm/opcodes/ec_add.ts +3 -4
- package/src/public/avm/opcodes/external_calls.ts +0 -1
- package/src/public/avm/opcodes/hashing.ts +3 -1
- package/src/public/avm/opcodes/memory.ts +1 -1
- package/src/public/avm/opcodes/misc.ts +4 -4
- package/src/public/avm/revert_reason.ts +6 -3
- package/src/public/avm/serialization/bytecode_serialization.ts +17 -6
- 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 +41 -0
- package/src/public/db_interfaces.ts +16 -1
- package/src/public/debug_fn_name.ts +26 -1
- package/src/public/executor_metrics.ts +2 -1
- package/src/public/executor_metrics_interface.ts +2 -1
- package/src/public/fixtures/amm_test.ts +2 -2
- package/src/public/fixtures/bulk_test.ts +1 -1
- package/src/public/fixtures/custom_bytecode_tester.ts +1 -1
- package/src/public/fixtures/custom_bytecode_tests.ts +24 -0
- package/src/public/fixtures/minimal_public_tx.ts +3 -4
- package/src/public/fixtures/public_tx_simulation_tester.ts +47 -16
- package/src/public/fixtures/simple_contract_data_source.ts +8 -9
- package/src/public/fixtures/token_test.ts +18 -10
- package/src/public/fixtures/utils.ts +4 -4
- package/src/public/fuzzing/avm_fuzzer_simulator.ts +233 -0
- package/src/public/fuzzing/avm_simulator_bin.ts +121 -0
- package/src/public/hinting_db_sources.ts +108 -10
- package/src/public/index.ts +6 -4
- package/src/public/public_db_sources.ts +93 -172
- package/src/public/public_processor/guarded_merkle_tree.ts +4 -3
- package/src/public/public_processor/public_processor.ts +63 -48
- package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +116 -0
- package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +84 -57
- package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +132 -0
- package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +236 -0
- package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +81 -0
- package/src/public/public_tx_simulator/factories.ts +41 -0
- package/src/public/public_tx_simulator/index.ts +4 -0
- package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +10 -14
- package/src/public/public_tx_simulator/public_tx_context.ts +9 -3
- package/src/public/public_tx_simulator/public_tx_simulator.ts +161 -193
- package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +1 -2
- package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +3 -3
- package/src/public/side_effect_trace.ts +1 -1
- 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 +14 -14
- package/src/public/test_executor_metrics.ts +7 -5
- 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/tx_contract_cache.ts +0 -69
|
@@ -1,20 +1,11 @@
|
|
|
1
|
-
import { AVM_MAX_PROCESSABLE_L2_GAS
|
|
2
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { AVM_MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { ProtocolContractAddress, ProtocolContractsList } from '@aztec/protocol-contracts';
|
|
5
5
|
import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
6
|
-
import {
|
|
7
|
-
AvmCircuitInputs,
|
|
8
|
-
AvmCircuitPublicInputs,
|
|
9
|
-
AvmExecutionHints,
|
|
10
|
-
type AvmProvingRequest,
|
|
11
|
-
AvmTxHint,
|
|
12
|
-
type RevertCode,
|
|
13
|
-
} from '@aztec/stdlib/avm';
|
|
6
|
+
import { AvmExecutionHints, AvmTxHint, PublicSimulatorConfig, PublicTxEffect, PublicTxResult } from '@aztec/stdlib/avm';
|
|
14
7
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
15
|
-
import
|
|
16
|
-
import type { DebugLog } from '@aztec/stdlib/logs';
|
|
17
|
-
import { ProvingRequestType } from '@aztec/stdlib/proofs';
|
|
8
|
+
import { Gas } from '@aztec/stdlib/gas';
|
|
18
9
|
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
19
10
|
import {
|
|
20
11
|
type GlobalVariables,
|
|
@@ -41,33 +32,6 @@ import type { PublicPersistableStateManager } from '../state_manager/state_manag
|
|
|
41
32
|
import { PublicTxContext } from './public_tx_context.js';
|
|
42
33
|
import type { PublicTxSimulatorInterface } from './public_tx_simulator_interface.js';
|
|
43
34
|
|
|
44
|
-
export type ProcessedPhase = {
|
|
45
|
-
phase: TxExecutionPhase;
|
|
46
|
-
durationMs?: number;
|
|
47
|
-
returnValues: NestedProcessReturnValues[];
|
|
48
|
-
reverted: boolean;
|
|
49
|
-
revertReason?: SimulationError;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export type PublicTxResult = {
|
|
53
|
-
avmProvingRequest: AvmProvingRequest;
|
|
54
|
-
/** Gas used during the execution of this tx */
|
|
55
|
-
gasUsed: GasUsed;
|
|
56
|
-
revertCode: RevertCode;
|
|
57
|
-
/** Revert reason, if any */
|
|
58
|
-
revertReason?: SimulationError;
|
|
59
|
-
processedPhases: ProcessedPhase[];
|
|
60
|
-
logs: DebugLog[];
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export type PublicTxSimulatorConfig = {
|
|
64
|
-
proverId: Fr;
|
|
65
|
-
doMerkleOperations: boolean;
|
|
66
|
-
skipFeeEnforcement: boolean;
|
|
67
|
-
clientInitiatedSimulation: boolean;
|
|
68
|
-
maxDebugLogMemoryReads: number;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
35
|
// The errors below are only thrown here in the public tx simulator,
|
|
72
36
|
// and only during revertible phases (revertible insertions, app logic and teardown).
|
|
73
37
|
// These are strictly "checked" errors (not exported and never propagated).
|
|
@@ -103,23 +67,26 @@ class TxSimTeardownRevert extends Error {
|
|
|
103
67
|
}
|
|
104
68
|
}
|
|
105
69
|
|
|
70
|
+
/** Only used internally. */
|
|
71
|
+
type ProcessedPhase = {
|
|
72
|
+
phase: TxExecutionPhase;
|
|
73
|
+
durationMs?: number;
|
|
74
|
+
returnValues: NestedProcessReturnValues[];
|
|
75
|
+
reverted: boolean;
|
|
76
|
+
revertReason?: SimulationError;
|
|
77
|
+
};
|
|
78
|
+
|
|
106
79
|
export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
107
80
|
protected log: Logger;
|
|
108
|
-
|
|
81
|
+
protected readonly config: PublicSimulatorConfig;
|
|
109
82
|
|
|
110
83
|
constructor(
|
|
111
84
|
protected merkleTree: MerkleTreeWriteOperations,
|
|
112
85
|
protected contractsDB: PublicContractsDB,
|
|
113
86
|
protected globalVariables: GlobalVariables,
|
|
114
|
-
config?: Partial<
|
|
87
|
+
config?: Partial<PublicSimulatorConfig>,
|
|
115
88
|
) {
|
|
116
|
-
this.config = {
|
|
117
|
-
proverId: config?.proverId ?? Fr.ZERO,
|
|
118
|
-
doMerkleOperations: config?.doMerkleOperations ?? false,
|
|
119
|
-
skipFeeEnforcement: config?.skipFeeEnforcement ?? false,
|
|
120
|
-
clientInitiatedSimulation: config?.clientInitiatedSimulation ?? false,
|
|
121
|
-
maxDebugLogMemoryReads: config?.maxDebugLogMemoryReads ?? DEFAULT_MAX_DEBUG_LOG_MEMORY_READS,
|
|
122
|
-
};
|
|
89
|
+
this.config = PublicSimulatorConfig.from(config ?? {});
|
|
123
90
|
this.log = createLogger(`simulator:public_tx_simulator`);
|
|
124
91
|
}
|
|
125
92
|
|
|
@@ -129,136 +96,143 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
129
96
|
* @returns The result of the transaction's public execution.
|
|
130
97
|
*/
|
|
131
98
|
public async simulate(tx: Tx): Promise<PublicTxResult> {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
this.log.debug(`Simulating ${tx.publicFunctionCalldata.length} public calls for tx ${txHash}`, { txHash });
|
|
135
|
-
|
|
136
|
-
// Create hinting DBs.
|
|
137
|
-
const hints = new AvmExecutionHints(
|
|
138
|
-
this.globalVariables,
|
|
139
|
-
AvmTxHint.fromTx(tx, this.globalVariables.gasFees),
|
|
140
|
-
ProtocolContractsList, // imported from file
|
|
141
|
-
);
|
|
142
|
-
const hintingMerkleTree = await HintingMerkleWriteOperations.create(this.merkleTree, hints);
|
|
143
|
-
const hintingTreesDB = new PublicTreesDB(hintingMerkleTree);
|
|
144
|
-
const hintingContractsDB = new HintingPublicContractsDB(this.contractsDB, hints);
|
|
145
|
-
|
|
146
|
-
const context = await PublicTxContext.create(
|
|
147
|
-
hintingTreesDB,
|
|
148
|
-
hintingContractsDB,
|
|
149
|
-
tx,
|
|
150
|
-
this.globalVariables,
|
|
151
|
-
ProtocolContractsList, // imported from file
|
|
152
|
-
this.config.doMerkleOperations,
|
|
153
|
-
this.config.proverId,
|
|
154
|
-
);
|
|
99
|
+
const txHash = this.computeTxHash(tx);
|
|
100
|
+
this.log.debug(`Simulating ${tx.publicFunctionCalldata.length} public calls for tx ${txHash}`, { txHash });
|
|
155
101
|
|
|
156
|
-
|
|
102
|
+
// Create hinting DBs.
|
|
103
|
+
const hints = new AvmExecutionHints(
|
|
104
|
+
this.globalVariables,
|
|
105
|
+
AvmTxHint.fromTx(tx, this.globalVariables.gasFees),
|
|
106
|
+
ProtocolContractsList, // imported from file
|
|
107
|
+
);
|
|
108
|
+
const hintingMerkleTree = await HintingMerkleWriteOperations.create(this.merkleTree, hints);
|
|
109
|
+
const hintingTreesDB = new PublicTreesDB(hintingMerkleTree);
|
|
110
|
+
const hintingContractsDB = new HintingPublicContractsDB(this.contractsDB, hints);
|
|
111
|
+
|
|
112
|
+
const context = await PublicTxContext.create(
|
|
113
|
+
hintingTreesDB,
|
|
114
|
+
hintingContractsDB,
|
|
115
|
+
tx,
|
|
116
|
+
this.globalVariables,
|
|
117
|
+
ProtocolContractsList, // imported from file
|
|
118
|
+
this.config.proverId,
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
// This will throw if there is a nullifier collision.
|
|
122
|
+
// In that case the transaction will be thrown out.
|
|
123
|
+
await this.insertNonRevertiblesFromPrivate(context);
|
|
124
|
+
|
|
125
|
+
const processedPhases: ProcessedPhase[] = [];
|
|
126
|
+
if (context.hasPhase(TxExecutionPhase.SETUP)) {
|
|
127
|
+
// This will throw if the setup phase reverts.
|
|
157
128
|
// In that case the transaction will be thrown out.
|
|
158
|
-
await this.
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
// In that case the transaction will be thrown out.
|
|
164
|
-
const setupResult = await this.simulatePhase(TxExecutionPhase.SETUP, context);
|
|
165
|
-
if (setupResult.reverted) {
|
|
166
|
-
throw new Error(
|
|
167
|
-
`Setup phase reverted! The transaction will be thrown out. ${setupResult.revertReason?.message}`,
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
processedPhases.push(setupResult);
|
|
129
|
+
const setupResult = await this.simulatePhase(TxExecutionPhase.SETUP, context);
|
|
130
|
+
if (setupResult.reverted) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
`[SETUP] UNRECOVERABLE ERROR! The transaction will be thrown out. ${setupResult.revertReason?.message}`,
|
|
133
|
+
);
|
|
171
134
|
}
|
|
135
|
+
processedPhases.push(setupResult);
|
|
136
|
+
}
|
|
172
137
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
try {
|
|
177
|
-
// This will throw if there is a nullifier collision or other insertion error (limit reached).
|
|
178
|
-
await this.insertRevertiblesFromPrivate(context, tx);
|
|
138
|
+
// The checkpoint we should go back to if anything from now on reverts.
|
|
139
|
+
await context.state.fork();
|
|
140
|
+
hintingContractsDB.createCheckpoint();
|
|
179
141
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
// We revert to the post-setup state.
|
|
191
|
-
await context.state.discardForkedState();
|
|
192
|
-
// But we also create a new fork so that the teardown phase can transparently
|
|
193
|
-
// commit or rollback at the end of teardown.
|
|
194
|
-
await context.state.fork();
|
|
195
|
-
} else {
|
|
196
|
-
// Unchecked/unknown error - re-throw as-is
|
|
197
|
-
throw e;
|
|
142
|
+
try {
|
|
143
|
+
// This will throw if there is a nullifier collision or other insertion error (limit reached).
|
|
144
|
+
await this.insertRevertiblesFromPrivate(context);
|
|
145
|
+
|
|
146
|
+
// Only proceed with app logic if there was no revert during revertible insertion.
|
|
147
|
+
if (context.hasPhase(TxExecutionPhase.APP_LOGIC)) {
|
|
148
|
+
const appLogicResult = await this.simulatePhase(TxExecutionPhase.APP_LOGIC, context);
|
|
149
|
+
processedPhases.push(appLogicResult);
|
|
150
|
+
if (appLogicResult.reverted) {
|
|
151
|
+
throw new TxSimAppLogicRevert();
|
|
198
152
|
}
|
|
199
153
|
}
|
|
154
|
+
} catch (e: any) {
|
|
155
|
+
if (e instanceof TxSimRevertibleInsertionsRevert || e instanceof TxSimAppLogicRevert) {
|
|
156
|
+
// We revert to the post-setup state.
|
|
157
|
+
await context.state.discardForkedState();
|
|
158
|
+
hintingContractsDB.revertCheckpoint();
|
|
159
|
+
// But we also create a new fork so that the teardown phase can transparently
|
|
160
|
+
// commit or rollback at the end of teardown.
|
|
161
|
+
await context.state.fork();
|
|
162
|
+
hintingContractsDB.createCheckpoint();
|
|
163
|
+
} else {
|
|
164
|
+
// Unchecked/unknown error - re-throw as-is
|
|
165
|
+
throw e;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
200
168
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
// We commit the forked state and we are done.
|
|
210
|
-
await context.state.mergeForkedState();
|
|
211
|
-
} catch (e: any) {
|
|
212
|
-
if (e instanceof TxSimTeardownRevert) {
|
|
213
|
-
// We revert to the post-setup state and we are done.
|
|
214
|
-
await context.state.discardForkedState();
|
|
215
|
-
} else {
|
|
216
|
-
// Unchecked/unknown error - re-throw as-is
|
|
217
|
-
throw e;
|
|
169
|
+
try {
|
|
170
|
+
if (context.hasPhase(TxExecutionPhase.TEARDOWN)) {
|
|
171
|
+
const teardownResult = await this.simulatePhase(TxExecutionPhase.TEARDOWN, context);
|
|
172
|
+
processedPhases.push(teardownResult);
|
|
173
|
+
if (teardownResult.reverted) {
|
|
174
|
+
throw new TxSimTeardownRevert();
|
|
218
175
|
}
|
|
219
176
|
}
|
|
177
|
+
// We commit the forked state and we are done.
|
|
178
|
+
await context.state.mergeForkedState();
|
|
179
|
+
hintingContractsDB.commitCheckpoint();
|
|
180
|
+
} catch (e: any) {
|
|
181
|
+
if (e instanceof TxSimTeardownRevert) {
|
|
182
|
+
// We revert to the post-setup state and we are done.
|
|
183
|
+
await context.state.discardForkedState();
|
|
184
|
+
hintingContractsDB.revertCheckpoint();
|
|
185
|
+
} else {
|
|
186
|
+
// Unchecked/unknown error - re-throw as-is
|
|
187
|
+
throw e;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
220
190
|
|
|
221
|
-
|
|
191
|
+
context.halt();
|
|
222
192
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
this.contractsDB.commitContractsForTx(/*onlyNonRevertibles=*/ !revertCode.isOK());
|
|
241
|
-
|
|
242
|
-
return {
|
|
243
|
-
avmProvingRequest,
|
|
244
|
-
gasUsed: {
|
|
245
|
-
totalGas: context.getActualGasUsed(),
|
|
246
|
-
teardownGas: context.teardownGasUsed,
|
|
247
|
-
publicGas: context.getActualPublicGasUsed(),
|
|
248
|
-
billedGas: context.getTotalGasUsed(),
|
|
249
|
-
},
|
|
250
|
-
revertCode,
|
|
251
|
-
revertReason: context.revertReason,
|
|
252
|
-
processedPhases: processedPhases,
|
|
253
|
-
logs: context.state.getActiveStateManager().getLogs(),
|
|
254
|
-
};
|
|
255
|
-
} finally {
|
|
256
|
-
// Make sure there are no new contracts in the tx-level cache.
|
|
257
|
-
// They should either be committed to block-level cache or cleared.
|
|
258
|
-
// FIXME(fcarreiro): this should conceptually use the hinted contracts db.
|
|
259
|
-
// However things should work as they are now because the hinted db would still pick up the new contracts.
|
|
260
|
-
this.contractsDB.clearContractsForTx();
|
|
193
|
+
// Such transactions should be filtered by GasTxValidator.
|
|
194
|
+
assert(
|
|
195
|
+
context.getActualGasUsed().l2Gas <= AVM_MAX_PROCESSABLE_L2_GAS,
|
|
196
|
+
`Transaction consumes ${context.getActualGasUsed().l2Gas} L2 gas, which exceeds the AVM maximum processable gas of ${AVM_MAX_PROCESSABLE_L2_GAS}`,
|
|
197
|
+
);
|
|
198
|
+
await this.payFee(context);
|
|
199
|
+
|
|
200
|
+
const publicInputs = await context.generateAvmCircuitPublicInputs();
|
|
201
|
+
const revertCode = context.getFinalRevertCode();
|
|
202
|
+
|
|
203
|
+
// We only return the app logic phase information, and only 1 per phase.
|
|
204
|
+
const appLogicReturnValues: NestedProcessReturnValues[] =
|
|
205
|
+
processedPhases.find(({ phase }) => phase === TxExecutionPhase.APP_LOGIC)?.returnValues ?? [];
|
|
206
|
+
|
|
207
|
+
// TODO(fcarreiro): This is a temporary backwards compatibility layer until we migrate to the C++ simulator.
|
|
208
|
+
if (context.revertReason !== undefined) {
|
|
209
|
+
(appLogicReturnValues as any).revertReason = context.revertReason;
|
|
261
210
|
}
|
|
211
|
+
|
|
212
|
+
// Create PublicTxEffect from PublicInputs.
|
|
213
|
+
const publicTxEffect = new PublicTxEffect(
|
|
214
|
+
publicInputs.transactionFee,
|
|
215
|
+
publicInputs.accumulatedData.noteHashes.filter(h => !h.isEmpty()),
|
|
216
|
+
publicInputs.accumulatedData.nullifiers.filter(n => !n.isEmpty()),
|
|
217
|
+
publicInputs.accumulatedData.l2ToL1Msgs.filter(m => !m.isEmpty()),
|
|
218
|
+
publicInputs.accumulatedData.publicLogs.toLogs(),
|
|
219
|
+
publicInputs.accumulatedData.publicDataWrites.filter(w => !w.isEmpty()),
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
return new PublicTxResult(
|
|
223
|
+
/*gasUsed=*/ {
|
|
224
|
+
totalGas: context.getActualGasUsed(),
|
|
225
|
+
teardownGas: context.teardownGasUsed,
|
|
226
|
+
publicGas: context.getActualPublicGasUsed(),
|
|
227
|
+
billedGas: context.getTotalGasUsed(),
|
|
228
|
+
},
|
|
229
|
+
/*revertCode=*/ revertCode,
|
|
230
|
+
/*publicTxEffect=*/ publicTxEffect,
|
|
231
|
+
/*callStackMetadata=*/ appLogicReturnValues,
|
|
232
|
+
/*logs=*/ context.state.getActiveStateManager().getLogs(),
|
|
233
|
+
/*hints=*/ hints,
|
|
234
|
+
/*publicInputs=*/ publicInputs,
|
|
235
|
+
);
|
|
262
236
|
}
|
|
263
237
|
|
|
264
238
|
protected computeTxHash(tx: Tx) {
|
|
@@ -340,7 +314,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
340
314
|
);
|
|
341
315
|
|
|
342
316
|
if (result.reverted) {
|
|
343
|
-
const culprit = `${contractAddress}:${
|
|
317
|
+
const culprit = `${contractAddress}:${fnName}`;
|
|
344
318
|
context.revert(phase, result.revertReason, culprit);
|
|
345
319
|
}
|
|
346
320
|
|
|
@@ -383,8 +357,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
383
357
|
request.isStaticCall,
|
|
384
358
|
calldata,
|
|
385
359
|
allocatedGas,
|
|
386
|
-
this.config
|
|
387
|
-
this.config.maxDebugLogMemoryReads,
|
|
360
|
+
this.config,
|
|
388
361
|
);
|
|
389
362
|
const avmCallResult = await simulator.execute();
|
|
390
363
|
return avmCallResult.finalize();
|
|
@@ -393,7 +366,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
393
366
|
/**
|
|
394
367
|
* Insert the non-revertible accumulated data from private into the public state.
|
|
395
368
|
*/
|
|
396
|
-
protected async insertNonRevertiblesFromPrivate(context: PublicTxContext
|
|
369
|
+
protected async insertNonRevertiblesFromPrivate(context: PublicTxContext) {
|
|
397
370
|
const stateManager = context.state.getActiveStateManager();
|
|
398
371
|
|
|
399
372
|
for (const siloedNullifier of context.nonRevertibleAccumulatedDataFromPrivate.nullifiers.filter(
|
|
@@ -412,11 +385,12 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
412
385
|
}
|
|
413
386
|
}
|
|
414
387
|
|
|
415
|
-
// add new contracts to the contracts db so that their
|
|
416
|
-
//
|
|
417
|
-
//
|
|
418
|
-
//
|
|
419
|
-
|
|
388
|
+
// add new contracts to the contracts db so that their code may be found and called
|
|
389
|
+
// FIXME(fcarreiro): this should conceptually use the hinting contracts db.
|
|
390
|
+
// However, things work as expected because later calls to getters on the hintingContractsDB
|
|
391
|
+
// will pick up the new contracts and will generate the necessary hints.
|
|
392
|
+
// So, a consumer of the hints will always see the new contracts.
|
|
393
|
+
await this.contractsDB.addContracts(context.nonRevertibleContractDeploymentData);
|
|
420
394
|
}
|
|
421
395
|
|
|
422
396
|
/**
|
|
@@ -428,7 +402,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
428
402
|
* - NoteHashLimitReachedError
|
|
429
403
|
* - L2ToL1MessageLimitReachedError
|
|
430
404
|
*/
|
|
431
|
-
protected async insertRevertiblesFromPrivate(context: PublicTxContext
|
|
405
|
+
protected async insertRevertiblesFromPrivate(context: PublicTxContext) {
|
|
432
406
|
const stateManager = context.state.getActiveStateManager();
|
|
433
407
|
|
|
434
408
|
try {
|
|
@@ -497,16 +471,21 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
497
471
|
}
|
|
498
472
|
|
|
499
473
|
// add new contracts to the contracts db so that their functions may be found and called
|
|
500
|
-
// FIXME(fcarreiro): this should conceptually use the
|
|
501
|
-
// However things
|
|
502
|
-
|
|
474
|
+
// FIXME(fcarreiro): this should conceptually use the hinting contracts db.
|
|
475
|
+
// However, things work as expected because later calls to getters on the hintingContractsDB
|
|
476
|
+
// will pick up the new contracts and will generate the necessary hints.
|
|
477
|
+
// So, a consumer of the hints will always see the new contracts.
|
|
478
|
+
await this.contractsDB.addContracts(context.revertibleContractDeploymentData);
|
|
503
479
|
}
|
|
504
480
|
|
|
505
481
|
private async payFee(context: PublicTxContext) {
|
|
506
482
|
const txFee = context.getTransactionFee(TxExecutionPhase.TEARDOWN);
|
|
507
483
|
|
|
508
484
|
if (context.feePayer.isZero()) {
|
|
509
|
-
|
|
485
|
+
// Real transactions are enforced by private kernel to have nonzero fee payer.
|
|
486
|
+
// Real transactions cannot skip fee enforcement (skipping fee enforcement makes them unprovable).
|
|
487
|
+
assert(this.config.skipFeeEnforcement, 'Fee payer cannot be 0 unless skipping fee enforcement for simulation');
|
|
488
|
+
this.log.debug(`Fee payer is 0. Skipping fee enforcement. No one is paying the fee of ${txFee.toBigInt()}`);
|
|
510
489
|
return;
|
|
511
490
|
}
|
|
512
491
|
|
|
@@ -526,23 +505,12 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
526
505
|
this.config.skipFeeEnforcement,
|
|
527
506
|
`Not enough balance for fee payer to pay for transaction (got ${currentBalance.toBigInt()} needs ${txFee.toBigInt()})`,
|
|
528
507
|
);
|
|
508
|
+
this.log.debug(`Fee payer balance insufficient, but we're skipping fee enforcement`);
|
|
509
|
+
// We still proceed and perform the storage write to minimize deviation from normal execution.
|
|
529
510
|
currentBalance = txFee;
|
|
530
511
|
}
|
|
531
512
|
|
|
532
513
|
const updatedBalance = currentBalance.sub(txFee);
|
|
533
514
|
await stateManager.writeStorage(feeJuiceAddress, balanceSlot, updatedBalance, true);
|
|
534
515
|
}
|
|
535
|
-
|
|
536
|
-
/**
|
|
537
|
-
* Generate the proving request for the AVM circuit.
|
|
538
|
-
*/
|
|
539
|
-
private static generateProvingRequest(
|
|
540
|
-
publicInputs: AvmCircuitPublicInputs,
|
|
541
|
-
hints: AvmExecutionHints,
|
|
542
|
-
): AvmProvingRequest {
|
|
543
|
-
return {
|
|
544
|
-
type: ProvingRequestType.PUBLIC_VM,
|
|
545
|
-
inputs: new AvmCircuitInputs(hints, publicInputs),
|
|
546
|
-
};
|
|
547
|
-
}
|
|
548
516
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import type { PublicTxResult } from '@aztec/stdlib/avm';
|
|
1
2
|
import type { Tx } from '@aztec/stdlib/tx';
|
|
2
3
|
|
|
3
|
-
import type { PublicTxResult } from './public_tx_simulator.js';
|
|
4
|
-
|
|
5
4
|
export interface PublicTxSimulatorInterface {
|
|
6
5
|
simulate(tx: Tx): Promise<PublicTxResult>;
|
|
7
6
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Fr } from '@aztec/foundation/
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import type { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
2
3
|
import type { Gas } from '@aztec/stdlib/gas';
|
|
3
4
|
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
4
5
|
import { type GlobalVariables, PublicCallRequestWithCalldata, TxExecutionPhase } from '@aztec/stdlib/tx';
|
|
@@ -10,7 +11,6 @@ import type { PublicContractsDB } from '../public_db_sources.js';
|
|
|
10
11
|
import type { PublicPersistableStateManager } from '../state_manager/state_manager.js';
|
|
11
12
|
import { MeasuredPublicTxSimulator } from './measured_public_tx_simulator.js';
|
|
12
13
|
import { PublicTxContext } from './public_tx_context.js';
|
|
13
|
-
import type { PublicTxSimulatorConfig } from './public_tx_simulator.js';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* A public tx simulator that tracks runtime/production metrics with telemetry.
|
|
@@ -24,7 +24,7 @@ export class TelemetryPublicTxSimulator extends MeasuredPublicTxSimulator {
|
|
|
24
24
|
contractsDB: PublicContractsDB,
|
|
25
25
|
globalVariables: GlobalVariables,
|
|
26
26
|
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
27
|
-
config?: Partial<
|
|
27
|
+
config?: Partial<PublicSimulatorConfig>,
|
|
28
28
|
) {
|
|
29
29
|
const metrics = new ExecutorMetrics(telemetryClient, 'PublicTxSimulator');
|
|
30
30
|
super(merkleTree, contractsDB, globalVariables, metrics, config);
|
|
@@ -7,8 +7,8 @@ import {
|
|
|
7
7
|
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
8
8
|
PROTOCOL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
9
9
|
} from '@aztec/constants';
|
|
10
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
10
11
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
11
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
12
12
|
import { type LogLevel, createLogger } from '@aztec/foundation/log';
|
|
13
13
|
import { PublicDataUpdateRequest } from '@aztec/stdlib/avm';
|
|
14
14
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Fr } from '@aztec/foundation/
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { LogLevel } from '@aztec/foundation/log';
|
|
3
3
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
4
|
import type { DebugLog } from '@aztec/stdlib/logs';
|
|
@@ -6,11 +6,12 @@ import {
|
|
|
6
6
|
MULTI_CALL_ENTRYPOINT_ADDRESS,
|
|
7
7
|
ROUTER_ADDRESS,
|
|
8
8
|
} from '@aztec/constants';
|
|
9
|
-
import { poseidon2Hash } from '@aztec/foundation/crypto';
|
|
10
|
-
import { Fr } from '@aztec/foundation/
|
|
9
|
+
import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
|
|
10
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
11
11
|
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
12
12
|
import { type LogLevel, createLogger } from '@aztec/foundation/log';
|
|
13
13
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
14
|
+
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
14
15
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
15
16
|
import type { ContractClassPublicWithCommitment, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
16
17
|
import { SerializableContractInstance } from '@aztec/stdlib/contract';
|
|
@@ -26,7 +27,7 @@ import { strict as assert } from 'assert';
|
|
|
26
27
|
|
|
27
28
|
import type { AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
|
|
28
29
|
import type { PublicContractsDBInterface } from '../db_interfaces.js';
|
|
29
|
-
import { getPublicFunctionDebugName } from '../debug_fn_name.js';
|
|
30
|
+
import { getPublicFunctionDebugName, getPublicFunctionSelectorAndName } from '../debug_fn_name.js';
|
|
30
31
|
import type { PublicTreesDB } from '../public_db_sources.js';
|
|
31
32
|
import {
|
|
32
33
|
L1ToL2MessageIndexOutOfRangeError,
|
|
@@ -59,7 +60,7 @@ export class PublicPersistableStateManager {
|
|
|
59
60
|
private readonly trace: PublicSideEffectTraceInterface,
|
|
60
61
|
private readonly firstNullifier: Fr, // Needed for note hashes.
|
|
61
62
|
private readonly timestamp: UInt64, // Needed for contract updates.
|
|
62
|
-
private readonly doMerkleOperations: boolean =
|
|
63
|
+
private readonly doMerkleOperations: boolean = true,
|
|
63
64
|
private readonly publicStorage: PublicStorage = new PublicStorage(treesDB),
|
|
64
65
|
private readonly nullifiers: NullifierManager = new NullifierManager(treesDB),
|
|
65
66
|
) {}
|
|
@@ -71,18 +72,10 @@ export class PublicPersistableStateManager {
|
|
|
71
72
|
treesDB: PublicTreesDB,
|
|
72
73
|
contractsDB: PublicContractsDBInterface,
|
|
73
74
|
trace: PublicSideEffectTraceInterface,
|
|
74
|
-
doMerkleOperations: boolean = false,
|
|
75
75
|
firstNullifier: Fr,
|
|
76
76
|
timestamp: UInt64,
|
|
77
77
|
): PublicPersistableStateManager {
|
|
78
|
-
return new PublicPersistableStateManager(
|
|
79
|
-
treesDB,
|
|
80
|
-
contractsDB,
|
|
81
|
-
trace,
|
|
82
|
-
firstNullifier,
|
|
83
|
-
timestamp,
|
|
84
|
-
doMerkleOperations,
|
|
85
|
-
);
|
|
78
|
+
return new PublicPersistableStateManager(treesDB, contractsDB, trace, firstNullifier, timestamp);
|
|
86
79
|
}
|
|
87
80
|
|
|
88
81
|
/**
|
|
@@ -171,7 +164,6 @@ export class PublicPersistableStateManager {
|
|
|
171
164
|
if (this.doMerkleOperations) {
|
|
172
165
|
return await this.treesDB.storageRead(contractAddress, slot);
|
|
173
166
|
} else {
|
|
174
|
-
// TODO(fcarreiro): I don't get this. PublicStorage CAN end up reading the tree. Why is it in the "dont do merkle operations" branch?
|
|
175
167
|
const read = await this.publicStorage.read(contractAddress, slot);
|
|
176
168
|
this.log.trace(
|
|
177
169
|
`Storage read results (address=${contractAddress}, slot=${slot}): value=${read.value}, cached=${read.cached}`,
|
|
@@ -437,6 +429,8 @@ export class PublicPersistableStateManager {
|
|
|
437
429
|
await this.readStorage(ProtocolContractAddress.ContractInstanceRegistry, storageSlot);
|
|
438
430
|
|
|
439
431
|
const hash = await readDeployerStorage(delayedPublicMutableHashSlot);
|
|
432
|
+
// NOTE: The below reads are either not performed (if hash.isZero()) or only performed in unconstrained in c++ simulation.
|
|
433
|
+
// See UpdateCheck::check_current_class_id documentation - this means if we generate hints from the merkle db, they are unused:
|
|
440
434
|
const delayedPublicMutableValues = await DelayedPublicMutableValues.readFromTree(
|
|
441
435
|
delayedPublicMutableSlot,
|
|
442
436
|
readDeployerStorage,
|
|
@@ -539,6 +533,12 @@ export class PublicPersistableStateManager {
|
|
|
539
533
|
return await getPublicFunctionDebugName(this.contractsDB, avmEnvironment.address, avmEnvironment.calldata);
|
|
540
534
|
}
|
|
541
535
|
|
|
536
|
+
public async getPublicFunctionSelectorAndName(
|
|
537
|
+
avmEnvironment: AvmExecutionEnvironment,
|
|
538
|
+
): Promise<{ functionSelector?: FunctionSelector; functionName?: string }> {
|
|
539
|
+
return await getPublicFunctionSelectorAndName(this.contractsDB, avmEnvironment.address, avmEnvironment.calldata);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
542
|
public async padTree(treeId: MerkleTreeId, leavesToInsert: number): Promise<void> {
|
|
543
543
|
await this.treesDB.padTree(treeId, leavesToInsert);
|
|
544
544
|
}
|
|
@@ -2,6 +2,7 @@ import { sum } from '@aztec/foundation/collection';
|
|
|
2
2
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { Timer } from '@aztec/foundation/timer';
|
|
4
4
|
import type { RevertCode } from '@aztec/stdlib/avm';
|
|
5
|
+
import type { GasUsed } from '@aztec/stdlib/gas';
|
|
5
6
|
|
|
6
7
|
import { strict as assert } from 'assert';
|
|
7
8
|
|
|
@@ -18,7 +19,7 @@ export interface PublicEnqueuedCallMetrics {
|
|
|
18
19
|
export interface PublicTxMetrics {
|
|
19
20
|
// TS simulation
|
|
20
21
|
totalDurationMs: number;
|
|
21
|
-
manaUsed: number;
|
|
22
|
+
manaUsed: number | undefined;
|
|
22
23
|
totalInstructionsExecuted: number;
|
|
23
24
|
nonRevertiblePrivateInsertionsUs: number | undefined;
|
|
24
25
|
revertiblePrivateInsertionsUs: number | undefined;
|
|
@@ -99,7 +100,7 @@ export class TestExecutorMetrics implements ExecutorMetricsInterface {
|
|
|
99
100
|
this.txTimer = new Timer();
|
|
100
101
|
}
|
|
101
102
|
|
|
102
|
-
stopRecordingTxSimulation(txLabel: string, revertedCode?: RevertCode) {
|
|
103
|
+
stopRecordingTxSimulation(txLabel: string, gasUsed?: GasUsed, revertedCode?: RevertCode) {
|
|
103
104
|
assert(this.currentTxLabel === txLabel, 'Cannot stop recording metrics for tx when another is live');
|
|
104
105
|
|
|
105
106
|
const txMetrics = this.txMetrics.get(txLabel)!;
|
|
@@ -109,7 +110,7 @@ export class TestExecutorMetrics implements ExecutorMetricsInterface {
|
|
|
109
110
|
this.logger.debug(`Public TX simulation of ${txLabel} took ${txMetrics.totalDurationMs}ms`);
|
|
110
111
|
|
|
111
112
|
// add manaUsed across all enqueued calls
|
|
112
|
-
txMetrics.manaUsed =
|
|
113
|
+
txMetrics.manaUsed = gasUsed?.publicGas.l2Gas;
|
|
113
114
|
// add totalInstructionsExecuted across all enqueued calls
|
|
114
115
|
txMetrics.totalInstructionsExecuted = sum(txMetrics.enqueuedCalls.map(call => call.totalInstructionsExecuted));
|
|
115
116
|
txMetrics.revertedCode = revertedCode;
|
|
@@ -202,8 +203,9 @@ export class TestExecutorMetrics implements ExecutorMetricsInterface {
|
|
|
202
203
|
pretty += `${INDENT0}Total duration: ${fmtNum(txMetrics.totalDurationMs, 'ms')}\n`;
|
|
203
204
|
}
|
|
204
205
|
if (filter === PublicTxMetricsFilter.TOTALS || filter === PublicTxMetricsFilter.ALL) {
|
|
205
|
-
|
|
206
|
-
|
|
206
|
+
const manaUsed = txMetrics.manaUsed || 0;
|
|
207
|
+
pretty += `${INDENT0}Total mana used: ${fmtNum(manaUsed)}\n`;
|
|
208
|
+
const manaPerSecond = Math.round((manaUsed * 1000) / txMetrics.totalDurationMs);
|
|
207
209
|
pretty += `${INDENT0}Mana per second: ${fmtNum(manaPerSecond)}\n`;
|
|
208
210
|
}
|
|
209
211
|
|