Skip to content

Mempool: per-peer accounting for failed PQC verification time #275

Closed

Description

@djh58

Description updated on 2026-11-10 to consolidate #259 and #332 here. The original description is kept unchanged at the end.

Problem

A P2MR spend whose PQC (SLH-DSA) signature is invalid costs the receiving node a full signature verification before the transaction is rejected. This holds for transaction signatures (OP_CHECKSIGPQC) and for data signatures (OP_CHECKDATASIGPQC, OP_CHECKDATASIGADDPQC).

  • Cost. About 1.7–2.2 ms per failed verification of a ~3.75 KB witness, or about 0.5 µs of message-handler and cs_main time per witness byte (Review finding: OP_CHECKDATASIGPQC failures bypass the PQC signature cache #259, script: cache verified P2MR data-signature checks (v1.0.1) #265). The tx handler in src/net_processing.cpp takes cs_main before ProcessTransaction, and the mempool script checks (MemPoolAccept::PolicyScriptChecks in src/validation.cpp) run inline on the message-handler thread.
  • Repeats. The failing script does not consume the spent output, so the same spend can be resubmitted in mutated transactions (Review finding: OP_CHECKDATASIGPQC failures bypass the PQC signature cache #259). Each mutated copy has a new wtxid, so the reject filter does not stop it, and each copy is verified again in full.
  • Not cached. The signature cache stores verified successes only (CachingTransactionSignatureChecker::VerifyPQCSignature and VerifyPQCDataSignature in src/script/sigcache.cpp).
  • No peer penalty. A transaction failure never leads to disconnection or discouragement ("Tx failures never trigger disconnections/bans" in CheckInputScripts, src/validation.cpp; there is no transaction Misbehaving call in src/net_processing.cpp). This behaviour is inherited from Bitcoin Core 30.

At about 0.5 µs per witness byte, a peer sending about 2 MB/s of such witness data can keep the message-handler thread and cs_main busy, which delays block and transaction processing for every other peer.

Already fixed

Neither change caches failures, so neither lowers the cost of invalid signatures. The original description below says #265 added a failure cache. It did not, and byte-identical resubmissions were already stopped by the wtxid reject filter (#332).

Open scope

Bound the validation time that one peer can make the node spend on transactions that are rejected, in particular transactions with invalid PQC signatures on either signature path. The target is 1.x.x. The 1.1.0 branch does not have #265 yet (#310).

Proposed direction

  • Measure the time spent validating each transaction received from a peer that is rejected for a reason in the transaction itself (a script or signature failure, or a consensus or standardness failure), and charge it to that peer. This includes transactions from tx messages, orphan reconsideration and package evaluation.
  • Charge measured time rather than a count of failures, so the budget follows the actual work whichever check failed.
  • Give each peer a budget that refills over time. While a peer is over its budget, stop validating its transactions until the budget has refilled, instead of disconnecting or discouraging it. That keeps peers that run a different policy version connected.
  • Keep noban and manually added peers exempt, as for other misbehaviour handling.
  • Report the per-peer figures in getpeerinfo.

Caching failures is not enough on its own:

  • As script: cache verified P2MR data-signature checks (v1.0.1) #265 records, distinct invalid signatures can be derived freely. A cache of failed checks keyed on the exact signature bytes would only stop exact repeats.
  • A cache keyed without the signature bytes, for example on the message and key only, would also reject a later valid signature for the same message and key, so it cannot be used.

Related

Original description (2026-11-02)

Follow-up to #259. The failure cache added with #265 helps only byte-identical resubmissions. It does not lower the rate at which a peer can have the node run full PQC verifications that fail.

In the measured case, each failure costs about 1.7 ms of cs_main time per ~3.75 KB of witness. A transaction-level failure carries no peer penalty (validation.cpp:2252; no transaction Misbehaving in net_processing.cpp).

Bounding that needs local policy, such as per-peer accounting of failed PQC verification time in mempool acceptance, with throttling or disconnection past a budget. This is a design decision for the maintainers, so no code is attached.

Activity

  1. kiwidream commented on Nov 10, 2026

    @kiwidream
    Member

    Updated the description to consolidate #259 and #332 here. It now corrects what #265 does (it caches verified successes only), states the open scope and adds a proposed direction. The original text is kept at the end of the description. #332 is closed as a duplicate of this issue.

  2. kiwidream commented on Nov 12, 2026

    @kiwidream
    Member

    Fixed on 1.x.x by #386 (993521799e), with its follow-ups #422 (2f2ad3e7cd) and #425 (a7a70660ad), which ship in v1.0.1. What the "Open scope" asked for is in:

    • The node measures the time it spends validating a peer's transactions that are then rejected for a reason in the transaction itself (tx messages, orphan reconsideration and packages) and charges that time to the peer.
    • Each peer has a budget that refills. A peer over its budget is not disconnected or discouraged: its transactions are not validated until the budget has refilled, and what it announced or sent meanwhile is requested from it afterwards.
    • Peers with the noban permission and manual connections are exempt.
    • getpeerinfo reports failed_tx_validation_time, tx_validation_throttled and tx_dropped_while_throttled.

    Tests: tx_validation_budget_tests, peerman_tests/tx_validation_budget_* and p2p_tx_validation_budget.py. The deferred review findings stay open in #401.

    Closing by hand, because a merge into 1.x.x does not close issues automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions