@aztec/simulator 0.0.1-commit.2ed92850 → 0.0.1-commit.3100065
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 +4 -4
- package/dest/client.d.ts +1 -3
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +0 -2
- package/dest/private/acvm/acvm.d.ts +4 -2
- package/dest/private/acvm/acvm.d.ts.map +1 -1
- package/dest/private/acvm/acvm.js +4 -3
- package/dest/private/acvm_native.d.ts +5 -3
- package/dest/private/acvm_native.d.ts.map +1 -1
- package/dest/private/acvm_native.js +8 -6
- package/dest/private/acvm_wasm.d.ts +4 -3
- package/dest/private/acvm_wasm.d.ts.map +1 -1
- package/dest/private/acvm_wasm.js +7 -5
- package/dest/private/circuit_recording/circuit_recorder.d.ts +39 -25
- package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/circuit_recorder.js +70 -72
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts +9 -20
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/file_circuit_recorder.js +39 -43
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +7 -2
- package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/memory_circuit_recorder.js +4 -4
- package/dest/private/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_recording/simulator_recorder_wrapper.js +11 -14
- package/dest/private/factory.d.ts +3 -3
- package/dest/private/factory.d.ts.map +1 -1
- package/dest/private/factory.js +7 -4
- package/dest/public/avm/avm_gas.js +3 -3
- package/dest/public/avm/avm_simulator.js +1 -1
- package/dest/public/avm/calldata.d.ts +1 -1
- package/dest/public/avm/calldata.d.ts.map +1 -1
- package/dest/public/avm/calldata.js +3 -2
- package/dest/public/avm/fixtures/account_proof_fetcher.d.ts +2 -0
- package/dest/public/avm/fixtures/account_proof_fetcher.d.ts.map +1 -0
- package/dest/public/avm/fixtures/account_proof_fetcher.js +152 -0
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +2 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.js +18 -3
- package/dest/public/avm/fixtures/utils.d.ts +1 -1
- package/dest/public/avm/fixtures/utils.d.ts.map +1 -1
- package/dest/public/avm/fixtures/utils.js +4 -1
- package/dest/public/avm/opcodes/accrued_substate.d.ts +4 -5
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/accrued_substate.js +11 -16
- package/dest/public/avm/opcodes/contract.d.ts +3 -2
- package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/public/avm/opcodes/contract.js +5 -1
- package/dest/public/avm/opcodes/ec_add.d.ts +2 -4
- package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/public/avm/opcodes/ec_add.js +13 -27
- package/dest/public/avm/serialization/bytecode_serialization.js +3 -3
- package/dest/public/avm/serialization/instruction_serialization.d.ts +2 -2
- package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/instruction_serialization.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/contracts_db_checkpoint.js +1 -1
- 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 +7 -2
- package/dest/public/fixtures/amm_test.js +4 -4
- package/dest/public/fixtures/bulk_test.d.ts +1 -1
- package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
- package/dest/public/fixtures/bulk_test.js +33 -6
- package/dest/public/fixtures/custom_bytecode_tester.d.ts +1 -1
- package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
- package/dest/public/fixtures/custom_bytecode_tester.js +2 -2
- package/dest/public/fixtures/custom_bytecode_tests.d.ts +8 -1
- package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
- package/dest/public/fixtures/custom_bytecode_tests.js +91 -2
- package/dest/public/fixtures/opcode_spammer.d.ts +3 -4
- package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -1
- package/dest/public/fixtures/opcode_spammer.js +18 -66
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +6 -5
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +38 -9
- package/dest/public/fixtures/token_test.js +3 -3
- 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 +21 -20
- package/dest/public/hinting_db_sources.d.ts +5 -5
- package/dest/public/hinting_db_sources.d.ts.map +1 -1
- package/dest/public/hinting_db_sources.js +8 -7
- package/dest/public/public_db_sources.d.ts +9 -5
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +20 -14
- package/dest/public/public_processor/guarded_merkle_tree.d.ts +5 -5
- package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
- package/dest/public/public_processor/guarded_merkle_tree.js +5 -5
- package/dest/public/public_processor/public_processor.d.ts +11 -6
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +125 -68
- package/dest/public/public_processor/public_processor_metrics.d.ts +5 -2
- package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor_metrics.js +28 -4
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +3 -2
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +7 -6
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +5 -5
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +10 -11
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +4 -4
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +7 -7
- package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +4 -4
- package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +6 -6
- package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +3 -2
- package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.js +2 -2
- package/dest/public/public_tx_simulator/factories.d.ts +3 -2
- package/dest/public/public_tx_simulator/factories.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/factories.js +4 -4
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +10 -5
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +16 -18
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +9 -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 +19 -12
- package/dest/public/side_effect_trace.d.ts +4 -4
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +3 -3
- package/dest/public/state_manager/state_manager.d.ts +10 -4
- package/dest/public/state_manager/state_manager.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.js +13 -6
- package/dest/public/test_executor_metrics.d.ts +8 -2
- package/dest/public/test_executor_metrics.d.ts.map +1 -1
- package/dest/public/test_executor_metrics.js +24 -2
- package/package.json +16 -16
- package/src/client.ts +0 -2
- package/src/private/acvm/acvm.ts +4 -3
- package/src/private/acvm_native.ts +11 -5
- package/src/private/acvm_wasm.ts +11 -4
- package/src/private/circuit_recording/circuit_recorder.ts +89 -81
- package/src/private/circuit_recording/file_circuit_recorder.ts +45 -50
- package/src/private/circuit_recording/memory_circuit_recorder.ts +6 -4
- package/src/private/circuit_recording/simulator_recorder_wrapper.ts +9 -15
- package/src/private/factory.ts +7 -4
- package/src/public/avm/avm_gas.ts +2 -2
- package/src/public/avm/avm_simulator.ts +1 -1
- package/src/public/avm/calldata.ts +3 -2
- package/src/public/avm/fixtures/account_proof.json +553 -0
- package/src/public/avm/fixtures/account_proof_fetcher.ts +166 -0
- package/src/public/avm/fixtures/base_avm_simulation_tester.ts +23 -3
- package/src/public/avm/fixtures/utils.ts +4 -1
- package/src/public/avm/opcodes/accrued_substate.ts +10 -19
- package/src/public/avm/opcodes/contract.ts +5 -1
- package/src/public/avm/opcodes/ec_add.ts +12 -31
- package/src/public/avm/opcodes/external_calls.ts +1 -1
- package/src/public/avm/serialization/bytecode_serialization.ts +2 -2
- package/src/public/avm/serialization/instruction_serialization.ts +1 -1
- package/src/public/contracts_db_checkpoint.ts +1 -1
- package/src/public/executor_metrics.ts +4 -1
- package/src/public/fixtures/amm_test.ts +4 -4
- package/src/public/fixtures/bulk_test.ts +31 -6
- package/src/public/fixtures/custom_bytecode_tester.ts +2 -2
- package/src/public/fixtures/custom_bytecode_tests.ts +209 -2
- package/src/public/fixtures/opcode_spammer.ts +22 -63
- package/src/public/fixtures/public_tx_simulation_tester.ts +45 -5
- package/src/public/fixtures/token_test.ts +3 -3
- package/src/public/fixtures/utils.ts +23 -24
- package/src/public/fuzzing/avm_fuzzer_simulator.ts +1 -1
- package/src/public/hinting_db_sources.ts +10 -7
- package/src/public/public_db_sources.ts +36 -19
- package/src/public/public_processor/guarded_merkle_tree.ts +6 -6
- package/src/public/public_processor/public_processor.ts +173 -90
- package/src/public/public_processor/public_processor_metrics.ts +22 -4
- package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +11 -7
- package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +10 -8
- package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +7 -5
- package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +7 -5
- package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +3 -1
- package/src/public/public_tx_simulator/factories.ts +6 -3
- package/src/public/public_tx_simulator/public_tx_context.ts +21 -16
- package/src/public/public_tx_simulator/public_tx_simulator.ts +20 -12
- package/src/public/side_effect_trace.ts +5 -2
- package/src/public/state_manager/state_manager.ts +28 -5
- package/src/public/test_executor_metrics.ts +27 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Logger,
|
|
1
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import { sleep } from '@aztec/foundation/sleep';
|
|
3
3
|
import { type CancellationToken, avmSimulate, cancelSimulation, createCancellationToken } from '@aztec/native';
|
|
4
4
|
import { ProtocolContractsList } from '@aztec/protocol-contracts';
|
|
@@ -44,9 +44,10 @@ export class CppPublicTxSimulator extends PublicTxSimulator implements PublicTxS
|
|
|
44
44
|
contractsDB: PublicContractsDB,
|
|
45
45
|
globalVariables: GlobalVariables,
|
|
46
46
|
config?: Partial<PublicSimulatorConfig>,
|
|
47
|
+
bindings?: LoggerBindings,
|
|
47
48
|
) {
|
|
48
|
-
super(merkleTree, contractsDB, globalVariables, config);
|
|
49
|
-
this.log = createLogger(`simulator:cpp_public_tx_simulator
|
|
49
|
+
super(merkleTree, contractsDB, globalVariables, config, undefined, bindings);
|
|
50
|
+
this.log = createLogger(`simulator:cpp_public_tx_simulator`, bindings);
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
/**
|
|
@@ -84,7 +85,7 @@ export class CppPublicTxSimulator extends PublicTxSimulator implements PublicTxS
|
|
|
84
85
|
);
|
|
85
86
|
|
|
86
87
|
// Create contract provider for callbacks to TypeScript PublicContractsDB from C++
|
|
87
|
-
const contractProvider = new ContractProviderForCpp(this.contractsDB, this.globalVariables);
|
|
88
|
+
const contractProvider = new ContractProviderForCpp(this.contractsDB, this.globalVariables, this.bindings);
|
|
88
89
|
|
|
89
90
|
// Serialize to msgpack and call the C++ simulator
|
|
90
91
|
this.log.trace(`Serializing fast simulation inputs to msgpack...`);
|
|
@@ -99,8 +100,7 @@ export class CppPublicTxSimulator extends PublicTxSimulator implements PublicTxS
|
|
|
99
100
|
inputBuffer,
|
|
100
101
|
contractProvider,
|
|
101
102
|
wsCppHandle,
|
|
102
|
-
|
|
103
|
-
// TODO: re-enable logging
|
|
103
|
+
this.log.level,
|
|
104
104
|
undefined,
|
|
105
105
|
this.cancellationToken,
|
|
106
106
|
);
|
|
@@ -171,8 +171,9 @@ export class MeasuredCppPublicTxSimulator extends CppPublicTxSimulator implement
|
|
|
171
171
|
globalVariables: GlobalVariables,
|
|
172
172
|
protected readonly metrics: ExecutorMetricsInterface,
|
|
173
173
|
config?: Partial<PublicSimulatorConfig>,
|
|
174
|
+
bindings?: LoggerBindings,
|
|
174
175
|
) {
|
|
175
|
-
super(merkleTree, contractsDB, globalVariables, config);
|
|
176
|
+
super(merkleTree, contractsDB, globalVariables, config, bindings);
|
|
176
177
|
}
|
|
177
178
|
|
|
178
179
|
public override async simulate(tx: Tx, txLabel: string = 'unlabeledTx'): Promise<PublicTxResult> {
|
|
@@ -200,9 +201,10 @@ export class TelemetryCppPublicTxSimulator extends MeasuredCppPublicTxSimulator
|
|
|
200
201
|
globalVariables: GlobalVariables,
|
|
201
202
|
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
202
203
|
config?: Partial<PublicSimulatorConfig>,
|
|
204
|
+
bindings?: LoggerBindings,
|
|
203
205
|
) {
|
|
204
206
|
const metrics = new ExecutorMetrics(telemetryClient, 'CppPublicTxSimulator');
|
|
205
|
-
super(merkleTree, contractsDB, globalVariables, metrics, config);
|
|
207
|
+
super(merkleTree, contractsDB, globalVariables, metrics, config, bindings);
|
|
206
208
|
this.tracer = metrics.tracer;
|
|
207
209
|
}
|
|
208
210
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Logger,
|
|
1
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import { avmSimulateWithHintedDbs } from '@aztec/native';
|
|
3
3
|
import {
|
|
4
4
|
AvmCircuitInputs,
|
|
@@ -34,9 +34,10 @@ export class CppPublicTxSimulatorHintedDbs extends PublicTxSimulator implements
|
|
|
34
34
|
contractsDB: PublicContractsDB,
|
|
35
35
|
globalVariables: GlobalVariables,
|
|
36
36
|
config?: Partial<PublicSimulatorConfig>,
|
|
37
|
+
bindings?: LoggerBindings,
|
|
37
38
|
) {
|
|
38
|
-
super(merkleTree, contractsDB, globalVariables, config);
|
|
39
|
-
this.log = createLogger(`simulator:cpp_public_tx_simulator_hinted_dbs
|
|
39
|
+
super(merkleTree, contractsDB, globalVariables, config, undefined, bindings);
|
|
40
|
+
this.log = createLogger(`simulator:cpp_public_tx_simulator_hinted_dbs`, bindings);
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
/**
|
|
@@ -74,7 +75,7 @@ export class CppPublicTxSimulatorHintedDbs extends PublicTxSimulator implements
|
|
|
74
75
|
|
|
75
76
|
let resultBuffer: Buffer;
|
|
76
77
|
try {
|
|
77
|
-
resultBuffer = await avmSimulateWithHintedDbs(inputBuffer,
|
|
78
|
+
resultBuffer = await avmSimulateWithHintedDbs(inputBuffer, this.log.level);
|
|
78
79
|
} catch (error: any) {
|
|
79
80
|
throw new SimulationError(`C++ hinted simulation failed: ${error.message}`, []);
|
|
80
81
|
}
|
|
@@ -115,8 +116,9 @@ export class MeasuredCppPublicTxSimulatorHintedDbs
|
|
|
115
116
|
globalVariables: GlobalVariables,
|
|
116
117
|
protected readonly metrics: ExecutorMetricsInterface,
|
|
117
118
|
config?: Partial<PublicSimulatorConfig>,
|
|
119
|
+
bindings?: LoggerBindings,
|
|
118
120
|
) {
|
|
119
|
-
super(merkleTree, contractsDB, globalVariables, config);
|
|
121
|
+
super(merkleTree, contractsDB, globalVariables, config, bindings);
|
|
120
122
|
}
|
|
121
123
|
|
|
122
124
|
public override async simulate(tx: Tx, txLabel: string = 'unlabeledTx'): Promise<PublicTxResult> {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Logger, createLogger, logLevel } from '@aztec/foundation/log';
|
|
1
|
+
import { type Logger, type LoggerBindings, createLogger, logLevel } from '@aztec/foundation/log';
|
|
2
2
|
import { avmSimulate } from '@aztec/native';
|
|
3
3
|
import { ProtocolContractsList } from '@aztec/protocol-contracts';
|
|
4
4
|
import {
|
|
@@ -37,9 +37,10 @@ export class CppVsTsPublicTxSimulator extends PublicTxSimulator implements Publi
|
|
|
37
37
|
contractsDB: PublicContractsDB,
|
|
38
38
|
globalVariables: GlobalVariables,
|
|
39
39
|
config?: Partial<PublicSimulatorConfig>,
|
|
40
|
+
bindings?: LoggerBindings,
|
|
40
41
|
) {
|
|
41
|
-
super(merkleTree, contractsDB, globalVariables, config);
|
|
42
|
-
this.log = createLogger(`simulator:cpp_vs_public_tx_simulator
|
|
42
|
+
super(merkleTree, contractsDB, globalVariables, config, undefined, bindings);
|
|
43
|
+
this.log = createLogger(`simulator:cpp_vs_public_tx_simulator`, bindings);
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
/**
|
|
@@ -103,7 +104,7 @@ export class CppVsTsPublicTxSimulator extends PublicTxSimulator implements Publi
|
|
|
103
104
|
);
|
|
104
105
|
|
|
105
106
|
// Create contract provider for callbacks to TypeScript PublicContractsDB from C++
|
|
106
|
-
const contractProvider = new ContractProviderForCpp(this.contractsDB, this.globalVariables);
|
|
107
|
+
const contractProvider = new ContractProviderForCpp(this.contractsDB, this.globalVariables, this.bindings);
|
|
107
108
|
|
|
108
109
|
// Serialize to msgpack and call the C++ simulator
|
|
109
110
|
this.log.debug(`Serializing fast simulation inputs to msgpack...`);
|
|
@@ -220,8 +221,9 @@ export class MeasuredCppVsTsPublicTxSimulator
|
|
|
220
221
|
globalVariables: GlobalVariables,
|
|
221
222
|
protected readonly metrics: ExecutorMetricsInterface,
|
|
222
223
|
config?: Partial<PublicSimulatorConfig>,
|
|
224
|
+
bindings?: LoggerBindings,
|
|
223
225
|
) {
|
|
224
|
-
super(merkleTree, contractsDB, globalVariables, config);
|
|
226
|
+
super(merkleTree, contractsDB, globalVariables, config, bindings);
|
|
225
227
|
}
|
|
226
228
|
|
|
227
229
|
public override async simulate(tx: Tx, txLabel: string = 'unlabeledTx'): Promise<PublicTxResult> {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LoggerBindings } from '@aztec/foundation/log';
|
|
1
2
|
import {
|
|
2
3
|
AvmCircuitInputs,
|
|
3
4
|
AvmCircuitPublicInputs,
|
|
@@ -29,8 +30,9 @@ export class DumpingCppPublicTxSimulator extends CppPublicTxSimulator {
|
|
|
29
30
|
globalVariables: GlobalVariables,
|
|
30
31
|
config: Partial<PublicSimulatorConfig>,
|
|
31
32
|
outputDir: string,
|
|
33
|
+
bindings?: LoggerBindings,
|
|
32
34
|
) {
|
|
33
|
-
super(merkleTree, contractsDB, globalVariables, config);
|
|
35
|
+
super(merkleTree, contractsDB, globalVariables, config, bindings);
|
|
34
36
|
assert(config.collectHints === true, 'collectHints must be enabled to dump AVM circuit inputs');
|
|
35
37
|
assert(config.collectPublicInputs === true, 'collectPublicInputs must be enabled to dump AVM circuit inputs');
|
|
36
38
|
this.outputDir = outputDir;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LoggerBindings } from '@aztec/foundation/log';
|
|
1
2
|
import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
2
3
|
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
3
4
|
import type { GlobalVariables } from '@aztec/stdlib/tx';
|
|
@@ -17,10 +18,12 @@ export function createPublicTxSimulatorForBlockBuilding(
|
|
|
17
18
|
contractsDB: PublicContractsDB,
|
|
18
19
|
globalVariables: GlobalVariables,
|
|
19
20
|
telemetryClient: TelemetryClient,
|
|
21
|
+
bindings?: LoggerBindings,
|
|
22
|
+
collectDebugLogs = false,
|
|
20
23
|
) {
|
|
21
24
|
const config = PublicSimulatorConfig.from({
|
|
22
25
|
skipFeeEnforcement: false,
|
|
23
|
-
collectDebugLogs
|
|
26
|
+
collectDebugLogs,
|
|
24
27
|
collectHints: false,
|
|
25
28
|
collectPublicInputs: false,
|
|
26
29
|
collectStatistics: false,
|
|
@@ -35,7 +38,7 @@ export function createPublicTxSimulatorForBlockBuilding(
|
|
|
35
38
|
collectHints: true,
|
|
36
39
|
collectPublicInputs: true,
|
|
37
40
|
};
|
|
38
|
-
return new DumpingCppPublicTxSimulator(merkleTree, contractsDB, globalVariables, dumpingConfig, dumpDir);
|
|
41
|
+
return new DumpingCppPublicTxSimulator(merkleTree, contractsDB, globalVariables, dumpingConfig, dumpDir, bindings);
|
|
39
42
|
}
|
|
40
|
-
return new TelemetryCppPublicTxSimulator(merkleTree, contractsDB, globalVariables, telemetryClient, config);
|
|
43
|
+
return new TelemetryCppPublicTxSimulator(merkleTree, contractsDB, globalVariables, telemetryClient, config, bindings);
|
|
41
44
|
}
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from '@aztec/constants';
|
|
8
8
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
9
9
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
10
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
10
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
11
11
|
import {
|
|
12
12
|
AvmAccumulatedData,
|
|
13
13
|
AvmAccumulatedDataArrayLengths,
|
|
@@ -87,8 +87,9 @@ export class PublicTxContext {
|
|
|
87
87
|
public readonly revertibleAccumulatedDataFromPrivate: PrivateToPublicAccumulatedData,
|
|
88
88
|
public readonly feePayer: AztecAddress,
|
|
89
89
|
private readonly trace: SideEffectTrace,
|
|
90
|
+
bindings?: LoggerBindings,
|
|
90
91
|
) {
|
|
91
|
-
this.log = createLogger(`simulator:public_tx_context
|
|
92
|
+
this.log = createLogger(`simulator:public_tx_context`, bindings);
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
public static async create(
|
|
@@ -98,13 +99,14 @@ export class PublicTxContext {
|
|
|
98
99
|
globalVariables: GlobalVariables,
|
|
99
100
|
protocolContracts: ProtocolContracts,
|
|
100
101
|
proverId: Fr,
|
|
102
|
+
bindings?: LoggerBindings,
|
|
101
103
|
) {
|
|
102
104
|
const contractDeploymentData = AllContractDeploymentData.fromTx(tx);
|
|
103
105
|
const nonRevertibleContractDeploymentData = contractDeploymentData.getNonRevertibleContractDeploymentData();
|
|
104
106
|
const revertibleContractDeploymentData = contractDeploymentData.getRevertibleContractDeploymentData();
|
|
105
107
|
const nonRevertibleAccumulatedDataFromPrivate = tx.data.forPublic!.nonRevertibleAccumulatedData;
|
|
106
108
|
|
|
107
|
-
const trace = new SideEffectTrace();
|
|
109
|
+
const trace = new SideEffectTrace(0, bindings);
|
|
108
110
|
|
|
109
111
|
const firstNullifier = nonRevertibleAccumulatedDataFromPrivate.nullifiers[0];
|
|
110
112
|
|
|
@@ -115,6 +117,7 @@ export class PublicTxContext {
|
|
|
115
117
|
trace,
|
|
116
118
|
firstNullifier,
|
|
117
119
|
globalVariables.timestamp,
|
|
120
|
+
bindings,
|
|
118
121
|
);
|
|
119
122
|
|
|
120
123
|
const gasSettings = tx.data.constants.txContext.gasSettings;
|
|
@@ -124,7 +127,7 @@ export class PublicTxContext {
|
|
|
124
127
|
|
|
125
128
|
return new PublicTxContext(
|
|
126
129
|
tx.getTxHash(),
|
|
127
|
-
new PhaseStateManager(txStateManager),
|
|
130
|
+
new PhaseStateManager(txStateManager, bindings),
|
|
128
131
|
await txStateManager.getTreeSnapshots(),
|
|
129
132
|
globalVariables,
|
|
130
133
|
protocolContracts,
|
|
@@ -142,6 +145,7 @@ export class PublicTxContext {
|
|
|
142
145
|
tx.data.forPublic!.revertibleAccumulatedData,
|
|
143
146
|
tx.data.feePayer,
|
|
144
147
|
trace,
|
|
148
|
+
bindings,
|
|
145
149
|
);
|
|
146
150
|
}
|
|
147
151
|
|
|
@@ -170,14 +174,8 @@ export class PublicTxContext {
|
|
|
170
174
|
}
|
|
171
175
|
if (phase === TxExecutionPhase.SETUP) {
|
|
172
176
|
this.log.warn(`Setup phase reverted! The transaction will be thrown out.`);
|
|
173
|
-
} else if (phase === TxExecutionPhase.APP_LOGIC) {
|
|
174
|
-
this.revertCode = RevertCode.
|
|
175
|
-
} else if (phase === TxExecutionPhase.TEARDOWN) {
|
|
176
|
-
if (this.revertCode.equals(RevertCode.APP_LOGIC_REVERTED)) {
|
|
177
|
-
this.revertCode = RevertCode.BOTH_REVERTED;
|
|
178
|
-
} else {
|
|
179
|
-
this.revertCode = RevertCode.TEARDOWN_REVERTED;
|
|
180
|
-
}
|
|
177
|
+
} else if (phase === TxExecutionPhase.APP_LOGIC || phase === TxExecutionPhase.TEARDOWN) {
|
|
178
|
+
this.revertCode = RevertCode.REVERTED;
|
|
181
179
|
}
|
|
182
180
|
}
|
|
183
181
|
|
|
@@ -243,8 +241,12 @@ export class PublicTxContext {
|
|
|
243
241
|
}
|
|
244
242
|
|
|
245
243
|
/**
|
|
246
|
-
* The gasUsed by public and private,
|
|
247
|
-
*
|
|
244
|
+
* The gasUsed by public and private, as if the entire teardown gas limit was consumed.
|
|
245
|
+
*
|
|
246
|
+
* This is intentional: teardown is used for gas accounting and refunds, so the transaction
|
|
247
|
+
* fee must be deterministic _before_ teardown executes. If fees depended on teardown's actual
|
|
248
|
+
* consumption there would be a circular dependency. Billing the full teardown gas limit
|
|
249
|
+
* (set by the user) makes the fee known in advance and available to the teardown function.
|
|
248
250
|
*/
|
|
249
251
|
getTotalGasUsed(): Gas {
|
|
250
252
|
return this.gasUsedByPrivate.add(this.gasUsedByPublic);
|
|
@@ -441,8 +443,11 @@ class PhaseStateManager {
|
|
|
441
443
|
|
|
442
444
|
private currentlyActiveStateManager: PublicPersistableStateManager | undefined;
|
|
443
445
|
|
|
444
|
-
constructor(
|
|
445
|
-
|
|
446
|
+
constructor(
|
|
447
|
+
private readonly txStateManager: PublicPersistableStateManager,
|
|
448
|
+
bindings?: LoggerBindings,
|
|
449
|
+
) {
|
|
450
|
+
this.log = createLogger(`simulator:public_phase_state_manager`, bindings);
|
|
446
451
|
}
|
|
447
452
|
|
|
448
453
|
async fork() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { ProtocolContractAddress, ProtocolContractsList } from '@aztec/protocol-contracts';
|
|
5
5
|
import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
6
6
|
import { AvmExecutionHints, AvmTxHint, PublicSimulatorConfig, PublicTxEffect, PublicTxResult } from '@aztec/stdlib/avm';
|
|
@@ -27,7 +27,6 @@ import { type PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
|
|
|
27
27
|
import {
|
|
28
28
|
L2ToL1MessageLimitReachedError,
|
|
29
29
|
NoteHashLimitReachedError,
|
|
30
|
-
NullifierCollisionError,
|
|
31
30
|
NullifierLimitReachedError,
|
|
32
31
|
} from '../side_effect_errors.js';
|
|
33
32
|
import type { PublicPersistableStateManager } from '../state_manager/state_manager.js';
|
|
@@ -81,6 +80,7 @@ type ProcessedPhase = {
|
|
|
81
80
|
export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
82
81
|
protected log: Logger;
|
|
83
82
|
protected readonly config: PublicSimulatorConfig;
|
|
83
|
+
protected readonly bindings?: LoggerBindings;
|
|
84
84
|
|
|
85
85
|
constructor(
|
|
86
86
|
protected merkleTree: MerkleTreeWriteOperations,
|
|
@@ -88,9 +88,11 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
88
88
|
protected globalVariables: GlobalVariables,
|
|
89
89
|
config?: Partial<PublicSimulatorConfig>,
|
|
90
90
|
protected protocolContracts: ProtocolContracts = ProtocolContractsList,
|
|
91
|
+
bindings?: LoggerBindings,
|
|
91
92
|
) {
|
|
92
93
|
this.config = PublicSimulatorConfig.from(config ?? {});
|
|
93
|
-
this.
|
|
94
|
+
this.bindings = bindings;
|
|
95
|
+
this.log = createLogger(`simulator:public_tx_simulator`, bindings);
|
|
94
96
|
}
|
|
95
97
|
|
|
96
98
|
/**
|
|
@@ -119,6 +121,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
119
121
|
this.globalVariables,
|
|
120
122
|
this.protocolContracts,
|
|
121
123
|
this.config.proverId,
|
|
124
|
+
this.bindings,
|
|
122
125
|
);
|
|
123
126
|
|
|
124
127
|
// This will throw if there is a nullifier collision.
|
|
@@ -143,7 +146,8 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
143
146
|
hintingContractsDB.createCheckpoint();
|
|
144
147
|
|
|
145
148
|
try {
|
|
146
|
-
// This
|
|
149
|
+
// This may throw: a side-effect limit error triggers a soft revert (caught below), while a
|
|
150
|
+
// nullifier collision is unrecoverable and propagates out of simulate() to throw out the tx.
|
|
147
151
|
await this.insertRevertiblesFromPrivate(context);
|
|
148
152
|
|
|
149
153
|
// Only proceed with app logic if there was no revert during revertible insertion.
|
|
@@ -195,8 +199,8 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
195
199
|
|
|
196
200
|
// Such transactions should be filtered by GasTxValidator.
|
|
197
201
|
assert(
|
|
198
|
-
context.getActualGasUsed().l2Gas <=
|
|
199
|
-
`Transaction consumes ${context.getActualGasUsed().l2Gas} L2 gas, which exceeds the
|
|
202
|
+
context.getActualGasUsed().l2Gas <= MAX_PROCESSABLE_L2_GAS,
|
|
203
|
+
`Transaction consumes ${context.getActualGasUsed().l2Gas} L2 gas, which exceeds the maximum processable gas of ${MAX_PROCESSABLE_L2_GAS}`,
|
|
200
204
|
);
|
|
201
205
|
await this.payFee(context);
|
|
202
206
|
|
|
@@ -397,7 +401,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
397
401
|
// However, things work as expected because later calls to getters on the hintingContractsDB
|
|
398
402
|
// will pick up the new contracts and will generate the necessary hints.
|
|
399
403
|
// So, a consumer of the hints will always see the new contracts.
|
|
400
|
-
|
|
404
|
+
this.contractsDB.addContractsFromLogs(context.nonRevertibleContractDeploymentData);
|
|
401
405
|
}
|
|
402
406
|
|
|
403
407
|
/**
|
|
@@ -405,9 +409,13 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
405
409
|
* Throws TxSimRevertibleInsertionsRevert if there is some checked error during revertible insertions.
|
|
406
410
|
* This function checks for the following errors:
|
|
407
411
|
* - NullifierLimitReachedError
|
|
408
|
-
* - NullifierCollisionError
|
|
409
412
|
* - NoteHashLimitReachedError
|
|
410
413
|
* - L2ToL1MessageLimitReachedError
|
|
414
|
+
*
|
|
415
|
+
* Note: NullifierCollisionError is intentionally NOT caught here. A nullifier collision
|
|
416
|
+
* during revertible insertions is unprovable (the nullifier originated from private, so
|
|
417
|
+
* a collision indicates the tx should never have been proposed). It propagates as-is to
|
|
418
|
+
* make the transaction unrecoverable, matching the AVM circuit behavior.
|
|
411
419
|
*/
|
|
412
420
|
protected async insertRevertiblesFromPrivate(context: PublicTxContext) {
|
|
413
421
|
const stateManager = context.state.getActiveStateManager();
|
|
@@ -417,7 +425,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
417
425
|
await stateManager.writeSiloedNullifier(siloedNullifier);
|
|
418
426
|
}
|
|
419
427
|
} catch (e: any) {
|
|
420
|
-
if (e instanceof NullifierLimitReachedError
|
|
428
|
+
if (e instanceof NullifierLimitReachedError) {
|
|
421
429
|
context.revert(
|
|
422
430
|
TxExecutionPhase.APP_LOGIC,
|
|
423
431
|
new SimulationError(
|
|
@@ -427,7 +435,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
427
435
|
);
|
|
428
436
|
throw new TxSimRevertibleInsertionsRevert();
|
|
429
437
|
} else {
|
|
430
|
-
// Unchecked/unknown error - re-throw as-is
|
|
438
|
+
// Unchecked/unknown error or NullifierCollisionError (unrecoverable) - re-throw as-is
|
|
431
439
|
throw e;
|
|
432
440
|
}
|
|
433
441
|
}
|
|
@@ -482,7 +490,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
482
490
|
// However, things work as expected because later calls to getters on the hintingContractsDB
|
|
483
491
|
// will pick up the new contracts and will generate the necessary hints.
|
|
484
492
|
// So, a consumer of the hints will always see the new contracts.
|
|
485
|
-
|
|
493
|
+
this.contractsDB.addContractsFromLogs(context.revertibleContractDeploymentData);
|
|
486
494
|
}
|
|
487
495
|
|
|
488
496
|
private async payFee(context: PublicTxContext) {
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from '@aztec/constants';
|
|
10
10
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
11
11
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
12
|
-
import { type LogLevel, createLogger } from '@aztec/foundation/log';
|
|
12
|
+
import { type LogLevel, type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
13
13
|
import { PublicDataUpdateRequest } from '@aztec/stdlib/avm';
|
|
14
14
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
15
15
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
@@ -61,7 +61,7 @@ export class SideEffectArrayLengths {
|
|
|
61
61
|
* Trace side effects for an enqueued public call's execution.
|
|
62
62
|
*/
|
|
63
63
|
export class SideEffectTrace implements PublicSideEffectTraceInterface {
|
|
64
|
-
public log
|
|
64
|
+
public log: Logger;
|
|
65
65
|
|
|
66
66
|
/** The side effect counter increments with every call to the trace. */
|
|
67
67
|
private sideEffectCounter: number;
|
|
@@ -79,6 +79,7 @@ export class SideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
79
79
|
constructor(
|
|
80
80
|
/** The counter of this trace's first side effect. */
|
|
81
81
|
public readonly startSideEffectCounter: number = 0,
|
|
82
|
+
bindings?: LoggerBindings,
|
|
82
83
|
/** Track parent's (or previous kernel's) lengths so the AVM can properly enforce TX-wide limits,
|
|
83
84
|
* otherwise the public kernel can fail to prove because TX limits are breached.
|
|
84
85
|
*/
|
|
@@ -90,11 +91,13 @@ export class SideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
90
91
|
private debugLogMemoryReads: number = 0,
|
|
91
92
|
) {
|
|
92
93
|
this.sideEffectCounter = startSideEffectCounter;
|
|
94
|
+
this.log = createLogger('simulator:side_effect_trace', bindings);
|
|
93
95
|
}
|
|
94
96
|
|
|
95
97
|
public fork() {
|
|
96
98
|
return new SideEffectTrace(
|
|
97
99
|
this.sideEffectCounter,
|
|
100
|
+
this.log.getBindings(),
|
|
98
101
|
new SideEffectArrayLengths(
|
|
99
102
|
this.previousSideEffectArrayLengths.publicDataWrites + this.userPublicDataWritesLength,
|
|
100
103
|
this.previousSideEffectArrayLengths.protocolPublicDataWrites + this.protocolPublicDataWritesLength,
|
|
@@ -2,7 +2,7 @@ import { CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS, MAX_PROTOCOL_CONTRACTS } f
|
|
|
2
2
|
import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
|
|
3
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
4
|
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
5
|
-
import { type LogLevel, createLogger } from '@aztec/foundation/log';
|
|
5
|
+
import { type LogLevel, type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
6
6
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
7
7
|
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
8
8
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
@@ -42,7 +42,7 @@ import { PublicStorage } from './public_storage.js';
|
|
|
42
42
|
* Manages merging of successful/reverted child state into current state.
|
|
43
43
|
*/
|
|
44
44
|
export class PublicPersistableStateManager {
|
|
45
|
-
private readonly log
|
|
45
|
+
private readonly log: Logger;
|
|
46
46
|
|
|
47
47
|
/** Make sure a forked state is never merged twice. */
|
|
48
48
|
private alreadyMergedIntoParent = false;
|
|
@@ -56,7 +56,10 @@ export class PublicPersistableStateManager {
|
|
|
56
56
|
private readonly doMerkleOperations: boolean = true,
|
|
57
57
|
private readonly publicStorage: PublicStorage = new PublicStorage(treesDB),
|
|
58
58
|
private readonly nullifiers: NullifierManager = new NullifierManager(treesDB),
|
|
59
|
-
|
|
59
|
+
bindings?: LoggerBindings,
|
|
60
|
+
) {
|
|
61
|
+
this.log = createLogger('simulator:state_manager', bindings);
|
|
62
|
+
}
|
|
60
63
|
|
|
61
64
|
/**
|
|
62
65
|
* Create a new state manager
|
|
@@ -67,8 +70,19 @@ export class PublicPersistableStateManager {
|
|
|
67
70
|
trace: PublicSideEffectTraceInterface,
|
|
68
71
|
firstNullifier: Fr,
|
|
69
72
|
timestamp: UInt64,
|
|
73
|
+
bindings?: LoggerBindings,
|
|
70
74
|
): PublicPersistableStateManager {
|
|
71
|
-
return new PublicPersistableStateManager(
|
|
75
|
+
return new PublicPersistableStateManager(
|
|
76
|
+
treesDB,
|
|
77
|
+
contractsDB,
|
|
78
|
+
trace,
|
|
79
|
+
firstNullifier,
|
|
80
|
+
timestamp,
|
|
81
|
+
undefined,
|
|
82
|
+
undefined,
|
|
83
|
+
undefined,
|
|
84
|
+
bindings,
|
|
85
|
+
);
|
|
72
86
|
}
|
|
73
87
|
|
|
74
88
|
/**
|
|
@@ -85,6 +99,7 @@ export class PublicPersistableStateManager {
|
|
|
85
99
|
this.doMerkleOperations,
|
|
86
100
|
this.publicStorage.fork(),
|
|
87
101
|
this.nullifiers.fork(),
|
|
102
|
+
this.log.getBindings(),
|
|
88
103
|
);
|
|
89
104
|
}
|
|
90
105
|
|
|
@@ -233,7 +248,15 @@ export class PublicPersistableStateManager {
|
|
|
233
248
|
public async checkNullifierExists(contractAddress: AztecAddress, nullifier: Fr): Promise<boolean> {
|
|
234
249
|
this.log.trace(`Checking existence of nullifier (address=${contractAddress}, nullifier=${nullifier})`);
|
|
235
250
|
const siloedNullifier = await siloNullifier(contractAddress, nullifier);
|
|
251
|
+
return this.checkSiloedNullifierExists(siloedNullifier);
|
|
252
|
+
}
|
|
236
253
|
|
|
254
|
+
/**
|
|
255
|
+
* Check if a siloed nullifier exists.
|
|
256
|
+
* @param siloedNullifier - the siloed nullifier to check
|
|
257
|
+
* @returns exists - whether the nullifier exists in the nullifier set
|
|
258
|
+
*/
|
|
259
|
+
public async checkSiloedNullifierExists(siloedNullifier: Fr): Promise<boolean> {
|
|
237
260
|
if (this.doMerkleOperations) {
|
|
238
261
|
const exists = await this.treesDB.checkNullifierExists(siloedNullifier);
|
|
239
262
|
this.log.trace(`Checked siloed nullifier ${siloedNullifier} (exists=${exists})`);
|
|
@@ -379,7 +402,7 @@ export class PublicPersistableStateManager {
|
|
|
379
402
|
|
|
380
403
|
// This will internally decide whether to check the nullifier tree or not depending on doMerkleOperations.
|
|
381
404
|
const nullifierExistsInTree = await this.checkNullifierExists(
|
|
382
|
-
AztecAddress.
|
|
405
|
+
AztecAddress.fromNumberUnsafe(CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS),
|
|
383
406
|
contractAddress.toField(),
|
|
384
407
|
);
|
|
385
408
|
assert(
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { sum } from '@aztec/foundation/collection';
|
|
2
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { Timer } from '@aztec/foundation/timer';
|
|
4
4
|
import type { RevertCode } from '@aztec/stdlib/avm';
|
|
5
5
|
import type { GasUsed } from '@aztec/stdlib/gas';
|
|
@@ -21,6 +21,7 @@ export interface PublicTxMetrics {
|
|
|
21
21
|
totalDurationMs: number;
|
|
22
22
|
manaUsed: number | undefined;
|
|
23
23
|
totalInstructionsExecuted: number;
|
|
24
|
+
bytecodeSizes: { contractName: string; sizeBytes: number }[];
|
|
24
25
|
nonRevertiblePrivateInsertionsUs: number | undefined;
|
|
25
26
|
revertiblePrivateInsertionsUs: number | undefined;
|
|
26
27
|
enqueuedCalls: PublicEnqueuedCallMetrics[];
|
|
@@ -62,6 +63,7 @@ function createEmptyTxMetrics(): PublicTxMetrics {
|
|
|
62
63
|
totalDurationMs: 0,
|
|
63
64
|
manaUsed: 0,
|
|
64
65
|
totalInstructionsExecuted: 0,
|
|
66
|
+
bytecodeSizes: [],
|
|
65
67
|
nonRevertiblePrivateInsertionsUs: undefined,
|
|
66
68
|
revertiblePrivateInsertionsUs: undefined,
|
|
67
69
|
enqueuedCalls: [],
|
|
@@ -88,8 +90,8 @@ export class TestExecutorMetrics implements ExecutorMetricsInterface {
|
|
|
88
90
|
private currentTxLabel: string | undefined;
|
|
89
91
|
private txTimer: Timer | undefined;
|
|
90
92
|
|
|
91
|
-
constructor() {
|
|
92
|
-
this.logger = createLogger(`simulator:test_executor_metrics
|
|
93
|
+
constructor(bindings?: LoggerBindings) {
|
|
94
|
+
this.logger = createLogger(`simulator:test_executor_metrics`, bindings);
|
|
93
95
|
}
|
|
94
96
|
|
|
95
97
|
startRecordingTxSimulation(txLabel: string) {
|
|
@@ -172,6 +174,12 @@ export class TestExecutorMetrics implements ExecutorMetricsInterface {
|
|
|
172
174
|
}
|
|
173
175
|
}
|
|
174
176
|
|
|
177
|
+
recordBytecodeSize(txLabel: string, contractName: string, sizeBytes: number) {
|
|
178
|
+
const txMetrics = this.txMetrics.get(txLabel);
|
|
179
|
+
assert(txMetrics, `Cannot record bytecode size for unknown tx label: ${txLabel}`);
|
|
180
|
+
txMetrics.bytecodeSizes.push({ contractName, sizeBytes });
|
|
181
|
+
}
|
|
182
|
+
|
|
175
183
|
recordProverMetrics(txLabel: string, metrics: Partial<PublicTxMetrics>) {
|
|
176
184
|
if (!this.txMetrics.has(txLabel)) {
|
|
177
185
|
this.txMetrics.set(txLabel, createEmptyTxMetrics());
|
|
@@ -216,6 +224,15 @@ export class TestExecutorMetrics implements ExecutorMetricsInterface {
|
|
|
216
224
|
) {
|
|
217
225
|
pretty += `${INDENT0}Total instructions executed: ${fmtNum(txMetrics.totalInstructionsExecuted)}\n`;
|
|
218
226
|
}
|
|
227
|
+
if (
|
|
228
|
+
(filter === PublicTxMetricsFilter.TOTALS || filter === PublicTxMetricsFilter.ALL) &&
|
|
229
|
+
txMetrics.bytecodeSizes.length > 0
|
|
230
|
+
) {
|
|
231
|
+
pretty += `${INDENT0}Bytecode sizes:\n`;
|
|
232
|
+
for (const { contractName, sizeBytes } of txMetrics.bytecodeSizes) {
|
|
233
|
+
pretty += `${INDENT1}${contractName}: ${fmtNum(sizeBytes, 'bytes')}\n`;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
219
236
|
if (filter === PublicTxMetricsFilter.DURATIONS || filter === PublicTxMetricsFilter.ALL) {
|
|
220
237
|
pretty += `${INDENT0}Private insertions:\n`;
|
|
221
238
|
pretty += `${INDENT1}Non-revertible: ${fmtNum(txMetrics.nonRevertiblePrivateInsertionsUs! / 1_000, 'ms')}\n`;
|
|
@@ -387,6 +404,13 @@ export class TestExecutorMetrics implements ExecutorMetricsInterface {
|
|
|
387
404
|
});
|
|
388
405
|
}
|
|
389
406
|
}
|
|
407
|
+
for (const { contractName, sizeBytes } of txMetrics.bytecodeSizes) {
|
|
408
|
+
data.push({
|
|
409
|
+
name: `${txLabel}/bytecodeSizeBytes/${contractName}`,
|
|
410
|
+
value: sizeBytes,
|
|
411
|
+
unit: 'bytes',
|
|
412
|
+
});
|
|
413
|
+
}
|
|
390
414
|
}
|
|
391
415
|
return JSON.stringify(data, null, indent);
|
|
392
416
|
}
|