@aztec/p2p 0.0.1-commit.cb6bed7c2 → 0.0.1-commit.cbf2c2d5d

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.
Files changed (147) hide show
  1. package/README.md +129 -3
  2. package/dest/client/factory.d.ts +1 -1
  3. package/dest/client/factory.d.ts.map +1 -1
  4. package/dest/client/factory.js +19 -7
  5. package/dest/client/p2p_client.d.ts +1 -1
  6. package/dest/client/p2p_client.d.ts.map +1 -1
  7. package/dest/client/p2p_client.js +22 -10
  8. package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +3 -3
  9. package/dest/config.d.ts +13 -1
  10. package/dest/config.d.ts.map +1 -1
  11. package/dest/config.js +20 -0
  12. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +3 -3
  13. package/dest/mem_pools/attestation_pool/attestation_pool.js +3 -3
  14. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +6 -6
  15. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  16. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  17. package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +2 -1
  18. package/dest/mem_pools/tx_pool/priority.d.ts +2 -2
  19. package/dest/mem_pools/tx_pool/priority.d.ts.map +1 -1
  20. package/dest/mem_pools/tx_pool/priority.js +4 -4
  21. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts +1 -1
  22. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  23. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +3 -1
  24. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
  25. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
  26. package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +2 -1
  27. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +7 -5
  28. package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
  29. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +9 -2
  30. package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
  31. package/dest/mem_pools/tx_pool_v2/tx_metadata.js +7 -1
  32. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +4 -2
  33. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
  34. package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +3 -0
  35. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +1 -1
  36. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
  37. package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +19 -5
  38. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +1 -1
  39. package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
  40. package/dest/msg_validators/attestation_validator/attestation_validator.js +5 -4
  41. package/dest/msg_validators/clock_tolerance.d.ts +1 -1
  42. package/dest/msg_validators/clock_tolerance.d.ts.map +1 -1
  43. package/dest/msg_validators/clock_tolerance.js +4 -3
  44. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +1 -1
  45. package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
  46. package/dest/msg_validators/proposal_validator/proposal_validator.js +5 -5
  47. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts +9 -0
  48. package/dest/msg_validators/tx_validator/contract_instance_validator.d.ts.map +1 -0
  49. package/dest/msg_validators/tx_validator/contract_instance_validator.js +48 -0
  50. package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
  51. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  52. package/dest/msg_validators/tx_validator/data_validator.js +35 -2
  53. package/dest/msg_validators/tx_validator/factory.d.ts +23 -4
  54. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
  55. package/dest/msg_validators/tx_validator/factory.js +36 -10
  56. package/dest/msg_validators/tx_validator/gas_validator.d.ts +13 -4
  57. package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
  58. package/dest/msg_validators/tx_validator/gas_validator.js +39 -9
  59. package/dest/msg_validators/tx_validator/phases_validator.d.ts +21 -1
  60. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  61. package/dest/msg_validators/tx_validator/phases_validator.js +28 -1
  62. package/dest/services/encoding.d.ts +5 -1
  63. package/dest/services/encoding.d.ts.map +1 -1
  64. package/dest/services/encoding.js +7 -1
  65. package/dest/services/libp2p/libp2p_service.d.ts +4 -9
  66. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  67. package/dest/services/libp2p/libp2p_service.js +115 -59
  68. package/dest/services/peer-manager/peer_manager.d.ts +1 -1
  69. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  70. package/dest/services/peer-manager/peer_manager.js +4 -2
  71. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +11 -8
  72. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
  73. package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +69 -65
  74. package/dest/services/reqresp/batch-tx-requester/interface.d.ts +3 -2
  75. package/dest/services/reqresp/batch-tx-requester/interface.d.ts.map +1 -1
  76. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts +5 -4
  77. package/dest/services/reqresp/batch-tx-requester/missing_txs.d.ts.map +1 -1
  78. package/dest/services/reqresp/batch-tx-requester/missing_txs.js +13 -7
  79. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +3 -1
  80. package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
  81. package/dest/services/reqresp/batch-tx-requester/peer_collection.js +3 -0
  82. package/dest/services/reqresp/reqresp.d.ts +1 -1
  83. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  84. package/dest/services/reqresp/reqresp.js +17 -9
  85. package/dest/services/tx_collection/fast_tx_collection.d.ts +1 -4
  86. package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
  87. package/dest/services/tx_collection/fast_tx_collection.js +57 -73
  88. package/dest/services/tx_collection/proposal_tx_collector.d.ts +6 -7
  89. package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
  90. package/dest/services/tx_collection/proposal_tx_collector.js +4 -4
  91. package/dest/services/tx_collection/request_tracker.d.ts +53 -0
  92. package/dest/services/tx_collection/request_tracker.d.ts.map +1 -0
  93. package/dest/services/tx_collection/request_tracker.js +84 -0
  94. package/dest/services/tx_collection/slow_tx_collection.js +1 -1
  95. package/dest/services/tx_collection/tx_collection.d.ts +3 -6
  96. package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
  97. package/dest/test-helpers/testbench-utils.d.ts +1 -1
  98. package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
  99. package/dest/test-helpers/testbench-utils.js +22 -3
  100. package/dest/testbench/p2p_client_testbench_worker.js +3 -3
  101. package/package.json +14 -14
  102. package/src/client/factory.ts +34 -11
  103. package/src/client/p2p_client.ts +22 -12
  104. package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +3 -5
  105. package/src/config.ts +33 -0
  106. package/src/mem_pools/attestation_pool/attestation_pool.ts +3 -3
  107. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +6 -6
  108. package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +2 -1
  109. package/src/mem_pools/tx_pool/priority.ts +4 -4
  110. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +3 -1
  111. package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +2 -1
  112. package/src/mem_pools/tx_pool_v2/interfaces.ts +6 -4
  113. package/src/mem_pools/tx_pool_v2/tx_metadata.ts +11 -1
  114. package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +13 -1
  115. package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +20 -5
  116. package/src/msg_validators/attestation_validator/README.md +49 -0
  117. package/src/msg_validators/attestation_validator/attestation_validator.ts +5 -4
  118. package/src/msg_validators/clock_tolerance.ts +4 -3
  119. package/src/msg_validators/proposal_validator/README.md +123 -0
  120. package/src/msg_validators/proposal_validator/proposal_validator.ts +6 -5
  121. package/src/msg_validators/tx_validator/README.md +5 -1
  122. package/src/msg_validators/tx_validator/contract_instance_validator.ts +56 -0
  123. package/src/msg_validators/tx_validator/data_validator.ts +42 -1
  124. package/src/msg_validators/tx_validator/factory.ts +43 -3
  125. package/src/msg_validators/tx_validator/gas_validator.ts +41 -8
  126. package/src/msg_validators/tx_validator/phases_validator.ts +31 -1
  127. package/src/services/encoding.ts +9 -1
  128. package/src/services/libp2p/libp2p_service.ts +108 -70
  129. package/src/services/peer-manager/peer_manager.ts +5 -2
  130. package/src/services/reqresp/README.md +229 -0
  131. package/src/services/reqresp/batch-tx-requester/README.md +46 -7
  132. package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +64 -69
  133. package/src/services/reqresp/batch-tx-requester/interface.ts +2 -1
  134. package/src/services/reqresp/batch-tx-requester/missing_txs.ts +13 -6
  135. package/src/services/reqresp/batch-tx-requester/peer_collection.ts +5 -0
  136. package/src/services/reqresp/reqresp.ts +19 -11
  137. package/src/services/tx_collection/fast_tx_collection.ts +57 -83
  138. package/src/services/tx_collection/proposal_tx_collector.ts +8 -13
  139. package/src/services/tx_collection/request_tracker.ts +127 -0
  140. package/src/services/tx_collection/slow_tx_collection.ts +1 -1
  141. package/src/services/tx_collection/tx_collection.ts +3 -5
  142. package/src/test-helpers/testbench-utils.ts +29 -3
  143. package/src/testbench/p2p_client_testbench_worker.ts +3 -5
  144. package/dest/services/tx_collection/missing_txs_tracker.d.ts +0 -32
  145. package/dest/services/tx_collection/missing_txs_tracker.d.ts.map +0 -1
  146. package/dest/services/tx_collection/missing_txs_tracker.js +0 -27
  147. package/src/services/tx_collection/missing_txs_tracker.ts +0 -52
