@aztec/simulator 0.0.1-commit.b655e406 → 0.0.1-commit.fce3e4f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/client.d.ts +1 -1
- package/dest/common/errors.d.ts +1 -7
- package/dest/common/errors.d.ts.map +1 -1
- package/dest/common/index.d.ts +1 -1
- package/dest/common/stats/index.d.ts +1 -1
- package/dest/common/stats/stats.d.ts +1 -1
- package/dest/private/acvm/acvm.d.ts +1 -1
- package/dest/private/acvm/acvm_types.d.ts +1 -1
- package/dest/private/acvm/deserialize.d.ts +1 -1
- package/dest/private/acvm/index.d.ts +1 -1
- package/dest/private/acvm/serialize.d.ts +1 -1
- package/dest/private/acvm_native.d.ts +1 -1
- package/dest/private/acvm_native.d.ts.map +1 -1
- package/dest/private/acvm_wasm.d.ts +1 -1
- package/dest/private/acvm_wasm.d.ts.map +1 -1
- package/dest/private/acvm_wasm_with_blobs.d.ts +1 -1
- package/dest/private/acvm_wasm_with_blobs.d.ts.map +1 -1
- package/dest/private/circuit_recording/circuit_recorder.d.ts +1 -1
- package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts +1 -1
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +1 -1
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +1 -1
- package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -1
- package/dest/private/circuit_simulator.d.ts +1 -1
- package/dest/private/factory.d.ts +1 -1
- package/dest/public/avm/avm_context.d.ts +1 -1
- package/dest/public/avm/avm_context.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.d.ts +1 -1
- package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
- package/dest/public/avm/avm_execution_environment.d.ts +4 -4
- package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/public/avm/avm_execution_environment.js +4 -7
- package/dest/public/avm/avm_gas.d.ts +2 -2
- package/dest/public/avm/avm_gas.d.ts.map +1 -1
- package/dest/public/avm/avm_machine_state.d.ts +1 -1
- package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/public/avm/avm_memory_types.d.ts +13 -13
- package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
- 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 +2 -2
- package/dest/public/avm/avm_simulator_interface.d.ts +1 -1
- package/dest/public/avm/errors.d.ts +1 -1
- package/dest/public/avm/errors.d.ts.map +1 -1
- 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 +11 -2
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/initializers.d.ts +1 -2
- package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
- package/dest/public/avm/fixtures/initializers.js +6 -4
- package/dest/public/avm/fixtures/utils.d.ts +1 -1
- package/dest/public/avm/index.d.ts +1 -1
- package/dest/public/avm/opcodes/accrued_substate.d.ts +1 -1
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/addressing_mode.d.ts +1 -1
- package/dest/public/avm/opcodes/addressing_mode.d.ts.map +1 -1
- package/dest/public/avm/opcodes/arithmetic.d.ts +8 -8
- package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/public/avm/opcodes/bitwise.d.ts +5 -5
- package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/public/avm/opcodes/comparators.d.ts +4 -4
- package/dest/public/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/public/avm/opcodes/contract.d.ts +1 -1
- package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/public/avm/opcodes/control_flow.d.ts +1 -1
- package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
- package/dest/public/avm/opcodes/conversion.d.ts +1 -1
- package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/public/avm/opcodes/ec_add.d.ts +2 -2
- package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/public/avm/opcodes/environment_getters.d.ts +1 -1
- package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.d.ts +1 -1
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/public/avm/opcodes/hashing.d.ts +2 -2
- package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/public/avm/opcodes/index.d.ts +1 -1
- package/dest/public/avm/opcodes/instruction.d.ts +2 -2
- package/dest/public/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/public/avm/opcodes/instruction_impl.d.ts +1 -1
- package/dest/public/avm/opcodes/instruction_impl.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.d.ts +2 -2
- package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/public/avm/opcodes/misc.d.ts +1 -1
- package/dest/public/avm/opcodes/misc.d.ts.map +1 -1
- package/dest/public/avm/opcodes/misc.js +4 -4
- package/dest/public/avm/opcodes/storage.d.ts +3 -3
- package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/public/avm/revert_reason.d.ts +1 -1
- package/dest/public/avm/serialization/buffer_cursor.d.ts +1 -1
- package/dest/public/avm/serialization/buffer_cursor.d.ts.map +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.d.ts +1 -1
- package/dest/public/avm/serialization/instruction_serialization.d.ts +1 -1
- package/dest/public/avm/test_utils.d.ts +1 -1
- package/dest/public/contracts_db_checkpoint.d.ts +16 -0
- package/dest/public/contracts_db_checkpoint.d.ts.map +1 -0
- package/dest/public/contracts_db_checkpoint.js +30 -0
- package/dest/public/db_interfaces.d.ts +13 -1
- package/dest/public/db_interfaces.d.ts.map +1 -1
- package/dest/public/debug_fn_name.d.ts +1 -1
- package/dest/public/executor_metrics.d.ts +3 -2
- package/dest/public/executor_metrics.d.ts.map +1 -1
- package/dest/public/executor_metrics.js +1 -1
- package/dest/public/executor_metrics_interface.d.ts +3 -2
- package/dest/public/executor_metrics_interface.d.ts.map +1 -1
- package/dest/public/fixtures/amm_test.d.ts +1 -1
- package/dest/public/fixtures/bulk_test.d.ts +1 -1
- package/dest/public/fixtures/custom_bytecode_tester.d.ts +2 -2
- package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
- package/dest/public/fixtures/custom_bytecode_tests.d.ts +1 -1
- package/dest/public/fixtures/index.d.ts +1 -1
- package/dest/public/fixtures/minimal_public_tx.d.ts +2 -3
- package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -1
- package/dest/public/fixtures/minimal_public_tx.js +2 -2
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +4 -5
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +15 -11
- package/dest/public/fixtures/simple_contract_data_source.d.ts +1 -1
- package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -1
- package/dest/public/fixtures/token_test.d.ts +1 -1
- package/dest/public/fixtures/token_test.js +3 -4
- package/dest/public/fixtures/utils.d.ts +1 -1
- package/dest/public/hinting_db_sources.d.ts +10 -2
- package/dest/public/hinting_db_sources.d.ts.map +1 -1
- package/dest/public/hinting_db_sources.js +64 -11
- package/dest/public/index.d.ts +3 -2
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/public_db_sources.d.ts +21 -62
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +73 -130
- package/dest/public/public_errors.d.ts +1 -1
- package/dest/public/public_errors.d.ts.map +1 -1
- package/dest/public/public_processor/guarded_merkle_tree.d.ts +3 -3
- package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.d.ts +7 -14
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +27 -29
- package/dest/public/public_processor/public_processor_metrics.d.ts +1 -1
- package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +30 -0
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +133 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +29 -4
- 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 +138 -17
- package/dest/public/public_tx_simulator/index.d.ts +2 -1
- package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +13 -6
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +5 -5
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +5 -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 +12 -4
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +10 -30
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +102 -125
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +2 -2
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +3 -3
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/side_effect_errors.d.ts +1 -1
- package/dest/public/side_effect_errors.d.ts.map +1 -1
- package/dest/public/side_effect_trace.d.ts +1 -2
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace_interface.d.ts +2 -3
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/dest/public/state_manager/index.d.ts +1 -1
- package/dest/public/state_manager/nullifiers.d.ts +1 -1
- package/dest/public/state_manager/nullifiers.d.ts.map +1 -1
- package/dest/public/state_manager/public_storage.d.ts +1 -1
- package/dest/public/state_manager/public_storage.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.d.ts +3 -10
- package/dest/public/state_manager/state_manager.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.js +5 -4
- package/dest/public/test_executor_metrics.d.ts +4 -3
- package/dest/public/test_executor_metrics.d.ts.map +1 -1
- package/dest/public/test_executor_metrics.js +5 -4
- package/dest/public/unique_class_ids.d.ts +1 -1
- package/dest/public/unique_class_ids.d.ts.map +1 -1
- package/dest/public/utils.d.ts +1 -1
- package/dest/server.d.ts +1 -1
- package/dest/testing.d.ts +1 -1
- package/package.json +21 -20
- package/src/public/avm/avm_execution_environment.ts +3 -5
- package/src/public/avm/avm_simulator.ts +3 -4
- package/src/public/avm/fixtures/avm_simulation_tester.ts +9 -1
- package/src/public/avm/fixtures/initializers.ts +6 -8
- package/src/public/avm/opcodes/misc.ts +4 -4
- package/src/public/contracts_db_checkpoint.ts +41 -0
- package/src/public/db_interfaces.ts +15 -0
- package/src/public/executor_metrics.ts +2 -1
- package/src/public/executor_metrics_interface.ts +2 -1
- package/src/public/fixtures/custom_bytecode_tester.ts +1 -1
- package/src/public/fixtures/minimal_public_tx.ts +3 -4
- package/src/public/fixtures/public_tx_simulation_tester.ts +18 -10
- package/src/public/fixtures/token_test.ts +3 -4
- package/src/public/hinting_db_sources.ts +104 -7
- package/src/public/index.ts +2 -6
- package/src/public/public_db_sources.ts +92 -171
- package/src/public/public_processor/guarded_merkle_tree.ts +2 -2
- package/src/public/public_processor/public_processor.ts +46 -36
- package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +162 -0
- package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +199 -21
- package/src/public/public_tx_simulator/index.ts +1 -0
- package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +9 -13
- package/src/public/public_tx_simulator/public_tx_context.ts +8 -2
- package/src/public/public_tx_simulator/public_tx_simulator.ts +145 -192
- package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +1 -2
- package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +2 -2
- package/src/public/state_manager/state_manager.ts +4 -11
- package/src/public/test_executor_metrics.ts +7 -5
- package/dest/public/tx_contract_cache.d.ts +0 -41
- package/dest/public/tx_contract_cache.d.ts.map +0 -1
- package/dest/public/tx_contract_cache.js +0 -49
- package/src/public/tx_contract_cache.ts +0 -69
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Fr } from '@aztec/foundation/fields';
|
|
2
2
|
import { Timer } from '@aztec/foundation/timer';
|
|
3
|
+
import type { PublicSimulatorConfig, PublicTxResult } from '@aztec/stdlib/avm';
|
|
3
4
|
import type { Gas } from '@aztec/stdlib/gas';
|
|
4
5
|
import type { AvmSimulationStats } from '@aztec/stdlib/stats';
|
|
5
6
|
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
@@ -10,12 +11,7 @@ import type { ExecutorMetricsInterface } from '../executor_metrics_interface.js'
|
|
|
10
11
|
import type { PublicContractsDB } from '../public_db_sources.js';
|
|
11
12
|
import type { PublicPersistableStateManager } from '../state_manager/state_manager.js';
|
|
12
13
|
import { PublicTxContext } from './public_tx_context.js';
|
|
13
|
-
import {
|
|
14
|
-
type ProcessedPhase,
|
|
15
|
-
type PublicTxResult,
|
|
16
|
-
PublicTxSimulator,
|
|
17
|
-
type PublicTxSimulatorConfig,
|
|
18
|
-
} from './public_tx_simulator.js';
|
|
14
|
+
import { PublicTxSimulator } from './public_tx_simulator.js';
|
|
19
15
|
import type { MeasuredPublicTxSimulatorInterface } from './public_tx_simulator_interface.js';
|
|
20
16
|
|
|
21
17
|
/**
|
|
@@ -27,7 +23,7 @@ export class MeasuredPublicTxSimulator extends PublicTxSimulator implements Meas
|
|
|
27
23
|
contractsDB: PublicContractsDB,
|
|
28
24
|
globalVariables: GlobalVariables,
|
|
29
25
|
protected readonly metrics: ExecutorMetricsInterface,
|
|
30
|
-
config?: Partial<
|
|
26
|
+
config?: Partial<PublicSimulatorConfig>,
|
|
31
27
|
) {
|
|
32
28
|
super(merkleTree, contractsDB, globalVariables, config);
|
|
33
29
|
}
|
|
@@ -38,24 +34,24 @@ export class MeasuredPublicTxSimulator extends PublicTxSimulator implements Meas
|
|
|
38
34
|
try {
|
|
39
35
|
avmResult = await super.simulate(tx);
|
|
40
36
|
} finally {
|
|
41
|
-
this.metrics.stopRecordingTxSimulation(txLabel, avmResult?.revertCode);
|
|
37
|
+
this.metrics.stopRecordingTxSimulation(txLabel, avmResult?.gasUsed, avmResult?.revertCode);
|
|
42
38
|
}
|
|
43
39
|
return avmResult;
|
|
44
40
|
}
|
|
45
41
|
|
|
46
|
-
protected override async insertNonRevertiblesFromPrivate(context: PublicTxContext
|
|
42
|
+
protected override async insertNonRevertiblesFromPrivate(context: PublicTxContext) {
|
|
47
43
|
const timer = new Timer();
|
|
48
|
-
await super.insertNonRevertiblesFromPrivate(context
|
|
44
|
+
await super.insertNonRevertiblesFromPrivate(context);
|
|
49
45
|
this.metrics.recordPrivateEffectsInsertion(timer.us(), 'non-revertible');
|
|
50
46
|
}
|
|
51
47
|
|
|
52
|
-
protected override async insertRevertiblesFromPrivate(context: PublicTxContext
|
|
48
|
+
protected override async insertRevertiblesFromPrivate(context: PublicTxContext) {
|
|
53
49
|
const timer = new Timer();
|
|
54
|
-
await super.insertRevertiblesFromPrivate(context
|
|
50
|
+
await super.insertRevertiblesFromPrivate(context);
|
|
55
51
|
this.metrics.recordPrivateEffectsInsertion(timer.us(), 'revertible');
|
|
56
52
|
}
|
|
57
53
|
|
|
58
|
-
protected override async simulatePhase(phase: TxExecutionPhase, context: PublicTxContext)
|
|
54
|
+
protected override async simulatePhase(phase: TxExecutionPhase, context: PublicTxContext) {
|
|
59
55
|
const timer = new Timer();
|
|
60
56
|
const result = await super.simulatePhase(phase, context);
|
|
61
57
|
result.durationMs = timer.ms();
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
RevertCode,
|
|
17
17
|
} from '@aztec/stdlib/avm';
|
|
18
18
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
19
|
+
import { AllContractDeploymentData, type ContractDeploymentData } from '@aztec/stdlib/contract';
|
|
19
20
|
import type { SimulationError } from '@aztec/stdlib/errors';
|
|
20
21
|
import { computeEffectiveGasFees, computeTransactionFee } from '@aztec/stdlib/fees';
|
|
21
22
|
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
@@ -80,6 +81,8 @@ export class PublicTxContext {
|
|
|
80
81
|
private readonly setupCallRequests: PublicCallRequestWithCalldata[],
|
|
81
82
|
private readonly appLogicCallRequests: PublicCallRequestWithCalldata[],
|
|
82
83
|
private readonly teardownCallRequests: PublicCallRequestWithCalldata[],
|
|
84
|
+
public readonly nonRevertibleContractDeploymentData: ContractDeploymentData,
|
|
85
|
+
public readonly revertibleContractDeploymentData: ContractDeploymentData,
|
|
83
86
|
public readonly nonRevertibleAccumulatedDataFromPrivate: PrivateToPublicAccumulatedData,
|
|
84
87
|
public readonly revertibleAccumulatedDataFromPrivate: PrivateToPublicAccumulatedData,
|
|
85
88
|
public readonly feePayer: AztecAddress,
|
|
@@ -94,9 +97,11 @@ export class PublicTxContext {
|
|
|
94
97
|
tx: Tx,
|
|
95
98
|
globalVariables: GlobalVariables,
|
|
96
99
|
protocolContracts: ProtocolContracts,
|
|
97
|
-
doMerkleOperations: boolean,
|
|
98
100
|
proverId: Fr,
|
|
99
101
|
) {
|
|
102
|
+
const contractDeploymentData = AllContractDeploymentData.fromTx(tx);
|
|
103
|
+
const nonRevertibleContractDeploymentData = contractDeploymentData.getNonRevertibleContractDeploymentData();
|
|
104
|
+
const revertibleContractDeploymentData = contractDeploymentData.getRevertibleContractDeploymentData();
|
|
100
105
|
const nonRevertibleAccumulatedDataFromPrivate = tx.data.forPublic!.nonRevertibleAccumulatedData;
|
|
101
106
|
|
|
102
107
|
const trace = new SideEffectTrace();
|
|
@@ -108,7 +113,6 @@ export class PublicTxContext {
|
|
|
108
113
|
treesDB,
|
|
109
114
|
contractsDB,
|
|
110
115
|
trace,
|
|
111
|
-
doMerkleOperations,
|
|
112
116
|
firstNullifier,
|
|
113
117
|
globalVariables.timestamp,
|
|
114
118
|
);
|
|
@@ -132,6 +136,8 @@ export class PublicTxContext {
|
|
|
132
136
|
getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.SETUP),
|
|
133
137
|
getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.APP_LOGIC),
|
|
134
138
|
getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.TEARDOWN),
|
|
139
|
+
nonRevertibleContractDeploymentData,
|
|
140
|
+
revertibleContractDeploymentData,
|
|
135
141
|
tx.data.forPublic!.nonRevertibleAccumulatedData,
|
|
136
142
|
tx.data.forPublic!.revertibleAccumulatedData,
|
|
137
143
|
tx.data.feePayer,
|
|
@@ -1,20 +1,11 @@
|
|
|
1
|
-
import { AVM_MAX_PROCESSABLE_L2_GAS
|
|
1
|
+
import { AVM_MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
|
|
2
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { ProtocolContractAddress, ProtocolContractsList } from '@aztec/protocol-contracts';
|
|
5
5
|
import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
6
|
-
import {
|
|
7
|
-
AvmCircuitInputs,
|
|
8
|
-
AvmCircuitPublicInputs,
|
|
9
|
-
AvmExecutionHints,
|
|
10
|
-
type AvmProvingRequest,
|
|
11
|
-
AvmTxHint,
|
|
12
|
-
type RevertCode,
|
|
13
|
-
} from '@aztec/stdlib/avm';
|
|
6
|
+
import { AvmExecutionHints, AvmTxHint, PublicSimulatorConfig, PublicTxResult } from '@aztec/stdlib/avm';
|
|
14
7
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
15
|
-
import type { Gas
|
|
16
|
-
import type { DebugLog } from '@aztec/stdlib/logs';
|
|
17
|
-
import { ProvingRequestType } from '@aztec/stdlib/proofs';
|
|
8
|
+
import type { Gas } from '@aztec/stdlib/gas';
|
|
18
9
|
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
19
10
|
import {
|
|
20
11
|
type GlobalVariables,
|
|
@@ -41,33 +32,6 @@ import type { PublicPersistableStateManager } from '../state_manager/state_manag
|
|
|
41
32
|
import { PublicTxContext } from './public_tx_context.js';
|
|
42
33
|
import type { PublicTxSimulatorInterface } from './public_tx_simulator_interface.js';
|
|
43
34
|
|
|
44
|
-
export type ProcessedPhase = {
|
|
45
|
-
phase: TxExecutionPhase;
|
|
46
|
-
durationMs?: number;
|
|
47
|
-
returnValues: NestedProcessReturnValues[];
|
|
48
|
-
reverted: boolean;
|
|
49
|
-
revertReason?: SimulationError;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export type PublicTxResult = {
|
|
53
|
-
avmProvingRequest: AvmProvingRequest;
|
|
54
|
-
/** Gas used during the execution of this tx */
|
|
55
|
-
gasUsed: GasUsed;
|
|
56
|
-
revertCode: RevertCode;
|
|
57
|
-
/** Revert reason, if any */
|
|
58
|
-
revertReason?: SimulationError;
|
|
59
|
-
processedPhases: ProcessedPhase[];
|
|
60
|
-
logs: DebugLog[];
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export type PublicTxSimulatorConfig = {
|
|
64
|
-
proverId: Fr;
|
|
65
|
-
doMerkleOperations: boolean;
|
|
66
|
-
skipFeeEnforcement: boolean;
|
|
67
|
-
clientInitiatedSimulation: boolean;
|
|
68
|
-
maxDebugLogMemoryReads: number;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
35
|
// The errors below are only thrown here in the public tx simulator,
|
|
72
36
|
// and only during revertible phases (revertible insertions, app logic and teardown).
|
|
73
37
|
// These are strictly "checked" errors (not exported and never propagated).
|
|
@@ -103,23 +67,26 @@ class TxSimTeardownRevert extends Error {
|
|
|
103
67
|
}
|
|
104
68
|
}
|
|
105
69
|
|
|
70
|
+
/** Only used internally. */
|
|
71
|
+
type ProcessedPhase = {
|
|
72
|
+
phase: TxExecutionPhase;
|
|
73
|
+
durationMs?: number;
|
|
74
|
+
returnValues: NestedProcessReturnValues[];
|
|
75
|
+
reverted: boolean;
|
|
76
|
+
revertReason?: SimulationError;
|
|
77
|
+
};
|
|
78
|
+
|
|
106
79
|
export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
107
80
|
protected log: Logger;
|
|
108
|
-
|
|
81
|
+
protected readonly config: PublicSimulatorConfig;
|
|
109
82
|
|
|
110
83
|
constructor(
|
|
111
84
|
protected merkleTree: MerkleTreeWriteOperations,
|
|
112
85
|
protected contractsDB: PublicContractsDB,
|
|
113
86
|
protected globalVariables: GlobalVariables,
|
|
114
|
-
config?: Partial<
|
|
87
|
+
config?: Partial<PublicSimulatorConfig>,
|
|
115
88
|
) {
|
|
116
|
-
this.config = {
|
|
117
|
-
proverId: config?.proverId ?? Fr.ZERO,
|
|
118
|
-
doMerkleOperations: config?.doMerkleOperations ?? false,
|
|
119
|
-
skipFeeEnforcement: config?.skipFeeEnforcement ?? false,
|
|
120
|
-
clientInitiatedSimulation: config?.clientInitiatedSimulation ?? false,
|
|
121
|
-
maxDebugLogMemoryReads: config?.maxDebugLogMemoryReads ?? DEFAULT_MAX_DEBUG_LOG_MEMORY_READS,
|
|
122
|
-
};
|
|
89
|
+
this.config = PublicSimulatorConfig.from(config ?? {});
|
|
123
90
|
this.log = createLogger(`simulator:public_tx_simulator`);
|
|
124
91
|
}
|
|
125
92
|
|
|
@@ -129,136 +96,128 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
129
96
|
* @returns The result of the transaction's public execution.
|
|
130
97
|
*/
|
|
131
98
|
public async simulate(tx: Tx): Promise<PublicTxResult> {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
this.log.debug(`Simulating ${tx.publicFunctionCalldata.length} public calls for tx ${txHash}`, { txHash });
|
|
135
|
-
|
|
136
|
-
// Create hinting DBs.
|
|
137
|
-
const hints = new AvmExecutionHints(
|
|
138
|
-
this.globalVariables,
|
|
139
|
-
AvmTxHint.fromTx(tx, this.globalVariables.gasFees),
|
|
140
|
-
ProtocolContractsList, // imported from file
|
|
141
|
-
);
|
|
142
|
-
const hintingMerkleTree = await HintingMerkleWriteOperations.create(this.merkleTree, hints);
|
|
143
|
-
const hintingTreesDB = new PublicTreesDB(hintingMerkleTree);
|
|
144
|
-
const hintingContractsDB = new HintingPublicContractsDB(this.contractsDB, hints);
|
|
145
|
-
|
|
146
|
-
const context = await PublicTxContext.create(
|
|
147
|
-
hintingTreesDB,
|
|
148
|
-
hintingContractsDB,
|
|
149
|
-
tx,
|
|
150
|
-
this.globalVariables,
|
|
151
|
-
ProtocolContractsList, // imported from file
|
|
152
|
-
this.config.doMerkleOperations,
|
|
153
|
-
this.config.proverId,
|
|
154
|
-
);
|
|
99
|
+
const txHash = this.computeTxHash(tx);
|
|
100
|
+
this.log.debug(`Simulating ${tx.publicFunctionCalldata.length} public calls for tx ${txHash}`, { txHash });
|
|
155
101
|
|
|
156
|
-
|
|
102
|
+
// Create hinting DBs.
|
|
103
|
+
const hints = new AvmExecutionHints(
|
|
104
|
+
this.globalVariables,
|
|
105
|
+
AvmTxHint.fromTx(tx, this.globalVariables.gasFees),
|
|
106
|
+
ProtocolContractsList, // imported from file
|
|
107
|
+
);
|
|
108
|
+
const hintingMerkleTree = await HintingMerkleWriteOperations.create(this.merkleTree, hints);
|
|
109
|
+
const hintingTreesDB = new PublicTreesDB(hintingMerkleTree);
|
|
110
|
+
const hintingContractsDB = new HintingPublicContractsDB(this.contractsDB, hints);
|
|
111
|
+
|
|
112
|
+
const context = await PublicTxContext.create(
|
|
113
|
+
hintingTreesDB,
|
|
114
|
+
hintingContractsDB,
|
|
115
|
+
tx,
|
|
116
|
+
this.globalVariables,
|
|
117
|
+
ProtocolContractsList, // imported from file
|
|
118
|
+
this.config.proverId,
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
// This will throw if there is a nullifier collision.
|
|
122
|
+
// In that case the transaction will be thrown out.
|
|
123
|
+
await this.insertNonRevertiblesFromPrivate(context);
|
|
124
|
+
|
|
125
|
+
const processedPhases: ProcessedPhase[] = [];
|
|
126
|
+
if (context.hasPhase(TxExecutionPhase.SETUP)) {
|
|
127
|
+
// This will throw if the setup phase reverts.
|
|
157
128
|
// In that case the transaction will be thrown out.
|
|
158
|
-
await this.
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
// In that case the transaction will be thrown out.
|
|
164
|
-
const setupResult = await this.simulatePhase(TxExecutionPhase.SETUP, context);
|
|
165
|
-
if (setupResult.reverted) {
|
|
166
|
-
throw new Error(
|
|
167
|
-
`Setup phase reverted! The transaction will be thrown out. ${setupResult.revertReason?.message}`,
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
processedPhases.push(setupResult);
|
|
129
|
+
const setupResult = await this.simulatePhase(TxExecutionPhase.SETUP, context);
|
|
130
|
+
if (setupResult.reverted) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
`Setup phase reverted! The transaction will be thrown out. ${setupResult.revertReason?.message}`,
|
|
133
|
+
);
|
|
171
134
|
}
|
|
135
|
+
processedPhases.push(setupResult);
|
|
136
|
+
}
|
|
172
137
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
try {
|
|
177
|
-
// This will throw if there is a nullifier collision or other insertion error (limit reached).
|
|
178
|
-
await this.insertRevertiblesFromPrivate(context, tx);
|
|
138
|
+
// The checkpoint we should go back to if anything from now on reverts.
|
|
139
|
+
await context.state.fork();
|
|
140
|
+
hintingContractsDB.createCheckpoint();
|
|
179
141
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
// We revert to the post-setup state.
|
|
191
|
-
await context.state.discardForkedState();
|
|
192
|
-
// But we also create a new fork so that the teardown phase can transparently
|
|
193
|
-
// commit or rollback at the end of teardown.
|
|
194
|
-
await context.state.fork();
|
|
195
|
-
} else {
|
|
196
|
-
// Unchecked/unknown error - re-throw as-is
|
|
197
|
-
throw e;
|
|
142
|
+
try {
|
|
143
|
+
// This will throw if there is a nullifier collision or other insertion error (limit reached).
|
|
144
|
+
await this.insertRevertiblesFromPrivate(context);
|
|
145
|
+
|
|
146
|
+
// Only proceed with app logic if there was no revert during revertible insertion.
|
|
147
|
+
if (context.hasPhase(TxExecutionPhase.APP_LOGIC)) {
|
|
148
|
+
const appLogicResult = await this.simulatePhase(TxExecutionPhase.APP_LOGIC, context);
|
|
149
|
+
processedPhases.push(appLogicResult);
|
|
150
|
+
if (appLogicResult.reverted) {
|
|
151
|
+
throw new TxSimAppLogicRevert();
|
|
198
152
|
}
|
|
199
153
|
}
|
|
154
|
+
} catch (e: any) {
|
|
155
|
+
if (e instanceof TxSimRevertibleInsertionsRevert || e instanceof TxSimAppLogicRevert) {
|
|
156
|
+
// We revert to the post-setup state.
|
|
157
|
+
await context.state.discardForkedState();
|
|
158
|
+
hintingContractsDB.revertCheckpoint();
|
|
159
|
+
// But we also create a new fork so that the teardown phase can transparently
|
|
160
|
+
// commit or rollback at the end of teardown.
|
|
161
|
+
await context.state.fork();
|
|
162
|
+
hintingContractsDB.createCheckpoint();
|
|
163
|
+
} else {
|
|
164
|
+
// Unchecked/unknown error - re-throw as-is
|
|
165
|
+
throw e;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
200
168
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
// We commit the forked state and we are done.
|
|
210
|
-
await context.state.mergeForkedState();
|
|
211
|
-
} catch (e: any) {
|
|
212
|
-
if (e instanceof TxSimTeardownRevert) {
|
|
213
|
-
// We revert to the post-setup state and we are done.
|
|
214
|
-
await context.state.discardForkedState();
|
|
215
|
-
} else {
|
|
216
|
-
// Unchecked/unknown error - re-throw as-is
|
|
217
|
-
throw e;
|
|
169
|
+
try {
|
|
170
|
+
if (context.hasPhase(TxExecutionPhase.TEARDOWN)) {
|
|
171
|
+
const teardownResult = await this.simulatePhase(TxExecutionPhase.TEARDOWN, context);
|
|
172
|
+
processedPhases.push(teardownResult);
|
|
173
|
+
if (teardownResult.reverted) {
|
|
174
|
+
throw new TxSimTeardownRevert();
|
|
218
175
|
}
|
|
219
176
|
}
|
|
177
|
+
// We commit the forked state and we are done.
|
|
178
|
+
await context.state.mergeForkedState();
|
|
179
|
+
hintingContractsDB.commitCheckpoint();
|
|
180
|
+
} catch (e: any) {
|
|
181
|
+
if (e instanceof TxSimTeardownRevert) {
|
|
182
|
+
// We revert to the post-setup state and we are done.
|
|
183
|
+
await context.state.discardForkedState();
|
|
184
|
+
hintingContractsDB.revertCheckpoint();
|
|
185
|
+
} else {
|
|
186
|
+
// Unchecked/unknown error - re-throw as-is
|
|
187
|
+
throw e;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
220
190
|
|
|
221
|
-
|
|
191
|
+
context.halt();
|
|
222
192
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
revertReason: context.revertReason,
|
|
252
|
-
processedPhases: processedPhases,
|
|
253
|
-
logs: context.state.getActiveStateManager().getLogs(),
|
|
254
|
-
};
|
|
255
|
-
} finally {
|
|
256
|
-
// Make sure there are no new contracts in the tx-level cache.
|
|
257
|
-
// They should either be committed to block-level cache or cleared.
|
|
258
|
-
// FIXME(fcarreiro): this should conceptually use the hinted contracts db.
|
|
259
|
-
// However things should work as they are now because the hinted db would still pick up the new contracts.
|
|
260
|
-
this.contractsDB.clearContractsForTx();
|
|
261
|
-
}
|
|
193
|
+
// Such transactions should be filtered by GasTxValidator.
|
|
194
|
+
assert(
|
|
195
|
+
context.getActualGasUsed().l2Gas <= AVM_MAX_PROCESSABLE_L2_GAS,
|
|
196
|
+
`Transaction consumes ${context.getActualGasUsed().l2Gas} L2 gas, which exceeds the AVM maximum processable gas of ${AVM_MAX_PROCESSABLE_L2_GAS}`,
|
|
197
|
+
);
|
|
198
|
+
await this.payFee(context);
|
|
199
|
+
|
|
200
|
+
const publicInputs = await context.generateAvmCircuitPublicInputs();
|
|
201
|
+
const revertCode = context.getFinalRevertCode();
|
|
202
|
+
|
|
203
|
+
// We only return the app logic phase information.
|
|
204
|
+
const appLogicReturnValues =
|
|
205
|
+
processedPhases.find(({ phase }) => phase === TxExecutionPhase.APP_LOGIC)?.returnValues ?? [];
|
|
206
|
+
|
|
207
|
+
return new PublicTxResult(
|
|
208
|
+
/*gasUsed=*/ {
|
|
209
|
+
totalGas: context.getActualGasUsed(),
|
|
210
|
+
teardownGas: context.teardownGasUsed,
|
|
211
|
+
publicGas: context.getActualPublicGasUsed(),
|
|
212
|
+
billedGas: context.getTotalGasUsed(),
|
|
213
|
+
},
|
|
214
|
+
/*revertCode=*/ revertCode,
|
|
215
|
+
/*revertReason=*/ context.revertReason,
|
|
216
|
+
/*appLogicReturnValues=*/ appLogicReturnValues,
|
|
217
|
+
/*logs=*/ context.state.getActiveStateManager().getLogs(),
|
|
218
|
+
/*hints=*/ hints,
|
|
219
|
+
/*publicInputs=*/ publicInputs,
|
|
220
|
+
);
|
|
262
221
|
}
|
|
263
222
|
|
|
264
223
|
protected computeTxHash(tx: Tx) {
|
|
@@ -383,8 +342,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
383
342
|
request.isStaticCall,
|
|
384
343
|
calldata,
|
|
385
344
|
allocatedGas,
|
|
386
|
-
this.config
|
|
387
|
-
this.config.maxDebugLogMemoryReads,
|
|
345
|
+
this.config,
|
|
388
346
|
);
|
|
389
347
|
const avmCallResult = await simulator.execute();
|
|
390
348
|
return avmCallResult.finalize();
|
|
@@ -393,7 +351,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
393
351
|
/**
|
|
394
352
|
* Insert the non-revertible accumulated data from private into the public state.
|
|
395
353
|
*/
|
|
396
|
-
protected async insertNonRevertiblesFromPrivate(context: PublicTxContext
|
|
354
|
+
protected async insertNonRevertiblesFromPrivate(context: PublicTxContext) {
|
|
397
355
|
const stateManager = context.state.getActiveStateManager();
|
|
398
356
|
|
|
399
357
|
for (const siloedNullifier of context.nonRevertibleAccumulatedDataFromPrivate.nullifiers.filter(
|
|
@@ -412,11 +370,12 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
412
370
|
}
|
|
413
371
|
}
|
|
414
372
|
|
|
415
|
-
// add new contracts to the contracts db so that their
|
|
416
|
-
//
|
|
417
|
-
//
|
|
418
|
-
//
|
|
419
|
-
|
|
373
|
+
// add new contracts to the contracts db so that their code may be found and called
|
|
374
|
+
// FIXME(fcarreiro): this should conceptually use the hinting contracts db.
|
|
375
|
+
// However, things work as expected because later calls to getters on the hintingContractsDB
|
|
376
|
+
// will pick up the new contracts and will generate the necessary hints.
|
|
377
|
+
// So, a consumer of the hints will always see the new contracts.
|
|
378
|
+
await this.contractsDB.addContracts(context.nonRevertibleContractDeploymentData);
|
|
420
379
|
}
|
|
421
380
|
|
|
422
381
|
/**
|
|
@@ -428,7 +387,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
428
387
|
* - NoteHashLimitReachedError
|
|
429
388
|
* - L2ToL1MessageLimitReachedError
|
|
430
389
|
*/
|
|
431
|
-
protected async insertRevertiblesFromPrivate(context: PublicTxContext
|
|
390
|
+
protected async insertRevertiblesFromPrivate(context: PublicTxContext) {
|
|
432
391
|
const stateManager = context.state.getActiveStateManager();
|
|
433
392
|
|
|
434
393
|
try {
|
|
@@ -497,16 +456,21 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
497
456
|
}
|
|
498
457
|
|
|
499
458
|
// add new contracts to the contracts db so that their functions may be found and called
|
|
500
|
-
// FIXME(fcarreiro): this should conceptually use the
|
|
501
|
-
// However things
|
|
502
|
-
|
|
459
|
+
// FIXME(fcarreiro): this should conceptually use the hinting contracts db.
|
|
460
|
+
// However, things work as expected because later calls to getters on the hintingContractsDB
|
|
461
|
+
// will pick up the new contracts and will generate the necessary hints.
|
|
462
|
+
// So, a consumer of the hints will always see the new contracts.
|
|
463
|
+
await this.contractsDB.addContracts(context.revertibleContractDeploymentData);
|
|
503
464
|
}
|
|
504
465
|
|
|
505
466
|
private async payFee(context: PublicTxContext) {
|
|
506
467
|
const txFee = context.getTransactionFee(TxExecutionPhase.TEARDOWN);
|
|
507
468
|
|
|
508
469
|
if (context.feePayer.isZero()) {
|
|
509
|
-
|
|
470
|
+
// Real transactions are enforced by private kernel to have nonzero fee payer.
|
|
471
|
+
// Real transactions cannot skip fee enforcement (skipping fee enforcement makes them unprovable).
|
|
472
|
+
assert(this.config.skipFeeEnforcement, 'Fee payer cannot be 0 unless skipping fee enforcement for simulation');
|
|
473
|
+
this.log.debug(`Fee payer is 0. Skipping fee enforcement. No one is paying the fee of ${txFee.toBigInt()}`);
|
|
510
474
|
return;
|
|
511
475
|
}
|
|
512
476
|
|
|
@@ -526,23 +490,12 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
526
490
|
this.config.skipFeeEnforcement,
|
|
527
491
|
`Not enough balance for fee payer to pay for transaction (got ${currentBalance.toBigInt()} needs ${txFee.toBigInt()})`,
|
|
528
492
|
);
|
|
493
|
+
this.log.debug(`Fee payer balance insufficient, but we're skipping fee enforcement`);
|
|
494
|
+
// We still proceed and perform the storage write to minimize deviation from normal execution.
|
|
529
495
|
currentBalance = txFee;
|
|
530
496
|
}
|
|
531
497
|
|
|
532
498
|
const updatedBalance = currentBalance.sub(txFee);
|
|
533
499
|
await stateManager.writeStorage(feeJuiceAddress, balanceSlot, updatedBalance, true);
|
|
534
500
|
}
|
|
535
|
-
|
|
536
|
-
/**
|
|
537
|
-
* Generate the proving request for the AVM circuit.
|
|
538
|
-
*/
|
|
539
|
-
private static generateProvingRequest(
|
|
540
|
-
publicInputs: AvmCircuitPublicInputs,
|
|
541
|
-
hints: AvmExecutionHints,
|
|
542
|
-
): AvmProvingRequest {
|
|
543
|
-
return {
|
|
544
|
-
type: ProvingRequestType.PUBLIC_VM,
|
|
545
|
-
inputs: new AvmCircuitInputs(hints, publicInputs),
|
|
546
|
-
};
|
|
547
|
-
}
|
|
548
501
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import type { PublicTxResult } from '@aztec/stdlib/avm';
|
|
1
2
|
import type { Tx } from '@aztec/stdlib/tx';
|
|
2
3
|
|
|
3
|
-
import type { PublicTxResult } from './public_tx_simulator.js';
|
|
4
|
-
|
|
5
4
|
export interface PublicTxSimulatorInterface {
|
|
6
5
|
simulate(tx: Tx): Promise<PublicTxResult>;
|
|
7
6
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import type { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
2
3
|
import type { Gas } from '@aztec/stdlib/gas';
|
|
3
4
|
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
4
5
|
import { type GlobalVariables, PublicCallRequestWithCalldata, TxExecutionPhase } from '@aztec/stdlib/tx';
|
|
@@ -10,7 +11,6 @@ import type { PublicContractsDB } from '../public_db_sources.js';
|
|
|
10
11
|
import type { PublicPersistableStateManager } from '../state_manager/state_manager.js';
|
|
11
12
|
import { MeasuredPublicTxSimulator } from './measured_public_tx_simulator.js';
|
|
12
13
|
import { PublicTxContext } from './public_tx_context.js';
|
|
13
|
-
import type { PublicTxSimulatorConfig } from './public_tx_simulator.js';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* A public tx simulator that tracks runtime/production metrics with telemetry.
|
|
@@ -24,7 +24,7 @@ export class TelemetryPublicTxSimulator extends MeasuredPublicTxSimulator {
|
|
|
24
24
|
contractsDB: PublicContractsDB,
|
|
25
25
|
globalVariables: GlobalVariables,
|
|
26
26
|
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
27
|
-
config?: Partial<
|
|
27
|
+
config?: Partial<PublicSimulatorConfig>,
|
|
28
28
|
) {
|
|
29
29
|
const metrics = new ExecutorMetrics(telemetryClient, 'PublicTxSimulator');
|
|
30
30
|
super(merkleTree, contractsDB, globalVariables, metrics, config);
|
|
@@ -59,7 +59,7 @@ export class PublicPersistableStateManager {
|
|
|
59
59
|
private readonly trace: PublicSideEffectTraceInterface,
|
|
60
60
|
private readonly firstNullifier: Fr, // Needed for note hashes.
|
|
61
61
|
private readonly timestamp: UInt64, // Needed for contract updates.
|
|
62
|
-
private readonly doMerkleOperations: boolean =
|
|
62
|
+
private readonly doMerkleOperations: boolean = true,
|
|
63
63
|
private readonly publicStorage: PublicStorage = new PublicStorage(treesDB),
|
|
64
64
|
private readonly nullifiers: NullifierManager = new NullifierManager(treesDB),
|
|
65
65
|
) {}
|
|
@@ -71,18 +71,10 @@ export class PublicPersistableStateManager {
|
|
|
71
71
|
treesDB: PublicTreesDB,
|
|
72
72
|
contractsDB: PublicContractsDBInterface,
|
|
73
73
|
trace: PublicSideEffectTraceInterface,
|
|
74
|
-
doMerkleOperations: boolean = false,
|
|
75
74
|
firstNullifier: Fr,
|
|
76
75
|
timestamp: UInt64,
|
|
77
76
|
): PublicPersistableStateManager {
|
|
78
|
-
return new PublicPersistableStateManager(
|
|
79
|
-
treesDB,
|
|
80
|
-
contractsDB,
|
|
81
|
-
trace,
|
|
82
|
-
firstNullifier,
|
|
83
|
-
timestamp,
|
|
84
|
-
doMerkleOperations,
|
|
85
|
-
);
|
|
77
|
+
return new PublicPersistableStateManager(treesDB, contractsDB, trace, firstNullifier, timestamp);
|
|
86
78
|
}
|
|
87
79
|
|
|
88
80
|
/**
|
|
@@ -171,7 +163,6 @@ export class PublicPersistableStateManager {
|
|
|
171
163
|
if (this.doMerkleOperations) {
|
|
172
164
|
return await this.treesDB.storageRead(contractAddress, slot);
|
|
173
165
|
} else {
|
|
174
|
-
// TODO(fcarreiro): I don't get this. PublicStorage CAN end up reading the tree. Why is it in the "dont do merkle operations" branch?
|
|
175
166
|
const read = await this.publicStorage.read(contractAddress, slot);
|
|
176
167
|
this.log.trace(
|
|
177
168
|
`Storage read results (address=${contractAddress}, slot=${slot}): value=${read.value}, cached=${read.cached}`,
|
|
@@ -437,6 +428,8 @@ export class PublicPersistableStateManager {
|
|
|
437
428
|
await this.readStorage(ProtocolContractAddress.ContractInstanceRegistry, storageSlot);
|
|
438
429
|
|
|
439
430
|
const hash = await readDeployerStorage(delayedPublicMutableHashSlot);
|
|
431
|
+
// NOTE: The below reads are either not performed (if hash.isZero()) or only performed in unconstrained in c++ simulation.
|
|
432
|
+
// See UpdateCheck::check_current_class_id documentation - this means if we generate hints from the merkle db, they are unused:
|
|
440
433
|
const delayedPublicMutableValues = await DelayedPublicMutableValues.readFromTree(
|
|
441
434
|
delayedPublicMutableSlot,
|
|
442
435
|
readDeployerStorage,
|