Skip to content

fix(consensus): count CHECKDATASIG as a signature operation (policy now, consensus dormant) - #7848

Draft
PastaPastaPasta wants to merge 3 commits into
dashpay:developfrom
PastaPastaPasta:codex/security-checkdatasig-sigops
Draft

PastaPastaPasta wants to merge 3 commits into
dashpay:developfrom
PastaPastaPasta:codex/security-checkdatasig-sigops

Conversation

@PastaPastaPasta

@PastaPastaPasta PastaPastaPasta commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

CScript::GetSigOpCount counts CHECKSIG and CHECKMULTISIG, but not the DIP0020 opcodes CHECKDATASIG and CHECKDATASIGVERIFY, although each performs one ECDSA verification. A script can run many signature checks while counting zero sigops. For example, a 201-byte script with 99 data-signature checks counts 0. Because of that, none of these bound the work:

  • the P2SH redeem-script standardness limit (MAX_P2SH_SIGOPS)
  • the transaction sigop limit and sigop-adjusted virtual size at mempool admission
  • the block sigop limit

The result is under-accounted verification work during relay and block validation. Spending such outputs needs funded UTXOs and fees, and the scripts must fit the existing script, stack and size limits. No outage has been measured. The point is that sigop limits exist to bound exactly this work, and today these opcodes slip past them.

Counting them in the block limit changes block validity, so that part ships as a dormant, draft deployment. The policy part takes effect immediately.

What was done?

  • CScript::GetSigOpCount (both overloads), GetLegacySigOpCount, GetP2SHSigOpCount and GetTransactionSigOpCount take an opt-in count_data_sigs argument. It defaults to false, which keeps every existing caller and historical count unchanged. When it is set, each CHECKDATASIG / CHECKDATASIGVERIFY counts as one sigop.

  • Policy counts data signatures now:

    • AreInputsStandard (P2SH redeem-script limit)
    • the transaction sigop count stored in the mempool entry, which also feeds the sigop limit and virtual size
    • the mempool stats counter
    • the PSBT size estimate in AnalyzePSBT

    Block assembly budgets from the stored mempool counts, so it now over-counts before activation, which is the safe direction.

  • Consensus: ConnectBlock counts data signatures toward the block limit only when the new signature_work deployment is active at the candidate block. CreateNewBlock counts the coinbase the same way, using the gate for the template's parent. The contextless legacy counts in CheckBlock / ContextualCheckBlock are unchanged.

  • New deployment DEPLOYMENT_SIGNATURE_WORK (signature_work), bit 18, nStartTime = NEVER_ACTIVE on mainnet, testnet, devnet and regtest. nTimeout is deliberately left at its NEVER_ACTIVE default rather than NO_TIMEOUT. CChainParams::IsValidMNActivation accepts unknown bits and deployments outside their start/timeout window, but rejects a known in-window non-EHF deployment. With NO_TIMEOUT, historical MNHF signals on bit 18 would become invalid on reindex.

  • doc/release-notes-7848.md describes the policy change.

  • The RPC deployment enumeration and two count-dependent test fixtures are adjusted, the same as in the other dormant drafts. A deployment with a NEVER_ACTIVE start is hidden from RPC.

Deliberately out of scope: the audit's recommendation also covered routing data-signature checks through the signature checker so that the signature cache applies. Today CPubKey::Verify is called directly. That work will follow in a separate, narrow PR. This PR fixes the accounting only and does not claim to complete the full recommendation.

Bit 18 is a provisional choice. Bits 15–18 are reserved for a set of independent dormant drafts, and each of those branches adds its own enum entry. Whichever of them lands second must keep both entries in consensus/params.h, deploymentinfo.cpp, chainparams.cpp and rpc/blockchain.cpp. Choosing the final bit and an activation schedule needs separate review.

How Has This Been Tested?

macOS arm64, depends build, make -j1.

  • New cases in sigopcount_tests:
    • GetSigOpCountDataSigs: CHECKDATASIG CHECKDATASIGVERIFY CHECKSIG counts 1 by default and 3 with count_data_sigs, in both accurate and inaccurate modes and through a P2SH redeem script.
    • GetTransactionSigOpCountDataSigs: the legacy, P2SH and total counts for a transaction spending a P2SH data-signature script, with and without the argument.
    • P2SHDataSigsAreStandardOnlyWithinSigOpLimit: AreInputsStandard accepts a redeem script with 15 CHECKDATASIGVERIFY and rejects one with 16. With the baseline policy line restored, the 16-signature case is accepted and the test fails.
  • New sigopcount_tests/block_sigop_limit_ignores_data_sigs_while_dormant and block_sigop_limit_counts_data_sigs_once_active (-vbparams=signature_work:-1:-1). Each connects a real block whose transaction output holds one more OP_CHECKDATASIG than the block sigop limit. CheckBlock doesn't count data signatures, so only the gated ConnectBlock count can reject it. The block connects while the gate is dormant and is rejected with bad-blk-sigops once it is active. With the ConnectBlock gate forced off, the active-case test fails.
  • versionbits_tests/signature_work_is_dormant:
    • The deployment is disabled and inactive on all four networks, and its timeout is NEVER_ACTIVE.
    • IsValidMNActivation(18, t) still accepts at time 0, at genesis time and at INT64_MAX.
    • A copied ALWAYS_ACTIVE override activates it, and a copied test-only schedule shows that activation follows the candidate's own branch.
  • ./src/test/test_dash --run_test='sigopcount_tests:versionbits_tests:evo_snapshot_tests:checkdatasig_tests:script_p2sh_tests:transaction_tests:miner_tests:txvalidationcache_tests:dip0020opcodes_tests': 59 cases, no errors. This was the original accounting validation before the two additional ConnectBlock cases. After the coverage-only follow-up, the complete sigopcount_tests suite passes six cases, including both new cases; the broader suites were not repeated.
  • test/functional/mempool_accept.py and test/functional/rpc_blockchain.py: pass.
  • git diff --check, lint-whitespace.py, lint-circular-dependencies.py, lint-includes.py, lint-logs.py: clean.