@@ -62,6 +62,7 @@ export class TxPoolV2Impl {
62
62
  #l2BlockSource: L2BlockSource;
63
63
  #worldStateSynchronizer: WorldStateSynchronizer;
64
64
  #createTxValidator: TxPoolV2Dependencies['createTxValidator'];
65
+ #checkAllowedSetupCalls: TxPoolV2Dependencies['checkAllowedSetupCalls'];
65
66
 
66
67
  // === In-Memory Indices ===
67
68
  #indices: TxPoolIndices = new TxPoolIndices();
@@ -93,6 +94,7 @@ export class TxPoolV2Impl {
93
94
  this.#l2BlockSource = deps.l2BlockSource;
94
95
  this.#worldStateSynchronizer = deps.worldStateSynchronizer;
95
96
  this.#createTxValidator = deps.createTxValidator;
97
+ this.#checkAllowedSetupCalls = deps.checkAllowedSetupCalls;
96
98
 
97
99
  this.#config = { ...DEFAULT_TX_POOL_V2_CONFIG, ...config };
98
100
  this.#archive = new TxArchive(archiveStore, this.#config.archivedTxLimit, log);
@@ -354,6 +356,7 @@ export class TxPoolV2Impl {
354
356
 
355
357
  // Check if already in pool
356
358
  if (this.#indices.has(txHashStr)) {
359
+ this.#log.verbose(`canAddPendingTx: tx ${txHashStr} already in pool`);
357
360
  return 'ignored';
358
361
  }
359
362
 
@@ -362,26 +365,37 @@ export class TxPoolV2Impl {
362
365
  const poolAccess = this.#createPreAddPoolAccess();
363
366
  const preAddResult = await this.#evictionManager.runPreAddRules(meta, poolAccess);
364
367
 
365
- return preAddResult.shouldIgnore ? 'ignored' : 'accepted';
368
+ if (preAddResult.shouldIgnore) {
369
+ this.#log.verbose(`canAddPendingTx: tx ${txHashStr} ignored by pre-add rule`, {
370
+ reason: preAddResult.reason?.message ?? 'no reason provided',
371
+ });
372
+ return 'ignored';
373
+ }
374
+ return 'accepted';
366
375
  }
367
376
 
368
377
  async addProtectedTxs(txs: Tx[], block: BlockHeader, opts: { source?: string }): Promise<void> {
369
378
  const slotNumber = block.globalVariables.slotNumber;
370
379
 
380
+ // Precompute setup-call allow-list flags outside the store transaction
381
+ const allowedFlags = await Promise.all(txs.map(tx => this.#checkAllowedSetupCalls(tx)));
382
+
371
383
  await this.#store.transactionAsync(async () => {
372
- for (const tx of txs) {
384
+ for (let i = 0; i < txs.length; i++) {
385
+ const tx = txs[i];
373
386
  const txHash = tx.getTxHash();
374
387
  const txHashStr = txHash.toString();
375
388
  const isNew = !this.#indices.has(txHashStr);
376
389
  const minedBlockId = await this.#getMinedBlockId(txHash);
377
390
 
378
391
  if (isNew) {
392
+ const meta = await buildTxMetaData(tx, allowedFlags[i]);
379
393
  // New tx - add as mined or protected (callback emitted by #addTx)
380
394
  if (minedBlockId) {
381
- await this.#addTx(tx, { mined: minedBlockId }, opts);
395
+ await this.#addTx(tx, { mined: minedBlockId }, opts, meta);
382
396
  this.#indices.setProtection(txHashStr, slotNumber);
383
397
  } else {
384
- await this.#addTx(tx, { protected: slotNumber }, opts);
398
+ await this.#addTx(tx, { protected: slotNumber }, opts, meta);
385
399
  }
386
400
  } else {
387
401
  // Existing tx - update protection and mined status
@@ -976,7 +990,8 @@ export class TxPoolV2Impl {
976
990
 
977
991
  try {
978
992
  const tx = Tx.fromBuffer(buffer);
979
- const meta = await buildTxMetaData(tx);
993
+ const allowedSetupCalls = await this.#checkAllowedSetupCalls(tx);
994
+ const meta = await buildTxMetaData(tx, allowedSetupCalls);
980
995
  loaded.push({ tx, meta });
981
996
  } catch (err) {
982
997
  this.#log.warn(`Failed to deserialize tx ${txHashStr}, deleting`, { err });
@@ -0,0 +1,49 @@
1
+ # Attestation Validation
2
+
3
+ This module validates `CheckpointAttestation` gossipsub messages. Attestations are signatures from committee members endorsing a checkpoint proposal.
4
+
5
+ **Topic**: `checkpoint_attestation` | **Snappy size limit**: 5 KB
6
+
7
+ ## Stage 1: AttestationValidator (Gossipsub Validation)
8
+
9
+ | # | Rule | Consequence | Severity | File |
10
+ |---|------|-------------|----------|------|
11
+ | 1 | **Slot timeliness**: `currentSlot` or `nextSlot`. Previous slot within 500ms: IGNORE. Older: REJECT. | REJECT or IGNORE | HighToleranceError | `attestation_validator.ts` |
12
+ | 2 | **Attester signature**: `getSender()` must recover valid address | REJECT | LowToleranceError | same |
13
+ | 3 | **Attester in committee**: recovered address in committee for slot | REJECT | HighToleranceError | same |
14
+ | 4 | **Proposer exists**: `getProposerAttesterAddressInSlot` must return defined | REJECT | HighToleranceError | same |
15
+ | 5 | **Proposer signature**: `getProposer()` must recover valid address | REJECT | LowToleranceError | same |
16
+ | 6 | **Proposer matches expected**: recovered proposer = expected for slot | REJECT | HighToleranceError | same |
17
+ | 7 | **NoCommitteeError**: committee unavailable | REJECT | LowToleranceError | same |
18
+
19
+ **Fisherman mode extension** (`FishermanAttestationValidator`): if a checkpoint proposal for the same archive exists in pool, the attestation's `ConsensusPayload` must `.equals()` the stored proposal's payload. On mismatch: REJECT + LowToleranceError.
20
+
21
+ ## Stage 2: Pool Admission
22
+
23
+ | # | Rule | Consequence |
24
+ |---|------|-------------|
25
+ | 8 | Sender recoverable (pool-side) | Silent drop |
26
+ | 9 | Not a duplicate (same slot + proposalId + signer) | IGNORE |
27
+ | 10 | Per-signer cap: `MAX_ATTESTATIONS_PER_SLOT_AND_SIGNER` = 2 | IGNORE |
28
+
29
+ Own attestations added via `addOwnCheckpointAttestations` bypass the per-signer cap.
30
+
31
+ ## Stage 3: Equivocation Detection
32
+
33
+ When a signer's attestation count for a slot reaches exactly 2 (different proposals): `duplicateAttestationCallback` fires -> `WANT_TO_SLASH_EVENT` with `OffenseType.DUPLICATE_ATTESTATION`. Attestation still ACCEPTED and rebroadcast. Callback fires once (not again at count 3+).
34
+
35
+ ## Validation at L1 Checkpoint Submission (Archiver)
36
+
37
+ | Rule | Consequence | File |
38
+ |------|-------------|------|
39
+ | Each attestation must have recoverable signature (or address-only is allowed but does not count toward quorum) | Checkpoint rejected as invalid | `archiver/src/modules/validation.ts` |
40
+ | Attestation at index `i` must correspond to committee member at index `i` | Checkpoint rejected as invalid | same |
41
+ | Valid attestation count >= floor(committee * 2/3) + 1 | Checkpoint rejected as invalid | same |
42
+ | No committee / escape hatch open | Accepted unconditionally | same |
43
+
44
+ Note: `skipValidateCheckpointAttestations` config flag bypasses all archiver attestation validation.
45
+
46
+ ## Gossipsub Topic Scoring
47
+
48
+ P3 enabled with expected messages per slot = `targetCommitteeSize`. Conservative threshold (30% of convergence value). Max P3 penalty = -34 per topic.
49
+
@@ -23,13 +23,14 @@ export class CheckpointAttestationValidator implements P2PValidator<CheckpointAt
23
23
  const slotNumber = message.payload.header.slotNumber;
24
24
 
25
25
  try {
26
- const { currentSlot, nextSlot } = this.epochCache.getCurrentAndNextSlot();
26
+ // Use target slots since proposals target pipeline slots (slot + 1 when pipelining)
27
+ const { targetSlot, nextSlot } = this.epochCache.getTargetAndNextSlot();
27
28
 
28
- if (slotNumber !== currentSlot && slotNumber !== nextSlot) {
29
+ if (slotNumber !== targetSlot && slotNumber !== nextSlot) {
29
30
  // Check if message is for previous slot and within clock tolerance
30
- if (!isWithinClockTolerance(slotNumber, currentSlot, this.epochCache)) {
31
+ if (!isWithinClockTolerance(slotNumber, targetSlot, this.epochCache)) {
31
32
  this.logger.warn(
32
- `Checkpoint attestation slot ${slotNumber} is not current (${currentSlot}) or next (${nextSlot}) slot`,
33
+ `Checkpoint attestation slot ${slotNumber} is not current (${targetSlot}) or next (${nextSlot}) slot`,
33
34
  );
34
35
  return { result: 'reject', severity: PeerErrorSeverity.HighToleranceError };
35
36
  }
@@ -36,10 +36,11 @@ export function isWithinClockTolerance(
36
36
  }
37
37
 
38
38
  // Check how far we are into the current slot (in milliseconds)
39
- const { ts: slotStartTs, nowMs, slot } = epochCache.getEpochAndSlotNow();
39
+ const { ts: slotStartTs, nowMs } = epochCache.getEpochAndSlotNow();
40
+ const targetSlot = epochCache.getTargetSlot();
40
41
 
41
- // Sanity check: ensure the epoch cache's current slot matches the expected current slot
42
- if (slot !== currentSlot) {
42
+ // Sanity check: ensure the epoch cache's target slot matches the expected current slot
43
+ if (targetSlot !== currentSlot) {
43
44
  return false;
44
45
  }
45
46
 
@@ -0,0 +1,123 @@
1
+ # Proposal Validation
2
+
3
+ This module validates `BlockProposal` and `CheckpointProposal` gossipsub messages. Both share the same base `ProposalValidator` (neither subclass overrides `validate()`), with checkpoint-specific logic layered on top in the gossipsub handler.
4
+
5
+ ## BlockProposal
6
+
7
+ **Topic**: `block_proposal` | **Snappy size limit**: 10 MB
8
+
9
+ ### Stage 1: Gossipsub Validation (ProposalValidator)
10
+
11
+ File: `proposal_validator.ts`
12
+
13
+ | # | Rule | Consequence | Severity |
14
+ |---|------|-------------|----------|
15
+ | 1 | **Slot check**: must be `currentSlot` or `nextSlot`. Previous slot within 500ms tolerance: IGNORE. | REJECT | HighToleranceError |
16
+ | 2 | **Signature**: `getSender()` must recover a valid address. If `signedTxs` present, its recovered sender must match. | REJECT | MidToleranceError |
17
+ | 3 | **Txs permitted**: if `disableTransactions`, must have 0 txHashes and 0 embedded txs | REJECT | MidToleranceError |
18
+ | 4 | **Max txs**: `txHashes.length <= maxTxsPerBlock` | REJECT | MidToleranceError |
19
+ | 5 | **Embedded txs in txHashes**: every embedded tx's hash must appear in `txHashes` | REJECT | MidToleranceError |
20
+ | 6 | **Proposer check**: signer must match expected proposer for slot (skipped if committee size = 0) | REJECT | MidToleranceError |
21
+ | 7 | **Tx hash integrity**: each embedded tx's recomputed hash must match declared hash | REJECT | LowToleranceError |
22
+ | 8 | **NoCommitteeError**: epoch cache cannot determine committee | REJECT | LowToleranceError |
23
+
24
+ Deserialization guards: `BlockProposal.fromBuffer` and `SignedTxs.fromBuffer` both enforce `txCount <= MAX_TXS_PER_BLOCK` (65536). Violation -> REJECT + LowToleranceError.
25
+
26
+ ### Stage 2: Mempool (Attestation Pool)
27
+
28
+ | # | Rule | Consequence |
29
+ |---|------|-------------|
30
+ | 9 | **Duplicate**: same archive root already stored | IGNORE (no penalty) |
31
+ | 10 | **Per-position cap**: max 2 proposals per (slot, indexWithinCheckpoint) | REJECT + HighToleranceError |
32
+ | 11 | **Equivocation**: >1 distinct proposal for same (slot, index) | ACCEPT (rebroadcast for detection). At count=2: `duplicateProposalCallback` fires -> slash event (`OffenseType.DUPLICATE_PROPOSAL`, configured via `slashDuplicateProposalPenalty`) |
33
+
34
+ ### Stage 3: Validator-Client Processing (BlockProposalHandler)
35
+
36
+ Only runs on validator nodes. Non-validator nodes use a default handler that triggers tx collection without deep validation.
37
+
38
+ | # | Rule | Failure Reason |
39
+ |---|------|----------------|
40
+ | 12 | Signature re-check | `invalid_proposal` |
41
+ | 13 | ProposalValidator re-run | `invalid_proposal` |
42
+ | 14 | Self-proposal filter | Ignored silently |
43
+ | 15 | Parent block exists (`lastArchive.root` matches known block or genesis) | `parent_block_not_found` |
44
+ | 16 | Parent block slot <= proposal slot | `parent_block_wrong_slot` |
45
+ | 17 | Block number not already in archiver | `block_number_already_exists` |
46
+ | 18 | Checkpoint number consistency (multiple sub-rules for first/non-first blocks) | `invalid_proposal` |
47
+ | 19 | Global variables consistency (non-first block: chainId, version, slot, timestamp, coinbase, feeRecipient, gasFees match parent) | `global_variables_mismatch` |
48
+ | 20 | L1-to-L2 message hash matches `proposal.inHash` | `in_hash_mismatch` |
49
+ | 21 | All txs referenced by `txHashes` obtainable | `txs_not_available` |
50
+ | 22 | **Re-execution**: processed tx count matches `txHashes.length` | `timeout` (ReExTimeoutError) |
51
+ | 23 | **Re-execution**: no failed txs | `failed_txs` (ReExFailedTxsError) -- **SLASHABLE** |
52
+ | 24 | **Re-execution**: archive root and header match proposal | `state_mismatch` (ReExStateMismatchError) -- **SLASHABLE** |
53
+
54
+ **Escape hatch**: during escape hatch periods (`isEscapeHatchOpenAtSlot`), re-execution and slashing are both disabled, and the proposal is rejected locally.
55
+
56
+ **Conditional re-execution**: rules 22-24 only run when at least one condition is true: `fishermanMode` enabled, `slashBroadcastedInvalidBlockPenalty > 0` with `validatorReexecute`, committee membership with `validatorReexecute`, `alwaysReexecuteBlockProposals`, or `blobClient.canUpload()`.
57
+
58
+ **Slashing**: only `state_mismatch` and `failed_txs` trigger on-chain slashing (`OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL`, gated by `slashBroadcastedInvalidBlockPenalty > 0`). Unknown errors during re-execution do NOT slash.
59
+
60
+ **Embedded tx validation**: txs in `signedTxs` are validated via `createTxValidatorForBlockProposalReceivedTxs` (well-formedness only) when stored in the tx pool. Invalid embedded txs are rejected from the pool but do not cause the block proposal itself to be rejected at gossipsub level.
61
+
62
+ ### Gossipsub Topic Scoring
63
+
64
+ | Parameter | Effect |
65
+ |-----------|--------|
66
+ | P4 (invalidMessageDeliveries) | weight = -20, decay over 4 slots |
67
+ | P3 (meshMessageDeliveries) | Enabled only when `expectedBlockProposalsPerSlot > 0` (MBPS mode) |
68
+ | P1/P2 | Only active when P3 is enabled |
69
+
70
+ ---
71
+
72
+ ## CheckpointProposal
73
+
74
+ **Topic**: `checkpoint_proposal` | **Snappy size limit**: 10 MB
75
+
76
+ ### Stage 1: Gossipsub Validation (ProposalValidator)
77
+
78
+ Same `ProposalValidator.validate()` as BlockProposal (shared implementation, neither subclass overrides it). See BlockProposal Stage 1 rules 1-8.
79
+
80
+ ### Stage 2: Embedded Block Proposal Validation (if `lastBlock` present)
81
+
82
+ The checkpoint's embedded `lastBlock` is extracted via `getBlockProposal()` and validated through `BlockProposalValidator.validate()` plus block mempool checks.
83
+
84
+ | Rule | Consequence | File |
85
+ |------|-------------|------|
86
+ | Block proposal must pass `BlockProposalValidator.validate()` | If REJECT: entire checkpoint REJECTED | `libp2p_service.ts` |
87
+ | Block proposal must not exceed per-position cap (2) | Checkpoint REJECTED + HighToleranceError | same |
88
+ | Block equivocation detected (>1 proposals for same slot+index) | Checkpoint REJECTED (block itself is ACCEPT for re-broadcast) | same |
89
+
90
+ ### Stage 3: Mempool (Attestation Pool)
91
+
92
+ | Rule | Consequence | File |
93
+ |------|-------------|------|
94
+ | Duplicate (same archive ID) | IGNORE (no penalty). Embedded block still processed if valid. | `attestation_pool.ts` |
95
+ | Per-slot cap: `MAX_CHECKPOINT_PROPOSALS_PER_SLOT` = 2 | REJECT + HighToleranceError. Embedded block still processed. | same |
96
+
97
+ ### Stage 4: Equivocation Detection
98
+
99
+ When >1 checkpoint proposals exist for same slot (count > 1): ACCEPT (re-broadcast). At count == 2 (exactly): `duplicateProposalCallback` fires. Proposal NOT further processed. Callback fires only once per equivocation pair.
100
+
101
+ ### Stage 5: Validator-Client Consensus Validation
102
+
103
+ Determines whether the validator signs an attestation.
104
+
105
+ | Rule | Consequence | File |
106
+ |------|-------------|------|
107
+ | Escape hatch open | No attestation | `validator-client/src/validator.ts` |
108
+ | Signature invalid (re-check) | No attestation | same |
109
+ | Self-proposal | No attestation (ignored) | same |
110
+ | `feeAssetPriceModifier` outside [-100, +100] bps | No attestation | same |
111
+ | Not in committee (unless fisherman mode) | No attestation | same |
112
+ | Checkpoint header mismatch (computed vs proposal) | No attestation | same |
113
+ | Archive root mismatch | No attestation | same |
114
+ | Epoch out hash mismatch | No attestation | same |
115
+ | Last block not found / not matching | No attestation | same |
116
+ | Already attested to this or earlier slot | No attestation (unless `attestToEquivocatedProposals`) | same |
117
+
118
+ **`skipCheckpointProposalValidation` config**: when true, the re-execution checks (header/archive/epoch hash) are all skipped. Signature, fee modifier, committee, escape hatch, and equivocation checks still apply.
119
+
120
+ ### Gossipsub Topic Scoring
121
+
122
+ P3 enabled with expected rate of 1 message per slot. P4 weight = -20, max P3 penalty = -34 per topic.
123
+
@@ -31,13 +31,14 @@ export class ProposalValidator {
31
31
  /** Validates header-level fields: slot, signature, and proposer. */
32
32
  public async validate(proposal: BlockProposal | CheckpointProposalCore): Promise<ValidationResult> {
33
33
  try {
34
- // Slot check
35
- const { currentSlot, nextSlot } = this.epochCache.getCurrentAndNextSlot();
34
+ // Slot check: use target slots since proposals target pipeline slots (slot + 1 when pipelining)
35
+ const { targetSlot, nextSlot } = this.epochCache.getTargetAndNextSlot();
36
+
36
37
  const slotNumber = proposal.slotNumber;
37
- if (slotNumber !== currentSlot && slotNumber !== nextSlot) {
38
+ if (slotNumber !== targetSlot && slotNumber !== nextSlot) {
38
39
  // Check if message is for previous slot and within clock tolerance
39
- if (!isWithinClockTolerance(slotNumber, currentSlot, this.epochCache)) {
40
- this.logger.warn(`Penalizing peer for invalid slot number ${slotNumber}`, { currentSlot, nextSlot });
40
+ if (!isWithinClockTolerance(slotNumber, targetSlot, this.epochCache)) {
41
+ this.logger.warn(`Penalizing peer for invalid slot number ${slotNumber}`, { targetSlot, nextSlot });
41
42
  return { result: 'reject', severity: PeerErrorSeverity.HighToleranceError };
42
43
  }
43
44
  this.logger.verbose(`Ignoring proposal for previous slot ${slotNumber} within clock tolerance`);
@@ -75,10 +75,12 @@ This validator is invoked on **every** transaction potentially entering the pend
75
75
  - Startup hydration — revalidating persisted non-mined txs on node restart
76
76
 
77
77
  Runs:
78
- - DoubleSpend, BlockHeader, GasLimits, Timestamp
78
+ - DoubleSpend, BlockHeader, GasLimits, Timestamp, AllowedSetupCalls
79
79
 
80
80
  Operates on `TxMetaData` (pre-built by the pool) rather than full `Tx` objects.
81
81
 
82
+ The `AllowedSetupCallsMetaValidator` checks a precomputed boolean flag (`TxMetaData.allowedSetupCalls`) rather than re-running the full `PhasesTxValidator`. This flag is computed by `createCheckAllowedSetupCalls` when the tx first enters the pool (via `addProtectedTxs` or startup hydration), so the pool migration validator can reject txs with disallowed setup calls without needing the full `Tx` object or its dependencies.
83
+
82
84
  ## Individual Validators
83
85
 
84
86
  | Validator | What it checks | Benchmarked verification duration |
@@ -92,6 +94,7 @@ Operates on `TxMetaData` (pre-built by the pool) rather than full `Tx` objects.
92
94
  | `GasTxValidator` | Gas limits are within bounds (delegates to `GasLimitsValidator`), max fee per gas meets current block fees, and fee payer has sufficient FeeJuice balance | 1.02 ms |
93
95
  | `GasLimitsValidator` | Gas limits are >= fixed minimums and <= AVM max processable L2 gas. Used standalone in pool migration; also called internally by `GasTxValidator` | 3–10 us |
94
96
  | `PhasesTxValidator` | Public function calls in setup phase are on the allow list | 10.12–13.12 us |
97
+ | `AllowedSetupCallsMetaValidator` | Checks the precomputed `allowedSetupCalls` flag on `TxMetaData`. Used in pool migration instead of the full `PhasesTxValidator` | — |
95
98
  | `BlockHeaderTxValidator` | Transaction's anchor block hash exists in the archive tree | 98.88 us |
96
99
  | `TxProofValidator` | Client proof verifies correctly | ~250ms |
97
100
 
@@ -108,6 +111,7 @@ Operates on `TxMetaData` (pre-built by the pool) rather than full `Tx` objects.
108
111
  | Gas (balance + limits) | Stage 1 | Optional* | — | Yes | — |
109
112
  | GasLimits (standalone) | — | — | — | — | Yes |
110
113
  | Phases | Stage 1 | Yes | — | Yes | — |
114
+ | AllowedSetupCalls | — | — | — | — | Yes |
111
115
  | BlockHeader | Stage 1 | Yes | — | Yes | Yes |
112
116
  | Proof | Stage 2 | Optional** | Yes | — | — |
113
117
 
@@ -0,0 +1,56 @@
1
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
2
+ import { ContractInstancePublishedEvent } from '@aztec/protocol-contracts/instance-registry';
3
+ import { computeContractAddressFromInstance } from '@aztec/stdlib/contract';
4
+ import {
5
+ TX_ERROR_INCORRECT_CONTRACT_ADDRESS,
6
+ TX_ERROR_MALFORMED_CONTRACT_INSTANCE_LOG,
7
+ type Tx,
8
+ type TxValidationResult,
9
+ type TxValidator,
10
+ } from '@aztec/stdlib/tx';
11
+
12
+ /** Validates that contract instance deployment logs contain correct addresses. */
13
+ export class ContractInstanceTxValidator implements TxValidator<Tx> {
14
+ #log: Logger;
15
+
16
+ constructor(bindings?: LoggerBindings) {
17
+ this.#log = createLogger('p2p:tx_validator:contract_instance', bindings);
18
+ }
19
+
20
+ async validateTx(tx: Tx): Promise<TxValidationResult> {
21
+ const reason = await this.#hasCorrectContractInstanceAddresses(tx);
22
+ return reason ? { result: 'invalid', reason: [reason] } : { result: 'valid' };
23
+ }
24
+
25
+ async #hasCorrectContractInstanceAddresses(tx: Tx): Promise<string | undefined> {
26
+ const privateLogs = tx.data.getNonEmptyPrivateLogs();
27
+ for (const log of privateLogs) {
28
+ if (!ContractInstancePublishedEvent.isContractInstancePublishedEvent(log)) {
29
+ continue;
30
+ }
31
+
32
+ let event;
33
+ try {
34
+ event = ContractInstancePublishedEvent.fromLog(log);
35
+ } catch (e) {
36
+ this.#log.warn(`Rejecting tx ${tx.getTxHash()}: failed to parse contract instance event: ${e}`);
37
+ return TX_ERROR_MALFORMED_CONTRACT_INSTANCE_LOG;
38
+ }
39
+
40
+ try {
41
+ const instance = event.toContractInstance();
42
+ const computedAddress = await computeContractAddressFromInstance(instance);
43
+ if (!computedAddress.equals(instance.address)) {
44
+ this.#log.warn(
45
+ `Rejecting tx ${tx.getTxHash()}: contract instance address mismatch. Claimed ${instance.address}, computed ${computedAddress}`,
46
+ );
47
+ return TX_ERROR_INCORRECT_CONTRACT_ADDRESS;
48
+ }
49
+ } catch (e) {
50
+ this.#log.warn(`Rejecting tx ${tx.getTxHash()}: failed to compute contract instance address: ${e}`);
51
+ return TX_ERROR_MALFORMED_CONTRACT_INSTANCE_LOG;
52
+ }
53
+ }
54
+ return undefined;
55
+ }
56
+ }
@@ -1,5 +1,7 @@
1
1
  import { MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS } from '@aztec/constants';
2
2
  import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
3
+ import { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-registry';
4
+ import { computeContractClassId } from '@aztec/stdlib/contract';
3
5
  import { computeCalldataHash } from '@aztec/stdlib/hash';
4
6
  import {
5
7
  TX_ERROR_CALLDATA_COUNT_MISMATCH,
@@ -9,7 +11,9 @@ import {
9
11
  TX_ERROR_CONTRACT_CLASS_LOG_LENGTH,
10
12
  TX_ERROR_CONTRACT_CLASS_LOG_SORTING,
11
13
  TX_ERROR_INCORRECT_CALLDATA,
14
+ TX_ERROR_INCORRECT_CONTRACT_CLASS_ID,
12
15
  TX_ERROR_INCORRECT_HASH,
16
+ TX_ERROR_MALFORMED_CONTRACT_CLASS_LOG,
13
17
  Tx,
14
18
  type TxValidationResult,
15
19
  type TxValidator,
@@ -26,7 +30,8 @@ export class DataTxValidator implements TxValidator<Tx> {
26
30
  const reason =
27
31
  (await this.#hasCorrectHash(tx)) ??
28
32
  (await this.#hasCorrectCalldata(tx)) ??
29
- (await this.#hasCorrectContractClassLogs(tx));
33
+ (await this.#hasCorrectContractClassLogs(tx)) ??
34
+ (await this.#hasCorrectContractClassIds(tx));
30
35
  return reason ? { result: 'invalid', reason: [reason] } : { result: 'valid' };
31
36
  }
32
37
 
@@ -127,4 +132,40 @@ export class DataTxValidator implements TxValidator<Tx> {
127
132
 
128
133
  return undefined;
129
134
  }
135
+
136
+ async #hasCorrectContractClassIds(tx: Tx): Promise<string | undefined> {
137
+ const contractClassLogs = tx.getContractClassLogs();
138
+ for (const log of contractClassLogs) {
139
+ if (!ContractClassPublishedEvent.isContractClassPublishedEvent(log)) {
140
+ continue;
141
+ }
142
+
143
+ let event;
144
+ try {
145
+ event = ContractClassPublishedEvent.fromLog(log);
146
+ } catch (e) {
147
+ this.#log.warn(`Rejecting tx ${tx.getTxHash()}: failed to parse contract class event: ${e}`);
148
+ return TX_ERROR_MALFORMED_CONTRACT_CLASS_LOG;
149
+ }
150
+
151
+ try {
152
+ const { publicBytecodeCommitment } = await event.toContractClassPublicWithBytecodeCommitment();
153
+ const computedClassId = await computeContractClassId({
154
+ artifactHash: event.artifactHash,
155
+ privateFunctionsRoot: event.privateFunctionsRoot,
156
+ publicBytecodeCommitment,
157
+ });
158
+ if (!computedClassId.equals(event.contractClassId)) {
159
+ this.#log.warn(
160
+ `Rejecting tx ${tx.getTxHash()}: contract class id mismatch. Claimed ${event.contractClassId}, computed ${computedClassId}`,
161
+ );
162
+ return TX_ERROR_INCORRECT_CONTRACT_CLASS_ID;
163
+ }
164
+ } catch (e) {
165
+ this.#log.warn(`Rejecting tx ${tx.getTxHash()}: failed to compute contract class id: ${e}`);
166
+ return TX_ERROR_MALFORMED_CONTRACT_CLASS_LOG;
167
+ }
168
+ }
169
+ return undefined;
170
+ }
130
171
  }
@@ -53,12 +53,13 @@ import type { TxMetaData } from '../../mem_pools/tx_pool_v2/tx_metadata.js';
53
53
  import { AggregateTxValidator } from './aggregate_tx_validator.js';
54
54
  import { ArchiveCache } from './archive_cache.js';
55
55
  import { type ArchiveSource, BlockHeaderTxValidator } from './block_header_validator.js';
56
+ import { ContractInstanceTxValidator } from './contract_instance_validator.js';
56
57
  import { DataTxValidator } from './data_validator.js';
57
58
  import { DoubleSpendTxValidator, type NullifierSource } from './double_spend_validator.js';
58
59
  import { GasLimitsValidator, GasTxValidator } from './gas_validator.js';
59
60
  import { MetadataTxValidator } from './metadata_validator.js';
60
61
  import { NullifierCache } from './nullifier_cache.js';
61
- import { PhasesTxValidator } from './phases_validator.js';
62
+ import { AllowedSetupCallsMetaValidator, PhasesTxValidator } from './phases_validator.js';
62
63
  import { SizeTxValidator } from './size_validator.js';
63
64
  import { TimestampTxValidator } from './timestamp_validator.js';
64
65
  import { TxPermittedValidator } from './tx_permitted_validator.js';
@@ -97,6 +98,7 @@ export function createFirstStageTxValidationsForGossipedTransactions(
97
98
  txsPermitted: boolean,
98
99
  allowedInSetup: AllowedElement[] = [],
99
100
  bindings?: LoggerBindings,
101
+ gasLimitOpts?: { rollupManaLimit?: number; maxBlockL2Gas?: number; maxBlockDAGas?: number },
100
102
  ): Record<string, TransactionValidator> {
101
103
  const merkleTree = worldStateSynchronizer.getCommitted();
102
104
 
@@ -158,6 +160,7 @@ export function createFirstStageTxValidationsForGossipedTransactions(
158
160
  ProtocolContractAddress.FeeJuice,
159
161
  gasFees,
160
162
  bindings,
163
+ gasLimitOpts,
161
164
  ),
162
165
  severity: PeerErrorSeverity.MidToleranceError,
163
166
  },
@@ -165,6 +168,10 @@ export function createFirstStageTxValidationsForGossipedTransactions(
165
168
  validator: new DataTxValidator(bindings),
166
169
  severity: PeerErrorSeverity.MidToleranceError,
167
170
  },
171
+ contractInstanceValidator: {
172
+ validator: new ContractInstanceTxValidator(bindings),
173
+ severity: PeerErrorSeverity.MidToleranceError,
174
+ },
168
175
  };
169
176
  }
170
177
 
@@ -216,6 +223,7 @@ function createTxValidatorForMinimumTxIntegrityChecks(
216
223
  ),
217
224
  new SizeTxValidator(bindings),
218
225
  new DataTxValidator(bindings),
226
+ new ContractInstanceTxValidator(bindings),
219
227
  new TxProofValidator(verifier, bindings),
220
228
  );
221
229
  }
@@ -278,6 +286,9 @@ export function createTxValidatorForAcceptingTxsOverRPC(
278
286
  timestamp,
279
287
  blockNumber,
280
288
  txsPermitted,
289
+ rollupManaLimit,
290
+ maxBlockL2Gas,
291
+ maxBlockDAGas,
281
292
  }: {
282
293
  l1ChainId: number;
283
294
  rollupVersion: number;
@@ -287,6 +298,9 @@ export function createTxValidatorForAcceptingTxsOverRPC(
287
298
  timestamp: UInt64;
288
299
  blockNumber: BlockNumber;
289
300
  txsPermitted: boolean;
301
+ rollupManaLimit: number;
302
+ maxBlockL2Gas?: number;
303
+ maxBlockDAGas?: number;
290
304
  },
291
305
  bindings?: LoggerBindings,
292
306
  ): TxValidator<Tx> {
@@ -313,11 +327,16 @@ export function createTxValidatorForAcceptingTxsOverRPC(
313
327
  new BlockHeaderTxValidator(new ArchiveCache(db), bindings),
314
328
  new DoubleSpendTxValidator(new NullifierCache(db), bindings),
315
329
  new DataTxValidator(bindings),
330
+ new ContractInstanceTxValidator(bindings),
316
331
  ];
317
332
 
318
333
  if (!skipFeeEnforcement) {
319
334
  validators.push(
320
- new GasTxValidator(new DatabasePublicStateSource(db), ProtocolContractAddress.FeeJuice, gasFees, bindings),
335
+ new GasTxValidator(new DatabasePublicStateSource(db), ProtocolContractAddress.FeeJuice, gasFees, bindings, {
336
+ rollupManaLimit,
337
+ maxBlockL2Gas,
338
+ maxBlockDAGas,
339
+ }),
321
340
  );
322
341
  }
323
342
 
@@ -403,6 +422,7 @@ export async function createTxValidatorForTransactionsEnteringPendingTxPool(
403
422
  worldStateSynchronizer: WorldStateSynchronizer,
404
423
  timestamp: bigint,
405
424
  blockNumber: BlockNumber,
425
+ gasLimitOpts: { rollupManaLimit?: number; maxBlockL2Gas?: number; maxBlockDAGas?: number },
406
426
  bindings?: LoggerBindings,
407
427
  ): Promise<TxValidator<TxMetaData>> {
408
428
  await worldStateSynchronizer.syncImmediate();
@@ -419,9 +439,29 @@ export async function createTxValidatorForTransactionsEnteringPendingTxPool(
419
439
  },
420
440
  };
421
441
  return new AggregateTxValidator<TxMetaData>(
422
- new GasLimitsValidator<TxMetaData>(bindings),
442
+ new GasLimitsValidator<TxMetaData>({ ...gasLimitOpts, bindings }),
423
443
  new TimestampTxValidator<TxMetaData>({ timestamp, blockNumber }, bindings),
424
444
  new DoubleSpendTxValidator<TxMetaData>(nullifierSource, bindings),
425
445
  new BlockHeaderTxValidator<TxMetaData>(archiveSource, bindings),
446
+ new AllowedSetupCallsMetaValidator<TxMetaData>(bindings),
426
447
  );
427
448
  }
449
+
450
+ /**
451
+ * Creates a function that checks whether a tx's setup-phase calls are on the allow list.
452
+ *
453
+ * Uses the `PhasesTxValidator` on the full Tx. The result is stored as a boolean
454
+ * flag in `TxMetaData.allowedSetupCalls` at receipt time, so the pending pool
455
+ * migration validator can check it without needing the full Tx or its dependencies.
456
+ */
457
+ export function createCheckAllowedSetupCalls(
458
+ contractDataSource: ContractDataSource,
459
+ setupAllowList: AllowedElement[],
460
+ getTimestamp: () => UInt64,
461
+ ): (tx: Tx) => Promise<boolean> {
462
+ return async (tx: Tx) => {
463
+ const validator = new PhasesTxValidator(contractDataSource, setupAllowList, getTimestamp());
464
+ const result = await validator.validateTx(tx);
465
+ return result.result === 'valid';
466
+ };
467
+ }