@aztec/simulator 0.0.1-commit.d3ec352c → 0.0.1-commit.f295ac2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dest/common/errors.d.ts +8 -2
- package/dest/common/errors.d.ts.map +1 -1
- package/dest/private/acvm/deserialize.d.ts +2 -2
- package/dest/private/acvm/deserialize.d.ts.map +1 -1
- package/dest/private/acvm/deserialize.js +1 -1
- package/dest/private/acvm/serialize.d.ts +2 -2
- package/dest/private/acvm/serialize.d.ts.map +1 -1
- package/dest/private/acvm/serialize.js +1 -1
- package/dest/private/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 +16 -15
- 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 +2 -2
- package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/public/avm/avm_execution_environment.js +1 -1
- package/dest/public/avm/avm_gas.d.ts +1 -1
- package/dest/public/avm/avm_gas.d.ts.map +1 -1
- package/dest/public/avm/avm_machine_state.d.ts +2 -2
- package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/public/avm/avm_memory_types.d.ts +2 -2
- package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/public/avm/avm_memory_types.js +1 -1
- package/dest/public/avm/avm_simulator.d.ts +2 -2
- package/dest/public/avm/avm_simulator.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.js +1 -1
- package/dest/public/avm/errors.d.ts +2 -2
- package/dest/public/avm/errors.d.ts.map +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.js +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +2 -2
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.js +1 -1
- package/dest/public/avm/fixtures/initializers.d.ts +2 -2
- package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
- package/dest/public/avm/fixtures/initializers.js +1 -1
- package/dest/public/avm/fixtures/utils.d.ts +2 -2
- package/dest/public/avm/fixtures/utils.d.ts.map +1 -1
- package/dest/public/avm/fixtures/utils.js +1 -1
- package/dest/public/avm/opcodes/accrued_substate.d.ts +15 -15
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/accrued_substate.js +29 -29
- package/dest/public/avm/opcodes/arithmetic.d.ts +10 -8
- package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/public/avm/opcodes/arithmetic.js +12 -2
- package/dest/public/avm/opcodes/bitwise.d.ts +7 -7
- package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/public/avm/opcodes/bitwise.js +5 -5
- package/dest/public/avm/opcodes/comparators.d.ts +4 -4
- package/dest/public/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/public/avm/opcodes/comparators.js +1 -1
- package/dest/public/avm/opcodes/contract.d.ts +3 -3
- package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/public/avm/opcodes/contract.js +4 -4
- package/dest/public/avm/opcodes/control_flow.d.ts +3 -3
- package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
- package/dest/public/avm/opcodes/control_flow.js +4 -4
- package/dest/public/avm/opcodes/conversion.d.ts +3 -3
- package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/public/avm/opcodes/conversion.js +4 -4
- package/dest/public/avm/opcodes/ec_add.d.ts +4 -4
- package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/public/avm/opcodes/ec_add.js +17 -8
- package/dest/public/avm/opcodes/environment_getters.d.ts +5 -5
- package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/public/avm/opcodes/environment_getters.js +6 -6
- package/dest/public/avm/opcodes/external_calls.d.ts +9 -9
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.js +17 -16
- package/dest/public/avm/opcodes/hashing.d.ts +8 -8
- package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/public/avm/opcodes/hashing.js +21 -16
- package/dest/public/avm/opcodes/instruction_impl.d.ts +4 -4
- package/dest/public/avm/opcodes/instruction_impl.d.ts.map +1 -1
- package/dest/public/avm/opcodes/instruction_impl.js +4 -4
- package/dest/public/avm/opcodes/memory.d.ts +14 -14
- package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.js +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 +7 -7
- package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/public/avm/opcodes/storage.js +9 -9
- package/dest/public/avm/revert_reason.d.ts +2 -2
- package/dest/public/avm/revert_reason.d.ts.map +1 -1
- package/dest/public/avm/serialization/instruction_serialization.js +1 -1
- package/dest/public/avm/test_utils.d.ts +2 -2
- package/dest/public/avm/test_utils.d.ts.map +1 -1
- package/dest/public/avm/test_utils.js +1 -1
- package/dest/public/contracts_db_checkpoint.d.ts +2 -2
- package/dest/public/contracts_db_checkpoint.d.ts.map +1 -1
- package/dest/public/db_interfaces.d.ts +2 -2
- package/dest/public/db_interfaces.d.ts.map +1 -1
- package/dest/public/debug_fn_name.d.ts +2 -2
- package/dest/public/debug_fn_name.d.ts.map +1 -1
- package/dest/public/debug_fn_name.js +10 -3
- 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 +8 -34
- package/dest/public/fixtures/amm_test.js +2 -2
- package/dest/public/fixtures/bulk_test.d.ts +3 -3
- package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
- package/dest/public/fixtures/bulk_test.js +5 -69
- package/dest/public/fixtures/custom_bytecode_tester.d.ts +28 -6
- package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
- package/dest/public/fixtures/custom_bytecode_tester.js +36 -12
- package/dest/public/fixtures/custom_bytecode_tests.d.ts +11 -8
- package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
- package/dest/public/fixtures/custom_bytecode_tests.js +83 -18
- package/dest/public/fixtures/index.d.ts +4 -2
- package/dest/public/fixtures/index.d.ts.map +1 -1
- package/dest/public/fixtures/index.js +3 -1
- package/dest/public/fixtures/minimal_public_tx.d.ts +2 -7
- package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -1
- package/dest/public/fixtures/minimal_public_tx.js +4 -14
- package/dest/public/fixtures/opcode_spammer.d.ts +123 -0
- package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -0
- package/dest/public/fixtures/opcode_spammer.js +1681 -0
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +15 -2
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +36 -8
- package/dest/public/fixtures/simple_contract_data_source.d.ts +2 -2
- package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -1
- package/dest/public/fixtures/token_test.js +1 -1
- package/dest/public/fixtures/utils.d.ts +2 -2
- package/dest/public/fixtures/utils.d.ts.map +1 -1
- package/dest/public/fixtures/utils.js +4 -3
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +60 -0
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -0
- package/dest/public/fuzzing/avm_fuzzer_simulator.js +171 -0
- package/dest/public/fuzzing/avm_simulator_bin.d.ts +2 -0
- package/dest/public/fuzzing/avm_simulator_bin.d.ts.map +1 -0
- package/dest/public/fuzzing/avm_simulator_bin.js +115 -0
- package/dest/public/hinting_db_sources.d.ts +3 -2
- package/dest/public/hinting_db_sources.d.ts.map +1 -1
- package/dest/public/hinting_db_sources.js +7 -2
- package/dest/public/index.d.ts +2 -2
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +1 -1
- package/dest/public/public_db_sources.d.ts +2 -2
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +1 -1
- 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 +3 -3
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +425 -32
- 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_processor/public_processor_metrics.js +12 -45
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +1 -13
- 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 +18 -53
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +16 -1
- 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 +42 -3
- package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +1 -1
- 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 +7 -6
- 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 +3 -1
- package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/index.js +2 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +3 -3
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +2 -2
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +5 -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 +10 -6
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +24 -1
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +2 -2
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +395 -19
- package/dest/public/side_effect_trace.d.ts +3 -2
- 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 +2 -2
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/dest/public/state_manager/nullifiers.d.ts +2 -2
- package/dest/public/state_manager/nullifiers.d.ts.map +1 -1
- package/dest/public/state_manager/public_storage.d.ts +2 -2
- package/dest/public/state_manager/public_storage.d.ts.map +1 -1
- package/dest/public/state_manager/public_storage.js +1 -1
- package/dest/public/state_manager/state_manager.d.ts +2 -2
- package/dest/public/state_manager/state_manager.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.js +3 -3
- package/package.json +18 -18
- 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/circuit_recording/circuit_recorder.ts +17 -16
- 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 +1 -1
- 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 +1 -1
- package/src/public/avm/errors.ts +1 -1
- package/src/public/avm/fixtures/avm_simulation_tester.ts +1 -1
- package/src/public/avm/fixtures/base_avm_simulation_tester.ts +1 -1
- package/src/public/avm/fixtures/initializers.ts +1 -1
- package/src/public/avm/fixtures/utils.ts +1 -1
- package/src/public/avm/opcodes/accrued_substate.ts +15 -15
- package/src/public/avm/opcodes/arithmetic.ts +14 -2
- package/src/public/avm/opcodes/bitwise.ts +3 -3
- package/src/public/avm/opcodes/comparators.ts +1 -1
- package/src/public/avm/opcodes/contract.ts +3 -3
- package/src/public/avm/opcodes/control_flow.ts +2 -2
- package/src/public/avm/opcodes/conversion.ts +3 -3
- package/src/public/avm/opcodes/ec_add.ts +15 -6
- package/src/public/avm/opcodes/environment_getters.ts +7 -7
- package/src/public/avm/opcodes/external_calls.ts +10 -9
- package/src/public/avm/opcodes/hashing.ts +16 -10
- package/src/public/avm/opcodes/instruction_impl.ts +2 -2
- package/src/public/avm/opcodes/memory.ts +19 -19
- package/src/public/avm/opcodes/misc.ts +2 -2
- package/src/public/avm/opcodes/storage.ts +7 -7
- package/src/public/avm/revert_reason.ts +1 -1
- package/src/public/avm/serialization/instruction_serialization.ts +1 -1
- package/src/public/avm/test_utils.ts +1 -1
- package/src/public/contracts_db_checkpoint.ts +1 -1
- package/src/public/db_interfaces.ts +1 -1
- package/src/public/debug_fn_name.ts +11 -4
- package/src/public/executor_metrics.ts +7 -34
- package/src/public/fixtures/amm_test.ts +2 -2
- package/src/public/fixtures/bulk_test.ts +9 -9
- package/src/public/fixtures/custom_bytecode_tester.ts +53 -19
- package/src/public/fixtures/custom_bytecode_tests.ts +111 -18
- package/src/public/fixtures/index.ts +7 -1
- package/src/public/fixtures/minimal_public_tx.ts +6 -15
- package/src/public/fixtures/opcode_spammer.ts +1725 -0
- package/src/public/fixtures/public_tx_simulation_tester.ts +40 -6
- package/src/public/fixtures/simple_contract_data_source.ts +1 -1
- package/src/public/fixtures/token_test.ts +1 -1
- package/src/public/fixtures/utils.ts +2 -3
- package/src/public/fuzzing/avm_fuzzer_simulator.ts +288 -0
- package/src/public/fuzzing/avm_simulator_bin.ts +165 -0
- package/src/public/hinting_db_sources.ts +6 -2
- package/src/public/index.ts +2 -0
- package/src/public/public_db_sources.ts +1 -1
- package/src/public/public_processor/guarded_merkle_tree.ts +4 -0
- package/src/public/public_processor/public_processor.ts +31 -14
- package/src/public/public_processor/public_processor_metrics.ts +11 -45
- package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +19 -60
- package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +56 -3
- package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +1 -1
- package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +7 -10
- 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 +2 -0
- package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +1 -1
- package/src/public/public_tx_simulator/public_tx_context.ts +1 -1
- package/src/public/public_tx_simulator/public_tx_simulator.ts +18 -5
- package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +23 -0
- package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +1 -1
- package/src/public/side_effect_trace.ts +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 +4 -18
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NULLIFIER_SUBTREE_HEIGHT } from '@aztec/constants';
|
|
2
2
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
3
|
-
import { Fr } from '@aztec/foundation/
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
5
5
|
import { sleep } from '@aztec/foundation/sleep';
|
|
6
6
|
import { DateProvider, Timer, elapsed, executeTimeout } from '@aztec/foundation/timer';
|
|
@@ -126,7 +126,7 @@ export class PublicProcessor implements Traceable {
|
|
|
126
126
|
private dateProvider: DateProvider,
|
|
127
127
|
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
128
128
|
private log = createLogger('simulator:public-processor'),
|
|
129
|
-
private opts: Pick<SequencerConfig, 'fakeProcessingDelayPerTxMs'> = {},
|
|
129
|
+
private opts: Pick<SequencerConfig, 'fakeProcessingDelayPerTxMs' | 'fakeThrowAfterProcessingTxCount'> = {},
|
|
130
130
|
) {
|
|
131
131
|
this.metrics = new PublicProcessorMetrics(telemetryClient, 'PublicProcessor');
|
|
132
132
|
}
|
|
@@ -146,7 +146,7 @@ export class PublicProcessor implements Traceable {
|
|
|
146
146
|
txs: Iterable<Tx> | AsyncIterable<Tx>,
|
|
147
147
|
limits: PublicProcessorLimits = {},
|
|
148
148
|
validator: PublicProcessorValidator = {},
|
|
149
|
-
): Promise<[ProcessedTx[], FailedTx[], Tx[], NestedProcessReturnValues[]]> {
|
|
149
|
+
): Promise<[ProcessedTx[], FailedTx[], Tx[], NestedProcessReturnValues[], number]> {
|
|
150
150
|
const { maxTransactions, maxBlockSize, deadline, maxBlockGas, maxBlobFields } = limits;
|
|
151
151
|
const { preprocessValidator, nullifierCache } = validator;
|
|
152
152
|
const result: ProcessedTx[] = [];
|
|
@@ -160,7 +160,7 @@ export class PublicProcessor implements Traceable {
|
|
|
160
160
|
let totalBlockGas = new Gas(0, 0);
|
|
161
161
|
let totalBlobFields = 0;
|
|
162
162
|
|
|
163
|
-
for await (const
|
|
163
|
+
for await (const tx of txs) {
|
|
164
164
|
// Only process up to the max tx limit
|
|
165
165
|
if (maxTransactions !== undefined && result.length >= maxTransactions) {
|
|
166
166
|
this.log.debug(`Stopping tx processing due to reaching the max tx limit.`);
|
|
@@ -174,8 +174,8 @@ export class PublicProcessor implements Traceable {
|
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
// Skip this tx if it'd exceed max block size
|
|
177
|
-
const txHash =
|
|
178
|
-
const preTxSizeInBytes =
|
|
177
|
+
const txHash = tx.getTxHash().toString();
|
|
178
|
+
const preTxSizeInBytes = tx.getEstimatedPrivateTxEffectsSize();
|
|
179
179
|
if (maxBlockSize !== undefined && totalSizeInBytes + preTxSizeInBytes > maxBlockSize) {
|
|
180
180
|
this.log.warn(`Skipping processing of tx ${txHash} sized ${preTxSizeInBytes} bytes due to block size limit`, {
|
|
181
181
|
txHash,
|
|
@@ -187,7 +187,7 @@ export class PublicProcessor implements Traceable {
|
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
// Skip this tx if its gas limit would exceed the block gas limit
|
|
190
|
-
const txGasLimit =
|
|
190
|
+
const txGasLimit = tx.data.constants.txContext.gasSettings.gasLimits;
|
|
191
191
|
if (maxBlockGas !== undefined && totalBlockGas.add(txGasLimit).gtAny(maxBlockGas)) {
|
|
192
192
|
this.log.warn(`Skipping processing of tx ${txHash} due to block gas limit`, {
|
|
193
193
|
txHash,
|
|
@@ -198,9 +198,6 @@ export class PublicProcessor implements Traceable {
|
|
|
198
198
|
continue;
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
-
// The processor modifies the tx objects in place, so we need to clone them.
|
|
202
|
-
const tx = Tx.clone(origTx);
|
|
203
|
-
|
|
204
201
|
// We validate the tx before processing it, to avoid unnecessary work.
|
|
205
202
|
if (preprocessValidator) {
|
|
206
203
|
const result = await preprocessValidator.validateTx(tx);
|
|
@@ -233,6 +230,12 @@ export class PublicProcessor implements Traceable {
|
|
|
233
230
|
try {
|
|
234
231
|
const [processedTx, returnValues] = await this.processTx(tx, deadline);
|
|
235
232
|
|
|
233
|
+
// Inject a fake processing failure after N txs if requested
|
|
234
|
+
const fakeThrowAfter = this.opts.fakeThrowAfterProcessingTxCount;
|
|
235
|
+
if (fakeThrowAfter !== undefined && result.length + failed.length + 1 >= fakeThrowAfter) {
|
|
236
|
+
throw new Error(`Fake error after processing ${fakeThrowAfter} txs`);
|
|
237
|
+
}
|
|
238
|
+
|
|
236
239
|
const txBlobFields = processedTx.txEffect.getNumBlobFields();
|
|
237
240
|
|
|
238
241
|
// If the actual size of this tx would exceed block size, skip it
|
|
@@ -251,6 +254,7 @@ export class PublicProcessor implements Traceable {
|
|
|
251
254
|
}
|
|
252
255
|
|
|
253
256
|
// If the actual blob fields of this tx would exceed the limit, skip it
|
|
257
|
+
// Note: maxBlobFields already accounts for block end blob fields and previous blocks in checkpoint.
|
|
254
258
|
if (maxBlobFields !== undefined && totalBlobFields + txBlobFields > maxBlobFields) {
|
|
255
259
|
this.log.debug(
|
|
256
260
|
`Skipping processed tx ${txHash} with ${txBlobFields} blob fields due to max blob fields limit.`,
|
|
@@ -282,7 +286,15 @@ export class PublicProcessor implements Traceable {
|
|
|
282
286
|
if (err?.name === 'PublicProcessorTimeoutError') {
|
|
283
287
|
this.log.warn(`Stopping tx processing due to timeout.`);
|
|
284
288
|
// We hit the transaction execution deadline.
|
|
285
|
-
// There may still be a transaction executing
|
|
289
|
+
// There may still be a transaction executing on a worker thread (C++ via NAPI).
|
|
290
|
+
// Signal cancellation AND WAIT for the simulation to actually stop.
|
|
291
|
+
// This is critical because C++ might be in the middle of a slow operation (e.g., pad_trees)
|
|
292
|
+
// and won't check the cancellation flag until that operation completes.
|
|
293
|
+
// Without waiting, we'd proceed to revert checkpoints while C++ is still writing to state.
|
|
294
|
+
// Wait for C++ to stop gracefully.
|
|
295
|
+
await this.publicTxSimulator.cancel?.();
|
|
296
|
+
|
|
297
|
+
// Now stop the guarded fork to prevent any further TS-side access to the world state.
|
|
286
298
|
await this.guardedMerkleTree.stop();
|
|
287
299
|
|
|
288
300
|
// We now know there can't be any further access to world state. The fork is in a state where there is:
|
|
@@ -338,7 +350,7 @@ export class PublicProcessor implements Traceable {
|
|
|
338
350
|
totalSizeInBytes,
|
|
339
351
|
});
|
|
340
352
|
|
|
341
|
-
return [result, failed, usedTxs, returns];
|
|
353
|
+
return [result, failed, usedTxs, returns, totalBlobFields];
|
|
342
354
|
}
|
|
343
355
|
|
|
344
356
|
private async checkWorldStateUnchanged(
|
|
@@ -523,7 +535,7 @@ export class PublicProcessor implements Traceable {
|
|
|
523
535
|
|
|
524
536
|
const result = await this.publicTxSimulator.simulate(tx);
|
|
525
537
|
// TODO: use the callStackMetadata here to extract more data about public execution
|
|
526
|
-
const { hints, publicInputs, gasUsed, revertCode /*callStackMetadata*/ } = result;
|
|
538
|
+
const { hints, publicInputs, publicTxEffect, gasUsed, revertCode /*callStackMetadata*/ } = result;
|
|
527
539
|
|
|
528
540
|
const contractClassLogs = revertCode.isOK()
|
|
529
541
|
? tx.getContractClassLogs()
|
|
@@ -542,10 +554,15 @@ export class PublicProcessor implements Traceable {
|
|
|
542
554
|
const appLogicReturnValues: NestedProcessReturnValues[] = result.getAppLogicReturnValues();
|
|
543
555
|
// Extract the revert reason from the call stack metadata.
|
|
544
556
|
const revertReason = result.findRevertReason();
|
|
557
|
+
// Create proving request if we have hints and public inputs.
|
|
558
|
+
const avmProvingRequest =
|
|
559
|
+
hints && publicInputs ? PublicProcessor.generateProvingRequest(publicInputs, hints) : undefined;
|
|
545
560
|
|
|
546
561
|
const processedTx = makeProcessedTxFromTxWithPublicCalls(
|
|
547
562
|
tx,
|
|
548
|
-
|
|
563
|
+
this.globalVariables,
|
|
564
|
+
avmProvingRequest,
|
|
565
|
+
publicTxEffect,
|
|
549
566
|
gasUsed,
|
|
550
567
|
revertCode,
|
|
551
568
|
revertReason,
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
type TelemetryClient,
|
|
10
10
|
type Tracer,
|
|
11
11
|
type UpDownCounter,
|
|
12
|
-
ValueType,
|
|
13
12
|
} from '@aztec/telemetry-client';
|
|
14
13
|
|
|
15
14
|
export class PublicProcessorMetrics {
|
|
@@ -34,60 +33,27 @@ export class PublicProcessorMetrics {
|
|
|
34
33
|
this.tracer = client.getTracer(name);
|
|
35
34
|
const meter = client.getMeter(name);
|
|
36
35
|
|
|
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
|
-
});
|
|
36
|
+
this.txDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TX_DURATION);
|
|
42
37
|
|
|
43
|
-
this.txCount = meter.createUpDownCounter(Metrics.PUBLIC_PROCESSOR_TX_COUNT
|
|
44
|
-
description: 'Number of transactions processed',
|
|
45
|
-
});
|
|
38
|
+
this.txCount = meter.createUpDownCounter(Metrics.PUBLIC_PROCESSOR_TX_COUNT);
|
|
46
39
|
|
|
47
|
-
this.txPhaseCount = meter.createUpDownCounter(Metrics.PUBLIC_PROCESSOR_TX_PHASE_COUNT
|
|
48
|
-
description: 'Number of phases processed',
|
|
49
|
-
});
|
|
40
|
+
this.txPhaseCount = meter.createUpDownCounter(Metrics.PUBLIC_PROCESSOR_TX_PHASE_COUNT);
|
|
50
41
|
|
|
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
|
-
});
|
|
42
|
+
this.phaseDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_PHASE_DURATION);
|
|
56
43
|
|
|
57
|
-
this.phaseCount = meter.createUpDownCounter(Metrics.PUBLIC_PROCESSOR_PHASE_COUNT
|
|
58
|
-
description: 'Number of failed phases',
|
|
59
|
-
});
|
|
44
|
+
this.phaseCount = meter.createUpDownCounter(Metrics.PUBLIC_PROCESSOR_PHASE_COUNT);
|
|
60
45
|
|
|
61
|
-
this.bytecodeDeployed = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_DEPLOY_BYTECODE_SIZE
|
|
62
|
-
description: 'Size of deployed bytecode',
|
|
63
|
-
unit: 'By',
|
|
64
|
-
});
|
|
46
|
+
this.bytecodeDeployed = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_DEPLOY_BYTECODE_SIZE);
|
|
65
47
|
|
|
66
|
-
this.totalGas = meter.createGauge(Metrics.PUBLIC_PROCESSOR_TOTAL_GAS
|
|
67
|
-
description: 'Total gas used in block',
|
|
68
|
-
unit: 'gas',
|
|
69
|
-
});
|
|
48
|
+
this.totalGas = meter.createGauge(Metrics.PUBLIC_PROCESSOR_TOTAL_GAS);
|
|
70
49
|
|
|
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
|
-
});
|
|
50
|
+
this.totalGasHistogram = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TOTAL_GAS_HISTOGRAM);
|
|
75
51
|
|
|
76
|
-
this.txGas = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TX_GAS
|
|
77
|
-
description: 'Gas used in transaction',
|
|
78
|
-
unit: 'gas/tx',
|
|
79
|
-
});
|
|
52
|
+
this.txGas = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TX_GAS);
|
|
80
53
|
|
|
81
|
-
this.gasRate = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_GAS_RATE
|
|
82
|
-
description: 'L2 gas per second for complete block',
|
|
83
|
-
unit: 'gas/s',
|
|
84
|
-
});
|
|
54
|
+
this.gasRate = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_GAS_RATE);
|
|
85
55
|
|
|
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
|
-
});
|
|
56
|
+
this.treeInsertionDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TREE_INSERTION);
|
|
91
57
|
}
|
|
92
58
|
|
|
93
59
|
recordPhaseDuration(phaseName: TxExecutionPhase, durationMs: number) {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import type { ContractProvider } from '@aztec/native';
|
|
4
4
|
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
5
5
|
import { deserializeFromMessagePack, serializeWithMessagePack } from '@aztec/stdlib/avm';
|
|
6
6
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
7
7
|
import { ContractDeploymentData } from '@aztec/stdlib/contract';
|
|
8
|
-
import { ContractClassLog, ContractClassLogFields, PrivateLog } from '@aztec/stdlib/logs';
|
|
9
8
|
import type { GlobalVariables } from '@aztec/stdlib/tx';
|
|
10
9
|
|
|
11
10
|
import type { PublicContractsDB } from '../public_db_sources.js';
|
|
@@ -19,7 +18,7 @@ export class ContractProviderForCpp implements ContractProvider {
|
|
|
19
18
|
) {}
|
|
20
19
|
|
|
21
20
|
public getContractInstance = async (address: string): Promise<Buffer | undefined> => {
|
|
22
|
-
this.log.
|
|
21
|
+
this.log.trace(`Contract provider callback: getContractInstance(${address})`);
|
|
23
22
|
|
|
24
23
|
const aztecAddr = AztecAddress.fromString(address);
|
|
25
24
|
|
|
@@ -34,7 +33,7 @@ export class ContractProviderForCpp implements ContractProvider {
|
|
|
34
33
|
};
|
|
35
34
|
|
|
36
35
|
public getContractClass = async (classId: string): Promise<Buffer | undefined> => {
|
|
37
|
-
this.log.
|
|
36
|
+
this.log.trace(`Contract provider callback: getContractClass(${classId})`);
|
|
38
37
|
|
|
39
38
|
// Parse classId string to Fr
|
|
40
39
|
const classIdFr = Fr.fromString(classId);
|
|
@@ -51,20 +50,20 @@ export class ContractProviderForCpp implements ContractProvider {
|
|
|
51
50
|
};
|
|
52
51
|
|
|
53
52
|
public addContracts = async (contractDeploymentDataBuffer: Buffer): Promise<void> => {
|
|
54
|
-
this.log.
|
|
53
|
+
this.log.trace(`Contract provider callback: addContracts`);
|
|
55
54
|
|
|
56
55
|
const rawData: any = deserializeFromMessagePack(contractDeploymentDataBuffer);
|
|
57
56
|
|
|
58
|
-
// Construct
|
|
59
|
-
const contractDeploymentData =
|
|
57
|
+
// Construct ContractDeploymentData from plain object.
|
|
58
|
+
const contractDeploymentData = ContractDeploymentData.fromPlainObject(rawData);
|
|
60
59
|
|
|
61
60
|
// Add contracts to the contracts DB
|
|
62
|
-
this.log.
|
|
61
|
+
this.log.trace(`Calling contractsDB.addContracts`);
|
|
63
62
|
await this.contractsDB.addContracts(contractDeploymentData);
|
|
64
63
|
};
|
|
65
64
|
|
|
66
65
|
public getBytecodeCommitment = async (classId: string): Promise<Buffer | undefined> => {
|
|
67
|
-
this.log.
|
|
66
|
+
this.log.trace(`Contract provider callback: getBytecodeCommitment(${classId})`);
|
|
68
67
|
|
|
69
68
|
// Parse classId string to Fr
|
|
70
69
|
const classIdFr = Fr.fromString(classId);
|
|
@@ -82,18 +81,23 @@ export class ContractProviderForCpp implements ContractProvider {
|
|
|
82
81
|
};
|
|
83
82
|
|
|
84
83
|
public getDebugFunctionName = async (address: string, selector: string): Promise<string | undefined> => {
|
|
85
|
-
this.log.
|
|
84
|
+
this.log.trace(`Contract provider callback: getDebugFunctionName(${address}, ${selector})`);
|
|
86
85
|
|
|
87
86
|
// Parse address and selector strings
|
|
88
87
|
const aztecAddr = AztecAddress.fromString(address);
|
|
89
88
|
const selectorFr = Fr.fromString(selector);
|
|
90
|
-
const functionSelector = FunctionSelector.
|
|
89
|
+
const functionSelector = FunctionSelector.fromFieldOrUndefined(selectorFr);
|
|
90
|
+
|
|
91
|
+
if (!functionSelector) {
|
|
92
|
+
this.log.trace(`calldata[0] is not a function selector: ${selector}`);
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
91
95
|
|
|
92
96
|
// Fetch debug function name from the contracts DB
|
|
93
97
|
const name = await this.contractsDB.getDebugFunctionName(aztecAddr, functionSelector);
|
|
94
98
|
|
|
95
99
|
if (!name) {
|
|
96
|
-
this.log.
|
|
100
|
+
this.log.trace(`Debug function name not found for ${address}:${selector}`);
|
|
97
101
|
return undefined;
|
|
98
102
|
}
|
|
99
103
|
|
|
@@ -101,62 +105,17 @@ export class ContractProviderForCpp implements ContractProvider {
|
|
|
101
105
|
};
|
|
102
106
|
|
|
103
107
|
public createCheckpoint = (): Promise<void> => {
|
|
104
|
-
this.log.
|
|
108
|
+
this.log.trace(`Contract provider callback: createCheckpoint`);
|
|
105
109
|
return Promise.resolve(this.contractsDB.createCheckpoint());
|
|
106
110
|
};
|
|
107
111
|
|
|
108
112
|
public commitCheckpoint = (): Promise<void> => {
|
|
109
|
-
this.log.
|
|
113
|
+
this.log.trace(`Contract provider callback: commitCheckpoint`);
|
|
110
114
|
return Promise.resolve(this.contractsDB.commitCheckpoint());
|
|
111
115
|
};
|
|
112
116
|
|
|
113
117
|
public revertCheckpoint = (): Promise<void> => {
|
|
114
|
-
this.log.
|
|
118
|
+
this.log.trace(`Contract provider callback: revertCheckpoint`);
|
|
115
119
|
return Promise.resolve(this.contractsDB.revertCheckpoint());
|
|
116
120
|
};
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Reconstruct ContractDeploymentData from plain msgpack-deserialized objects.
|
|
120
|
-
*
|
|
121
|
-
* msgpackr does not automatically apply extensions to nested fields, so we need to
|
|
122
|
-
* manually reconstruct ContractClassLog and PrivateLog instances with proper types.
|
|
123
|
-
*
|
|
124
|
-
* TODO(dbanks12): we really shouldn't have to do this.... We need to for now because
|
|
125
|
-
* msgpack deserialization doesn't give us actual typed objects, but rather just JSON.
|
|
126
|
-
* It would be easier if all types matched between languages (like AztecAddress which is just
|
|
127
|
-
* FF in C++).
|
|
128
|
-
*/
|
|
129
|
-
private reconstructContractDeploymentData(rawData: any): ContractDeploymentData {
|
|
130
|
-
// Helper to ensure a value is an Fr instance
|
|
131
|
-
const toFr = (value: any): Fr => {
|
|
132
|
-
if (value instanceof Fr) {
|
|
133
|
-
return value;
|
|
134
|
-
}
|
|
135
|
-
if (Buffer.isBuffer(value)) {
|
|
136
|
-
return Fr.fromBuffer(value);
|
|
137
|
-
}
|
|
138
|
-
return new Fr(value);
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
// Reconstruct ContractClassLogs
|
|
142
|
-
const contractClassLogs = (rawData.contractClassLogs || []).map((log: any) => {
|
|
143
|
-
// Convert contractAddress to TS AztecAddress
|
|
144
|
-
const addressFr = toFr(log.contractAddress);
|
|
145
|
-
const address = AztecAddress.fromField(addressFr);
|
|
146
|
-
|
|
147
|
-
// Ensure all fields are Fr instances
|
|
148
|
-
const fields = (log.fields.fields || []).map((field: any) => toFr(field));
|
|
149
|
-
|
|
150
|
-
// Create proper ContractClassLog instance
|
|
151
|
-
return new ContractClassLog(address, new ContractClassLogFields(fields), log.emittedLength);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
// Reconstruct PrivateLogs - ensure fields are Fr instances
|
|
155
|
-
const privateLogs = (rawData.privateLogs || []).map((log: any) => {
|
|
156
|
-
const fields = (log.fields || []).map((field: any) => toFr(field));
|
|
157
|
-
return new PrivateLog(fields as any, log.emittedLength);
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
return new ContractDeploymentData(contractClassLogs, privateLogs);
|
|
161
|
-
}
|
|
162
121
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Logger, createLogger, logLevel } from '@aztec/foundation/log';
|
|
2
|
-
import {
|
|
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,6 +34,10 @@ 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,
|
|
@@ -85,12 +90,33 @@ export class CppPublicTxSimulator extends PublicTxSimulator implements PublicTxS
|
|
|
85
90
|
this.log.trace(`Serializing fast simulation inputs to msgpack...`);
|
|
86
91
|
const inputBuffer = fastSimInputs.serializeWithMessagePack();
|
|
87
92
|
|
|
93
|
+
// Create cancellation token for this simulation
|
|
94
|
+
this.cancellationToken = createCancellationToken();
|
|
95
|
+
|
|
96
|
+
// Store the promise so cancel() can wait for it
|
|
97
|
+
this.log.debug(`Calling C++ simulator for tx ${txHash}`);
|
|
98
|
+
this.simulationPromise = avmSimulate(
|
|
99
|
+
inputBuffer,
|
|
100
|
+
contractProvider,
|
|
101
|
+
wsCppHandle,
|
|
102
|
+
logLevel,
|
|
103
|
+
// TODO: re-enable logging
|
|
104
|
+
undefined,
|
|
105
|
+
this.cancellationToken,
|
|
106
|
+
);
|
|
107
|
+
|
|
88
108
|
let resultBuffer: Buffer;
|
|
89
109
|
try {
|
|
90
|
-
|
|
91
|
-
resultBuffer = await avmSimulate(inputBuffer, contractProvider, wsCppHandle, logLevel);
|
|
110
|
+
resultBuffer = await this.simulationPromise;
|
|
92
111
|
} catch (error: any) {
|
|
112
|
+
// Check if this was a cancellation
|
|
113
|
+
if (error.message?.includes('Simulation cancelled')) {
|
|
114
|
+
throw new SimulationError(`C++ simulation cancelled`, []);
|
|
115
|
+
}
|
|
93
116
|
throw new SimulationError(`C++ simulation failed: ${error.message}`, []);
|
|
117
|
+
} finally {
|
|
118
|
+
this.cancellationToken = undefined;
|
|
119
|
+
this.simulationPromise = undefined;
|
|
94
120
|
}
|
|
95
121
|
|
|
96
122
|
// If we've reached this point, C++ succeeded during simulation,
|
|
@@ -109,6 +135,33 @@ export class CppPublicTxSimulator extends PublicTxSimulator implements PublicTxS
|
|
|
109
135
|
|
|
110
136
|
return cppResult;
|
|
111
137
|
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Cancel the current simulation if one is in progress.
|
|
141
|
+
* This signals the C++ simulator to stop at the next opcode or before the next WorldState write.
|
|
142
|
+
* Safe to call even if no simulation is in progress.
|
|
143
|
+
*
|
|
144
|
+
* @param waitTimeoutMs - If provided, wait up to this many ms for the simulation to actually stop.
|
|
145
|
+
* This is important because C++ might be in the middle of a slow operation
|
|
146
|
+
* (e.g., pad_trees) and won't check the cancellation flag until it completes.
|
|
147
|
+
* Default timeout of 100ms after cancellation.
|
|
148
|
+
*/
|
|
149
|
+
public async cancel(waitTimeoutMs: number = 100): Promise<void> {
|
|
150
|
+
if (this.cancellationToken) {
|
|
151
|
+
this.log.debug('Cancelling C++ simulation');
|
|
152
|
+
cancelSimulation(this.cancellationToken);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Wait for the simulation to actually complete if not already done
|
|
156
|
+
if (this.simulationPromise) {
|
|
157
|
+
this.log.debug(`Waiting up to ${waitTimeoutMs}ms for C++ simulation to stop`);
|
|
158
|
+
await Promise.race([
|
|
159
|
+
this.simulationPromise.catch(() => {}), // Ignore rejection, just wait for completion
|
|
160
|
+
sleep(waitTimeoutMs),
|
|
161
|
+
]);
|
|
162
|
+
this.log.debug('C++ simulation stopped or wait timed out');
|
|
163
|
+
}
|
|
164
|
+
}
|
|
112
165
|
}
|
|
113
166
|
|
|
114
167
|
export class MeasuredCppPublicTxSimulator extends CppPublicTxSimulator implements MeasuredPublicTxSimulatorInterface {
|
|
@@ -64,7 +64,7 @@ export class CppPublicTxSimulatorHintedDbs extends PublicTxSimulator implements
|
|
|
64
64
|
this.log.debug(`TS simulation succeeded for tx ${txHash}`);
|
|
65
65
|
|
|
66
66
|
// Extract the full AvmCircuitInputs from the TS result
|
|
67
|
-
const avmCircuitInputs = new AvmCircuitInputs(tsResult.hints!, tsResult.publicInputs);
|
|
67
|
+
const avmCircuitInputs = new AvmCircuitInputs(tsResult.hints!, tsResult.publicInputs!);
|
|
68
68
|
|
|
69
69
|
// Second, run C++ simulation with hinted DBs
|
|
70
70
|
this.log.debug(`Running C++ simulation with hinted DBs for tx ${txHash}`);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type Logger, createLogger, logLevel } from '@aztec/foundation/log';
|
|
2
|
-
import { writeTestData } from '@aztec/foundation/testing/files';
|
|
3
2
|
import { avmSimulate } from '@aztec/native';
|
|
4
3
|
import { ProtocolContractsList } from '@aztec/protocol-contracts';
|
|
5
4
|
import {
|
|
@@ -40,7 +39,7 @@ export class CppVsTsPublicTxSimulator extends PublicTxSimulator implements Publi
|
|
|
40
39
|
config?: Partial<PublicSimulatorConfig>,
|
|
41
40
|
) {
|
|
42
41
|
super(merkleTree, contractsDB, globalVariables, config);
|
|
43
|
-
this.log = createLogger(`simulator:
|
|
42
|
+
this.log = createLogger(`simulator:cpp_vs_public_tx_simulator`);
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
/**
|
|
@@ -126,12 +125,6 @@ export class CppVsTsPublicTxSimulator extends PublicTxSimulator implements Publi
|
|
|
126
125
|
// Deserialize the msgpack result
|
|
127
126
|
this.log.debug(`Deserializing C++ from buffer (size: ${resultBuffer.length})...`);
|
|
128
127
|
const cppResultJSON: object = deserializeFromMessagePack(resultBuffer);
|
|
129
|
-
// Write testdata if AZTEC_WRITE_TESTDATA=1.
|
|
130
|
-
writeTestData(
|
|
131
|
-
`barretenberg/cpp/src/barretenberg/vm2/testing/tx_result_${txHash}.testdata.bin`,
|
|
132
|
-
resultBuffer,
|
|
133
|
-
/*raw=*/ true,
|
|
134
|
-
);
|
|
135
128
|
this.log.debug(`Deserializing C++ result to PublicTxResult...`);
|
|
136
129
|
const cppResult = PublicTxResult.fromPlainObject(cppResultJSON);
|
|
137
130
|
this.log.debug(`Done.`);
|
|
@@ -140,7 +133,10 @@ export class CppVsTsPublicTxSimulator extends PublicTxSimulator implements Publi
|
|
|
140
133
|
assert(cppResult.gasUsed.publicGas.equals(tsResult.gasUsed.publicGas));
|
|
141
134
|
assert(cppResult.gasUsed.teardownGas.equals(tsResult.gasUsed.teardownGas));
|
|
142
135
|
assert(cppResult.gasUsed.billedGas.equals(tsResult.gasUsed.billedGas));
|
|
143
|
-
assert(cppResult.
|
|
136
|
+
assert(cppResult.publicTxEffect.equals(tsResult.publicTxEffect));
|
|
137
|
+
if (cppResult.publicInputs !== undefined) {
|
|
138
|
+
assert(cppResult.publicInputs!.toBuffer().equals(tsResult.publicInputs!.toBuffer()));
|
|
139
|
+
}
|
|
144
140
|
|
|
145
141
|
// TODO(fcarreiro): complete this.
|
|
146
142
|
// Check that C++ hints are a strict subset of TS hints.
|
|
@@ -209,7 +205,8 @@ export class CppVsTsPublicTxSimulator extends PublicTxSimulator implements Publi
|
|
|
209
205
|
cppGasUsed: cppResult.gasUsed.totalGas.l2Gas,
|
|
210
206
|
});
|
|
211
207
|
|
|
212
|
-
|
|
208
|
+
// Return cpp result as it has more detailed metadata / revert reasons
|
|
209
|
+
return cppResult;
|
|
213
210
|
}
|
|
214
211
|
}
|
|
215
212
|
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AvmCircuitInputs,
|
|
3
|
+
AvmCircuitPublicInputs,
|
|
4
|
+
AvmExecutionHints,
|
|
5
|
+
type PublicSimulatorConfig,
|
|
6
|
+
PublicTxResult,
|
|
7
|
+
serializeWithMessagePack,
|
|
8
|
+
} from '@aztec/stdlib/avm';
|
|
9
|
+
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
10
|
+
import type { GlobalVariables, Tx, TxHash } from '@aztec/stdlib/tx';
|
|
11
|
+
|
|
12
|
+
import { strict as assert } from 'assert';
|
|
13
|
+
import { mkdirSync, writeFileSync } from 'fs';
|
|
14
|
+
import { join } from 'path';
|
|
15
|
+
|
|
16
|
+
import type { PublicContractsDB } from '../public_db_sources.js';
|
|
17
|
+
import { CppPublicTxSimulator } from './cpp_public_tx_simulator.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A C++ public tx simulator that dumps AVM circuit inputs to disk after simulation.
|
|
21
|
+
* Used during nightly CI runs to collect circuit inputs for benchmarking.
|
|
22
|
+
*/
|
|
23
|
+
export class DumpingCppPublicTxSimulator extends CppPublicTxSimulator {
|
|
24
|
+
private readonly outputDir: string;
|
|
25
|
+
|
|
26
|
+
constructor(
|
|
27
|
+
merkleTree: MerkleTreeWriteOperations,
|
|
28
|
+
contractsDB: PublicContractsDB,
|
|
29
|
+
globalVariables: GlobalVariables,
|
|
30
|
+
config: Partial<PublicSimulatorConfig>,
|
|
31
|
+
outputDir: string,
|
|
32
|
+
) {
|
|
33
|
+
super(merkleTree, contractsDB, globalVariables, config);
|
|
34
|
+
assert(config.collectHints === true, 'collectHints must be enabled to dump AVM circuit inputs');
|
|
35
|
+
assert(config.collectPublicInputs === true, 'collectPublicInputs must be enabled to dump AVM circuit inputs');
|
|
36
|
+
this.outputDir = outputDir;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public override async simulate(tx: Tx): Promise<PublicTxResult> {
|
|
40
|
+
const result = await super.simulate(tx);
|
|
41
|
+
|
|
42
|
+
// Dump the circuit inputs after successful simulation
|
|
43
|
+
const txHash = this.computeTxHash(tx);
|
|
44
|
+
this.dumpAvmCircuitInputs(result, txHash);
|
|
45
|
+
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Dumps AVM circuit inputs to disk.
|
|
51
|
+
*
|
|
52
|
+
* @param result - The simulation result containing hints and public inputs
|
|
53
|
+
* @param txHash - The transaction hash to use in the filename
|
|
54
|
+
*/
|
|
55
|
+
private dumpAvmCircuitInputs(result: PublicTxResult, txHash: TxHash): void {
|
|
56
|
+
try {
|
|
57
|
+
// Ensure the output directory exists
|
|
58
|
+
mkdirSync(this.outputDir, { recursive: true });
|
|
59
|
+
|
|
60
|
+
// Generate filename using transaction hash
|
|
61
|
+
const filename = `avm-circuit-inputs-tx-${txHash.toString()}.bin`;
|
|
62
|
+
const filepath = join(this.outputDir, filename);
|
|
63
|
+
|
|
64
|
+
// Create circuit inputs from the result
|
|
65
|
+
const hints = result.hints ?? AvmExecutionHints.empty();
|
|
66
|
+
const publicInputs = result.publicInputs ?? AvmCircuitPublicInputs.empty();
|
|
67
|
+
const avmCircuitInputs = new AvmCircuitInputs(hints, publicInputs);
|
|
68
|
+
|
|
69
|
+
// Serialize the circuit inputs using MessagePack
|
|
70
|
+
const serialized = serializeWithMessagePack(avmCircuitInputs);
|
|
71
|
+
|
|
72
|
+
// Write to disk
|
|
73
|
+
writeFileSync(filepath, serialized);
|
|
74
|
+
|
|
75
|
+
this.log.debug(`Dumped AVM circuit inputs to ${filepath}`);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
// Non-blocking error handling - log but don't interrupt processing
|
|
78
|
+
this.log.warn(`Failed to dump AVM circuit inputs for tx ${txHash.toString()}: ${error}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
2
|
+
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
3
|
+
import type { GlobalVariables } from '@aztec/stdlib/tx';
|
|
4
|
+
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
5
|
+
|
|
6
|
+
import type { PublicContractsDB } from '../public_db_sources.js';
|
|
7
|
+
import { TelemetryCppPublicTxSimulator } from './cpp_public_tx_simulator.js';
|
|
8
|
+
import { DumpingCppPublicTxSimulator } from './dumping_cpp_public_tx_simulator.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Creates a public tx simulator for block building.
|
|
12
|
+
* Uses DumpingCppPublicTxSimulator if DUMP_AVM_INPUTS_TO_DIR env var is set (for CI/testing avm circuit),
|
|
13
|
+
* otherwise uses TelemetryCppPublicTxSimulator (for production).
|
|
14
|
+
*/
|
|
15
|
+
export function createPublicTxSimulatorForBlockBuilding(
|
|
16
|
+
merkleTree: MerkleTreeWriteOperations,
|
|
17
|
+
contractsDB: PublicContractsDB,
|
|
18
|
+
globalVariables: GlobalVariables,
|
|
19
|
+
telemetryClient: TelemetryClient,
|
|
20
|
+
) {
|
|
21
|
+
const config = PublicSimulatorConfig.from({
|
|
22
|
+
skipFeeEnforcement: false,
|
|
23
|
+
collectDebugLogs: false,
|
|
24
|
+
collectHints: false,
|
|
25
|
+
collectPublicInputs: false,
|
|
26
|
+
collectStatistics: false,
|
|
27
|
+
collectCallMetadata: false,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const dumpDir = process.env.DUMP_AVM_INPUTS_TO_DIR;
|
|
31
|
+
if (dumpDir) {
|
|
32
|
+
// must collect hints and PIs for dumping
|
|
33
|
+
const dumpingConfig = {
|
|
34
|
+
...config,
|
|
35
|
+
collectHints: true,
|
|
36
|
+
collectPublicInputs: true,
|
|
37
|
+
};
|
|
38
|
+
return new DumpingCppPublicTxSimulator(merkleTree, contractsDB, globalVariables, dumpingConfig, dumpDir);
|
|
39
|
+
}
|
|
40
|
+
return new TelemetryCppPublicTxSimulator(merkleTree, contractsDB, globalVariables, telemetryClient, config);
|
|
41
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from './public_tx_simulator.js';
|
|
2
2
|
export { CppPublicTxSimulator, TelemetryCppPublicTxSimulator } from './cpp_public_tx_simulator.js';
|
|
3
|
+
export { DumpingCppPublicTxSimulator } from './dumping_cpp_public_tx_simulator.js';
|
|
4
|
+
export { createPublicTxSimulatorForBlockBuilding } from './factories.js';
|
|
3
5
|
export type { PublicTxSimulatorInterface } from './public_tx_simulator_interface.js';
|
|
4
6
|
export { TelemetryPublicTxSimulator } from './telemetry_public_tx_simulator.js';
|
|
5
7
|
export type { PublicTxResult, PublicSimulatorConfig as PublicTxSimulatorConfig } from '@aztec/stdlib/avm';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Fr } from '@aztec/foundation/
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import { Timer } from '@aztec/foundation/timer';
|
|
3
3
|
import type { PublicSimulatorConfig, PublicTxResult } from '@aztec/stdlib/avm';
|
|
4
4
|
import type { Gas } from '@aztec/stdlib/gas';
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
7
7
|
} from '@aztec/constants';
|
|
8
8
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
9
|
-
import { Fr } from '@aztec/foundation/
|
|
9
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
10
10
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
11
11
|
import {
|
|
12
12
|
AvmAccumulatedData,
|