@aztec/simulator 3.0.3-rc.3 → 4.0.0-devnet.1-patch.0
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 +7 -1
- 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_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 +20 -17
- 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 +6 -5
- package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/public/avm/avm_machine_state.d.ts +6 -5
- 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 +1 -1
- package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/public/avm/avm_memory_types.js +3 -0
- package/dest/public/avm/avm_simulator.d.ts +3 -2
- package/dest/public/avm/avm_simulator.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.js +5 -4
- 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/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 +3 -2
- package/dest/public/avm/fixtures/initializers.d.ts +1 -1
- package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
- package/dest/public/avm/fixtures/initializers.js +2 -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 +8 -8
- package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/public/avm/opcodes/arithmetic.js +1 -1
- 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 +15 -6
- 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 +18 -15
- 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 +25 -25
- 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/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/bulk_test.d.ts +3 -3
- package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
- package/dest/public/fixtures/bulk_test.js +4 -68
- 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 -9
- package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
- package/dest/public/fixtures/custom_bytecode_tests.js +66 -22
- 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 +34 -7
- package/dest/public/fixtures/utils.d.ts +1 -1
- package/dest/public/fixtures/utils.d.ts.map +1 -1
- package/dest/public/fixtures/utils.js +3 -2
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +21 -7
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -1
- package/dest/public/fuzzing/avm_fuzzer_simulator.js +46 -11
- package/dest/public/fuzzing/avm_simulator_bin.js +47 -13
- package/dest/public/hinting_db_sources.d.ts +2 -1
- package/dest/public/hinting_db_sources.d.ts.map +1 -1
- package/dest/public/hinting_db_sources.js +5 -0
- package/dest/public/public_db_sources.d.ts +4 -3
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +4 -4
- 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 +428 -34
- 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 -2
- 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 +17 -13
- 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 +8 -7
- package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +3 -2
- package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.js +2 -2
- package/dest/public/public_tx_simulator/factories.d.ts +3 -2
- package/dest/public/public_tx_simulator/factories.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/factories.js +3 -3
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +4 -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 +8 -8
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +6 -4
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +12 -7
- 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.js +395 -19
- package/dest/public/side_effect_trace.d.ts +5 -4
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +3 -3
- package/dest/public/state_manager/state_manager.d.ts +10 -4
- package/dest/public/state_manager/state_manager.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.js +14 -7
- 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 +17 -17
- package/src/private/acvm/acvm.ts +4 -3
- package/src/private/acvm_native.ts +11 -5
- package/src/private/acvm_wasm.ts +7 -3
- package/src/private/circuit_recording/circuit_recorder.ts +21 -18
- 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 +9 -4
- package/src/public/avm/avm_machine_state.ts +6 -5
- package/src/public/avm/avm_memory_types.ts +4 -0
- package/src/public/avm/avm_simulator.ts +8 -5
- package/src/public/avm/calldata.ts +100 -0
- 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 +8 -2
- package/src/public/avm/fixtures/initializers.ts +2 -1
- package/src/public/avm/opcodes/accrued_substate.ts +28 -30
- package/src/public/avm/opcodes/arithmetic.ts +1 -1
- 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 +13 -4
- 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 +13 -9
- package/src/public/avm/opcodes/instruction_impl.ts +2 -2
- package/src/public/avm/opcodes/memory.ts +19 -19
- package/src/public/avm/opcodes/misc.ts +2 -2
- package/src/public/avm/opcodes/storage.ts +30 -22
- package/src/public/debug_fn_name.ts +17 -8
- package/src/public/executor_metrics.ts +9 -33
- package/src/public/fixtures/bulk_test.ts +8 -8
- package/src/public/fixtures/custom_bytecode_tester.ts +53 -19
- package/src/public/fixtures/custom_bytecode_tests.ts +91 -22
- package/src/public/fixtures/index.ts +7 -1
- package/src/public/fixtures/minimal_public_tx.ts +5 -14
- package/src/public/fixtures/opcode_spammer.ts +1721 -0
- package/src/public/fixtures/public_tx_simulation_tester.ts +38 -5
- package/src/public/fixtures/utils.ts +1 -2
- package/src/public/fuzzing/avm_fuzzer_simulator.ts +67 -12
- package/src/public/fuzzing/avm_simulator_bin.ts +64 -10
- package/src/public/hinting_db_sources.ts +4 -0
- package/src/public/public_db_sources.ts +15 -5
- package/src/public/public_processor/guarded_merkle_tree.ts +4 -0
- package/src/public/public_processor/public_processor.ts +41 -16
- package/src/public/public_processor/public_processor_metrics.ts +16 -44
- package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +22 -14
- 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 +6 -4
- package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +9 -6
- package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +3 -1
- package/src/public/public_tx_simulator/factories.ts +4 -2
- package/src/public/public_tx_simulator/public_tx_context.ts +13 -6
- package/src/public/public_tx_simulator/public_tx_simulator.ts +18 -7
- package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +23 -0
- package/src/public/side_effect_trace.ts +5 -2
- package/src/public/state_manager/state_manager.ts +29 -20
- package/src/public/test_executor_metrics.ts +3 -3
|
@@ -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,5 +1,5 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
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';
|
|
@@ -10,15 +10,18 @@ import type { GlobalVariables } from '@aztec/stdlib/tx';
|
|
|
10
10
|
import type { PublicContractsDB } from '../public_db_sources.js';
|
|
11
11
|
|
|
12
12
|
export class ContractProviderForCpp implements ContractProvider {
|
|
13
|
-
private log: Logger
|
|
13
|
+
private log: Logger;
|
|
14
14
|
|
|
15
15
|
constructor(
|
|
16
16
|
private contractsDB: PublicContractsDB,
|
|
17
17
|
private globalVariables: GlobalVariables,
|
|
18
|
-
|
|
18
|
+
bindings?: LoggerBindings,
|
|
19
|
+
) {
|
|
20
|
+
this.log = createLogger('simulator:contract_provider_for_cpp', bindings);
|
|
21
|
+
}
|
|
19
22
|
|
|
20
23
|
public getContractInstance = async (address: string): Promise<Buffer | undefined> => {
|
|
21
|
-
this.log.
|
|
24
|
+
this.log.trace(`Contract provider callback: getContractInstance(${address})`);
|
|
22
25
|
|
|
23
26
|
const aztecAddr = AztecAddress.fromString(address);
|
|
24
27
|
|
|
@@ -33,7 +36,7 @@ export class ContractProviderForCpp implements ContractProvider {
|
|
|
33
36
|
};
|
|
34
37
|
|
|
35
38
|
public getContractClass = async (classId: string): Promise<Buffer | undefined> => {
|
|
36
|
-
this.log.
|
|
39
|
+
this.log.trace(`Contract provider callback: getContractClass(${classId})`);
|
|
37
40
|
|
|
38
41
|
// Parse classId string to Fr
|
|
39
42
|
const classIdFr = Fr.fromString(classId);
|
|
@@ -50,7 +53,7 @@ export class ContractProviderForCpp implements ContractProvider {
|
|
|
50
53
|
};
|
|
51
54
|
|
|
52
55
|
public addContracts = async (contractDeploymentDataBuffer: Buffer): Promise<void> => {
|
|
53
|
-
this.log.
|
|
56
|
+
this.log.trace(`Contract provider callback: addContracts`);
|
|
54
57
|
|
|
55
58
|
const rawData: any = deserializeFromMessagePack(contractDeploymentDataBuffer);
|
|
56
59
|
|
|
@@ -58,12 +61,12 @@ export class ContractProviderForCpp implements ContractProvider {
|
|
|
58
61
|
const contractDeploymentData = ContractDeploymentData.fromPlainObject(rawData);
|
|
59
62
|
|
|
60
63
|
// Add contracts to the contracts DB
|
|
61
|
-
this.log.
|
|
64
|
+
this.log.trace(`Calling contractsDB.addContracts`);
|
|
62
65
|
await this.contractsDB.addContracts(contractDeploymentData);
|
|
63
66
|
};
|
|
64
67
|
|
|
65
68
|
public getBytecodeCommitment = async (classId: string): Promise<Buffer | undefined> => {
|
|
66
|
-
this.log.
|
|
69
|
+
this.log.trace(`Contract provider callback: getBytecodeCommitment(${classId})`);
|
|
67
70
|
|
|
68
71
|
// Parse classId string to Fr
|
|
69
72
|
const classIdFr = Fr.fromString(classId);
|
|
@@ -81,18 +84,23 @@ export class ContractProviderForCpp implements ContractProvider {
|
|
|
81
84
|
};
|
|
82
85
|
|
|
83
86
|
public getDebugFunctionName = async (address: string, selector: string): Promise<string | undefined> => {
|
|
84
|
-
this.log.
|
|
87
|
+
this.log.trace(`Contract provider callback: getDebugFunctionName(${address}, ${selector})`);
|
|
85
88
|
|
|
86
89
|
// Parse address and selector strings
|
|
87
90
|
const aztecAddr = AztecAddress.fromString(address);
|
|
88
91
|
const selectorFr = Fr.fromString(selector);
|
|
89
|
-
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
|
+
}
|
|
90
98
|
|
|
91
99
|
// Fetch debug function name from the contracts DB
|
|
92
100
|
const name = await this.contractsDB.getDebugFunctionName(aztecAddr, functionSelector);
|
|
93
101
|
|
|
94
102
|
if (!name) {
|
|
95
|
-
this.log.
|
|
103
|
+
this.log.trace(`Debug function name not found for ${address}:${selector}`);
|
|
96
104
|
return undefined;
|
|
97
105
|
}
|
|
98
106
|
|
|
@@ -100,17 +108,17 @@ export class ContractProviderForCpp implements ContractProvider {
|
|
|
100
108
|
};
|
|
101
109
|
|
|
102
110
|
public createCheckpoint = (): Promise<void> => {
|
|
103
|
-
this.log.
|
|
111
|
+
this.log.trace(`Contract provider callback: createCheckpoint`);
|
|
104
112
|
return Promise.resolve(this.contractsDB.createCheckpoint());
|
|
105
113
|
};
|
|
106
114
|
|
|
107
115
|
public commitCheckpoint = (): Promise<void> => {
|
|
108
|
-
this.log.
|
|
116
|
+
this.log.trace(`Contract provider callback: commitCheckpoint`);
|
|
109
117
|
return Promise.resolve(this.contractsDB.commitCheckpoint());
|
|
110
118
|
};
|
|
111
119
|
|
|
112
120
|
public revertCheckpoint = (): Promise<void> => {
|
|
113
|
-
this.log.
|
|
121
|
+
this.log.trace(`Contract provider callback: revertCheckpoint`);
|
|
114
122
|
return Promise.resolve(this.contractsDB.revertCheckpoint());
|
|
115
123
|
};
|
|
116
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
|
/**
|
|
@@ -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> {
|
|
@@ -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 { avmSimulate } from '@aztec/native';
|
|
3
3
|
import { ProtocolContractsList } from '@aztec/protocol-contracts';
|
|
4
4
|
import {
|
|
@@ -37,9 +37,10 @@ export class CppVsTsPublicTxSimulator extends PublicTxSimulator implements Publi
|
|
|
37
37
|
contractsDB: PublicContractsDB,
|
|
38
38
|
globalVariables: GlobalVariables,
|
|
39
39
|
config?: Partial<PublicSimulatorConfig>,
|
|
40
|
+
bindings?: LoggerBindings,
|
|
40
41
|
) {
|
|
41
|
-
super(merkleTree, contractsDB, globalVariables, config);
|
|
42
|
-
this.log = createLogger(`simulator:
|
|
42
|
+
super(merkleTree, contractsDB, globalVariables, config, undefined, bindings);
|
|
43
|
+
this.log = createLogger(`simulator:cpp_vs_public_tx_simulator`, bindings);
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
/**
|
|
@@ -103,7 +104,7 @@ export class CppVsTsPublicTxSimulator extends PublicTxSimulator implements Publi
|
|
|
103
104
|
);
|
|
104
105
|
|
|
105
106
|
// Create contract provider for callbacks to TypeScript PublicContractsDB from C++
|
|
106
|
-
const contractProvider = new ContractProviderForCpp(this.contractsDB, this.globalVariables);
|
|
107
|
+
const contractProvider = new ContractProviderForCpp(this.contractsDB, this.globalVariables, this.bindings);
|
|
107
108
|
|
|
108
109
|
// Serialize to msgpack and call the C++ simulator
|
|
109
110
|
this.log.debug(`Serializing fast simulation inputs to msgpack...`);
|
|
@@ -205,7 +206,8 @@ export class CppVsTsPublicTxSimulator extends PublicTxSimulator implements Publi
|
|
|
205
206
|
cppGasUsed: cppResult.gasUsed.totalGas.l2Gas,
|
|
206
207
|
});
|
|
207
208
|
|
|
208
|
-
|
|
209
|
+
// Return cpp result as it has more detailed metadata / revert reasons
|
|
210
|
+
return cppResult;
|
|
209
211
|
}
|
|
210
212
|
}
|
|
211
213
|
|
|
@@ -219,8 +221,9 @@ export class MeasuredCppVsTsPublicTxSimulator
|
|
|
219
221
|
globalVariables: GlobalVariables,
|
|
220
222
|
protected readonly metrics: ExecutorMetricsInterface,
|
|
221
223
|
config?: Partial<PublicSimulatorConfig>,
|
|
224
|
+
bindings?: LoggerBindings,
|
|
222
225
|
) {
|
|
223
|
-
super(merkleTree, contractsDB, globalVariables, config);
|
|
226
|
+
super(merkleTree, contractsDB, globalVariables, config, bindings);
|
|
224
227
|
}
|
|
225
228
|
|
|
226
229
|
public override async simulate(tx: Tx, txLabel: string = 'unlabeledTx'): Promise<PublicTxResult> {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LoggerBindings } from '@aztec/foundation/log';
|
|
1
2
|
import {
|
|
2
3
|
AvmCircuitInputs,
|
|
3
4
|
AvmCircuitPublicInputs,
|
|
@@ -29,8 +30,9 @@ export class DumpingCppPublicTxSimulator extends CppPublicTxSimulator {
|
|
|
29
30
|
globalVariables: GlobalVariables,
|
|
30
31
|
config: Partial<PublicSimulatorConfig>,
|
|
31
32
|
outputDir: string,
|
|
33
|
+
bindings?: LoggerBindings,
|
|
32
34
|
) {
|
|
33
|
-
super(merkleTree, contractsDB, globalVariables, config);
|
|
35
|
+
super(merkleTree, contractsDB, globalVariables, config, bindings);
|
|
34
36
|
assert(config.collectHints === true, 'collectHints must be enabled to dump AVM circuit inputs');
|
|
35
37
|
assert(config.collectPublicInputs === true, 'collectPublicInputs must be enabled to dump AVM circuit inputs');
|
|
36
38
|
this.outputDir = outputDir;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LoggerBindings } from '@aztec/foundation/log';
|
|
1
2
|
import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
2
3
|
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
3
4
|
import type { GlobalVariables } from '@aztec/stdlib/tx';
|
|
@@ -17,6 +18,7 @@ export function createPublicTxSimulatorForBlockBuilding(
|
|
|
17
18
|
contractsDB: PublicContractsDB,
|
|
18
19
|
globalVariables: GlobalVariables,
|
|
19
20
|
telemetryClient: TelemetryClient,
|
|
21
|
+
bindings?: LoggerBindings,
|
|
20
22
|
) {
|
|
21
23
|
const config = PublicSimulatorConfig.from({
|
|
22
24
|
skipFeeEnforcement: false,
|
|
@@ -35,7 +37,7 @@ export function createPublicTxSimulatorForBlockBuilding(
|
|
|
35
37
|
collectHints: true,
|
|
36
38
|
collectPublicInputs: true,
|
|
37
39
|
};
|
|
38
|
-
return new DumpingCppPublicTxSimulator(merkleTree, contractsDB, globalVariables, dumpingConfig, dumpDir);
|
|
40
|
+
return new DumpingCppPublicTxSimulator(merkleTree, contractsDB, globalVariables, dumpingConfig, dumpDir, bindings);
|
|
39
41
|
}
|
|
40
|
-
return new TelemetryCppPublicTxSimulator(merkleTree, contractsDB, globalVariables, telemetryClient, config);
|
|
42
|
+
return new TelemetryCppPublicTxSimulator(merkleTree, contractsDB, globalVariables, telemetryClient, config, bindings);
|
|
41
43
|
}
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from '@aztec/constants';
|
|
8
8
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
9
9
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
10
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
10
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
11
11
|
import {
|
|
12
12
|
AvmAccumulatedData,
|
|
13
13
|
AvmAccumulatedDataArrayLengths,
|
|
@@ -87,8 +87,9 @@ export class PublicTxContext {
|
|
|
87
87
|
public readonly revertibleAccumulatedDataFromPrivate: PrivateToPublicAccumulatedData,
|
|
88
88
|
public readonly feePayer: AztecAddress,
|
|
89
89
|
private readonly trace: SideEffectTrace,
|
|
90
|
+
bindings?: LoggerBindings,
|
|
90
91
|
) {
|
|
91
|
-
this.log = createLogger(`simulator:public_tx_context
|
|
92
|
+
this.log = createLogger(`simulator:public_tx_context`, bindings);
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
public static async create(
|
|
@@ -98,13 +99,14 @@ export class PublicTxContext {
|
|
|
98
99
|
globalVariables: GlobalVariables,
|
|
99
100
|
protocolContracts: ProtocolContracts,
|
|
100
101
|
proverId: Fr,
|
|
102
|
+
bindings?: LoggerBindings,
|
|
101
103
|
) {
|
|
102
104
|
const contractDeploymentData = AllContractDeploymentData.fromTx(tx);
|
|
103
105
|
const nonRevertibleContractDeploymentData = contractDeploymentData.getNonRevertibleContractDeploymentData();
|
|
104
106
|
const revertibleContractDeploymentData = contractDeploymentData.getRevertibleContractDeploymentData();
|
|
105
107
|
const nonRevertibleAccumulatedDataFromPrivate = tx.data.forPublic!.nonRevertibleAccumulatedData;
|
|
106
108
|
|
|
107
|
-
const trace = new SideEffectTrace();
|
|
109
|
+
const trace = new SideEffectTrace(0, bindings);
|
|
108
110
|
|
|
109
111
|
const firstNullifier = nonRevertibleAccumulatedDataFromPrivate.nullifiers[0];
|
|
110
112
|
|
|
@@ -115,6 +117,7 @@ export class PublicTxContext {
|
|
|
115
117
|
trace,
|
|
116
118
|
firstNullifier,
|
|
117
119
|
globalVariables.timestamp,
|
|
120
|
+
bindings,
|
|
118
121
|
);
|
|
119
122
|
|
|
120
123
|
const gasSettings = tx.data.constants.txContext.gasSettings;
|
|
@@ -124,7 +127,7 @@ export class PublicTxContext {
|
|
|
124
127
|
|
|
125
128
|
return new PublicTxContext(
|
|
126
129
|
tx.getTxHash(),
|
|
127
|
-
new PhaseStateManager(txStateManager),
|
|
130
|
+
new PhaseStateManager(txStateManager, bindings),
|
|
128
131
|
await txStateManager.getTreeSnapshots(),
|
|
129
132
|
globalVariables,
|
|
130
133
|
protocolContracts,
|
|
@@ -142,6 +145,7 @@ export class PublicTxContext {
|
|
|
142
145
|
tx.data.forPublic!.revertibleAccumulatedData,
|
|
143
146
|
tx.data.feePayer,
|
|
144
147
|
trace,
|
|
148
|
+
bindings,
|
|
145
149
|
);
|
|
146
150
|
}
|
|
147
151
|
|
|
@@ -441,8 +445,11 @@ class PhaseStateManager {
|
|
|
441
445
|
|
|
442
446
|
private currentlyActiveStateManager: PublicPersistableStateManager | undefined;
|
|
443
447
|
|
|
444
|
-
constructor(
|
|
445
|
-
|
|
448
|
+
constructor(
|
|
449
|
+
private readonly txStateManager: PublicPersistableStateManager,
|
|
450
|
+
bindings?: LoggerBindings,
|
|
451
|
+
) {
|
|
452
|
+
this.log = createLogger(`simulator:public_phase_state_manager`, bindings);
|
|
446
453
|
}
|
|
447
454
|
|
|
448
455
|
async fork() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AVM_MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { type Logger, type LoggerBindings, 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
6
|
import { AvmExecutionHints, AvmTxHint, PublicSimulatorConfig, PublicTxEffect, PublicTxResult } from '@aztec/stdlib/avm';
|
|
@@ -10,6 +10,7 @@ import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
|
10
10
|
import {
|
|
11
11
|
type GlobalVariables,
|
|
12
12
|
NestedProcessReturnValues,
|
|
13
|
+
ProtocolContracts,
|
|
13
14
|
PublicCallRequestWithCalldata,
|
|
14
15
|
Tx,
|
|
15
16
|
TxExecutionPhase,
|
|
@@ -18,6 +19,7 @@ import {
|
|
|
18
19
|
import { strict as assert } from 'assert';
|
|
19
20
|
|
|
20
21
|
import type { AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
|
|
22
|
+
import { CallDataArray } from '../avm/calldata.js';
|
|
21
23
|
import { AvmSimulator } from '../avm/index.js';
|
|
22
24
|
import { getPublicFunctionDebugName } from '../debug_fn_name.js';
|
|
23
25
|
import { HintingMerkleWriteOperations, HintingPublicContractsDB } from '../hinting_db_sources.js';
|
|
@@ -79,15 +81,19 @@ type ProcessedPhase = {
|
|
|
79
81
|
export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
80
82
|
protected log: Logger;
|
|
81
83
|
protected readonly config: PublicSimulatorConfig;
|
|
84
|
+
protected readonly bindings?: LoggerBindings;
|
|
82
85
|
|
|
83
86
|
constructor(
|
|
84
87
|
protected merkleTree: MerkleTreeWriteOperations,
|
|
85
88
|
protected contractsDB: PublicContractsDB,
|
|
86
89
|
protected globalVariables: GlobalVariables,
|
|
87
90
|
config?: Partial<PublicSimulatorConfig>,
|
|
91
|
+
protected protocolContracts: ProtocolContracts = ProtocolContractsList,
|
|
92
|
+
bindings?: LoggerBindings,
|
|
88
93
|
) {
|
|
89
94
|
this.config = PublicSimulatorConfig.from(config ?? {});
|
|
90
|
-
this.
|
|
95
|
+
this.bindings = bindings;
|
|
96
|
+
this.log = createLogger(`simulator:public_tx_simulator`, bindings);
|
|
91
97
|
}
|
|
92
98
|
|
|
93
99
|
/**
|
|
@@ -103,7 +109,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
103
109
|
const hints = new AvmExecutionHints(
|
|
104
110
|
this.globalVariables,
|
|
105
111
|
AvmTxHint.fromTx(tx, this.globalVariables.gasFees),
|
|
106
|
-
|
|
112
|
+
this.protocolContracts,
|
|
107
113
|
);
|
|
108
114
|
const hintingMerkleTree = await HintingMerkleWriteOperations.create(this.merkleTree, hints);
|
|
109
115
|
const hintingTreesDB = new PublicTreesDB(hintingMerkleTree);
|
|
@@ -114,8 +120,9 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
114
120
|
hintingContractsDB,
|
|
115
121
|
tx,
|
|
116
122
|
this.globalVariables,
|
|
117
|
-
|
|
123
|
+
this.protocolContracts,
|
|
118
124
|
this.config.proverId,
|
|
125
|
+
this.bindings,
|
|
119
126
|
);
|
|
120
127
|
|
|
121
128
|
// This will throw if there is a nullifier collision.
|
|
@@ -265,7 +272,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
265
272
|
|
|
266
273
|
const enqueuedCallResult = await this.simulateEnqueuedCall(phase, context, callRequest);
|
|
267
274
|
|
|
268
|
-
returnValues.push(new NestedProcessReturnValues(enqueuedCallResult.output));
|
|
275
|
+
returnValues.push(new NestedProcessReturnValues(enqueuedCallResult.output.bestEffortReadAll()));
|
|
269
276
|
|
|
270
277
|
if (enqueuedCallResult.reverted) {
|
|
271
278
|
reverted = true;
|
|
@@ -295,7 +302,11 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
295
302
|
): Promise<AvmFinalizedCallResult> {
|
|
296
303
|
const stateManager = context.state.getActiveStateManager();
|
|
297
304
|
const contractAddress = callRequest.request.contractAddress;
|
|
298
|
-
const fnName = await getPublicFunctionDebugName(
|
|
305
|
+
const fnName = await getPublicFunctionDebugName(
|
|
306
|
+
this.contractsDB,
|
|
307
|
+
contractAddress,
|
|
308
|
+
new CallDataArray(callRequest.calldata),
|
|
309
|
+
);
|
|
299
310
|
|
|
300
311
|
const allocatedGas = context.getGasLeftAtPhase(phase);
|
|
301
312
|
|
|
@@ -355,7 +366,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
355
366
|
transactionFee,
|
|
356
367
|
this.globalVariables,
|
|
357
368
|
request.isStaticCall,
|
|
358
|
-
calldata,
|
|
369
|
+
new CallDataArray(calldata),
|
|
359
370
|
allocatedGas,
|
|
360
371
|
this.config,
|
|
361
372
|
);
|
|
@@ -3,8 +3,31 @@ import type { Tx } from '@aztec/stdlib/tx';
|
|
|
3
3
|
|
|
4
4
|
export interface PublicTxSimulatorInterface {
|
|
5
5
|
simulate(tx: Tx): Promise<PublicTxResult>;
|
|
6
|
+
/**
|
|
7
|
+
* Cancel the current simulation if one is in progress.
|
|
8
|
+
* This signals the underlying simulator (e.g., C++) to stop at the next safe point.
|
|
9
|
+
* Safe to call even if no simulation is in progress.
|
|
10
|
+
* Optional - not all implementations support cancellation.
|
|
11
|
+
*
|
|
12
|
+
* @param waitTimeoutMs - If provided, wait up to this many ms for the simulation to actually stop.
|
|
13
|
+
* This is important because signaling cancellation doesn't immediately stop C++ -
|
|
14
|
+
* it only sets a flag that C++ checks at certain points. If C++ is in the middle
|
|
15
|
+
* of a slow operation (e.g., pad_trees), it won't stop until that completes.
|
|
16
|
+
* @returns Promise that resolves when cancellation is signaled (and optionally when simulation stops)
|
|
17
|
+
*/
|
|
18
|
+
cancel?(waitTimeoutMs?: number): Promise<void>;
|
|
6
19
|
}
|
|
7
20
|
|
|
8
21
|
export interface MeasuredPublicTxSimulatorInterface {
|
|
9
22
|
simulate(tx: Tx, txLabel: string): Promise<PublicTxResult>;
|
|
23
|
+
/**
|
|
24
|
+
* Cancel the current simulation if one is in progress.
|
|
25
|
+
* This signals the underlying simulator (e.g., C++) to stop at the next safe point.
|
|
26
|
+
* Safe to call even if no simulation is in progress.
|
|
27
|
+
* Optional - not all implementations support cancellation.
|
|
28
|
+
*
|
|
29
|
+
* @param waitTimeoutMs - If provided, wait up to this many ms for the simulation to actually stop.
|
|
30
|
+
* @returns Promise that resolves when cancellation is signaled (and optionally when simulation stops)
|
|
31
|
+
*/
|
|
32
|
+
cancel?(waitTimeoutMs?: number): Promise<void>;
|
|
10
33
|
}
|