@aztec/simulator 0.0.1-commit.0c875d939 → 0.0.1-commit.0ec55a70b
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/private/circuit_recording/circuit_recorder.js +2 -2
- 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/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/fixtures/amm_test.js +2 -2
- 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 +4 -4
- package/dest/public/fixtures/custom_bytecode_tests.d.ts +3 -1
- package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
- package/dest/public/fixtures/custom_bytecode_tests.js +61 -1
- 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 +37 -10
- 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 +10 -10
- 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 +7 -6
- package/dest/public/public_db_sources.d.ts +3 -3
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +10 -10
- 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 +5 -3
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +68 -46
- package/dest/public/public_processor/public_processor_metrics.d.ts +4 -1
- package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor_metrics.js +8 -0
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +1 -1
- 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 +2 -1
- 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 -3
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +1 -1
- 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 +2 -2
- package/dest/public/public_tx_simulator/factories.d.ts +2 -2
- package/dest/public/public_tx_simulator/factories.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/factories.js +2 -2
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +7 -3
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +8 -10
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +6 -2
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +14 -9
- package/dest/public/test_executor_metrics.d.ts +6 -1
- package/dest/public/test_executor_metrics.d.ts.map +1 -1
- package/dest/public/test_executor_metrics.js +22 -0
- package/package.json +15 -16
- package/src/private/circuit_recording/circuit_recorder.ts +2 -2
- package/src/public/avm/avm_simulator.ts +1 -1
- package/src/public/avm/calldata.ts +3 -2
- package/src/public/avm/opcodes/external_calls.ts +1 -1
- package/src/public/contracts_db_checkpoint.ts +1 -1
- package/src/public/fixtures/amm_test.ts +2 -2
- package/src/public/fixtures/bulk_test.ts +2 -4
- package/src/public/fixtures/custom_bytecode_tests.ts +139 -1
- package/src/public/fixtures/public_tx_simulation_tester.ts +47 -6
- package/src/public/fixtures/utils.ts +17 -12
- package/src/public/fuzzing/avm_fuzzer_simulator.ts +1 -1
- package/src/public/hinting_db_sources.ts +9 -7
- package/src/public/public_db_sources.ts +12 -14
- package/src/public/public_processor/guarded_merkle_tree.ts +6 -6
- package/src/public/public_processor/public_processor.ts +94 -62
- package/src/public/public_processor/public_processor_metrics.ts +12 -0
- package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +2 -1
- package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +2 -3
- package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +2 -2
- package/src/public/public_tx_simulator/factories.ts +2 -1
- package/src/public/public_tx_simulator/public_tx_context.ts +8 -10
- package/src/public/public_tx_simulator/public_tx_simulator.ts +14 -10
- package/src/public/test_executor_metrics.ts +24 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public_tx_simulator.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/public_tx_simulator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,cAAc,EAAgB,MAAM,uBAAuB,CAAC;AAGvF,OAAO,EAAgC,qBAAqB,EAAkB,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxH,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EACL,KAAK,eAAe,EACpB,yBAAyB,EACzB,iBAAiB,EACjB,6BAA6B,EAC7B,EAAE,EACF,gBAAgB,EACjB,MAAM,kBAAkB,CAAC;AAI1B,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAKjF,OAAO,EAAE,KAAK,iBAAiB,EAAiB,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"public_tx_simulator.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/public_tx_simulator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,cAAc,EAAgB,MAAM,uBAAuB,CAAC;AAGvF,OAAO,EAAgC,qBAAqB,EAAkB,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxH,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EACL,KAAK,eAAe,EACpB,yBAAyB,EACzB,iBAAiB,EACjB,6BAA6B,EAC7B,EAAE,EACF,gBAAgB,EACjB,MAAM,kBAAkB,CAAC;AAI1B,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAKjF,OAAO,EAAE,KAAK,iBAAiB,EAAiB,MAAM,yBAAyB,CAAC;AAMhF,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAqCrF,4BAA4B;AAC5B,KAAK,cAAc,GAAG;IACpB,KAAK,EAAE,gBAAgB,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,yBAAyB,EAAE,CAAC;IAC1C,QAAQ,EAAE,OAAO,CAAC;IAClB,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CAAC,sBAAsB,CAAC,CAqBjC;IAED;;OAEG;IACH,UAAgB,+BAA+B,CAAC,OAAO,EAAE,eAAe,iBAyBvE;IAED;;;;;;;;;;;;OAYG;IACH,UAAgB,4BAA4B,CAAC,OAAO,EAAE,eAAe,iBA0EpE;YAEa,MAAM;CAmCrB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { ProtocolContractAddress, ProtocolContractsList } from '@aztec/protocol-contracts';
|
|
4
4
|
import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
@@ -11,7 +11,7 @@ import { AvmSimulator } from '../avm/index.js';
|
|
|
11
11
|
import { getPublicFunctionDebugName } from '../debug_fn_name.js';
|
|
12
12
|
import { HintingMerkleWriteOperations, HintingPublicContractsDB } from '../hinting_db_sources.js';
|
|
13
13
|
import { PublicTreesDB } from '../public_db_sources.js';
|
|
14
|
-
import { L2ToL1MessageLimitReachedError, NoteHashLimitReachedError,
|
|
14
|
+
import { L2ToL1MessageLimitReachedError, NoteHashLimitReachedError, NullifierLimitReachedError } from '../side_effect_errors.js';
|
|
15
15
|
import { PublicTxContext } from './public_tx_context.js';
|
|
16
16
|
// The errors below are only thrown here in the public tx simulator,
|
|
17
17
|
// and only during revertible phases (revertible insertions, app logic and teardown).
|
|
@@ -90,7 +90,8 @@ export class PublicTxSimulator {
|
|
|
90
90
|
await context.state.fork();
|
|
91
91
|
hintingContractsDB.createCheckpoint();
|
|
92
92
|
try {
|
|
93
|
-
// This
|
|
93
|
+
// This may throw: a side-effect limit error triggers a soft revert (caught below), while a
|
|
94
|
+
// nullifier collision is unrecoverable and propagates out of simulate() to throw out the tx.
|
|
94
95
|
await this.insertRevertiblesFromPrivate(context);
|
|
95
96
|
// Only proceed with app logic if there was no revert during revertible insertion.
|
|
96
97
|
if (context.hasPhase(TxExecutionPhase.APP_LOGIC)) {
|
|
@@ -137,7 +138,7 @@ export class PublicTxSimulator {
|
|
|
137
138
|
}
|
|
138
139
|
context.halt();
|
|
139
140
|
// Such transactions should be filtered by GasTxValidator.
|
|
140
|
-
assert(context.getActualGasUsed().l2Gas <=
|
|
141
|
+
assert(context.getActualGasUsed().l2Gas <= MAX_PROCESSABLE_L2_GAS, `Transaction consumes ${context.getActualGasUsed().l2Gas} L2 gas, which exceeds the maximum processable gas of ${MAX_PROCESSABLE_L2_GAS}`);
|
|
141
142
|
await this.payFee(context);
|
|
142
143
|
const publicInputs = await context.generateAvmCircuitPublicInputs();
|
|
143
144
|
const revertCode = context.getFinalRevertCode();
|
|
@@ -255,16 +256,20 @@ export class PublicTxSimulator {
|
|
|
255
256
|
// However, things work as expected because later calls to getters on the hintingContractsDB
|
|
256
257
|
// will pick up the new contracts and will generate the necessary hints.
|
|
257
258
|
// So, a consumer of the hints will always see the new contracts.
|
|
258
|
-
|
|
259
|
+
this.contractsDB.addContracts(context.nonRevertibleContractDeploymentData);
|
|
259
260
|
}
|
|
260
261
|
/**
|
|
261
262
|
* Insert the revertible accumulated data from private into the public state.
|
|
262
263
|
* Throws TxSimRevertibleInsertionsRevert if there is some checked error during revertible insertions.
|
|
263
264
|
* This function checks for the following errors:
|
|
264
265
|
* - NullifierLimitReachedError
|
|
265
|
-
* - NullifierCollisionError
|
|
266
266
|
* - NoteHashLimitReachedError
|
|
267
267
|
* - L2ToL1MessageLimitReachedError
|
|
268
|
+
*
|
|
269
|
+
* Note: NullifierCollisionError is intentionally NOT caught here. A nullifier collision
|
|
270
|
+
* during revertible insertions is unprovable (the nullifier originated from private, so
|
|
271
|
+
* a collision indicates the tx should never have been proposed). It propagates as-is to
|
|
272
|
+
* make the transaction unrecoverable, matching the AVM circuit behavior.
|
|
268
273
|
*/ async insertRevertiblesFromPrivate(context) {
|
|
269
274
|
const stateManager = context.state.getActiveStateManager();
|
|
270
275
|
try {
|
|
@@ -272,11 +277,11 @@ export class PublicTxSimulator {
|
|
|
272
277
|
await stateManager.writeSiloedNullifier(siloedNullifier);
|
|
273
278
|
}
|
|
274
279
|
} catch (e) {
|
|
275
|
-
if (e instanceof NullifierLimitReachedError
|
|
280
|
+
if (e instanceof NullifierLimitReachedError) {
|
|
276
281
|
context.revert(TxExecutionPhase.APP_LOGIC, new SimulationError(`Error encountered when inserting revertible nullifiers from private.\nDetails: ${e.message}`, []));
|
|
277
282
|
throw new TxSimRevertibleInsertionsRevert();
|
|
278
283
|
} else {
|
|
279
|
-
// Unchecked/unknown error - re-throw as-is
|
|
284
|
+
// Unchecked/unknown error or NullifierCollisionError (unrecoverable) - re-throw as-is
|
|
280
285
|
throw e;
|
|
281
286
|
}
|
|
282
287
|
}
|
|
@@ -316,7 +321,7 @@ export class PublicTxSimulator {
|
|
|
316
321
|
// However, things work as expected because later calls to getters on the hintingContractsDB
|
|
317
322
|
// will pick up the new contracts and will generate the necessary hints.
|
|
318
323
|
// So, a consumer of the hints will always see the new contracts.
|
|
319
|
-
|
|
324
|
+
this.contractsDB.addContracts(context.revertibleContractDeploymentData);
|
|
320
325
|
}
|
|
321
326
|
async payFee(context) {
|
|
322
327
|
const txFee = context.getTransactionFee(TxExecutionPhase.TEARDOWN);
|
|
@@ -13,6 +13,10 @@ export interface PublicTxMetrics {
|
|
|
13
13
|
totalDurationMs: number;
|
|
14
14
|
manaUsed: number | undefined;
|
|
15
15
|
totalInstructionsExecuted: number;
|
|
16
|
+
bytecodeSizes: {
|
|
17
|
+
contractName: string;
|
|
18
|
+
sizeBytes: number;
|
|
19
|
+
}[];
|
|
16
20
|
nonRevertiblePrivateInsertionsUs: number | undefined;
|
|
17
21
|
revertiblePrivateInsertionsUs: number | undefined;
|
|
18
22
|
enqueuedCalls: PublicEnqueuedCallMetrics[];
|
|
@@ -47,10 +51,11 @@ export declare class TestExecutorMetrics implements ExecutorMetricsInterface {
|
|
|
47
51
|
recordEnqueuedCallSimulation(fnName: string, durationMs: number, manaUsed: number, totalInstructionsExecuted: number): void;
|
|
48
52
|
recordEnqueuedCallSimulationFailure(fnName: string, durationMs: number, manaUsed: number, totalInstructionsExecuted: number): void;
|
|
49
53
|
recordPrivateEffectsInsertion(durationUs: number, type: 'revertible' | 'non-revertible'): void;
|
|
54
|
+
recordBytecodeSize(txLabel: string, contractName: string, sizeBytes: number): void;
|
|
50
55
|
recordProverMetrics(txLabel: string, metrics: Partial<PublicTxMetrics>): void;
|
|
51
56
|
prettyPrint(filter?: PublicTxMetricsFilter): void;
|
|
52
57
|
toPrettyString(filter?: PublicTxMetricsFilter): string;
|
|
53
58
|
toJSON(indent?: number): string;
|
|
54
59
|
toGithubActionBenchmarkJSON(indent?: number): string;
|
|
55
60
|
}
|
|
56
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
61
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdF9leGVjdXRvcl9tZXRyaWNzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvcHVibGljL3Rlc3RfZXhlY3V0b3JfbWV0cmljcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEVBQWUsS0FBSyxjQUFjLEVBQWdCLE1BQU0sdUJBQXVCLENBQUM7QUFFdkYsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0sbUJBQW1CLENBQUM7QUFDcEQsT0FBTyxLQUFLLEVBQUUsT0FBTyxFQUFFLE1BQU0sbUJBQW1CLENBQUM7QUFJakQsT0FBTyxLQUFLLEVBQUUsd0JBQXdCLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUVoRixNQUFNLFdBQVcseUJBQXlCO0lBQ3hDLE1BQU0sRUFBRSxNQUFNLENBQUM7SUFDZixVQUFVLEVBQUUsTUFBTSxDQUFDO0lBQ25CLFFBQVEsRUFBRSxNQUFNLENBQUM7SUFDakIseUJBQXlCL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AAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,yBAAyB,EAAE,MAAM,QAGlC;IAoBD,6BAA6B,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,gBAAgB,QAgBtF;IAED,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAI1E;IAED,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,eAAe,CAAC,QAUrE;IAED,WAAW,CAAC,MAAM,GAAE,qBAAiD,QAEpE;IAED,cAAc,CAAC,MAAM,GAAE,qBAAiD,UAwFvE;IA0BD,MAAM,CAAC,MAAM,SAAI,UAEhB;IAED,2BAA2B,CAAC,MAAM,SAAI,UAmGrC;CACF"}
|
|
@@ -24,6 +24,7 @@ function createEmptyTxMetrics() {
|
|
|
24
24
|
totalDurationMs: 0,
|
|
25
25
|
manaUsed: 0,
|
|
26
26
|
totalInstructionsExecuted: 0,
|
|
27
|
+
bytecodeSizes: [],
|
|
27
28
|
nonRevertiblePrivateInsertionsUs: undefined,
|
|
28
29
|
revertiblePrivateInsertionsUs: undefined,
|
|
29
30
|
enqueuedCalls: [],
|
|
@@ -99,6 +100,14 @@ export class TestExecutorMetrics {
|
|
|
99
100
|
txMetrics.nonRevertiblePrivateInsertionsUs = durationUs;
|
|
100
101
|
}
|
|
101
102
|
}
|
|
103
|
+
recordBytecodeSize(txLabel, contractName, sizeBytes) {
|
|
104
|
+
const txMetrics = this.txMetrics.get(txLabel);
|
|
105
|
+
assert(txMetrics, `Cannot record bytecode size for unknown tx label: ${txLabel}`);
|
|
106
|
+
txMetrics.bytecodeSizes.push({
|
|
107
|
+
contractName,
|
|
108
|
+
sizeBytes
|
|
109
|
+
});
|
|
110
|
+
}
|
|
102
111
|
recordProverMetrics(txLabel, metrics) {
|
|
103
112
|
if (!this.txMetrics.has(txLabel)) {
|
|
104
113
|
this.txMetrics.set(txLabel, createEmptyTxMetrics());
|
|
@@ -132,6 +141,12 @@ export class TestExecutorMetrics {
|
|
|
132
141
|
if (filter === 3 || filter === 1 || filter === 0) {
|
|
133
142
|
pretty += `${INDENT0}Total instructions executed: ${fmtNum(txMetrics.totalInstructionsExecuted)}\n`;
|
|
134
143
|
}
|
|
144
|
+
if ((filter === 1 || filter === 0) && txMetrics.bytecodeSizes.length > 0) {
|
|
145
|
+
pretty += `${INDENT0}Bytecode sizes:\n`;
|
|
146
|
+
for (const { contractName, sizeBytes } of txMetrics.bytecodeSizes){
|
|
147
|
+
pretty += `${INDENT1}${contractName}: ${fmtNum(sizeBytes, 'bytes')}\n`;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
135
150
|
if (filter === 2 || filter === 0) {
|
|
136
151
|
pretty += `${INDENT0}Private insertions:\n`;
|
|
137
152
|
pretty += `${INDENT1}Non-revertible: ${fmtNum(txMetrics.nonRevertiblePrivateInsertionsUs / 1_000, 'ms')}\n`;
|
|
@@ -298,6 +313,13 @@ export class TestExecutorMetrics {
|
|
|
298
313
|
});
|
|
299
314
|
}
|
|
300
315
|
}
|
|
316
|
+
for (const { contractName, sizeBytes } of txMetrics.bytecodeSizes){
|
|
317
|
+
data.push({
|
|
318
|
+
name: `${txLabel}/bytecodeSizeBytes/${contractName}`,
|
|
319
|
+
value: sizeBytes,
|
|
320
|
+
unit: 'bytes'
|
|
321
|
+
});
|
|
322
|
+
}
|
|
301
323
|
}
|
|
302
324
|
return JSON.stringify(data, null, indent);
|
|
303
325
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/simulator",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.0ec55a70b",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./server": "./dest/server.js",
|
|
@@ -64,26 +64,25 @@
|
|
|
64
64
|
]
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@aztec/constants": "0.0.1-commit.
|
|
68
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
69
|
-
"@aztec/native": "0.0.1-commit.
|
|
70
|
-
"@aztec/noir-acvm_js": "0.0.1-commit.
|
|
71
|
-
"@aztec/noir-noirc_abi": "0.0.1-commit.
|
|
72
|
-
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.
|
|
73
|
-
"@aztec/noir-types": "0.0.1-commit.
|
|
74
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
75
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
76
|
-
"@aztec/telemetry-client": "0.0.1-commit.
|
|
77
|
-
"@aztec/world-state": "0.0.1-commit.
|
|
67
|
+
"@aztec/constants": "0.0.1-commit.0ec55a70b",
|
|
68
|
+
"@aztec/foundation": "0.0.1-commit.0ec55a70b",
|
|
69
|
+
"@aztec/native": "0.0.1-commit.0ec55a70b",
|
|
70
|
+
"@aztec/noir-acvm_js": "0.0.1-commit.0ec55a70b",
|
|
71
|
+
"@aztec/noir-noirc_abi": "0.0.1-commit.0ec55a70b",
|
|
72
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.0ec55a70b",
|
|
73
|
+
"@aztec/noir-types": "0.0.1-commit.0ec55a70b",
|
|
74
|
+
"@aztec/protocol-contracts": "0.0.1-commit.0ec55a70b",
|
|
75
|
+
"@aztec/stdlib": "0.0.1-commit.0ec55a70b",
|
|
76
|
+
"@aztec/telemetry-client": "0.0.1-commit.0ec55a70b",
|
|
77
|
+
"@aztec/world-state": "0.0.1-commit.0ec55a70b",
|
|
78
78
|
"lodash.clonedeep": "^4.5.0",
|
|
79
79
|
"lodash.merge": "^4.6.2",
|
|
80
80
|
"tslib": "^2.4.0"
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|
|
83
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
84
|
-
"@aztec/
|
|
85
|
-
"@aztec/noir-contracts.js": "0.0.1-commit.
|
|
86
|
-
"@aztec/noir-test-contracts.js": "0.0.1-commit.0c875d939",
|
|
83
|
+
"@aztec/kv-store": "0.0.1-commit.0ec55a70b",
|
|
84
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.0ec55a70b",
|
|
85
|
+
"@aztec/noir-test-contracts.js": "0.0.1-commit.0ec55a70b",
|
|
87
86
|
"@jest/globals": "^30.0.0",
|
|
88
87
|
"@types/jest": "^30.0.0",
|
|
89
88
|
"@types/lodash.clonedeep": "^4.5.7",
|
|
@@ -161,11 +161,11 @@ export class CircuitRecorder {
|
|
|
161
161
|
throw new Error(`Oracle method ${name} not found when setting up recording callback`);
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
const isExternalCall = (name as keyof ACIRCallback) === '
|
|
164
|
+
const isExternalCall = (name as keyof ACIRCallback) === 'aztec_prv_callPrivateFunction';
|
|
165
165
|
|
|
166
166
|
recordingCallback[name as keyof ACIRCallback] = (...args: ForeignCallInput[]): ReturnType<typeof fn> => {
|
|
167
167
|
const timer = new Timer();
|
|
168
|
-
// If we're entering another circuit via `
|
|
168
|
+
// If we're entering another circuit via `aztec_prv_callPrivateFunction`, we increase the stack depth and set the
|
|
169
169
|
// newCircuit variable to ensure we are creating a new recording object.
|
|
170
170
|
if (isExternalCall) {
|
|
171
171
|
this.stackDepth++;
|
|
@@ -63,7 +63,7 @@ export class AvmSimulator implements AvmSimulatorInterface {
|
|
|
63
63
|
public static async build(context: AvmContext): Promise<AvmSimulator> {
|
|
64
64
|
const simulator = new AvmSimulator(context);
|
|
65
65
|
const fnName = await context.persistableState.getPublicFunctionDebugName(context.environment);
|
|
66
|
-
simulator.log = createLogger(`simulator:avm(f:${fnName})`);
|
|
66
|
+
simulator.log = createLogger(`simulator:avm(f:${fnName.slice(0, 128)})`);
|
|
67
67
|
|
|
68
68
|
return simulator;
|
|
69
69
|
}
|
|
@@ -33,13 +33,14 @@ export class LazyReaderMemory implements LazyReader {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
public slice(start: number, end: number): Fr[] {
|
|
36
|
-
const clampedEnd = Math.min(end, this.size);
|
|
36
|
+
const clampedEnd = Math.min(end, this.size, TaggedMemory.MAX_MEMORY_SIZE - this.offset);
|
|
37
37
|
const length = Math.max(0, clampedEnd - start);
|
|
38
38
|
return this.memory.getSlice(this.offset + start, length).map(word => word.toFr());
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
public readAll(): Fr[] {
|
|
42
|
-
|
|
42
|
+
const size = Math.min(this.size, TaggedMemory.MAX_MEMORY_SIZE - this.offset);
|
|
43
|
+
return this.memory.getSlice(this.offset, size).map(word => word.toFr());
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
public length(): number {
|
|
@@ -14,8 +14,8 @@ abstract class ExternalCall extends Instruction {
|
|
|
14
14
|
OperandType.UINT16, // L2 gas offset
|
|
15
15
|
OperandType.UINT16, // DA gas offset
|
|
16
16
|
OperandType.UINT16, // Address offset
|
|
17
|
-
OperandType.UINT16, // Args offset
|
|
18
17
|
OperandType.UINT16, // Args size offset
|
|
18
|
+
OperandType.UINT16, // Args offset
|
|
19
19
|
];
|
|
20
20
|
|
|
21
21
|
constructor(
|
|
@@ -31,7 +31,7 @@ export class ContractsDbCheckpoint {
|
|
|
31
31
|
return this.bytecodeCommitments.get(classId.toString());
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
public
|
|
34
|
+
public fork(): ContractsDbCheckpoint {
|
|
35
35
|
const copy = new ContractsDbCheckpoint();
|
|
36
36
|
this.instances.forEach((value, key) => copy.instances.set(key, value));
|
|
37
37
|
this.classes.forEach((value, key) => copy.classes.set(key, value));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DomainSeparator } from '@aztec/constants';
|
|
2
2
|
import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
|
|
3
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
4
|
import type { Logger } from '@aztec/foundation/log';
|
|
@@ -326,6 +326,6 @@ async function removeLiquidity(
|
|
|
326
326
|
async function computePartialNoteValidityCommitment(partialNote: { commitment: Fr }, completer: AztecAddress) {
|
|
327
327
|
return await poseidon2HashWithSeparator(
|
|
328
328
|
[partialNote.commitment, completer],
|
|
329
|
-
|
|
329
|
+
DomainSeparator.PARTIAL_NOTE_VALIDITY_COMMITMENT,
|
|
330
330
|
);
|
|
331
331
|
}
|
|
@@ -30,9 +30,7 @@ export async function bulkTest(
|
|
|
30
30
|
// for it to use as "expected" values when testing contract instance retrieval.
|
|
31
31
|
const expectContractInstance = avmTestContract;
|
|
32
32
|
const argsField = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
|
|
33
|
-
const argsU8 = [1, 2, 3, 4, 5, 6, 7, 8].map(x => new Fr(x));
|
|
34
|
-
argsU8.push(new Fr(2n ** 128n + 9n)); // Trigger truncation from large (> 128 bits) value (canonical decomposition event)
|
|
35
|
-
argsU8.push(new Fr(2n ** 125n + 10n)); // Trigger truncation from small (< 128 bits) value (no canonical decomposition event)
|
|
33
|
+
const argsU8 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
|
|
36
34
|
const args = [
|
|
37
35
|
argsField,
|
|
38
36
|
argsU8,
|
|
@@ -62,7 +60,7 @@ export async function bulkTest(
|
|
|
62
60
|
{
|
|
63
61
|
address: avmTestContract.address,
|
|
64
62
|
fnName: 'assert_calldata_copy',
|
|
65
|
-
args: [argsField.slice(3), /* with_selector: */ true],
|
|
63
|
+
args: [argsField.slice(0, 3), /* with_selector: */ true],
|
|
66
64
|
},
|
|
67
65
|
{
|
|
68
66
|
address: avmTestContract.address,
|
|
@@ -2,7 +2,7 @@ import { strict as assert } from 'assert';
|
|
|
2
2
|
|
|
3
3
|
import { TypeTag } from '../avm/avm_memory_types.js';
|
|
4
4
|
import { Addressing, AddressingMode } from '../avm/opcodes/addressing_mode.js';
|
|
5
|
-
import { Add, CalldataCopy, Jump, Return, Set } from '../avm/opcodes/index.js';
|
|
5
|
+
import { Add, CalldataCopy, Cast, Jump, Return, Set } from '../avm/opcodes/index.js';
|
|
6
6
|
import { encodeToBytecode } from '../avm/serialization/bytecode_serialization.js';
|
|
7
7
|
import {
|
|
8
8
|
MAX_OPCODE_VALUE,
|
|
@@ -208,6 +208,144 @@ export async function invalidTagValueAndInstructionTruncatedTest(tester: PublicT
|
|
|
208
208
|
return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
+
// Exercise SET truncation: set values whose widths exceed the target tag and
|
|
212
|
+
// rely on `buildFromTagTruncating` to truncate to the low bits of the tag.
|
|
213
|
+
// Covers sources larger than 128 bits (via SET_FF) and sources in (32, 128]
|
|
214
|
+
// bits (via SET_64) against destination tags U1/U8/U16/U32/U64/U128.
|
|
215
|
+
export async function setTruncationTest(tester: PublicTxSimulationTester) {
|
|
216
|
+
// 200-bit value: forces truncation for every target tag up to U128.
|
|
217
|
+
const LARGE_FIELD_VALUE = (1n << 200n) + 0x1234567890abcdef1234567890abcdefn;
|
|
218
|
+
// 40-bit value: forces truncation for target tags up to U32.
|
|
219
|
+
const LARGE_U64_VALUE = (1n << 40n) + 0xdeadbeefn;
|
|
220
|
+
|
|
221
|
+
const bytecode = encodeToBytecode([
|
|
222
|
+
// Zero U32 at offset 0 — used as the Return copy-size slot.
|
|
223
|
+
new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
|
|
224
|
+
|
|
225
|
+
// Source >128 bits (via SET_FF) truncated to smaller target tags.
|
|
226
|
+
new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 1, TypeTag.UINT128, LARGE_FIELD_VALUE).as(
|
|
227
|
+
Opcode.SET_FF,
|
|
228
|
+
Set.wireFormatFF,
|
|
229
|
+
),
|
|
230
|
+
new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 2, TypeTag.UINT64, LARGE_FIELD_VALUE).as(
|
|
231
|
+
Opcode.SET_FF,
|
|
232
|
+
Set.wireFormatFF,
|
|
233
|
+
),
|
|
234
|
+
new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 3, TypeTag.UINT32, LARGE_FIELD_VALUE).as(
|
|
235
|
+
Opcode.SET_FF,
|
|
236
|
+
Set.wireFormatFF,
|
|
237
|
+
),
|
|
238
|
+
new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 4, TypeTag.UINT16, LARGE_FIELD_VALUE).as(
|
|
239
|
+
Opcode.SET_FF,
|
|
240
|
+
Set.wireFormatFF,
|
|
241
|
+
),
|
|
242
|
+
new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 5, TypeTag.UINT8, LARGE_FIELD_VALUE).as(
|
|
243
|
+
Opcode.SET_FF,
|
|
244
|
+
Set.wireFormatFF,
|
|
245
|
+
),
|
|
246
|
+
new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 6, TypeTag.UINT1, LARGE_FIELD_VALUE).as(
|
|
247
|
+
Opcode.SET_FF,
|
|
248
|
+
Set.wireFormatFF,
|
|
249
|
+
),
|
|
250
|
+
|
|
251
|
+
// Source in (32, 128] bits (via SET_64) truncated to smaller target tags.
|
|
252
|
+
new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 7, TypeTag.UINT32, LARGE_U64_VALUE).as(
|
|
253
|
+
Opcode.SET_64,
|
|
254
|
+
Set.wireFormat64,
|
|
255
|
+
),
|
|
256
|
+
new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 8, TypeTag.UINT16, LARGE_U64_VALUE).as(
|
|
257
|
+
Opcode.SET_64,
|
|
258
|
+
Set.wireFormat64,
|
|
259
|
+
),
|
|
260
|
+
new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 9, TypeTag.UINT8, LARGE_U64_VALUE).as(
|
|
261
|
+
Opcode.SET_64,
|
|
262
|
+
Set.wireFormat64,
|
|
263
|
+
),
|
|
264
|
+
new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 10, TypeTag.UINT1, LARGE_U64_VALUE).as(
|
|
265
|
+
Opcode.SET_64,
|
|
266
|
+
Set.wireFormat64,
|
|
267
|
+
),
|
|
268
|
+
|
|
269
|
+
new Return(/*addressing_mode=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
|
|
270
|
+
]);
|
|
271
|
+
|
|
272
|
+
const txLabel = 'SetTruncation';
|
|
273
|
+
return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Exercise CAST truncation: store a wide source value in memory then CAST it
|
|
277
|
+
// to smaller destination tags. Covers sources larger than 128 bits (FIELD
|
|
278
|
+
// source) and sources in (32, 128] bits (UINT64 source) against destination
|
|
279
|
+
// tags U1/U8/U16/U32/U64/U128.
|
|
280
|
+
export async function castTruncationTest(tester: PublicTxSimulationTester) {
|
|
281
|
+
// 200-bit source: stored as FIELD so that CASTs to any integer tag truncate.
|
|
282
|
+
const LARGE_FIELD_VALUE = (1n << 200n) + 0x1234567890abcdef1234567890abcdefn;
|
|
283
|
+
// 40-bit source: stored as UINT64 so CASTs to U1/U8/U16/U32 truncate.
|
|
284
|
+
const LARGE_U64_VALUE = (1n << 40n) + 0xdeadbeefn;
|
|
285
|
+
|
|
286
|
+
const bytecode = encodeToBytecode([
|
|
287
|
+
// Zero U32 at offset 0 — used as the Return copy-size slot.
|
|
288
|
+
new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
|
|
289
|
+
|
|
290
|
+
// Store wide FIELD source at offset 10, then CAST to smaller tags.
|
|
291
|
+
new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 10, TypeTag.FIELD, LARGE_FIELD_VALUE).as(
|
|
292
|
+
Opcode.SET_FF,
|
|
293
|
+
Set.wireFormatFF,
|
|
294
|
+
),
|
|
295
|
+
new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 10, /*dstOffset=*/ 11, TypeTag.UINT128).as(
|
|
296
|
+
Opcode.CAST_8,
|
|
297
|
+
Cast.wireFormat8,
|
|
298
|
+
),
|
|
299
|
+
new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 10, /*dstOffset=*/ 12, TypeTag.UINT64).as(
|
|
300
|
+
Opcode.CAST_8,
|
|
301
|
+
Cast.wireFormat8,
|
|
302
|
+
),
|
|
303
|
+
new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 10, /*dstOffset=*/ 13, TypeTag.UINT32).as(
|
|
304
|
+
Opcode.CAST_8,
|
|
305
|
+
Cast.wireFormat8,
|
|
306
|
+
),
|
|
307
|
+
new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 10, /*dstOffset=*/ 14, TypeTag.UINT16).as(
|
|
308
|
+
Opcode.CAST_8,
|
|
309
|
+
Cast.wireFormat8,
|
|
310
|
+
),
|
|
311
|
+
new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 10, /*dstOffset=*/ 15, TypeTag.UINT8).as(
|
|
312
|
+
Opcode.CAST_8,
|
|
313
|
+
Cast.wireFormat8,
|
|
314
|
+
),
|
|
315
|
+
new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 10, /*dstOffset=*/ 16, TypeTag.UINT1).as(
|
|
316
|
+
Opcode.CAST_8,
|
|
317
|
+
Cast.wireFormat8,
|
|
318
|
+
),
|
|
319
|
+
|
|
320
|
+
// Store UINT64 source at offset 20, then CAST to smaller integer tags.
|
|
321
|
+
new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 20, TypeTag.UINT64, LARGE_U64_VALUE).as(
|
|
322
|
+
Opcode.SET_64,
|
|
323
|
+
Set.wireFormat64,
|
|
324
|
+
),
|
|
325
|
+
new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 20, /*dstOffset=*/ 21, TypeTag.UINT32).as(
|
|
326
|
+
Opcode.CAST_8,
|
|
327
|
+
Cast.wireFormat8,
|
|
328
|
+
),
|
|
329
|
+
new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 20, /*dstOffset=*/ 22, TypeTag.UINT16).as(
|
|
330
|
+
Opcode.CAST_8,
|
|
331
|
+
Cast.wireFormat8,
|
|
332
|
+
),
|
|
333
|
+
new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 20, /*dstOffset=*/ 23, TypeTag.UINT8).as(
|
|
334
|
+
Opcode.CAST_8,
|
|
335
|
+
Cast.wireFormat8,
|
|
336
|
+
),
|
|
337
|
+
new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 20, /*dstOffset=*/ 24, TypeTag.UINT1).as(
|
|
338
|
+
Opcode.CAST_8,
|
|
339
|
+
Cast.wireFormat8,
|
|
340
|
+
),
|
|
341
|
+
|
|
342
|
+
new Return(/*addressing_mode=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
|
|
343
|
+
]);
|
|
344
|
+
|
|
345
|
+
const txLabel = 'CastTruncation';
|
|
346
|
+
return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
|
|
347
|
+
}
|
|
348
|
+
|
|
211
349
|
/**
|
|
212
350
|
* Returns the offset of the tag in an instruction.
|
|
213
351
|
* @details Loops over the wire format operand type entries until it finds the tag.
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PUBLIC_TX_L2_GAS_OVERHEAD, TX_DA_GAS_OVERHEAD } from '@aztec/constants';
|
|
2
2
|
import { asyncMap } from '@aztec/foundation/async-map';
|
|
3
3
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
4
4
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
5
|
import { type ContractArtifact, encodeArguments } from '@aztec/stdlib/abi';
|
|
6
6
|
import { PublicSimulatorConfig, type PublicTxResult } from '@aztec/stdlib/avm';
|
|
7
7
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
|
-
import { Gas, GasFees } from '@aztec/stdlib/gas';
|
|
8
|
+
import { FALLBACK_TEARDOWN_DA_GAS_LIMIT, FALLBACK_TEARDOWN_L2_GAS_LIMIT, Gas, GasFees } from '@aztec/stdlib/gas';
|
|
9
9
|
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
10
10
|
import { PublicCallRequest } from '@aztec/stdlib/kernel';
|
|
11
11
|
import { GlobalVariables, PublicCallRequestWithCalldata, type Tx } from '@aztec/stdlib/tx';
|
|
@@ -112,6 +112,7 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
112
112
|
feePayer: AztecAddress = sender,
|
|
113
113
|
/* need some unique first nullifier for note-nonce computations */
|
|
114
114
|
privateInsertions: TestPrivateInsertions = { nonRevertible: { nullifiers: [new Fr(420000 + this.txCount)] } },
|
|
115
|
+
gasLimits?: Gas,
|
|
115
116
|
): Promise<Tx> {
|
|
116
117
|
const setupCallRequests = await asyncMap(setupCalls, call =>
|
|
117
118
|
this.#createPubicCallRequestForCall(call, call.sender ?? sender),
|
|
@@ -131,9 +132,13 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
131
132
|
teardownCallRequest,
|
|
132
133
|
feePayer,
|
|
133
134
|
/*gasUsedByPrivate*/ teardownCall
|
|
134
|
-
? new Gas(
|
|
135
|
-
|
|
135
|
+
? new Gas(
|
|
136
|
+
FALLBACK_TEARDOWN_DA_GAS_LIMIT + TX_DA_GAS_OVERHEAD,
|
|
137
|
+
FALLBACK_TEARDOWN_L2_GAS_LIMIT + PUBLIC_TX_L2_GAS_OVERHEAD,
|
|
138
|
+
)
|
|
139
|
+
: new Gas(TX_DA_GAS_OVERHEAD, PUBLIC_TX_L2_GAS_OVERHEAD),
|
|
136
140
|
defaultGlobals(),
|
|
141
|
+
gasLimits,
|
|
137
142
|
);
|
|
138
143
|
}
|
|
139
144
|
|
|
@@ -146,8 +151,9 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
146
151
|
/* need some unique first nullifier for note-nonce computations */
|
|
147
152
|
privateInsertions?: TestPrivateInsertions,
|
|
148
153
|
txLabel: string = 'unlabeledTx',
|
|
154
|
+
gasLimits?: Gas,
|
|
149
155
|
): Promise<PublicTxResult> {
|
|
150
|
-
const tx = await this.createTx(sender, setupCalls, appCalls, teardownCall, feePayer, privateInsertions);
|
|
156
|
+
const tx = await this.createTx(sender, setupCalls, appCalls, teardownCall, feePayer, privateInsertions, gasLimits);
|
|
151
157
|
|
|
152
158
|
await this.setFeePayerBalance(feePayer);
|
|
153
159
|
|
|
@@ -161,6 +167,8 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
161
167
|
}
|
|
162
168
|
const avmResult = await this.simulator.simulate(tx, fullTxLabel);
|
|
163
169
|
|
|
170
|
+
await this.#recordBytecodeSizes(fullTxLabel, [...setupCalls, ...appCalls, ...(teardownCall ? [teardownCall] : [])]);
|
|
171
|
+
|
|
164
172
|
// Something like this is often useful for debugging:
|
|
165
173
|
//if (avmResult.revertReason) {
|
|
166
174
|
// // resolve / enrich revert reason
|
|
@@ -190,8 +198,18 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
190
198
|
teardownCall?: TestEnqueuedCall,
|
|
191
199
|
feePayer?: AztecAddress,
|
|
192
200
|
privateInsertions?: TestPrivateInsertions,
|
|
201
|
+
gasLimits?: Gas,
|
|
193
202
|
): Promise<PublicTxResult> {
|
|
194
|
-
return await this.simulateTx(
|
|
203
|
+
return await this.simulateTx(
|
|
204
|
+
sender,
|
|
205
|
+
setupCalls,
|
|
206
|
+
appCalls,
|
|
207
|
+
teardownCall,
|
|
208
|
+
feePayer,
|
|
209
|
+
privateInsertions,
|
|
210
|
+
txLabel,
|
|
211
|
+
gasLimits,
|
|
212
|
+
);
|
|
195
213
|
}
|
|
196
214
|
|
|
197
215
|
/**
|
|
@@ -209,6 +227,7 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
209
227
|
teardownCall?: TestEnqueuedCall,
|
|
210
228
|
feePayer?: AztecAddress,
|
|
211
229
|
privateInsertions?: TestPrivateInsertions,
|
|
230
|
+
gasLimits?: Gas,
|
|
212
231
|
): Promise<PublicTxResult> {
|
|
213
232
|
return await this.simulateTxWithLabel(
|
|
214
233
|
txLabel,
|
|
@@ -218,6 +237,7 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
218
237
|
teardownCall,
|
|
219
238
|
feePayer,
|
|
220
239
|
privateInsertions,
|
|
240
|
+
gasLimits,
|
|
221
241
|
);
|
|
222
242
|
}
|
|
223
243
|
|
|
@@ -277,6 +297,27 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
277
297
|
|
|
278
298
|
return new PublicCallRequestWithCalldata(request, calldata);
|
|
279
299
|
}
|
|
300
|
+
|
|
301
|
+
// WARNING: Deduplicates by artifact name, so two different artifacts with the same name
|
|
302
|
+
// in a single tx would only record the first one's bytecode size.
|
|
303
|
+
async #recordBytecodeSizes(txLabel: string, calls: TestEnqueuedCall[]) {
|
|
304
|
+
const seenArtifactNames = new Set<string>();
|
|
305
|
+
for (const call of calls) {
|
|
306
|
+
const artifact = await this.contractDataSource.getContractArtifact(call.address);
|
|
307
|
+
if (!artifact || seenArtifactNames.has(artifact.name)) {
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
seenArtifactNames.add(artifact.name);
|
|
311
|
+
const instance = await this.contractDataSource.getContract(call.address);
|
|
312
|
+
if (!instance) {
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
const contractClass = await this.contractDataSource.getContractClass(instance.currentContractClassId);
|
|
316
|
+
if (contractClass) {
|
|
317
|
+
this.metrics.recordBytecodeSize(txLabel, artifact.name, contractClass.packedBytecode.length);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
280
321
|
}
|
|
281
322
|
|
|
282
323
|
export function defaultGlobals() {
|