Limits:

  • The CreateNewBlock coinbase count wiring was checked by reading.
  • No CPU or relay benchmark was run.

Breaking Changes

Policy: a P2SH redeem script with more than 15 signature operations, now including data signatures, is non-standard. Transactions heavy in data signatures also count more sigops toward the transaction limit and virtual size. Consensus: none while dormant.

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

🤖 Generated with Claude Code

@thepastaclaw

thepastaclaw commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

🕓 Review not started yet because this PR is a draft.

  • Request normal review — click when the PR is ready for review.
  • Request priority review — click to move this review to the front of the queue.

Commit d0f79a9. Normal review starts when eligible; priority review starts as soon as a slot is available.

thepastaclaw
thepastaclaw previously approved these changes Oct 7, 2026

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final validation — Phase 1 + Phase 2

The changes preserve historical sigop counts by default, tighten policy immediately, and gate consensus counting on the candidate block’s dormant deployment; deployment parameters, MNHF compatibility, RPC hiding, and regression-test wiring match the stated scope. Independent inspection of the complete three-commit range confirmed no in-scope defects. Validation was static only: the supplied CI snapshot shows the skip-condition check passing, with all other checks queued or pending.

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: dash-core-commit-history); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.1-sol (effort low) — The diff changes consensus sigop accounting in ConnectBlock and policy accounting across several callers, but the opt-in counting and dormant deployment gate are straightforward rather than large or intricate enough to qualify as critical.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity below 15% reserve: weekly 15% left, 5h 100% left), glm-5.3-flash (not used above high effort; tier asks max)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — dash-core-commit-history (completed, effort high); agent phase2-reviewer

@thepastaclaw thepastaclaw added the pastaclaw:approved thepastaclaw's latest review approved this PR label Oct 7, 2026
@github-actions

Copy link
Copy Markdown

This pull request has conflicts, please rebase.

@PastaPastaPasta
PastaPastaPasta force-pushed the codex/security-checkdatasig-sigops branch from eb27a55 to 74a03d2 Compare October 14, 2026 05:02
@thepastaclaw thepastaclaw removed the pastaclaw:approved thepastaclaw's latest review approved this PR label Oct 14, 2026
@github-actions

Copy link
Copy Markdown

This pull request has conflicts, please rebase.

PastaPastaPasta and others added 3 commits October 29, 2026 20:49
CScript::GetSigOpCount counts CHECKSIG and CHECKMULTISIG but not the
DIP0020 opcodes CHECKDATASIG and CHECKDATASIGVERIFY, which each perform
one ECDSA verification. A script can therefore run many signature
checks while counting zero sigops, so neither the per-transaction
standardness limits nor the block sigop limit bound that work.

Add an opt-in count_data_sigs argument to the sigop counters, with the
historical behavior as the default.

- Policy counts data signatures right away: the P2SH redeem script limit
  in AreInputsStandard, the transaction sigop limit and virtual size at
  mempool admission, and the PSBT size estimate. The stored mempool
  counts include them too, so block assembly budgets conservatively.
- ConnectBlock counts them toward the block limit only once the new
  signature_work deployment is active at the candidate block. The
  deployment uses bit 18 and is NEVER_ACTIVE on every network, with the
  timeout also left at NEVER_ACTIVE so that historical MNHF signals on
  bit 18 keep their current acceptance. The contextless CheckBlock and
  ContextualCheckBlock legacy counts are unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A block with one more data signature than the block sigop limit is
accepted while signature_work is dormant and rejected with
bad-blk-sigops once it is active. CheckBlock does not count data
signatures, so only the gated ConnectBlock count can reject it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@PastaPastaPasta
PastaPastaPasta force-pushed the codex/security-checkdatasig-sigops branch from 74a03d2 to d0f79a9 Compare October 30, 2026 01:49
@github-actions

Copy link
Copy Markdown

This pull request has conflicts, please rebase.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants