@aztec-labs/simulator 6.0.0-nightly.20260829
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 +57 -0
- package/dest/client.d.ts +6 -0
- package/dest/client.d.ts.map +1 -0
- package/dest/client.js +3 -0
- package/dest/common/errors.d.ts +51 -0
- package/dest/common/errors.d.ts.map +1 -0
- package/dest/common/errors.js +154 -0
- package/dest/common/index.d.ts +3 -0
- package/dest/common/index.d.ts.map +1 -0
- package/dest/common/index.js +2 -0
- package/dest/common/stats/index.d.ts +2 -0
- package/dest/common/stats/index.d.ts.map +1 -0
- package/dest/common/stats/index.js +1 -0
- package/dest/common/stats/stats.d.ts +4 -0
- package/dest/common/stats/stats.d.ts.map +1 -0
- package/dest/common/stats/stats.js +10 -0
- package/dest/private/acvm/acvm.d.ts +43 -0
- package/dest/private/acvm/acvm.d.ts.map +1 -0
- package/dest/private/acvm/acvm.js +65 -0
- package/dest/private/acvm/acvm_types.d.ts +10 -0
- package/dest/private/acvm/acvm_types.d.ts.map +1 -0
- package/dest/private/acvm/acvm_types.js +3 -0
- package/dest/private/acvm/deserialize.d.ts +35 -0
- package/dest/private/acvm/deserialize.d.ts.map +1 -0
- package/dest/private/acvm/deserialize.js +50 -0
- package/dest/private/acvm/index.d.ts +5 -0
- package/dest/private/acvm/index.d.ts.map +1 -0
- package/dest/private/acvm/index.js +4 -0
- package/dest/private/acvm/serialize.d.ts +41 -0
- package/dest/private/acvm/serialize.d.ts.map +1 -0
- package/dest/private/acvm/serialize.js +99 -0
- package/dest/private/acvm_native.d.ts +41 -0
- package/dest/private/acvm_native.d.ts.map +1 -0
- package/dest/private/acvm_native.js +147 -0
- package/dest/private/acvm_wasm.d.ts +16 -0
- package/dest/private/acvm_wasm.d.ts.map +1 -0
- package/dest/private/acvm_wasm.js +67 -0
- package/dest/private/acvm_wasm_with_blobs.d.ts +20 -0
- package/dest/private/acvm_wasm_with_blobs.d.ts.map +1 -0
- package/dest/private/acvm_wasm_with_blobs.js +35 -0
- package/dest/private/circuit_simulator.d.ts +35 -0
- package/dest/private/circuit_simulator.d.ts.map +1 -0
- package/dest/private/circuit_simulator.js +43 -0
- package/dest/private/factory.d.ts +12 -0
- package/dest/private/factory.d.ts.map +1 -0
- package/dest/private/factory.js +30 -0
- package/dest/public/avm/testing/account_proof_fetcher.d.ts +2 -0
- package/dest/public/avm/testing/account_proof_fetcher.d.ts.map +1 -0
- package/dest/public/avm/testing/account_proof_fetcher.js +152 -0
- package/dest/public/avm/testing/base_avm_simulation_tester.d.ts +39 -0
- package/dest/public/avm/testing/base_avm_simulation_tester.d.ts.map +1 -0
- package/dest/public/avm/testing/base_avm_simulation_tester.js +121 -0
- package/dest/public/avm/testing/utils.d.ts +32 -0
- package/dest/public/avm/testing/utils.d.ts.map +1 -0
- package/dest/public/avm/testing/utils.js +66 -0
- package/dest/public/avm_simulator.d.ts +28 -0
- package/dest/public/avm_simulator.d.ts.map +1 -0
- package/dest/public/avm_simulator.js +4 -0
- package/dest/public/avm_simulator_pool.d.ts +84 -0
- package/dest/public/avm_simulator_pool.d.ts.map +1 -0
- package/dest/public/avm_simulator_pool.js +311 -0
- package/dest/public/cdb_ipc_server.d.ts +40 -0
- package/dest/public/cdb_ipc_server.d.ts.map +1 -0
- package/dest/public/cdb_ipc_server.js +153 -0
- 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 +68 -0
- package/dest/public/db_interfaces.d.ts.map +1 -0
- package/dest/public/db_interfaces.js +3 -0
- package/dest/public/executor_metrics.d.ts +21 -0
- package/dest/public/executor_metrics.d.ts.map +1 -0
- package/dest/public/executor_metrics.js +64 -0
- package/dest/public/executor_metrics_interface.d.ts +10 -0
- package/dest/public/executor_metrics_interface.d.ts.map +1 -0
- package/dest/public/executor_metrics_interface.js +1 -0
- package/dest/public/fixtures/amm_test.d.ts +10 -0
- package/dest/public/fixtures/amm_test.d.ts.map +1 -0
- package/dest/public/fixtures/amm_test.js +213 -0
- package/dest/public/fixtures/bulk_test.d.ts +6 -0
- package/dest/public/fixtures/bulk_test.d.ts.map +1 -0
- package/dest/public/fixtures/bulk_test.js +289 -0
- package/dest/public/fixtures/custom_bytecode_tester.d.ts +34 -0
- package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -0
- package/dest/public/fixtures/custom_bytecode_tester.js +53 -0
- package/dest/public/fixtures/index.d.ts +10 -0
- package/dest/public/fixtures/index.d.ts.map +1 -0
- package/dest/public/fixtures/index.js +9 -0
- package/dest/public/fixtures/public_processor_test_env.d.ts +30 -0
- package/dest/public/fixtures/public_processor_test_env.d.ts.map +1 -0
- package/dest/public/fixtures/public_processor_test_env.js +73 -0
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +77 -0
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -0
- package/dest/public/fixtures/public_tx_simulation_tester.js +176 -0
- package/dest/public/fixtures/simple_contract_data_source.d.ts +36 -0
- package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -0
- package/dest/public/fixtures/simple_contract_data_source.js +95 -0
- package/dest/public/fixtures/token_test.d.ts +12 -0
- package/dest/public/fixtures/token_test.d.ts.map +1 -0
- package/dest/public/fixtures/token_test.js +96 -0
- package/dest/public/fixtures/utils.d.ts +26 -0
- package/dest/public/fixtures/utils.d.ts.map +1 -0
- package/dest/public/fixtures/utils.js +170 -0
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +65 -0
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -0
- package/dest/public/fuzzing/avm_fuzzer_simulator.js +181 -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 +108 -0
- package/dest/public/index.d.ts +10 -0
- package/dest/public/index.d.ts.map +1 -0
- package/dest/public/index.js +6 -0
- package/dest/public/public_db_sources.d.ts +83 -0
- package/dest/public/public_db_sources.d.ts.map +1 -0
- package/dest/public/public_db_sources.js +297 -0
- package/dest/public/public_errors.d.ts +12 -0
- package/dest/public/public_errors.d.ts.map +1 -0
- package/dest/public/public_errors.js +13 -0
- package/dest/public/public_processor/guarded_merkle_tree.d.ts +52 -0
- package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -0
- package/dest/public/public_processor/guarded_merkle_tree.js +116 -0
- package/dest/public/public_processor/public_processor.d.ts +71 -0
- package/dest/public/public_processor/public_processor.d.ts.map +1 -0
- package/dest/public/public_processor/public_processor.js +858 -0
- package/dest/public/public_processor/public_processor_metrics.d.ts +30 -0
- package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -0
- package/dest/public/public_processor/public_processor_metrics.js +116 -0
- package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts +17 -0
- package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/dumping_public_tx_simulator.js +39 -0
- package/dest/public/public_tx_simulator/factories.d.ts +14 -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 +6 -0
- package/dest/public/public_tx_simulator/index.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/index.js +3 -0
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +53 -0
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/public_tx_simulator.js +127 -0
- package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts +24 -0
- package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/public_tx_simulator_base.js +31 -0
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +32 -0
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.js +1 -0
- package/dest/public/side_effect_errors.d.ts +44 -0
- package/dest/public/side_effect_errors.d.ts.map +1 -0
- package/dest/public/side_effect_errors.js +75 -0
- package/dest/public/test_executor_metrics.d.ts +56 -0
- package/dest/public/test_executor_metrics.d.ts.map +1 -0
- package/dest/public/test_executor_metrics.js +305 -0
- package/dest/public/unique_class_ids.d.ts +37 -0
- package/dest/public/unique_class_ids.d.ts.map +1 -0
- package/dest/public/unique_class_ids.js +61 -0
- package/dest/public/utils.d.ts +3 -0
- package/dest/public/utils.d.ts.map +1 -0
- package/dest/public/utils.js +18 -0
- package/dest/server.d.ts +7 -0
- package/dest/server.d.ts.map +1 -0
- package/dest/server.js +5 -0
- package/package.json +109 -0
- package/src/client.ts +5 -0
- package/src/common/errors.ts +219 -0
- package/src/common/index.ts +2 -0
- package/src/common/stats/index.ts +1 -0
- package/src/common/stats/stats.ts +20 -0
- package/src/private/acvm/acvm.ts +114 -0
- package/src/private/acvm/acvm_types.ts +11 -0
- package/src/private/acvm/deserialize.ts +58 -0
- package/src/private/acvm/index.ts +4 -0
- package/src/private/acvm/serialize.ts +123 -0
- package/src/private/acvm_native.ts +200 -0
- package/src/private/acvm_wasm.ts +80 -0
- package/src/private/acvm_wasm_with_blobs.ts +55 -0
- package/src/private/circuit_simulator.ts +91 -0
- package/src/private/factory.ts +40 -0
- package/src/public/avm/testing/account_proof.json +553 -0
- package/src/public/avm/testing/account_proof_fetcher.ts +166 -0
- package/src/public/avm/testing/base_avm_simulation_tester.ts +162 -0
- package/src/public/avm/testing/utils.ts +114 -0
- package/src/public/avm_simulator.ts +29 -0
- package/src/public/avm_simulator_pool.ts +355 -0
- package/src/public/cdb_ipc_server.ts +198 -0
- package/src/public/contracts_db_checkpoint.ts +41 -0
- package/src/public/db_interfaces.ts +76 -0
- package/src/public/executor_metrics.ts +102 -0
- package/src/public/executor_metrics_interface.ts +20 -0
- package/src/public/fixtures/amm_test.ts +331 -0
- package/src/public/fixtures/bulk_test.ts +194 -0
- package/src/public/fixtures/custom_bytecode_tester.ts +83 -0
- package/src/public/fixtures/index.ts +13 -0
- package/src/public/fixtures/public_processor_test_env.ts +88 -0
- package/src/public/fixtures/public_tx_simulation_tester.ts +315 -0
- package/src/public/fixtures/simple_contract_data_source.ts +122 -0
- package/src/public/fixtures/token_test.ts +148 -0
- package/src/public/fixtures/utils.ts +269 -0
- package/src/public/fuzzing/avm_fuzzer_simulator.ts +302 -0
- package/src/public/fuzzing/avm_simulator_bin.ts +156 -0
- package/src/public/index.ts +16 -0
- package/src/public/public_db_sources.ts +405 -0
- package/src/public/public_errors.ts +14 -0
- package/src/public/public_processor/guarded_merkle_tree.ts +161 -0
- package/src/public/public_processor/public_processor.ts +657 -0
- package/src/public/public_processor/public_processor_metrics.ts +138 -0
- package/src/public/public_tx_simulator/dumping_public_tx_simulator.ts +66 -0
- package/src/public/public_tx_simulator/factories.ts +61 -0
- package/src/public/public_tx_simulator/index.ts +8 -0
- package/src/public/public_tx_simulator/public_tx_simulator.ts +190 -0
- package/src/public/public_tx_simulator/public_tx_simulator_base.ts +37 -0
- package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +33 -0
- package/src/public/side_effect_errors.ts +96 -0
- package/src/public/test_executor_metrics.ts +399 -0
- package/src/public/unique_class_ids.ts +79 -0
- package/src/public/utils.ts +16 -0
- package/src/server.ts +6 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type { ContractClassPublishedEvent } from '@aztec-labs/protocol-contracts/class-registry';
|
|
2
|
+
import type { Gas } from '@aztec-labs/stdlib/gas';
|
|
3
|
+
import { TxExecutionPhase } from '@aztec-labs/stdlib/tx';
|
|
4
|
+
import {
|
|
5
|
+
Attributes,
|
|
6
|
+
type Gauge,
|
|
7
|
+
type Histogram,
|
|
8
|
+
Metrics,
|
|
9
|
+
type TelemetryClient,
|
|
10
|
+
type Tracer,
|
|
11
|
+
type UpDownCounter,
|
|
12
|
+
createUpDownCounterWithDefault,
|
|
13
|
+
} from '@aztec-labs/telemetry-client';
|
|
14
|
+
|
|
15
|
+
export class PublicProcessorMetrics {
|
|
16
|
+
public readonly tracer: Tracer;
|
|
17
|
+
|
|
18
|
+
private txDuration: Histogram;
|
|
19
|
+
private txCount: UpDownCounter;
|
|
20
|
+
private txPhaseCount: UpDownCounter;
|
|
21
|
+
|
|
22
|
+
private phaseDuration: Histogram;
|
|
23
|
+
private phaseCount: UpDownCounter;
|
|
24
|
+
|
|
25
|
+
private bytecodeDeployed: Histogram;
|
|
26
|
+
private totalGas: Gauge;
|
|
27
|
+
private totalGasHistogram: Histogram;
|
|
28
|
+
private gasRate: Histogram;
|
|
29
|
+
private txGas: Histogram;
|
|
30
|
+
|
|
31
|
+
private treeInsertionDuration: Histogram;
|
|
32
|
+
|
|
33
|
+
private silentlySkippedCount: UpDownCounter;
|
|
34
|
+
private silentlySkippedDuration: Histogram;
|
|
35
|
+
|
|
36
|
+
constructor(client: TelemetryClient, name = 'PublicProcessor') {
|
|
37
|
+
this.tracer = client.getTracer(name);
|
|
38
|
+
const meter = client.getMeter(name);
|
|
39
|
+
|
|
40
|
+
this.txDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TX_DURATION);
|
|
41
|
+
|
|
42
|
+
this.txCount = createUpDownCounterWithDefault(meter, Metrics.PUBLIC_PROCESSOR_TX_COUNT, {
|
|
43
|
+
[Attributes.OK]: [true, false],
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
this.txPhaseCount = createUpDownCounterWithDefault(meter, Metrics.PUBLIC_PROCESSOR_TX_PHASE_COUNT);
|
|
47
|
+
|
|
48
|
+
this.phaseDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_PHASE_DURATION);
|
|
49
|
+
|
|
50
|
+
this.phaseCount = createUpDownCounterWithDefault(meter, Metrics.PUBLIC_PROCESSOR_PHASE_COUNT, {
|
|
51
|
+
[Attributes.TX_PHASE_NAME]: [TxExecutionPhase.SETUP, TxExecutionPhase.APP_LOGIC, TxExecutionPhase.TEARDOWN],
|
|
52
|
+
[Attributes.OK]: [true, false],
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
this.bytecodeDeployed = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_DEPLOY_BYTECODE_SIZE);
|
|
56
|
+
|
|
57
|
+
this.totalGas = meter.createGauge(Metrics.PUBLIC_PROCESSOR_TOTAL_GAS);
|
|
58
|
+
|
|
59
|
+
this.totalGasHistogram = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TOTAL_GAS_HISTOGRAM);
|
|
60
|
+
|
|
61
|
+
this.txGas = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TX_GAS);
|
|
62
|
+
|
|
63
|
+
this.gasRate = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_GAS_RATE);
|
|
64
|
+
|
|
65
|
+
this.treeInsertionDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TREE_INSERTION);
|
|
66
|
+
|
|
67
|
+
this.silentlySkippedCount = createUpDownCounterWithDefault(meter, Metrics.PUBLIC_PROCESSOR_SILENTLY_SKIPPED_COUNT);
|
|
68
|
+
|
|
69
|
+
this.silentlySkippedDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_SILENTLY_SKIPPED_DURATION);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
recordPhaseDuration(phaseName: TxExecutionPhase, durationMs: number) {
|
|
73
|
+
this.phaseCount.add(1, { [Attributes.TX_PHASE_NAME]: phaseName, [Attributes.OK]: true });
|
|
74
|
+
this.phaseDuration.record(Math.ceil(durationMs), { [Attributes.TX_PHASE_NAME]: phaseName });
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
recordTx(phaseCount: number, durationMs: number, gasUsed: Gas) {
|
|
78
|
+
this.txPhaseCount.add(phaseCount);
|
|
79
|
+
this.txDuration.record(Math.ceil(durationMs));
|
|
80
|
+
this.txCount.add(1, {
|
|
81
|
+
[Attributes.OK]: true,
|
|
82
|
+
});
|
|
83
|
+
this.txGas.record(gasUsed.daGas, {
|
|
84
|
+
[Attributes.GAS_DIMENSION]: 'DA',
|
|
85
|
+
});
|
|
86
|
+
this.txGas.record(gasUsed.l2Gas, {
|
|
87
|
+
[Attributes.GAS_DIMENSION]: 'L2',
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
recordAllTxs(totalGas: Gas, gasRate: number) {
|
|
92
|
+
this.totalGas.record(totalGas.daGas, {
|
|
93
|
+
[Attributes.GAS_DIMENSION]: 'DA',
|
|
94
|
+
});
|
|
95
|
+
this.totalGas.record(totalGas.l2Gas, {
|
|
96
|
+
[Attributes.GAS_DIMENSION]: 'L2',
|
|
97
|
+
});
|
|
98
|
+
this.gasRate.record(gasRate, {
|
|
99
|
+
[Attributes.GAS_DIMENSION]: 'L2',
|
|
100
|
+
});
|
|
101
|
+
this.totalGasHistogram.record(totalGas.daGas, {
|
|
102
|
+
[Attributes.GAS_DIMENSION]: 'DA',
|
|
103
|
+
});
|
|
104
|
+
this.totalGasHistogram.record(totalGas.l2Gas, {
|
|
105
|
+
[Attributes.GAS_DIMENSION]: 'L2',
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
recordFailedTx() {
|
|
110
|
+
this.txCount.add(1, {
|
|
111
|
+
[Attributes.OK]: false,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
recordRevertedPhase(phaseName: TxExecutionPhase) {
|
|
116
|
+
this.phaseCount.add(1, { [Attributes.TX_PHASE_NAME]: phaseName, [Attributes.OK]: false });
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
recordClassPublication(...events: ContractClassPublishedEvent[]) {
|
|
120
|
+
let totalBytecode = 0;
|
|
121
|
+
for (const event of events) {
|
|
122
|
+
totalBytecode += event.packedPublicBytecode.length;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (totalBytecode > 0) {
|
|
126
|
+
this.bytecodeDeployed.record(totalBytecode);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
recordTreeInsertions(durationUs: number) {
|
|
131
|
+
this.treeInsertionDuration.record(Math.ceil(durationUs));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
recordSilentlySkipped(durationMs: number) {
|
|
135
|
+
this.silentlySkippedCount.add(1);
|
|
136
|
+
this.silentlySkippedDuration.record(Math.ceil(durationMs));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { LoggerBindings } from '@aztec-labs/foundation/log';
|
|
2
|
+
import {
|
|
3
|
+
AvmCircuitInputs,
|
|
4
|
+
AvmCircuitPublicInputs,
|
|
5
|
+
AvmExecutionHints,
|
|
6
|
+
type PublicSimulatorConfig,
|
|
7
|
+
type PublicTxResult,
|
|
8
|
+
serializeWithMessagePack,
|
|
9
|
+
} from '@aztec-labs/stdlib/avm';
|
|
10
|
+
import type { GlobalVariables, Tx } from '@aztec-labs/stdlib/tx';
|
|
11
|
+
import { strict as assert } from 'assert';
|
|
12
|
+
import { mkdirSync, writeFileSync } from 'fs';
|
|
13
|
+
import { join } from 'path';
|
|
14
|
+
|
|
15
|
+
import type { AvmSimulator } from '../avm_simulator.js';
|
|
16
|
+
import type { PublicContractsDB } from '../public_db_sources.js';
|
|
17
|
+
import { PublicTxSimulator } from './public_tx_simulator.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A {@link PublicTxSimulator} that dumps AVM circuit inputs to disk after simulation.
|
|
21
|
+
* Used during nightly CI runs to collect circuit inputs for AVM proving benchmarks.
|
|
22
|
+
*/
|
|
23
|
+
export class DumpingPublicTxSimulator extends PublicTxSimulator {
|
|
24
|
+
private readonly outputDir: string;
|
|
25
|
+
|
|
26
|
+
constructor(
|
|
27
|
+
avmSimulator: AvmSimulator,
|
|
28
|
+
globalVariables: GlobalVariables,
|
|
29
|
+
contractsDB: PublicContractsDB,
|
|
30
|
+
forkId: number,
|
|
31
|
+
config: Partial<PublicSimulatorConfig>,
|
|
32
|
+
outputDir: string,
|
|
33
|
+
bindings?: LoggerBindings,
|
|
34
|
+
) {
|
|
35
|
+
super(avmSimulator, globalVariables, contractsDB, forkId, config, bindings);
|
|
36
|
+
assert(config.collectHints === true, 'collectHints must be enabled to dump AVM circuit inputs');
|
|
37
|
+
assert(config.collectPublicInputs === true, 'collectPublicInputs must be enabled to dump AVM circuit inputs');
|
|
38
|
+
this.outputDir = outputDir;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public override async simulate(tx: Tx): Promise<PublicTxResult> {
|
|
42
|
+
const result = await super.simulate(tx);
|
|
43
|
+
this.dumpAvmCircuitInputs(result, tx.getTxHash().toString());
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private dumpAvmCircuitInputs(result: PublicTxResult, txHash: string): void {
|
|
48
|
+
try {
|
|
49
|
+
mkdirSync(this.outputDir, { recursive: true });
|
|
50
|
+
|
|
51
|
+
const filename = `avm-circuit-inputs-tx-${txHash}.bin`;
|
|
52
|
+
const filepath = join(this.outputDir, filename);
|
|
53
|
+
|
|
54
|
+
const hints = result.hints ?? AvmExecutionHints.empty();
|
|
55
|
+
const publicInputs = result.publicInputs ?? AvmCircuitPublicInputs.empty();
|
|
56
|
+
const avmCircuitInputs = new AvmCircuitInputs(hints, publicInputs);
|
|
57
|
+
|
|
58
|
+
const serialized = serializeWithMessagePack(avmCircuitInputs);
|
|
59
|
+
writeFileSync(filepath, serialized);
|
|
60
|
+
|
|
61
|
+
this.log.debug(`Dumped AVM circuit inputs to ${filepath}`);
|
|
62
|
+
} catch (error) {
|
|
63
|
+
this.log.warn(`Failed to dump AVM circuit inputs for tx ${txHash}: ${error}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { LoggerBindings } from '@aztec-labs/foundation/log';
|
|
2
|
+
import { PublicSimulatorConfig } from '@aztec-labs/stdlib/avm';
|
|
3
|
+
import type { GlobalVariables } from '@aztec-labs/stdlib/tx';
|
|
4
|
+
import type { TelemetryClient } from '@aztec-labs/telemetry-client';
|
|
5
|
+
|
|
6
|
+
import type { AvmSimulator } from '../avm_simulator.js';
|
|
7
|
+
import type { PublicContractsDB } from '../public_db_sources.js';
|
|
8
|
+
import { DumpingPublicTxSimulator } from './dumping_public_tx_simulator.js';
|
|
9
|
+
import { TelemetryPublicTxSimulator } from './public_tx_simulator.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates an IPC-based public tx simulator for block building.
|
|
13
|
+
* Uses DumpingPublicTxSimulator if DUMP_AVM_INPUTS_TO_DIR env var is set (for CI/testing the AVM circuit),
|
|
14
|
+
* otherwise uses TelemetryPublicTxSimulator (for production).
|
|
15
|
+
*/
|
|
16
|
+
export function createPublicTxSimulatorForBlockBuilding(
|
|
17
|
+
avmSimulator: AvmSimulator,
|
|
18
|
+
globalVariables: GlobalVariables,
|
|
19
|
+
contractsDB: PublicContractsDB,
|
|
20
|
+
forkId: number,
|
|
21
|
+
telemetryClient: TelemetryClient,
|
|
22
|
+
bindings?: LoggerBindings,
|
|
23
|
+
collectDebugLogs = false,
|
|
24
|
+
) {
|
|
25
|
+
const config = PublicSimulatorConfig.from({
|
|
26
|
+
skipFeeEnforcement: false,
|
|
27
|
+
collectDebugLogs,
|
|
28
|
+
collectHints: false,
|
|
29
|
+
collectPublicInputs: false,
|
|
30
|
+
collectStatistics: false,
|
|
31
|
+
collectCallMetadata: false,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const dumpDir = process.env.DUMP_AVM_INPUTS_TO_DIR;
|
|
35
|
+
if (dumpDir) {
|
|
36
|
+
// must collect hints and PIs for dumping
|
|
37
|
+
const dumpingConfig = {
|
|
38
|
+
...config,
|
|
39
|
+
collectHints: true,
|
|
40
|
+
collectPublicInputs: true,
|
|
41
|
+
};
|
|
42
|
+
return new DumpingPublicTxSimulator(
|
|
43
|
+
avmSimulator,
|
|
44
|
+
globalVariables,
|
|
45
|
+
contractsDB,
|
|
46
|
+
forkId,
|
|
47
|
+
dumpingConfig,
|
|
48
|
+
dumpDir,
|
|
49
|
+
bindings,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
return new TelemetryPublicTxSimulator(
|
|
53
|
+
avmSimulator,
|
|
54
|
+
globalVariables,
|
|
55
|
+
contractsDB,
|
|
56
|
+
forkId,
|
|
57
|
+
telemetryClient,
|
|
58
|
+
config,
|
|
59
|
+
bindings,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { PublicTxSimulator, MeasuredPublicTxSimulator, TelemetryPublicTxSimulator } from './public_tx_simulator.js';
|
|
2
|
+
export { DumpingPublicTxSimulator } from './dumping_public_tx_simulator.js';
|
|
3
|
+
export { createPublicTxSimulatorForBlockBuilding } from './factories.js';
|
|
4
|
+
export type {
|
|
5
|
+
PublicTxSimulatorInterface,
|
|
6
|
+
MeasuredPublicTxSimulatorInterface,
|
|
7
|
+
} from './public_tx_simulator_interface.js';
|
|
8
|
+
export type { PublicTxResult, PublicSimulatorConfig as PublicTxSimulatorConfig } from '@aztec-labs/stdlib/avm';
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec-labs/foundation/log';
|
|
2
|
+
import { sleep } from '@aztec-labs/foundation/sleep';
|
|
3
|
+
import {
|
|
4
|
+
AvmFastSimulationInputs,
|
|
5
|
+
AvmTxHint,
|
|
6
|
+
type PublicSimulatorConfig,
|
|
7
|
+
PublicTxResult,
|
|
8
|
+
deserializeFromMessagePack,
|
|
9
|
+
} from '@aztec-labs/stdlib/avm';
|
|
10
|
+
import { SimulationError } from '@aztec-labs/stdlib/errors';
|
|
11
|
+
import type { GlobalVariables, Tx } from '@aztec-labs/stdlib/tx';
|
|
12
|
+
import { WorldStateRevision } from '@aztec-labs/stdlib/world-state';
|
|
13
|
+
import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec-labs/telemetry-client';
|
|
14
|
+
|
|
15
|
+
import type { AvmContractsDBContext, AvmSimulator } from '../avm_simulator.js';
|
|
16
|
+
import { ExecutorMetrics } from '../executor_metrics.js';
|
|
17
|
+
import type { ExecutorMetricsInterface } from '../executor_metrics_interface.js';
|
|
18
|
+
import type { PublicContractsDB } from '../public_db_sources.js';
|
|
19
|
+
import { PublicTxSimulatorBase } from './public_tx_simulator_base.js';
|
|
20
|
+
import type {
|
|
21
|
+
MeasuredPublicTxSimulatorInterface,
|
|
22
|
+
PublicTxSimulatorInterface,
|
|
23
|
+
} from './public_tx_simulator_interface.js';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Simulates a transaction's public portion by running its public calls through an {@link AvmSimulator}.
|
|
27
|
+
* `forkId` selects the fork whose contract data the simulation reads.
|
|
28
|
+
*/
|
|
29
|
+
export class PublicTxSimulator extends PublicTxSimulatorBase implements PublicTxSimulatorInterface {
|
|
30
|
+
protected override log: Logger;
|
|
31
|
+
/** Aborts the in-flight simulation. */
|
|
32
|
+
private abortController?: AbortController;
|
|
33
|
+
/** Current simulation promise, used to wait for completion after cancellation. */
|
|
34
|
+
private simulationPromise?: Promise<PublicTxResult>;
|
|
35
|
+
|
|
36
|
+
constructor(
|
|
37
|
+
avmSimulator: AvmSimulator,
|
|
38
|
+
globalVariables: GlobalVariables,
|
|
39
|
+
contractsDB: PublicContractsDB,
|
|
40
|
+
forkId: number,
|
|
41
|
+
config?: Partial<PublicSimulatorConfig>,
|
|
42
|
+
bindings?: LoggerBindings,
|
|
43
|
+
) {
|
|
44
|
+
super(avmSimulator, globalVariables, contractsDB, forkId, config, undefined, bindings);
|
|
45
|
+
this.log = createLogger(`simulator:public_tx_simulator`, bindings);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Simulate a transaction's public portion.
|
|
50
|
+
*
|
|
51
|
+
* @param tx - The transaction to simulate.
|
|
52
|
+
* @returns The result of the transaction's public execution.
|
|
53
|
+
*/
|
|
54
|
+
public async simulate(tx: Tx): Promise<PublicTxResult> {
|
|
55
|
+
this.abortController = new AbortController();
|
|
56
|
+
this.simulationPromise = this.doSimulate(tx, this.abortController.signal);
|
|
57
|
+
try {
|
|
58
|
+
return await this.simulationPromise;
|
|
59
|
+
} finally {
|
|
60
|
+
this.abortController = undefined;
|
|
61
|
+
this.simulationPromise = undefined;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
protected async doSimulate(tx: Tx, signal: AbortSignal): Promise<PublicTxResult> {
|
|
66
|
+
const txHash = this.computeTxHash(tx);
|
|
67
|
+
this.log.debug(
|
|
68
|
+
`Simulating ${tx.publicFunctionCalldata.length} public calls for tx ${txHash}, forkId=${this.forkId}`,
|
|
69
|
+
{ txHash },
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
// Create the fast simulation inputs.
|
|
73
|
+
const txHint = AvmTxHint.fromTx(tx, this.globalVariables.gasFees);
|
|
74
|
+
const fastSimInputs = new AvmFastSimulationInputs(
|
|
75
|
+
// blockNumber: WorldStateRevision.LATEST sentinel so the WSDB walks the fork's current
|
|
76
|
+
// uncommitted state. Using 0 here makes WSDB treat this as a historical query against
|
|
77
|
+
// the empty genesis tree and miss any in-fork uncommitted leaves (deployed contracts,
|
|
78
|
+
// etc.) from earlier txs in the same block.
|
|
79
|
+
{ forkId: this.forkId, blockNumber: WorldStateRevision.LATEST, includeUncommitted: true },
|
|
80
|
+
this.config,
|
|
81
|
+
txHint,
|
|
82
|
+
this.globalVariables,
|
|
83
|
+
this.protocolContracts,
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
this.log.trace(`Serializing fast simulation inputs to msgpack...`);
|
|
87
|
+
const inputBuffer = fastSimInputs.serializeWithMessagePack();
|
|
88
|
+
|
|
89
|
+
this.log.debug(`Running AVM simulation for tx ${txHash}`);
|
|
90
|
+
const context: AvmContractsDBContext = {
|
|
91
|
+
contractsDB: this.contractsDB,
|
|
92
|
+
forkId: this.forkId,
|
|
93
|
+
timestamp: this.globalVariables.timestamp,
|
|
94
|
+
};
|
|
95
|
+
let resultBuffer: Uint8Array;
|
|
96
|
+
try {
|
|
97
|
+
resultBuffer = await this.avmSimulator.simulate(inputBuffer, context, signal);
|
|
98
|
+
} catch (error: any) {
|
|
99
|
+
if (error.message?.includes('cancelled')) {
|
|
100
|
+
throw new SimulationError(`AVM simulation cancelled`, []);
|
|
101
|
+
}
|
|
102
|
+
throw new SimulationError(`AVM simulation failed: ${error.message}`, []);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
this.log.trace(`Deserializing simulation result from buffer (size: ${resultBuffer.length})...`);
|
|
106
|
+
const resultJSON: object = deserializeFromMessagePack(Buffer.from(resultBuffer));
|
|
107
|
+
const result = PublicTxResult.fromPlainObject(resultJSON);
|
|
108
|
+
|
|
109
|
+
this.log.trace(`AVM simulation completed for tx ${txHash}`, {
|
|
110
|
+
txHash,
|
|
111
|
+
reverted: !result.revertCode.isOK(),
|
|
112
|
+
l2GasUsed: result.gasUsed.totalGas.l2Gas,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Cancel the current simulation if one is in progress.
|
|
120
|
+
* This signals the underlying simulator to stop at the next safe point (between opcodes, before a
|
|
121
|
+
* world-state write). Safe to call even if no simulation is in progress.
|
|
122
|
+
*
|
|
123
|
+
* @param waitTimeoutMs - If provided, wait up to this many ms for the simulation to actually stop.
|
|
124
|
+
* Cancellation is cooperative: the simulator may be mid slow-operation and
|
|
125
|
+
* won't observe the cancellation until it completes.
|
|
126
|
+
* Default timeout of 100ms after cancellation.
|
|
127
|
+
*/
|
|
128
|
+
public async cancel(waitTimeoutMs: number = 100): Promise<void> {
|
|
129
|
+
if (this.abortController) {
|
|
130
|
+
this.log.debug('Cancelling AVM simulation');
|
|
131
|
+
this.abortController.abort();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (this.simulationPromise) {
|
|
135
|
+
this.log.debug(`Waiting up to ${waitTimeoutMs}ms for AVM simulation to stop`);
|
|
136
|
+
await Promise.race([
|
|
137
|
+
this.simulationPromise.catch(() => {}), // Ignore rejection, just wait for completion
|
|
138
|
+
sleep(waitTimeoutMs),
|
|
139
|
+
]);
|
|
140
|
+
this.log.debug('AVM simulation stopped or wait timed out');
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export class MeasuredPublicTxSimulator extends PublicTxSimulator implements MeasuredPublicTxSimulatorInterface {
|
|
146
|
+
constructor(
|
|
147
|
+
avmSimulator: AvmSimulator,
|
|
148
|
+
globalVariables: GlobalVariables,
|
|
149
|
+
contractsDB: PublicContractsDB,
|
|
150
|
+
forkId: number,
|
|
151
|
+
protected readonly metrics: ExecutorMetricsInterface,
|
|
152
|
+
config?: Partial<PublicSimulatorConfig>,
|
|
153
|
+
bindings?: LoggerBindings,
|
|
154
|
+
) {
|
|
155
|
+
super(avmSimulator, globalVariables, contractsDB, forkId, config, bindings);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
public override async simulate(tx: Tx, txLabel: string = 'unlabeledTx'): Promise<PublicTxResult> {
|
|
159
|
+
this.metrics.startRecordingTxSimulation(txLabel);
|
|
160
|
+
let result: PublicTxResult | undefined;
|
|
161
|
+
try {
|
|
162
|
+
result = await super.simulate(tx);
|
|
163
|
+
} finally {
|
|
164
|
+
this.metrics.stopRecordingTxSimulation(txLabel, result?.gasUsed, result?.revertCode, result?.stats);
|
|
165
|
+
}
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* A public tx simulator that tracks runtime/production metrics with telemetry.
|
|
172
|
+
*/
|
|
173
|
+
export class TelemetryPublicTxSimulator extends MeasuredPublicTxSimulator {
|
|
174
|
+
/* tracer needed by trackSpans */
|
|
175
|
+
public readonly tracer: Tracer;
|
|
176
|
+
|
|
177
|
+
constructor(
|
|
178
|
+
avmSimulator: AvmSimulator,
|
|
179
|
+
globalVariables: GlobalVariables,
|
|
180
|
+
contractsDB: PublicContractsDB,
|
|
181
|
+
forkId: number,
|
|
182
|
+
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
183
|
+
config?: Partial<PublicSimulatorConfig>,
|
|
184
|
+
bindings?: LoggerBindings,
|
|
185
|
+
) {
|
|
186
|
+
const metrics = new ExecutorMetrics(telemetryClient, 'PublicTxSimulator');
|
|
187
|
+
super(avmSimulator, globalVariables, contractsDB, forkId, metrics, config, bindings);
|
|
188
|
+
this.tracer = metrics.tracer;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec-labs/foundation/log';
|
|
2
|
+
import { ProtocolContractsList } from '@aztec-labs/protocol-contracts';
|
|
3
|
+
import { PublicSimulatorConfig } from '@aztec-labs/stdlib/avm';
|
|
4
|
+
import type { GlobalVariables, ProtocolContracts, Tx } from '@aztec-labs/stdlib/tx';
|
|
5
|
+
|
|
6
|
+
import type { AvmSimulator } from '../avm_simulator.js';
|
|
7
|
+
import type { PublicContractsDB } from '../public_db_sources.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Shared base for public tx simulators: holds the common configuration, the {@link AvmSimulator} used
|
|
11
|
+
* to run the transaction's public calls, the contracts DB and fork id that scope the simulation's
|
|
12
|
+
* contract-data lookups, the logger, and the tx-hash helper. Concrete simulators extend this and
|
|
13
|
+
* implement `simulate`.
|
|
14
|
+
*/
|
|
15
|
+
export abstract class PublicTxSimulatorBase {
|
|
16
|
+
protected log: Logger;
|
|
17
|
+
protected readonly config: PublicSimulatorConfig;
|
|
18
|
+
protected readonly bindings?: LoggerBindings;
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
protected avmSimulator: AvmSimulator,
|
|
22
|
+
protected globalVariables: GlobalVariables,
|
|
23
|
+
protected contractsDB: PublicContractsDB,
|
|
24
|
+
protected forkId: number,
|
|
25
|
+
config?: Partial<PublicSimulatorConfig>,
|
|
26
|
+
protected protocolContracts: ProtocolContracts = ProtocolContractsList,
|
|
27
|
+
bindings?: LoggerBindings,
|
|
28
|
+
) {
|
|
29
|
+
this.config = PublicSimulatorConfig.from(config ?? {});
|
|
30
|
+
this.bindings = bindings;
|
|
31
|
+
this.log = createLogger(`simulator:public_tx_simulator`, bindings);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
protected computeTxHash(tx: Tx) {
|
|
35
|
+
return tx.getTxHash();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { PublicTxResult } from '@aztec-labs/stdlib/avm';
|
|
2
|
+
import type { Tx } from '@aztec-labs/stdlib/tx';
|
|
3
|
+
|
|
4
|
+
export interface PublicTxSimulatorInterface {
|
|
5
|
+
simulate(tx: Tx): Promise<PublicTxResult>;
|
|
6
|
+
/**
|
|
7
|
+
* Cancel the current simulation if one is in progress.
|
|
8
|
+
* This signals the underlying simulator to stop at the next safe point.
|
|
9
|
+
* Safe to call even if no simulation is in progress.
|
|
10
|
+
* Optional - not all implementations support cancellation.
|
|
11
|
+
*
|
|
12
|
+
* @param waitTimeoutMs - If provided, wait up to this many ms for the simulation to actually stop.
|
|
13
|
+
* Cancellation is cooperative: signaling it only sets a flag the simulator
|
|
14
|
+
* checks at certain points, so if it's mid slow-operation it won't stop until
|
|
15
|
+
* that completes.
|
|
16
|
+
* @returns Promise that resolves when cancellation is signaled (and optionally when simulation stops)
|
|
17
|
+
*/
|
|
18
|
+
cancel?(waitTimeoutMs?: number): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface MeasuredPublicTxSimulatorInterface {
|
|
22
|
+
simulate(tx: Tx, txLabel: string): Promise<PublicTxResult>;
|
|
23
|
+
/**
|
|
24
|
+
* Cancel the current simulation if one is in progress.
|
|
25
|
+
* This signals the underlying simulator to stop at the next safe point.
|
|
26
|
+
* Safe to call even if no simulation is in progress.
|
|
27
|
+
* Optional - not all implementations support cancellation.
|
|
28
|
+
*
|
|
29
|
+
* @param waitTimeoutMs - If provided, wait up to this many ms for the simulation to actually stop.
|
|
30
|
+
* @returns Promise that resolves when cancellation is signaled (and optionally when simulation stops)
|
|
31
|
+
*/
|
|
32
|
+
cancel?(waitTimeoutMs?: number): Promise<void>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import {
|
|
2
|
+
L1_TO_L2_MSG_TREE_LEAF_COUNT,
|
|
3
|
+
MAX_L2_TO_L1_MSGS_PER_TX,
|
|
4
|
+
MAX_NOTE_HASHES_PER_TX,
|
|
5
|
+
MAX_NULLIFIERS_PER_TX,
|
|
6
|
+
MAX_PUBLIC_CALLS_TO_UNIQUE_CONTRACT_CLASS_IDS,
|
|
7
|
+
NOTE_HASH_TREE_LEAF_COUNT,
|
|
8
|
+
} from '@aztec-labs/constants';
|
|
9
|
+
|
|
10
|
+
import { CheckedPublicExecutionError } from './public_errors.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Any error that can be thrown during side effect insertion in public.
|
|
14
|
+
* Includes SideEffectLimitReachedError and NullifierCollisionError.
|
|
15
|
+
*/
|
|
16
|
+
export abstract class SideEffectError extends CheckedPublicExecutionError {
|
|
17
|
+
constructor(message: string) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.name = 'SideEffectInsertionError';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class SideEffectLimitReachedError extends SideEffectError {
|
|
24
|
+
constructor(sideEffectType: string, limit: number) {
|
|
25
|
+
super(`Reached the limit (${limit}) on number of '${sideEffectType}' per tx`);
|
|
26
|
+
this.name = 'SideEffectLimitReachedError';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class MaxCallsToUniqueContractClassIdsError extends SideEffectLimitReachedError {
|
|
31
|
+
constructor() {
|
|
32
|
+
super('contract calls to unique class IDs', MAX_PUBLIC_CALLS_TO_UNIQUE_CONTRACT_CLASS_IDS);
|
|
33
|
+
this.name = 'MaxCallsToUniqueContractClassIdsError';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class NullifierLimitReachedError extends SideEffectLimitReachedError {
|
|
38
|
+
constructor() {
|
|
39
|
+
super('nullifier', MAX_NULLIFIERS_PER_TX);
|
|
40
|
+
this.name = 'NullifierLimitReachedError';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class NoteHashLimitReachedError extends SideEffectLimitReachedError {
|
|
45
|
+
constructor() {
|
|
46
|
+
super('note hash', MAX_NOTE_HASHES_PER_TX);
|
|
47
|
+
this.name = 'NoteHashLimitReachedError';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export class L2ToL1MessageLimitReachedError extends SideEffectLimitReachedError {
|
|
52
|
+
constructor() {
|
|
53
|
+
super('l2 to l1 message', MAX_L2_TO_L1_MSGS_PER_TX);
|
|
54
|
+
this.name = 'L2ToL1MessageLimitReachedError';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export class NullifierCollisionError extends SideEffectError {
|
|
59
|
+
constructor(message: string) {
|
|
60
|
+
super(`Nullifier collision: ${message}`);
|
|
61
|
+
this.name = 'NullifierCollisionError';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Any error that can be thrown during side effect reads in public.
|
|
67
|
+
* Note: Thrown at state manager level and unknown by simulation, hence NOT considered
|
|
68
|
+
* CheckedPublicExecutionErrors. Currently only includes append-only tree reads.
|
|
69
|
+
*/
|
|
70
|
+
export abstract class SideEffectReadError extends Error {
|
|
71
|
+
constructor(message: string) {
|
|
72
|
+
super(message);
|
|
73
|
+
this.name = 'SideEffectReadError';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export class IndexOutOfRangeError extends SideEffectReadError {
|
|
78
|
+
constructor(tree: string, index: number, limit: number) {
|
|
79
|
+
super(`Attempting to read index ${index} of ${tree} tree with maximum ${limit} leaves`);
|
|
80
|
+
this.name = 'IndexOutOfRangeError';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export class NoteHashIndexOutOfRangeError extends IndexOutOfRangeError {
|
|
85
|
+
constructor(index: number) {
|
|
86
|
+
super('note hash', index, NOTE_HASH_TREE_LEAF_COUNT);
|
|
87
|
+
this.name = 'NoteHashIndexOutOfRangeError';
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export class L1ToL2MessageIndexOutOfRangeError extends IndexOutOfRangeError {
|
|
92
|
+
constructor(index: number) {
|
|
93
|
+
super('l1 to l2 message', index, L1_TO_L2_MSG_TREE_LEAF_COUNT);
|
|
94
|
+
this.name = 'L1ToL2MessageIndexOutOfRangeError';
|
|
95
|
+
}
|
|
96
|
+
}
|