@aztec/simulator 0.0.1-commit.f2ce05ee → 0.0.1-commit.f81dbcf
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/public/avm/avm_gas.js +3 -3
- package/dest/public/avm/opcodes/accrued_substate.d.ts +2 -2
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/accrued_substate.js +3 -4
- package/dest/public/avm/serialization/bytecode_serialization.js +3 -3
- package/dest/public/avm/serialization/instruction_serialization.d.ts +2 -2
- package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/instruction_serialization.js +1 -1
- package/dest/public/fixtures/amm_test.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 +6 -6
- 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 +9 -9
- 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 +6 -6
- 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_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 +50 -41
- 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_simulator.js +2 -2
- package/package.json +16 -16
- package/src/public/avm/avm_gas.ts +2 -2
- package/src/public/avm/opcodes/accrued_substate.ts +3 -4
- package/src/public/avm/serialization/bytecode_serialization.ts +2 -2
- package/src/public/avm/serialization/instruction_serialization.ts +1 -1
- package/src/public/fixtures/amm_test.ts +2 -2
- package/src/public/fixtures/opcode_spammer.ts +6 -10
- package/src/public/fixtures/public_tx_simulation_tester.ts +28 -5
- package/src/public/fixtures/utils.ts +6 -5
- package/src/public/fuzzing/avm_fuzzer_simulator.ts +1 -1
- package/src/public/hinting_db_sources.ts +9 -7
- package/src/public/public_processor/guarded_merkle_tree.ts +6 -6
- package/src/public/public_processor/public_processor.ts +64 -53
- 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_simulator.ts +3 -3
|
@@ -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
|
}
|
|
@@ -143,7 +143,7 @@
|
|
|
143
143
|
* - `EMITNOTEHASH`: max 64 per TX
|
|
144
144
|
* - `EMITNULLIFIER`: max 63 per TX (one reserved for TX nullifier)
|
|
145
145
|
* - `SENDL2TOL1MSG`: max 8 per TX
|
|
146
|
-
* - `
|
|
146
|
+
* - `EMITPUBLICLOG`: limited by total log payload size
|
|
147
147
|
*
|
|
148
148
|
* By having the inner contract REVERT after emitting side effects, those effects are discarded, allowing the outer contract to call it again. This enables thousands of opcode executions per TX instead of just the limit.
|
|
149
149
|
*
|
|
@@ -182,7 +182,7 @@ import {
|
|
|
182
182
|
EcAdd,
|
|
183
183
|
EmitNoteHash,
|
|
184
184
|
EmitNullifier,
|
|
185
|
-
|
|
185
|
+
EmitPublicLog,
|
|
186
186
|
Eq,
|
|
187
187
|
FieldDiv,
|
|
188
188
|
GetContractInstance,
|
|
@@ -1242,17 +1242,15 @@ export const SPAM_CONFIGS: Partial<Record<Opcode, SpamConfig[]>> = {
|
|
|
1242
1242
|
},
|
|
1243
1243
|
],
|
|
1244
1244
|
|
|
1245
|
-
//
|
|
1246
|
-
[Opcode.
|
|
1245
|
+
// EMITPUBLICLOG - two configs: minimal (many small logs) and max-size (one large log)
|
|
1246
|
+
[Opcode.EMITPUBLICLOG]: [
|
|
1247
1247
|
{
|
|
1248
1248
|
label: 'Many empty logs, revert, repeat',
|
|
1249
1249
|
setup: [
|
|
1250
1250
|
{ offset: 0, value: new Uint32(0n) }, // logSize = 0 fields (minimal)
|
|
1251
1251
|
{ offset: 1, value: new Uint32(0n) }, // revertSize
|
|
1252
1252
|
],
|
|
1253
|
-
targetInstructions: () => [
|
|
1254
|
-
new EmitUnencryptedLog(/*addressing_mode=*/ 0, /*logSizeOffset=*/ 0, /*logOffset=*/ 1),
|
|
1255
|
-
], // logOffset doesn't matter when size is 0
|
|
1253
|
+
targetInstructions: () => [new EmitPublicLog(/*addressing_mode=*/ 0, /*logSizeOffset=*/ 0, /*logOffset=*/ 1)], // logOffset doesn't matter when size is 0
|
|
1256
1254
|
cleanupInstructions: () => [
|
|
1257
1255
|
new Revert(/*addressing_mode=*/ 0, /*retSizeOffset=*/ 1, /*returnOffset=*/ 0).as(
|
|
1258
1256
|
Opcode.REVERT_8,
|
|
@@ -1276,9 +1274,7 @@ export const SPAM_CONFIGS: Partial<Record<Opcode, SpamConfig[]>> = {
|
|
|
1276
1274
|
// value: new Field(0n),
|
|
1277
1275
|
//})),
|
|
1278
1276
|
],
|
|
1279
|
-
targetInstructions: () => [
|
|
1280
|
-
new EmitUnencryptedLog(/*addressing_mode=*/ 0, /*logSizeOffset=*/ 0, /*logOffset=*/ 2),
|
|
1281
|
-
], // uses logOffset 2 (uninitialized Field(0))
|
|
1277
|
+
targetInstructions: () => [new EmitPublicLog(/*addressing_mode=*/ 0, /*logSizeOffset=*/ 0, /*logOffset=*/ 2)], // uses logOffset 2 (uninitialized Field(0))
|
|
1282
1278
|
cleanupInstructions: () => [
|
|
1283
1279
|
new Revert(/*addressing_mode=*/ 0, /*retSizeOffset=*/ 1, /*returnOffset=*/ 0).as(
|
|
1284
1280
|
Opcode.REVERT_8,
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_TEARDOWN_DA_GAS_LIMIT,
|
|
3
|
+
DEFAULT_TEARDOWN_L2_GAS_LIMIT,
|
|
4
|
+
PUBLIC_TX_L2_GAS_OVERHEAD,
|
|
5
|
+
TX_DA_GAS_OVERHEAD,
|
|
6
|
+
} from '@aztec/constants';
|
|
2
7
|
import { asyncMap } from '@aztec/foundation/async-map';
|
|
3
8
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
4
9
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
@@ -112,6 +117,7 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
112
117
|
feePayer: AztecAddress = sender,
|
|
113
118
|
/* need some unique first nullifier for note-nonce computations */
|
|
114
119
|
privateInsertions: TestPrivateInsertions = { nonRevertible: { nullifiers: [new Fr(420000 + this.txCount)] } },
|
|
120
|
+
gasLimits?: Gas,
|
|
115
121
|
): Promise<Tx> {
|
|
116
122
|
const setupCallRequests = await asyncMap(setupCalls, call =>
|
|
117
123
|
this.#createPubicCallRequestForCall(call, call.sender ?? sender),
|
|
@@ -131,9 +137,13 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
131
137
|
teardownCallRequest,
|
|
132
138
|
feePayer,
|
|
133
139
|
/*gasUsedByPrivate*/ teardownCall
|
|
134
|
-
? new Gas(
|
|
135
|
-
|
|
140
|
+
? new Gas(
|
|
141
|
+
DEFAULT_TEARDOWN_DA_GAS_LIMIT + TX_DA_GAS_OVERHEAD,
|
|
142
|
+
DEFAULT_TEARDOWN_L2_GAS_LIMIT + PUBLIC_TX_L2_GAS_OVERHEAD,
|
|
143
|
+
)
|
|
144
|
+
: new Gas(TX_DA_GAS_OVERHEAD, PUBLIC_TX_L2_GAS_OVERHEAD),
|
|
136
145
|
defaultGlobals(),
|
|
146
|
+
gasLimits,
|
|
137
147
|
);
|
|
138
148
|
}
|
|
139
149
|
|
|
@@ -146,8 +156,9 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
146
156
|
/* need some unique first nullifier for note-nonce computations */
|
|
147
157
|
privateInsertions?: TestPrivateInsertions,
|
|
148
158
|
txLabel: string = 'unlabeledTx',
|
|
159
|
+
gasLimits?: Gas,
|
|
149
160
|
): Promise<PublicTxResult> {
|
|
150
|
-
const tx = await this.createTx(sender, setupCalls, appCalls, teardownCall, feePayer, privateInsertions);
|
|
161
|
+
const tx = await this.createTx(sender, setupCalls, appCalls, teardownCall, feePayer, privateInsertions, gasLimits);
|
|
151
162
|
|
|
152
163
|
await this.setFeePayerBalance(feePayer);
|
|
153
164
|
|
|
@@ -190,8 +201,18 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
190
201
|
teardownCall?: TestEnqueuedCall,
|
|
191
202
|
feePayer?: AztecAddress,
|
|
192
203
|
privateInsertions?: TestPrivateInsertions,
|
|
204
|
+
gasLimits?: Gas,
|
|
193
205
|
): Promise<PublicTxResult> {
|
|
194
|
-
return await this.simulateTx(
|
|
206
|
+
return await this.simulateTx(
|
|
207
|
+
sender,
|
|
208
|
+
setupCalls,
|
|
209
|
+
appCalls,
|
|
210
|
+
teardownCall,
|
|
211
|
+
feePayer,
|
|
212
|
+
privateInsertions,
|
|
213
|
+
txLabel,
|
|
214
|
+
gasLimits,
|
|
215
|
+
);
|
|
195
216
|
}
|
|
196
217
|
|
|
197
218
|
/**
|
|
@@ -209,6 +230,7 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
209
230
|
teardownCall?: TestEnqueuedCall,
|
|
210
231
|
feePayer?: AztecAddress,
|
|
211
232
|
privateInsertions?: TestPrivateInsertions,
|
|
233
|
+
gasLimits?: Gas,
|
|
212
234
|
): Promise<PublicTxResult> {
|
|
213
235
|
return await this.simulateTxWithLabel(
|
|
214
236
|
txLabel,
|
|
@@ -218,6 +240,7 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
218
240
|
teardownCall,
|
|
219
241
|
feePayer,
|
|
220
242
|
privateInsertions,
|
|
243
|
+
gasLimits,
|
|
221
244
|
);
|
|
222
245
|
}
|
|
223
246
|
|
|
@@ -62,13 +62,14 @@ export async function createTxForPublicCalls(
|
|
|
62
62
|
feePayer = AztecAddress.zero(),
|
|
63
63
|
gasUsedByPrivate: Gas = Gas.empty(),
|
|
64
64
|
globals: GlobalVariables = GlobalVariables.empty(),
|
|
65
|
+
gasLimits?: Gas,
|
|
65
66
|
): Promise<Tx> {
|
|
66
67
|
assert(
|
|
67
68
|
setupCallRequests.length > 0 || appCallRequests.length > 0 || teardownCallRequest !== undefined,
|
|
68
69
|
"Can't create public tx with no enqueued calls",
|
|
69
70
|
);
|
|
70
71
|
// use max limits
|
|
71
|
-
|
|
72
|
+
gasLimits = gasLimits ?? new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
|
|
72
73
|
|
|
73
74
|
const forPublic = PartialPrivateTailPublicInputsForPublic.empty();
|
|
74
75
|
|
|
@@ -134,13 +135,13 @@ export async function createTxForPublicCalls(
|
|
|
134
135
|
const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings);
|
|
135
136
|
const header = BlockHeader.empty({ globalVariables: globals });
|
|
136
137
|
const constantData = new TxConstantData(header, txContext, Fr.zero(), Fr.zero());
|
|
137
|
-
const
|
|
138
|
+
const expirationTimestamp = 0n; // Not used in the simulator.
|
|
138
139
|
|
|
139
140
|
const txData = new PrivateKernelTailCircuitPublicInputs(
|
|
140
141
|
constantData,
|
|
141
142
|
/*gasUsed=*/ gasUsedByPrivate,
|
|
142
143
|
feePayer,
|
|
143
|
-
|
|
144
|
+
expirationTimestamp,
|
|
144
145
|
forPublic,
|
|
145
146
|
);
|
|
146
147
|
|
|
@@ -171,13 +172,13 @@ export async function createTxForPrivateOnly(
|
|
|
171
172
|
const gasSettings = new GasSettings(gasLimits, Gas.empty(), maxFeesPerGas, GasFees.empty());
|
|
172
173
|
const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings);
|
|
173
174
|
const constantData = new TxConstantData(BlockHeader.empty(), txContext, Fr.zero(), Fr.zero());
|
|
174
|
-
const
|
|
175
|
+
const expirationTimestamp = 0n; // Not used in the simulator.
|
|
175
176
|
|
|
176
177
|
const txData = new PrivateKernelTailCircuitPublicInputs(
|
|
177
178
|
constantData,
|
|
178
179
|
/*gasUsed=*/ gasUsedByPrivate,
|
|
179
180
|
feePayer,
|
|
180
|
-
|
|
181
|
+
expirationTimestamp,
|
|
181
182
|
/*forPublic=*/ undefined,
|
|
182
183
|
forRollup,
|
|
183
184
|
);
|
|
@@ -146,7 +146,7 @@ async function createTxFromHint(cppTx: AvmTxHint): Promise<Tx> {
|
|
|
146
146
|
constants,
|
|
147
147
|
cppTx.gasUsedByPrivate,
|
|
148
148
|
cppTx.feePayer,
|
|
149
|
-
0n, //
|
|
149
|
+
0n, // expirationTimestamp
|
|
150
150
|
forPublic,
|
|
151
151
|
undefined, // forRollup - not needed for public simulation
|
|
152
152
|
);
|
|
@@ -410,12 +410,12 @@ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
|
|
|
410
410
|
}
|
|
411
411
|
}
|
|
412
412
|
|
|
413
|
-
public async createCheckpoint(): Promise<
|
|
413
|
+
public async createCheckpoint(): Promise<number> {
|
|
414
414
|
const actionCounter = this.checkpointActionCounter++;
|
|
415
415
|
const oldCheckpointId = this.getCurrentCheckpointId();
|
|
416
416
|
const treesStateHash = await this.getTreesStateHash();
|
|
417
417
|
|
|
418
|
-
await this.db.createCheckpoint();
|
|
418
|
+
const depth = await this.db.createCheckpoint();
|
|
419
419
|
this.checkpointStack.push(this.nextCheckpointId++);
|
|
420
420
|
const newCheckpointId = this.getCurrentCheckpointId();
|
|
421
421
|
|
|
@@ -424,14 +424,16 @@ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
|
|
|
424
424
|
HintingMerkleWriteOperations.log.trace(
|
|
425
425
|
`[createCheckpoint:${actionCounter}] Checkpoint evolved ${oldCheckpointId} -> ${newCheckpointId} at trees state ${treesStateHash}.`,
|
|
426
426
|
);
|
|
427
|
+
|
|
428
|
+
return depth;
|
|
427
429
|
}
|
|
428
430
|
|
|
429
|
-
public
|
|
430
|
-
throw new Error('
|
|
431
|
+
public commitAllCheckpointsTo(_depth: number): Promise<void> {
|
|
432
|
+
throw new Error('commitAllCheckpointsTo is not supported in HintingMerkleWriteOperations.');
|
|
431
433
|
}
|
|
432
434
|
|
|
433
|
-
public
|
|
434
|
-
throw new Error('
|
|
435
|
+
public revertAllCheckpointsTo(_depth: number): Promise<void> {
|
|
436
|
+
throw new Error('revertAllCheckpointsTo is not supported in HintingMerkleWriteOperations.');
|
|
435
437
|
}
|
|
436
438
|
|
|
437
439
|
public async commitCheckpoint(): Promise<void> {
|
|
@@ -572,7 +574,7 @@ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
|
|
|
572
574
|
return await this.db.close();
|
|
573
575
|
}
|
|
574
576
|
|
|
575
|
-
async [Symbol.
|
|
577
|
+
async [Symbol.asyncDispose](): Promise<void> {
|
|
576
578
|
await this.close();
|
|
577
579
|
}
|
|
578
580
|
|
|
@@ -82,7 +82,7 @@ export class GuardedMerkleTreeOperations implements MerkleTreeWriteOperations {
|
|
|
82
82
|
return this.guardAndPush(() => this.target.close());
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
async [Symbol.
|
|
85
|
+
async [Symbol.asyncDispose](): Promise<void> {
|
|
86
86
|
await this.close();
|
|
87
87
|
}
|
|
88
88
|
getTreeInfo(treeId: MerkleTreeId): Promise<TreeInfo> {
|
|
@@ -134,7 +134,7 @@ export class GuardedMerkleTreeOperations implements MerkleTreeWriteOperations {
|
|
|
134
134
|
): Promise<(BlockNumber | undefined)[]> {
|
|
135
135
|
return this.guardAndPush(() => this.target.getBlockNumbersForLeafIndices(treeId, leafIndices));
|
|
136
136
|
}
|
|
137
|
-
createCheckpoint(): Promise<
|
|
137
|
+
createCheckpoint(): Promise<number> {
|
|
138
138
|
return this.guardAndPush(() => this.target.createCheckpoint());
|
|
139
139
|
}
|
|
140
140
|
commitCheckpoint(): Promise<void> {
|
|
@@ -143,11 +143,11 @@ export class GuardedMerkleTreeOperations implements MerkleTreeWriteOperations {
|
|
|
143
143
|
revertCheckpoint(): Promise<void> {
|
|
144
144
|
return this.guardAndPush(() => this.target.revertCheckpoint());
|
|
145
145
|
}
|
|
146
|
-
|
|
147
|
-
return this.guardAndPush(() => this.target.
|
|
146
|
+
commitAllCheckpointsTo(depth: number): Promise<void> {
|
|
147
|
+
return this.guardAndPush(() => this.target.commitAllCheckpointsTo(depth));
|
|
148
148
|
}
|
|
149
|
-
|
|
150
|
-
return this.guardAndPush(() => this.target.
|
|
149
|
+
revertAllCheckpointsTo(depth: number): Promise<void> {
|
|
150
|
+
return this.guardAndPush(() => this.target.revertAllCheckpointsTo(depth));
|
|
151
151
|
}
|
|
152
152
|
findSiblingPaths<ID extends MerkleTreeId>(
|
|
153
153
|
treeId: ID,
|
|
@@ -25,6 +25,7 @@ import type {
|
|
|
25
25
|
PublicProcessorValidator,
|
|
26
26
|
SequencerConfig,
|
|
27
27
|
} from '@aztec/stdlib/interfaces/server';
|
|
28
|
+
import { type DebugLog, type DebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
28
29
|
import { ProvingRequestType } from '@aztec/stdlib/proofs';
|
|
29
30
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
30
31
|
import {
|
|
@@ -130,7 +131,6 @@ class PublicProcessorTimeoutError extends Error {
|
|
|
130
131
|
*/
|
|
131
132
|
export class PublicProcessor implements Traceable {
|
|
132
133
|
private metrics: PublicProcessorMetrics;
|
|
133
|
-
|
|
134
134
|
constructor(
|
|
135
135
|
protected globalVariables: GlobalVariables,
|
|
136
136
|
private guardedMerkleTree: GuardedMerkleTreeOperations,
|
|
@@ -140,6 +140,7 @@ export class PublicProcessor implements Traceable {
|
|
|
140
140
|
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
141
141
|
private log: Logger,
|
|
142
142
|
private opts: Pick<SequencerConfig, 'fakeProcessingDelayPerTxMs' | 'fakeThrowAfterProcessingTxCount'> = {},
|
|
143
|
+
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
143
144
|
) {
|
|
144
145
|
this.metrics = new PublicProcessorMetrics(telemetryClient, 'PublicProcessor');
|
|
145
146
|
}
|
|
@@ -159,12 +160,13 @@ export class PublicProcessor implements Traceable {
|
|
|
159
160
|
txs: Iterable<Tx> | AsyncIterable<Tx>,
|
|
160
161
|
limits: PublicProcessorLimits = {},
|
|
161
162
|
validator: PublicProcessorValidator = {},
|
|
162
|
-
): Promise<[ProcessedTx[], FailedTx[], Tx[], NestedProcessReturnValues[],
|
|
163
|
-
const { maxTransactions,
|
|
163
|
+
): Promise<[ProcessedTx[], FailedTx[], Tx[], NestedProcessReturnValues[], DebugLog[]]> {
|
|
164
|
+
const { maxTransactions, deadline, maxBlockGas, maxBlobFields, isBuildingProposal } = limits;
|
|
164
165
|
const { preprocessValidator, nullifierCache } = validator;
|
|
165
166
|
const result: ProcessedTx[] = [];
|
|
166
167
|
const usedTxs: Tx[] = [];
|
|
167
168
|
const failed: FailedTx[] = [];
|
|
169
|
+
const debugLogs: DebugLog[] = [];
|
|
168
170
|
const timer = new Timer();
|
|
169
171
|
|
|
170
172
|
let totalSizeInBytes = 0;
|
|
@@ -186,22 +188,23 @@ export class PublicProcessor implements Traceable {
|
|
|
186
188
|
break;
|
|
187
189
|
}
|
|
188
190
|
|
|
189
|
-
// Skip this tx if it'd exceed max block size
|
|
190
191
|
const txHash = tx.getTxHash().toString();
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
192
|
+
|
|
193
|
+
// Skip this tx if its estimated blob fields would exceed the limit.
|
|
194
|
+
// Only done during proposal building: during re-execution we must process the exact txs from the proposal.
|
|
195
|
+
const txBlobFields = tx.getPrivateTxEffectsSizeInFields();
|
|
196
|
+
if (isBuildingProposal && maxBlobFields !== undefined && totalBlobFields + txBlobFields > maxBlobFields) {
|
|
197
|
+
this.log.warn(
|
|
198
|
+
`Skipping tx ${txHash} with ${txBlobFields} fields from private side effects due to blob fields limit`,
|
|
199
|
+
{ txHash, txBlobFields, totalBlobFields, maxBlobFields },
|
|
200
|
+
);
|
|
199
201
|
continue;
|
|
200
202
|
}
|
|
201
203
|
|
|
202
|
-
// Skip this tx if its gas limit would exceed the block gas limit
|
|
204
|
+
// Skip this tx if its gas limit would exceed the block gas limit (either da or l2).
|
|
205
|
+
// Only done during proposal building: during re-execution we must process the exact txs from the proposal.
|
|
203
206
|
const txGasLimit = tx.data.constants.txContext.gasSettings.gasLimits;
|
|
204
|
-
if (maxBlockGas !== undefined && totalBlockGas.add(txGasLimit).gtAny(maxBlockGas)) {
|
|
207
|
+
if (isBuildingProposal && maxBlockGas !== undefined && totalBlockGas.add(txGasLimit).gtAny(maxBlockGas)) {
|
|
205
208
|
this.log.warn(`Skipping processing of tx ${txHash} due to block gas limit`, {
|
|
206
209
|
txHash,
|
|
207
210
|
txGasLimit,
|
|
@@ -241,7 +244,7 @@ export class PublicProcessor implements Traceable {
|
|
|
241
244
|
this.contractsDB.createCheckpoint();
|
|
242
245
|
|
|
243
246
|
try {
|
|
244
|
-
const [processedTx, returnValues] = await this.processTx(tx, deadline);
|
|
247
|
+
const [processedTx, returnValues, txDebugLogs] = await this.processTx(tx, deadline);
|
|
245
248
|
|
|
246
249
|
// Inject a fake processing failure after N txs if requested
|
|
247
250
|
const fakeThrowAfter = this.opts.fakeThrowAfterProcessingTxCount;
|
|
@@ -250,23 +253,9 @@ export class PublicProcessor implements Traceable {
|
|
|
250
253
|
}
|
|
251
254
|
|
|
252
255
|
const txBlobFields = processedTx.txEffect.getNumBlobFields();
|
|
253
|
-
|
|
254
|
-
// If the actual size of this tx would exceed block size, skip it
|
|
255
256
|
const txSize = txBlobFields * Fr.SIZE_IN_BYTES;
|
|
256
|
-
if (maxBlockSize !== undefined && totalSizeInBytes + txSize > maxBlockSize) {
|
|
257
|
-
this.log.debug(`Skipping processed tx ${txHash} sized ${txSize} due to max block size.`, {
|
|
258
|
-
txHash,
|
|
259
|
-
sizeInBytes: txSize,
|
|
260
|
-
totalSizeInBytes,
|
|
261
|
-
maxBlockSize,
|
|
262
|
-
});
|
|
263
|
-
// Need to revert the checkpoint here and don't go any further
|
|
264
|
-
await checkpoint.revert();
|
|
265
|
-
this.contractsDB.revertCheckpoint();
|
|
266
|
-
continue;
|
|
267
|
-
}
|
|
268
257
|
|
|
269
|
-
// If the actual blob fields of this tx would exceed the limit, skip it
|
|
258
|
+
// If the actual blob fields of this tx would exceed the limit, skip it.
|
|
270
259
|
// Note: maxBlobFields already accounts for block end blob fields and previous blocks in checkpoint.
|
|
271
260
|
if (maxBlobFields !== undefined && totalBlobFields + txBlobFields > maxBlobFields) {
|
|
272
261
|
this.log.debug(
|
|
@@ -284,12 +273,34 @@ export class PublicProcessor implements Traceable {
|
|
|
284
273
|
continue;
|
|
285
274
|
}
|
|
286
275
|
|
|
276
|
+
// During re-execution, check if the actual gas used by this tx would push the block over the gas limit.
|
|
277
|
+
// Unlike the proposal-building check (which uses declared gas limits pessimistically before processing),
|
|
278
|
+
// this uses actual gas and stops processing when the limit is exceeded.
|
|
279
|
+
if (
|
|
280
|
+
!isBuildingProposal &&
|
|
281
|
+
maxBlockGas !== undefined &&
|
|
282
|
+
totalBlockGas.add(processedTx.gasUsed.totalGas).gtAny(maxBlockGas)
|
|
283
|
+
) {
|
|
284
|
+
this.log.warn(`Stopping re-execution since tx ${txHash} would push block gas over limit`, {
|
|
285
|
+
txHash,
|
|
286
|
+
txGas: processedTx.gasUsed.totalGas,
|
|
287
|
+
totalBlockGas,
|
|
288
|
+
maxBlockGas,
|
|
289
|
+
});
|
|
290
|
+
await checkpoint.revert();
|
|
291
|
+
this.contractsDB.revertCheckpoint();
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
|
|
287
295
|
// FIXME(fcarreiro): it's ugly to have to notify the validator of nullifiers.
|
|
288
296
|
// I'd rather pass the validators the processedTx as well and let them deal with it.
|
|
289
297
|
nullifierCache?.addNullifiers(processedTx.txEffect.nullifiers.map(n => n.toBuffer()));
|
|
290
298
|
result.push(processedTx);
|
|
291
299
|
usedTxs.push(tx);
|
|
292
300
|
returns = returns.concat(returnValues);
|
|
301
|
+
debugLogs.push(...txDebugLogs);
|
|
302
|
+
|
|
303
|
+
this.debugLogStore.storeLogs(processedTx.hash.toString(), txDebugLogs);
|
|
293
304
|
|
|
294
305
|
totalPublicGas = totalPublicGas.add(processedTx.gasUsed.publicGas);
|
|
295
306
|
totalBlockGas = totalBlockGas.add(processedTx.gasUsed.totalGas);
|
|
@@ -314,14 +325,10 @@ export class PublicProcessor implements Traceable {
|
|
|
314
325
|
// 1. At least one outstanding checkpoint that has not been committed (the one created before we processed the tx).
|
|
315
326
|
// 2. Possible state updates on that checkpoint or any others created during execution.
|
|
316
327
|
|
|
317
|
-
//
|
|
318
|
-
//
|
|
319
|
-
//
|
|
320
|
-
await checkpoint.
|
|
321
|
-
|
|
322
|
-
// Now we want to revert any/all remaining checkpoints, destroying any outstanding state updates.
|
|
323
|
-
// This needs to be done directly on the underlying fork as the guarded fork has been stopped.
|
|
324
|
-
await this.guardedMerkleTree.getUnderlyingFork().revertAllCheckpoints();
|
|
328
|
+
// Revert all checkpoints at or above this checkpoint's depth (inclusive), destroying any outstanding state
|
|
329
|
+
// updates from this tx and any nested checkpoints created during execution. This preserves any checkpoints
|
|
330
|
+
// created by callers below our depth.
|
|
331
|
+
await checkpoint.revertToCheckpoint();
|
|
325
332
|
|
|
326
333
|
// Revert any contracts added to the DB for the tx.
|
|
327
334
|
this.contractsDB.revertCheckpoint();
|
|
@@ -333,9 +340,9 @@ export class PublicProcessor implements Traceable {
|
|
|
333
340
|
break;
|
|
334
341
|
}
|
|
335
342
|
|
|
336
|
-
// Roll back state to start of TX before proceeding to next TX
|
|
337
|
-
|
|
338
|
-
await
|
|
343
|
+
// Roll back state to start of TX before proceeding to next TX.
|
|
344
|
+
// Reverts all checkpoints at or above this checkpoint's depth, preserving any caller checkpoints below.
|
|
345
|
+
await checkpoint.revertToCheckpoint();
|
|
339
346
|
this.contractsDB.revertCheckpoint();
|
|
340
347
|
const errorMessage = err instanceof Error || err instanceof AssertionError ? err.message : 'Unknown error';
|
|
341
348
|
this.log.warn(`Failed to process tx ${txHash.toString()}: ${errorMessage} ${err?.stack}`);
|
|
@@ -363,7 +370,7 @@ export class PublicProcessor implements Traceable {
|
|
|
363
370
|
totalSizeInBytes,
|
|
364
371
|
});
|
|
365
372
|
|
|
366
|
-
return [result, failed, usedTxs, returns,
|
|
373
|
+
return [result, failed, usedTxs, returns, debugLogs];
|
|
367
374
|
}
|
|
368
375
|
|
|
369
376
|
private async checkWorldStateUnchanged(
|
|
@@ -383,8 +390,13 @@ export class PublicProcessor implements Traceable {
|
|
|
383
390
|
}
|
|
384
391
|
|
|
385
392
|
@trackSpan('PublicProcessor.processTx', tx => ({ [Attributes.TX_HASH]: tx.getTxHash().toString() }))
|
|
386
|
-
private async processTx(
|
|
387
|
-
|
|
393
|
+
private async processTx(
|
|
394
|
+
tx: Tx,
|
|
395
|
+
deadline: Date | undefined,
|
|
396
|
+
): Promise<[ProcessedTx, NestedProcessReturnValues[], DebugLog[]]> {
|
|
397
|
+
const [time, [processedTx, returnValues, debugLogs]] = await elapsed(() =>
|
|
398
|
+
this.processTxWithinDeadline(tx, deadline),
|
|
399
|
+
);
|
|
388
400
|
|
|
389
401
|
this.log.verbose(
|
|
390
402
|
!tx.hasPublicCalls()
|
|
@@ -407,7 +419,7 @@ export class PublicProcessor implements Traceable {
|
|
|
407
419
|
},
|
|
408
420
|
);
|
|
409
421
|
|
|
410
|
-
return [processedTx, returnValues ?? []];
|
|
422
|
+
return [processedTx, returnValues ?? [], debugLogs];
|
|
411
423
|
}
|
|
412
424
|
|
|
413
425
|
private async doTreeInsertionsForPrivateOnlyTx(processedTx: ProcessedTx): Promise<void> {
|
|
@@ -441,10 +453,9 @@ export class PublicProcessor implements Traceable {
|
|
|
441
453
|
private async processTxWithinDeadline(
|
|
442
454
|
tx: Tx,
|
|
443
455
|
deadline: Date | undefined,
|
|
444
|
-
): Promise<[ProcessedTx, NestedProcessReturnValues[] | undefined]> {
|
|
445
|
-
const innerProcessFn: () => Promise<[ProcessedTx, NestedProcessReturnValues[] | undefined]> =
|
|
446
|
-
? () => this.processTxWithPublicCalls(tx)
|
|
447
|
-
: () => this.processPrivateOnlyTx(tx);
|
|
456
|
+
): Promise<[ProcessedTx, NestedProcessReturnValues[] | undefined, DebugLog[]]> {
|
|
457
|
+
const innerProcessFn: () => Promise<[ProcessedTx, NestedProcessReturnValues[] | undefined, DebugLog[]]> =
|
|
458
|
+
tx.hasPublicCalls() ? () => this.processTxWithPublicCalls(tx) : () => this.processPrivateOnlyTx(tx);
|
|
448
459
|
|
|
449
460
|
// Fake a delay per tx if instructed (used for tests)
|
|
450
461
|
const fakeDelayPerTxMs = this.opts.fakeProcessingDelayPerTxMs;
|
|
@@ -512,7 +523,7 @@ export class PublicProcessor implements Traceable {
|
|
|
512
523
|
@trackSpan('PublicProcessor.processPrivateOnlyTx', (tx: Tx) => ({
|
|
513
524
|
[Attributes.TX_HASH]: tx.getTxHash().toString(),
|
|
514
525
|
}))
|
|
515
|
-
private async processPrivateOnlyTx(tx: Tx): Promise<[ProcessedTx, undefined]> {
|
|
526
|
+
private async processPrivateOnlyTx(tx: Tx): Promise<[ProcessedTx, undefined, DebugLog[]]> {
|
|
516
527
|
const gasFees = this.globalVariables.gasFees;
|
|
517
528
|
const transactionFee = computeTransactionFee(gasFees, tx.data.constants.txContext.gasSettings, tx.data.gasUsed);
|
|
518
529
|
|
|
@@ -537,13 +548,13 @@ export class PublicProcessor implements Traceable {
|
|
|
537
548
|
|
|
538
549
|
await this.contractsDB.addNewContracts(tx);
|
|
539
550
|
|
|
540
|
-
return [processedTx, undefined];
|
|
551
|
+
return [processedTx, undefined, []];
|
|
541
552
|
}
|
|
542
553
|
|
|
543
554
|
@trackSpan('PublicProcessor.processTxWithPublicCalls', tx => ({
|
|
544
555
|
[Attributes.TX_HASH]: tx.getTxHash().toString(),
|
|
545
556
|
}))
|
|
546
|
-
private async processTxWithPublicCalls(tx: Tx): Promise<[ProcessedTx, NestedProcessReturnValues[]]> {
|
|
557
|
+
private async processTxWithPublicCalls(tx: Tx): Promise<[ProcessedTx, NestedProcessReturnValues[], DebugLog[]]> {
|
|
547
558
|
const timer = new Timer();
|
|
548
559
|
|
|
549
560
|
const result = await this.publicTxSimulator.simulate(tx);
|
|
@@ -581,7 +592,7 @@ export class PublicProcessor implements Traceable {
|
|
|
581
592
|
revertReason,
|
|
582
593
|
);
|
|
583
594
|
|
|
584
|
-
return [processedTx, appLogicReturnValues];
|
|
595
|
+
return [processedTx, appLogicReturnValues, result.logs ?? []];
|
|
585
596
|
}
|
|
586
597
|
|
|
587
598
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Logger, type LoggerBindings, createLogger
|
|
1
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import { sleep } from '@aztec/foundation/sleep';
|
|
3
3
|
import { type CancellationToken, avmSimulate, cancelSimulation, createCancellationToken } from '@aztec/native';
|
|
4
4
|
import { ProtocolContractsList } from '@aztec/protocol-contracts';
|
|
@@ -100,8 +100,7 @@ export class CppPublicTxSimulator extends PublicTxSimulator implements PublicTxS
|
|
|
100
100
|
inputBuffer,
|
|
101
101
|
contractProvider,
|
|
102
102
|
wsCppHandle,
|
|
103
|
-
|
|
104
|
-
// TODO: re-enable logging
|
|
103
|
+
this.log.level,
|
|
105
104
|
undefined,
|
|
106
105
|
this.cancellationToken,
|
|
107
106
|
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Logger, type LoggerBindings, createLogger
|
|
1
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import { avmSimulateWithHintedDbs } from '@aztec/native';
|
|
3
3
|
import {
|
|
4
4
|
AvmCircuitInputs,
|
|
@@ -75,7 +75,7 @@ export class CppPublicTxSimulatorHintedDbs extends PublicTxSimulator implements
|
|
|
75
75
|
|
|
76
76
|
let resultBuffer: Buffer;
|
|
77
77
|
try {
|
|
78
|
-
resultBuffer = await avmSimulateWithHintedDbs(inputBuffer,
|
|
78
|
+
resultBuffer = await avmSimulateWithHintedDbs(inputBuffer, this.log.level);
|
|
79
79
|
} catch (error: any) {
|
|
80
80
|
throw new SimulationError(`C++ hinted simulation failed: ${error.message}`, []);
|
|
81
81
|
}
|
|
@@ -19,10 +19,11 @@ export function createPublicTxSimulatorForBlockBuilding(
|
|
|
19
19
|
globalVariables: GlobalVariables,
|
|
20
20
|
telemetryClient: TelemetryClient,
|
|
21
21
|
bindings?: LoggerBindings,
|
|
22
|
+
collectDebugLogs = false,
|
|
22
23
|
) {
|
|
23
24
|
const config = PublicSimulatorConfig.from({
|
|
24
25
|
skipFeeEnforcement: false,
|
|
25
|
-
collectDebugLogs
|
|
26
|
+
collectDebugLogs,
|
|
26
27
|
collectHints: false,
|
|
27
28
|
collectPublicInputs: false,
|
|
28
29
|
collectStatistics: false,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { ProtocolContractAddress, ProtocolContractsList } from '@aztec/protocol-contracts';
|
|
@@ -199,8 +199,8 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
199
199
|
|
|
200
200
|
// Such transactions should be filtered by GasTxValidator.
|
|
201
201
|
assert(
|
|
202
|
-
context.getActualGasUsed().l2Gas <=
|
|
203
|
-
`Transaction consumes ${context.getActualGasUsed().l2Gas} L2 gas, which exceeds the
|
|
202
|
+
context.getActualGasUsed().l2Gas <= MAX_PROCESSABLE_L2_GAS,
|
|
203
|
+
`Transaction consumes ${context.getActualGasUsed().l2Gas} L2 gas, which exceeds the maximum processable gas of ${MAX_PROCESSABLE_L2_GAS}`,
|
|
204
204
|
);
|
|
205
205
|
await this.payFee(context);
|
|
206
206
|
|