@aztec/simulator 0.0.1-commit.fcb71a6 → 0.0.1-commit.fffb133c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dest/common/errors.d.ts +7 -1
- package/dest/common/errors.d.ts.map +1 -1
- package/dest/public/avm/avm_context.d.ts +3 -3
- package/dest/public/avm/avm_context.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.d.ts +6 -6
- package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.js +3 -3
- package/dest/public/avm/avm_execution_environment.d.ts +6 -5
- package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/public/avm/avm_machine_state.d.ts +6 -5
- package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/public/avm/avm_machine_state.js +3 -2
- package/dest/public/avm/avm_memory_types.d.ts +1 -1
- package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/public/avm/avm_memory_types.js +3 -0
- package/dest/public/avm/avm_simulator.d.ts +3 -2
- package/dest/public/avm/avm_simulator.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.js +5 -4
- package/dest/public/avm/calldata.d.ts +51 -0
- package/dest/public/avm/calldata.d.ts.map +1 -0
- package/dest/public/avm/calldata.js +63 -0
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.js +3 -2
- package/dest/public/avm/fixtures/initializers.d.ts +1 -1
- package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
- package/dest/public/avm/fixtures/initializers.js +2 -1
- package/dest/public/avm/opcodes/accrued_substate.d.ts +15 -15
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/accrued_substate.js +33 -29
- package/dest/public/avm/opcodes/arithmetic.d.ts +8 -8
- package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/public/avm/opcodes/arithmetic.js +1 -1
- package/dest/public/avm/opcodes/bitwise.d.ts +7 -7
- package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/public/avm/opcodes/bitwise.js +5 -5
- package/dest/public/avm/opcodes/comparators.d.ts +4 -4
- package/dest/public/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/public/avm/opcodes/comparators.js +1 -1
- package/dest/public/avm/opcodes/contract.d.ts +3 -3
- package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/public/avm/opcodes/contract.js +8 -8
- package/dest/public/avm/opcodes/control_flow.d.ts +3 -3
- package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
- package/dest/public/avm/opcodes/control_flow.js +4 -4
- package/dest/public/avm/opcodes/conversion.d.ts +3 -3
- package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/public/avm/opcodes/conversion.js +4 -4
- package/dest/public/avm/opcodes/ec_add.d.ts +4 -4
- package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/public/avm/opcodes/ec_add.js +15 -6
- package/dest/public/avm/opcodes/environment_getters.d.ts +5 -5
- package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/public/avm/opcodes/environment_getters.js +6 -6
- package/dest/public/avm/opcodes/external_calls.d.ts +9 -9
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.js +23 -22
- package/dest/public/avm/opcodes/hashing.d.ts +8 -8
- package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/public/avm/opcodes/hashing.js +12 -12
- package/dest/public/avm/opcodes/instruction_impl.d.ts +4 -4
- package/dest/public/avm/opcodes/instruction_impl.d.ts.map +1 -1
- package/dest/public/avm/opcodes/instruction_impl.js +4 -4
- package/dest/public/avm/opcodes/memory.d.ts +14 -14
- package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.js +25 -25
- package/dest/public/avm/opcodes/misc.d.ts +3 -3
- package/dest/public/avm/opcodes/misc.d.ts.map +1 -1
- package/dest/public/avm/opcodes/misc.js +4 -4
- package/dest/public/avm/opcodes/storage.d.ts +16 -15
- package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/public/avm/opcodes/storage.js +34 -24
- package/dest/public/debug_fn_name.d.ts +4 -4
- package/dest/public/debug_fn_name.d.ts.map +1 -1
- package/dest/public/debug_fn_name.js +7 -5
- package/dest/public/executor_metrics.d.ts +1 -1
- package/dest/public/executor_metrics.d.ts.map +1 -1
- package/dest/public/executor_metrics.js +8 -34
- package/dest/public/fixtures/bulk_test.d.ts +3 -3
- package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
- package/dest/public/fixtures/bulk_test.js +1 -17
- package/dest/public/fixtures/custom_bytecode_tests.d.ts +11 -11
- package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
- package/dest/public/fixtures/custom_bytecode_tests.js +18 -18
- package/dest/public/fixtures/minimal_public_tx.js +2 -2
- package/dest/public/fixtures/opcode_spammer.d.ts +1 -1
- package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -1
- package/dest/public/fixtures/opcode_spammer.js +92 -80
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +21 -7
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -1
- package/dest/public/fuzzing/avm_fuzzer_simulator.js +42 -10
- package/dest/public/fuzzing/avm_simulator_bin.js +29 -11
- package/dest/public/hinting_db_sources.js +3 -1
- package/dest/public/public_processor/guarded_merkle_tree.js +3 -1
- package/dest/public/public_processor/public_processor.d.ts +2 -2
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +402 -21
- package/dest/public/public_processor/public_processor_metrics.d.ts +1 -1
- package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor_metrics.js +12 -45
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +1 -1
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +2 -1
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +4 -3
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +9 -6
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +395 -19
- package/dest/public/side_effect_trace.d.ts +2 -1
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.d.ts +1 -1
- package/dest/public/state_manager/state_manager.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.js +2 -2
- package/package.json +17 -17
- package/src/public/avm/avm_context.ts +2 -2
- package/src/public/avm/avm_contract_call_result.ts +8 -6
- package/src/public/avm/avm_execution_environment.ts +9 -4
- package/src/public/avm/avm_machine_state.ts +6 -5
- package/src/public/avm/avm_memory_types.ts +4 -0
- package/src/public/avm/avm_simulator.ts +8 -5
- package/src/public/avm/calldata.ts +100 -0
- package/src/public/avm/fixtures/avm_simulation_tester.ts +8 -2
- package/src/public/avm/fixtures/initializers.ts +2 -1
- package/src/public/avm/opcodes/accrued_substate.ts +21 -15
- package/src/public/avm/opcodes/arithmetic.ts +1 -1
- package/src/public/avm/opcodes/bitwise.ts +3 -3
- package/src/public/avm/opcodes/comparators.ts +1 -1
- package/src/public/avm/opcodes/contract.ts +4 -7
- package/src/public/avm/opcodes/control_flow.ts +2 -2
- package/src/public/avm/opcodes/conversion.ts +3 -3
- package/src/public/avm/opcodes/ec_add.ts +13 -4
- package/src/public/avm/opcodes/environment_getters.ts +7 -7
- package/src/public/avm/opcodes/external_calls.ts +17 -15
- package/src/public/avm/opcodes/hashing.ts +6 -6
- package/src/public/avm/opcodes/instruction_impl.ts +2 -2
- package/src/public/avm/opcodes/memory.ts +19 -19
- package/src/public/avm/opcodes/misc.ts +2 -2
- package/src/public/avm/opcodes/storage.ts +30 -22
- package/src/public/debug_fn_name.ts +10 -8
- package/src/public/executor_metrics.ts +7 -34
- package/src/public/fixtures/bulk_test.ts +2 -2
- package/src/public/fixtures/custom_bytecode_tests.ts +27 -18
- package/src/public/fixtures/minimal_public_tx.ts +2 -2
- package/src/public/fixtures/opcode_spammer.ts +197 -81
- package/src/public/fuzzing/avm_fuzzer_simulator.ts +60 -12
- package/src/public/fuzzing/avm_simulator_bin.ts +43 -8
- package/src/public/public_processor/public_processor.ts +3 -2
- package/src/public/public_processor/public_processor_metrics.ts +11 -45
- package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +9 -1
- package/src/public/public_tx_simulator/public_tx_simulator.ts +12 -5
- package/src/public/state_manager/state_manager.ts +2 -16
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
MAX_NOTE_HASHES_PER_TX,
|
|
5
5
|
MAX_NULLIFIERS_PER_TX,
|
|
6
6
|
MAX_PRIVATE_LOGS_PER_TX,
|
|
7
|
+
MAX_PROTOCOL_CONTRACTS,
|
|
7
8
|
} from '@aztec/constants';
|
|
8
9
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
9
10
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
@@ -19,8 +20,17 @@ import {
|
|
|
19
20
|
import { PrivateLog } from '@aztec/stdlib/logs';
|
|
20
21
|
import { ScopedL2ToL1Message } from '@aztec/stdlib/messaging';
|
|
21
22
|
import { ChonkProof } from '@aztec/stdlib/proofs';
|
|
22
|
-
import type
|
|
23
|
-
import {
|
|
23
|
+
import { MerkleTreeId, type MerkleTreeWriteOperations, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
24
|
+
import {
|
|
25
|
+
BlockHeader,
|
|
26
|
+
GlobalVariables,
|
|
27
|
+
HashedValues,
|
|
28
|
+
ProtocolContracts,
|
|
29
|
+
Tx,
|
|
30
|
+
TxConstantData,
|
|
31
|
+
TxContext,
|
|
32
|
+
TxHash,
|
|
33
|
+
} from '@aztec/stdlib/tx';
|
|
24
34
|
import type { NativeWorldStateService } from '@aztec/world-state';
|
|
25
35
|
|
|
26
36
|
import { BaseAvmSimulationTester } from '../avm/fixtures/base_avm_simulation_tester.js';
|
|
@@ -40,6 +50,9 @@ export class FuzzerSimulationRequest {
|
|
|
40
50
|
public readonly globals: GlobalVariables,
|
|
41
51
|
public readonly contractClasses: any[], // Raw, processed by addContractClassFromCpp
|
|
42
52
|
public readonly contractInstances: [any, any][], // Raw pairs [address, instance]
|
|
53
|
+
public readonly publicDataWrites: any[], // Raw public data tree writes to apply before simulation
|
|
54
|
+
public readonly noteHashes: any[], // Raw note hashes to apply before simulation
|
|
55
|
+
public readonly protocolContracts: ProtocolContracts, // Protocol contracts mapping from C++
|
|
43
56
|
) {}
|
|
44
57
|
|
|
45
58
|
static fromPlainObject(obj: any): FuzzerSimulationRequest {
|
|
@@ -53,6 +66,9 @@ export class FuzzerSimulationRequest {
|
|
|
53
66
|
GlobalVariables.fromPlainObject(obj.globals),
|
|
54
67
|
obj.contractClasses,
|
|
55
68
|
obj.contractInstances,
|
|
69
|
+
obj.publicDataWrites ?? [],
|
|
70
|
+
obj.noteHashes ?? [],
|
|
71
|
+
ProtocolContracts.fromPlainObject(obj.protocolContracts),
|
|
56
72
|
);
|
|
57
73
|
}
|
|
58
74
|
}
|
|
@@ -181,16 +197,23 @@ export class AvmFuzzerSimulator extends BaseAvmSimulationTester {
|
|
|
181
197
|
merkleTrees: MerkleTreeWriteOperations,
|
|
182
198
|
contractDataSource: SimpleContractDataSource,
|
|
183
199
|
globals: GlobalVariables,
|
|
200
|
+
protocolContracts: ProtocolContracts,
|
|
184
201
|
) {
|
|
185
202
|
super(contractDataSource, merkleTrees);
|
|
186
203
|
const contractsDb = new PublicContractsDB(contractDataSource);
|
|
187
|
-
this.simulator = new PublicTxSimulator(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
204
|
+
this.simulator = new PublicTxSimulator(
|
|
205
|
+
merkleTrees,
|
|
206
|
+
contractsDb,
|
|
207
|
+
globals,
|
|
208
|
+
{
|
|
209
|
+
skipFeeEnforcement: false,
|
|
210
|
+
collectDebugLogs: false,
|
|
211
|
+
collectHints: false,
|
|
212
|
+
collectStatistics: false,
|
|
213
|
+
collectCallMetadata: false,
|
|
214
|
+
},
|
|
215
|
+
protocolContracts,
|
|
216
|
+
);
|
|
194
217
|
}
|
|
195
218
|
|
|
196
219
|
/**
|
|
@@ -199,10 +222,11 @@ export class AvmFuzzerSimulator extends BaseAvmSimulationTester {
|
|
|
199
222
|
public static async create(
|
|
200
223
|
worldStateService: NativeWorldStateService,
|
|
201
224
|
globals: GlobalVariables,
|
|
225
|
+
protocolContracts: ProtocolContracts,
|
|
202
226
|
): Promise<AvmFuzzerSimulator> {
|
|
203
227
|
const contractDataSource = new SimpleContractDataSource();
|
|
204
228
|
const merkleTrees = await worldStateService.fork();
|
|
205
|
-
return new AvmFuzzerSimulator(merkleTrees, contractDataSource, globals);
|
|
229
|
+
return new AvmFuzzerSimulator(merkleTrees, contractDataSource, globals, protocolContracts);
|
|
206
230
|
}
|
|
207
231
|
|
|
208
232
|
/**
|
|
@@ -230,11 +254,35 @@ export class AvmFuzzerSimulator extends BaseAvmSimulationTester {
|
|
|
230
254
|
|
|
231
255
|
/**
|
|
232
256
|
* Add a contract instance from C++ raw msgpack data.
|
|
233
|
-
* This also inserts the contract address nullifier into the nullifier tree
|
|
257
|
+
* This also inserts the contract address nullifier into the nullifier tree,
|
|
258
|
+
* unless the address is a protocol canonical address (1-11).
|
|
234
259
|
*/
|
|
235
260
|
public async addContractInstanceFromCpp(rawAddress: any, rawInstance: any): Promise<void> {
|
|
236
261
|
const address = AztecAddress.fromPlainObject(rawAddress);
|
|
237
262
|
const instance = contractInstanceWithAddressFromPlainObject(address, rawInstance);
|
|
238
|
-
|
|
263
|
+
// Protocol canonical addresses (1-11) should not have nullifiers inserted
|
|
264
|
+
const isProtocolCanonicalAddress = address.toBigInt() <= MAX_PROTOCOL_CONTRACTS && address.toBigInt() >= 1n;
|
|
265
|
+
await this.addContractInstance(instance, /* skipNullifierInsertion */ isProtocolCanonicalAddress);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Apply public data tree writes from C++ raw msgpack data.
|
|
270
|
+
* This is used to pre-populate the public data tree before simulation (e.g., for bytecode upgrades).
|
|
271
|
+
*/
|
|
272
|
+
public async applyPublicDataWrites(rawWrites: any[]): Promise<void> {
|
|
273
|
+
for (const rawWrite of rawWrites) {
|
|
274
|
+
const leaf = PublicDataTreeLeaf.fromPlainObject(rawWrite);
|
|
275
|
+
await this.merkleTrees.sequentialInsert(MerkleTreeId.PUBLIC_DATA_TREE, [leaf.toBuffer()]);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Apply note hashes from C++ raw msgpack data.
|
|
281
|
+
* This is used to pre-populate the note hash tree before simulation.
|
|
282
|
+
*/
|
|
283
|
+
public async applyNoteHashes(rawNoteHashes: any[]): Promise<void> {
|
|
284
|
+
const paddingLeaves = MAX_NOTE_HASHES_PER_TX - (rawNoteHashes.length % MAX_NOTE_HASHES_PER_TX);
|
|
285
|
+
const paddedNoteHashes = [...rawNoteHashes, ...Array(paddingLeaves).fill(Fr.ZERO)];
|
|
286
|
+
await this.merkleTrees.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, paddedNoteHashes);
|
|
239
287
|
}
|
|
240
288
|
}
|
|
@@ -3,17 +3,30 @@ import { EthAddress } from '@aztec/foundation/eth-address';
|
|
|
3
3
|
import {
|
|
4
4
|
AvmCircuitPublicInputs,
|
|
5
5
|
type AvmTxHint,
|
|
6
|
+
PublicTxEffect,
|
|
6
7
|
deserializeFromMessagePack,
|
|
7
8
|
serializeWithMessagePack,
|
|
8
9
|
} from '@aztec/stdlib/avm';
|
|
9
|
-
import { GlobalVariables, TreeSnapshots } from '@aztec/stdlib/tx';
|
|
10
|
+
import { GlobalVariables, ProtocolContracts, TreeSnapshots } from '@aztec/stdlib/tx';
|
|
10
11
|
import { NativeWorldStateService } from '@aztec/world-state';
|
|
11
12
|
|
|
12
|
-
import { writeSync } from 'fs';
|
|
13
13
|
import { createInterface } from 'readline';
|
|
14
14
|
|
|
15
15
|
import { AvmFuzzerSimulator, FuzzerSimulationRequest } from './avm_fuzzer_simulator.js';
|
|
16
16
|
|
|
17
|
+
/** Write data to stdout, letting Node handle buffering. */
|
|
18
|
+
function writeOutput(data: string): Promise<void> {
|
|
19
|
+
return new Promise<void>((resolve, reject) => {
|
|
20
|
+
process.stdout.write(data, err => {
|
|
21
|
+
if (err) {
|
|
22
|
+
reject(err);
|
|
23
|
+
} else {
|
|
24
|
+
resolve();
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
17
30
|
// This cache holds opened world states to avoid reopening them for each invocation.
|
|
18
31
|
// It's a map so that in the future we could support multiple world states (if we had multiple fuzzers).
|
|
19
32
|
const worldStateCache = new Map<string, NativeWorldStateService>();
|
|
@@ -43,12 +56,23 @@ async function simulateWithFuzzer(
|
|
|
43
56
|
globals: GlobalVariables,
|
|
44
57
|
rawContractClasses: any[], // Replace these when we are moving contract classes to TS
|
|
45
58
|
rawContractInstances: [any, any][], // Replace these when we are moving contract instances to TS
|
|
46
|
-
|
|
59
|
+
rawPublicDataWrites: any[], // Public data tree writes to apply before simulation
|
|
60
|
+
rawNoteHashes: any[], // Note hashes to apply before simulation
|
|
61
|
+
protocolContracts: ProtocolContracts, // Protocol contracts mapping from C++
|
|
62
|
+
): Promise<{
|
|
63
|
+
reverted: boolean;
|
|
64
|
+
output: Fr[];
|
|
65
|
+
revertReason?: string;
|
|
66
|
+
publicInputs: AvmCircuitPublicInputs;
|
|
67
|
+
publicTxEffect: PublicTxEffect;
|
|
68
|
+
}> {
|
|
47
69
|
const worldStateService = await openExistingWorldState(dataDir, mapSizeKb);
|
|
48
70
|
|
|
49
|
-
const simulator = await AvmFuzzerSimulator.create(worldStateService, globals);
|
|
71
|
+
const simulator = await AvmFuzzerSimulator.create(worldStateService, globals, protocolContracts);
|
|
72
|
+
|
|
73
|
+
await simulator.applyNoteHashes(rawNoteHashes);
|
|
50
74
|
|
|
51
|
-
// Register contract classes from C++
|
|
75
|
+
// Register contract classes from C++ (must happen before public data writes to match C++ order)
|
|
52
76
|
for (const rawClass of rawContractClasses) {
|
|
53
77
|
await simulator.addContractClassFromCpp(rawClass);
|
|
54
78
|
}
|
|
@@ -58,6 +82,10 @@ async function simulateWithFuzzer(
|
|
|
58
82
|
await simulator.addContractInstanceFromCpp(rawAddress, rawInstance);
|
|
59
83
|
}
|
|
60
84
|
|
|
85
|
+
// Apply public data writes after contract registration (e.g., for bytecode upgrades)
|
|
86
|
+
// This must happen last to match C++ setup_fuzzer_state ordering
|
|
87
|
+
await simulator.applyPublicDataWrites(rawPublicDataWrites);
|
|
88
|
+
|
|
61
89
|
const result = await simulator.simulate(txHint);
|
|
62
90
|
|
|
63
91
|
const output = result
|
|
@@ -69,6 +97,7 @@ async function simulateWithFuzzer(
|
|
|
69
97
|
output,
|
|
70
98
|
revertReason: result.findRevertReason()?.message,
|
|
71
99
|
publicInputs: result.publicInputs!,
|
|
100
|
+
publicTxEffect: result.publicTxEffect,
|
|
72
101
|
};
|
|
73
102
|
}
|
|
74
103
|
|
|
@@ -87,6 +116,9 @@ async function execute(base64Line: string): Promise<void> {
|
|
|
87
116
|
request.globals,
|
|
88
117
|
request.contractClasses,
|
|
89
118
|
request.contractInstances,
|
|
119
|
+
request.publicDataWrites,
|
|
120
|
+
request.noteHashes,
|
|
121
|
+
request.protocolContracts,
|
|
90
122
|
);
|
|
91
123
|
|
|
92
124
|
// Serialize the result to msgpack and encode it in base64 for output
|
|
@@ -95,17 +127,20 @@ async function execute(base64Line: string): Promise<void> {
|
|
|
95
127
|
output: result.output,
|
|
96
128
|
revertReason: result.revertReason ?? '',
|
|
97
129
|
endTreeSnapshots: result.publicInputs.endTreeSnapshots,
|
|
130
|
+
publicTxEffect: result.publicTxEffect,
|
|
98
131
|
});
|
|
99
|
-
|
|
132
|
+
const base64Response = resultBuffer.toString('base64') + '\n';
|
|
133
|
+
await writeOutput(base64Response);
|
|
100
134
|
} catch (error: any) {
|
|
101
135
|
// If we error, treat as reverted
|
|
102
136
|
const errorResult = serializeWithMessagePack({
|
|
103
137
|
reverted: true,
|
|
104
|
-
output: [] as
|
|
138
|
+
output: [] as Fr[],
|
|
105
139
|
revertReason: `Unexpected Error ${error.message}`,
|
|
106
140
|
endTreeSnapshots: TreeSnapshots.empty(),
|
|
141
|
+
publicTxEffect: PublicTxEffect.empty(),
|
|
107
142
|
});
|
|
108
|
-
|
|
143
|
+
await writeOutput(errorResult.toString('base64') + '\n');
|
|
109
144
|
}
|
|
110
145
|
}
|
|
111
146
|
|
|
@@ -146,7 +146,7 @@ export class PublicProcessor implements Traceable {
|
|
|
146
146
|
txs: Iterable<Tx> | AsyncIterable<Tx>,
|
|
147
147
|
limits: PublicProcessorLimits = {},
|
|
148
148
|
validator: PublicProcessorValidator = {},
|
|
149
|
-
): Promise<[ProcessedTx[], FailedTx[], Tx[], NestedProcessReturnValues[]]> {
|
|
149
|
+
): Promise<[ProcessedTx[], FailedTx[], Tx[], NestedProcessReturnValues[], number]> {
|
|
150
150
|
const { maxTransactions, maxBlockSize, deadline, maxBlockGas, maxBlobFields } = limits;
|
|
151
151
|
const { preprocessValidator, nullifierCache } = validator;
|
|
152
152
|
const result: ProcessedTx[] = [];
|
|
@@ -254,6 +254,7 @@ export class PublicProcessor implements Traceable {
|
|
|
254
254
|
}
|
|
255
255
|
|
|
256
256
|
// If the actual blob fields of this tx would exceed the limit, skip it
|
|
257
|
+
// Note: maxBlobFields already accounts for block end blob fields and previous blocks in checkpoint.
|
|
257
258
|
if (maxBlobFields !== undefined && totalBlobFields + txBlobFields > maxBlobFields) {
|
|
258
259
|
this.log.debug(
|
|
259
260
|
`Skipping processed tx ${txHash} with ${txBlobFields} blob fields due to max blob fields limit.`,
|
|
@@ -349,7 +350,7 @@ export class PublicProcessor implements Traceable {
|
|
|
349
350
|
totalSizeInBytes,
|
|
350
351
|
});
|
|
351
352
|
|
|
352
|
-
return [result, failed, usedTxs, returns];
|
|
353
|
+
return [result, failed, usedTxs, returns, totalBlobFields];
|
|
353
354
|
}
|
|
354
355
|
|
|
355
356
|
private async checkWorldStateUnchanged(
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
type TelemetryClient,
|
|
10
10
|
type Tracer,
|
|
11
11
|
type UpDownCounter,
|
|
12
|
-
ValueType,
|
|
13
12
|
} from '@aztec/telemetry-client';
|
|
14
13
|
|
|
15
14
|
export class PublicProcessorMetrics {
|
|
@@ -34,60 +33,27 @@ export class PublicProcessorMetrics {
|
|
|
34
33
|
this.tracer = client.getTracer(name);
|
|
35
34
|
const meter = client.getMeter(name);
|
|
36
35
|
|
|
37
|
-
this.txDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TX_DURATION
|
|
38
|
-
description: 'How long it takes to process a transaction',
|
|
39
|
-
unit: 'ms',
|
|
40
|
-
valueType: ValueType.INT,
|
|
41
|
-
});
|
|
36
|
+
this.txDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TX_DURATION);
|
|
42
37
|
|
|
43
|
-
this.txCount = meter.createUpDownCounter(Metrics.PUBLIC_PROCESSOR_TX_COUNT
|
|
44
|
-
description: 'Number of transactions processed',
|
|
45
|
-
});
|
|
38
|
+
this.txCount = meter.createUpDownCounter(Metrics.PUBLIC_PROCESSOR_TX_COUNT);
|
|
46
39
|
|
|
47
|
-
this.txPhaseCount = meter.createUpDownCounter(Metrics.PUBLIC_PROCESSOR_TX_PHASE_COUNT
|
|
48
|
-
description: 'Number of phases processed',
|
|
49
|
-
});
|
|
40
|
+
this.txPhaseCount = meter.createUpDownCounter(Metrics.PUBLIC_PROCESSOR_TX_PHASE_COUNT);
|
|
50
41
|
|
|
51
|
-
this.phaseDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_PHASE_DURATION
|
|
52
|
-
description: 'How long it takes to process a phase',
|
|
53
|
-
unit: 'ms',
|
|
54
|
-
valueType: ValueType.INT,
|
|
55
|
-
});
|
|
42
|
+
this.phaseDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_PHASE_DURATION);
|
|
56
43
|
|
|
57
|
-
this.phaseCount = meter.createUpDownCounter(Metrics.PUBLIC_PROCESSOR_PHASE_COUNT
|
|
58
|
-
description: 'Number of failed phases',
|
|
59
|
-
});
|
|
44
|
+
this.phaseCount = meter.createUpDownCounter(Metrics.PUBLIC_PROCESSOR_PHASE_COUNT);
|
|
60
45
|
|
|
61
|
-
this.bytecodeDeployed = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_DEPLOY_BYTECODE_SIZE
|
|
62
|
-
description: 'Size of deployed bytecode',
|
|
63
|
-
unit: 'By',
|
|
64
|
-
});
|
|
46
|
+
this.bytecodeDeployed = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_DEPLOY_BYTECODE_SIZE);
|
|
65
47
|
|
|
66
|
-
this.totalGas = meter.createGauge(Metrics.PUBLIC_PROCESSOR_TOTAL_GAS
|
|
67
|
-
description: 'Total gas used in block',
|
|
68
|
-
unit: 'gas',
|
|
69
|
-
});
|
|
48
|
+
this.totalGas = meter.createGauge(Metrics.PUBLIC_PROCESSOR_TOTAL_GAS);
|
|
70
49
|
|
|
71
|
-
this.totalGasHistogram = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TOTAL_GAS_HISTOGRAM
|
|
72
|
-
description: 'Total gas used in block as histogram',
|
|
73
|
-
unit: 'gas/block',
|
|
74
|
-
});
|
|
50
|
+
this.totalGasHistogram = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TOTAL_GAS_HISTOGRAM);
|
|
75
51
|
|
|
76
|
-
this.txGas = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TX_GAS
|
|
77
|
-
description: 'Gas used in transaction',
|
|
78
|
-
unit: 'gas/tx',
|
|
79
|
-
});
|
|
52
|
+
this.txGas = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TX_GAS);
|
|
80
53
|
|
|
81
|
-
this.gasRate = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_GAS_RATE
|
|
82
|
-
description: 'L2 gas per second for complete block',
|
|
83
|
-
unit: 'gas/s',
|
|
84
|
-
});
|
|
54
|
+
this.gasRate = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_GAS_RATE);
|
|
85
55
|
|
|
86
|
-
this.treeInsertionDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TREE_INSERTION
|
|
87
|
-
description: 'How long it takes for tree insertion',
|
|
88
|
-
unit: 'us',
|
|
89
|
-
valueType: ValueType.INT,
|
|
90
|
-
});
|
|
56
|
+
this.treeInsertionDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TREE_INSERTION);
|
|
91
57
|
}
|
|
92
58
|
|
|
93
59
|
recordPhaseDuration(phaseName: TxExecutionPhase, durationMs: number) {
|
|
@@ -95,7 +95,15 @@ export class CppPublicTxSimulator extends PublicTxSimulator implements PublicTxS
|
|
|
95
95
|
|
|
96
96
|
// Store the promise so cancel() can wait for it
|
|
97
97
|
this.log.debug(`Calling C++ simulator for tx ${txHash}`);
|
|
98
|
-
this.simulationPromise = avmSimulate(
|
|
98
|
+
this.simulationPromise = avmSimulate(
|
|
99
|
+
inputBuffer,
|
|
100
|
+
contractProvider,
|
|
101
|
+
wsCppHandle,
|
|
102
|
+
logLevel,
|
|
103
|
+
// TODO: re-enable logging
|
|
104
|
+
undefined,
|
|
105
|
+
this.cancellationToken,
|
|
106
|
+
);
|
|
99
107
|
|
|
100
108
|
let resultBuffer: Buffer;
|
|
101
109
|
try {
|
|
@@ -10,6 +10,7 @@ import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
|
10
10
|
import {
|
|
11
11
|
type GlobalVariables,
|
|
12
12
|
NestedProcessReturnValues,
|
|
13
|
+
ProtocolContracts,
|
|
13
14
|
PublicCallRequestWithCalldata,
|
|
14
15
|
Tx,
|
|
15
16
|
TxExecutionPhase,
|
|
@@ -18,6 +19,7 @@ import {
|
|
|
18
19
|
import { strict as assert } from 'assert';
|
|
19
20
|
|
|
20
21
|
import type { AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
|
|
22
|
+
import { CallDataArray } from '../avm/calldata.js';
|
|
21
23
|
import { AvmSimulator } from '../avm/index.js';
|
|
22
24
|
import { getPublicFunctionDebugName } from '../debug_fn_name.js';
|
|
23
25
|
import { HintingMerkleWriteOperations, HintingPublicContractsDB } from '../hinting_db_sources.js';
|
|
@@ -85,6 +87,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
85
87
|
protected contractsDB: PublicContractsDB,
|
|
86
88
|
protected globalVariables: GlobalVariables,
|
|
87
89
|
config?: Partial<PublicSimulatorConfig>,
|
|
90
|
+
protected protocolContracts: ProtocolContracts = ProtocolContractsList,
|
|
88
91
|
) {
|
|
89
92
|
this.config = PublicSimulatorConfig.from(config ?? {});
|
|
90
93
|
this.log = createLogger(`simulator:public_tx_simulator`);
|
|
@@ -103,7 +106,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
103
106
|
const hints = new AvmExecutionHints(
|
|
104
107
|
this.globalVariables,
|
|
105
108
|
AvmTxHint.fromTx(tx, this.globalVariables.gasFees),
|
|
106
|
-
|
|
109
|
+
this.protocolContracts,
|
|
107
110
|
);
|
|
108
111
|
const hintingMerkleTree = await HintingMerkleWriteOperations.create(this.merkleTree, hints);
|
|
109
112
|
const hintingTreesDB = new PublicTreesDB(hintingMerkleTree);
|
|
@@ -114,7 +117,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
114
117
|
hintingContractsDB,
|
|
115
118
|
tx,
|
|
116
119
|
this.globalVariables,
|
|
117
|
-
|
|
120
|
+
this.protocolContracts,
|
|
118
121
|
this.config.proverId,
|
|
119
122
|
);
|
|
120
123
|
|
|
@@ -265,7 +268,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
265
268
|
|
|
266
269
|
const enqueuedCallResult = await this.simulateEnqueuedCall(phase, context, callRequest);
|
|
267
270
|
|
|
268
|
-
returnValues.push(new NestedProcessReturnValues(enqueuedCallResult.output));
|
|
271
|
+
returnValues.push(new NestedProcessReturnValues(enqueuedCallResult.output.bestEffortReadAll()));
|
|
269
272
|
|
|
270
273
|
if (enqueuedCallResult.reverted) {
|
|
271
274
|
reverted = true;
|
|
@@ -295,7 +298,11 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
295
298
|
): Promise<AvmFinalizedCallResult> {
|
|
296
299
|
const stateManager = context.state.getActiveStateManager();
|
|
297
300
|
const contractAddress = callRequest.request.contractAddress;
|
|
298
|
-
const fnName = await getPublicFunctionDebugName(
|
|
301
|
+
const fnName = await getPublicFunctionDebugName(
|
|
302
|
+
this.contractsDB,
|
|
303
|
+
contractAddress,
|
|
304
|
+
new CallDataArray(callRequest.calldata),
|
|
305
|
+
);
|
|
299
306
|
|
|
300
307
|
const allocatedGas = context.getGasLeftAtPhase(phase);
|
|
301
308
|
|
|
@@ -355,7 +362,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
355
362
|
transactionFee,
|
|
356
363
|
this.globalVariables,
|
|
357
364
|
request.isStaticCall,
|
|
358
|
-
calldata,
|
|
365
|
+
new CallDataArray(calldata),
|
|
359
366
|
allocatedGas,
|
|
360
367
|
this.config,
|
|
361
368
|
);
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CANONICAL_AUTH_REGISTRY_ADDRESS,
|
|
3
|
-
CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS,
|
|
4
|
-
CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS,
|
|
5
|
-
FEE_JUICE_ADDRESS,
|
|
6
|
-
MULTI_CALL_ENTRYPOINT_ADDRESS,
|
|
7
|
-
ROUTER_ADDRESS,
|
|
8
|
-
} from '@aztec/constants';
|
|
1
|
+
import { CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS, MAX_PROTOCOL_CONTRACTS } from '@aztec/constants';
|
|
9
2
|
import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
|
|
10
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
11
4
|
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
@@ -549,12 +542,5 @@ export class PublicPersistableStateManager {
|
|
|
549
542
|
}
|
|
550
543
|
|
|
551
544
|
function contractAddressIsCanonical(contractAddress: AztecAddress): boolean {
|
|
552
|
-
return (
|
|
553
|
-
contractAddress.equals(AztecAddress.fromNumber(CANONICAL_AUTH_REGISTRY_ADDRESS)) ||
|
|
554
|
-
contractAddress.equals(AztecAddress.fromNumber(CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS)) ||
|
|
555
|
-
contractAddress.equals(AztecAddress.fromNumber(CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS)) ||
|
|
556
|
-
contractAddress.equals(AztecAddress.fromNumber(MULTI_CALL_ENTRYPOINT_ADDRESS)) ||
|
|
557
|
-
contractAddress.equals(AztecAddress.fromNumber(FEE_JUICE_ADDRESS)) ||
|
|
558
|
-
contractAddress.equals(AztecAddress.fromNumber(ROUTER_ADDRESS))
|
|
559
|
-
);
|
|
545
|
+
return contractAddress.toBigInt() >= 1 && contractAddress.toBigInt() <= MAX_PROTOCOL_CONTRACTS;
|
|
560
546
|
}
|