Repository navigation
fix(consensus): count CHECKDATASIG as a signature operation (policy now, consensus dormant) - #7848
PastaPastaPasta wants to merge 3 commits into
Conversation
|
🕓 Review not started yet because this PR is a draft.
Commit d0f79a9. Normal review starts when eligible; priority review starts as soon as a slot is available. |
thepastaclaw
left a comment
There was a problem hiding this comment.
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:
normalbygpt-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); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-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; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— dash-core-commit-history (completed, effort high); agentphase2-reviewer
|
This pull request has conflicts, please rebase. |
eb27a55 to
74a03d2
Compare
|
This pull request has conflicts, please rebase. |
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]>
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]>
74a03d2 to
d0f79a9
Compare
|
This pull request has conflicts, please rebase. |
Issue being fixed or feature implemented
CScript::GetSigOpCountcountsCHECKSIGandCHECKMULTISIG, but not the DIP0020 opcodesCHECKDATASIGandCHECKDATASIGVERIFY, 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:MAX_P2SH_SIGOPS)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,GetP2SHSigOpCountandGetTransactionSigOpCounttake an opt-incount_data_sigsargument. It defaults tofalse, which keeps every existing caller and historical count unchanged. When it is set, eachCHECKDATASIG/CHECKDATASIGVERIFYcounts as one sigop.Policy counts data signatures now:
AreInputsStandard(P2SH redeem-script limit)AnalyzePSBTBlock assembly budgets from the stored mempool counts, so it now over-counts before activation, which is the safe direction.
Consensus:
ConnectBlockcounts data signatures toward the block limit only when the newsignature_workdeployment is active at the candidate block.CreateNewBlockcounts the coinbase the same way, using the gate for the template's parent. The contextless legacy counts inCheckBlock/ContextualCheckBlockare unchanged.New deployment
DEPLOYMENT_SIGNATURE_WORK(signature_work), bit 18,nStartTime = NEVER_ACTIVEon mainnet, testnet, devnet and regtest.nTimeoutis deliberately left at itsNEVER_ACTIVEdefault rather thanNO_TIMEOUT.CChainParams::IsValidMNActivationaccepts unknown bits and deployments outside their start/timeout window, but rejects a known in-window non-EHF deployment. WithNO_TIMEOUT, historical MNHF signals on bit 18 would become invalid on reindex.doc/release-notes-7848.mddescribes 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_ACTIVEstart 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::Verifyis 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.cppandrpc/blockchain.cpp. Choosing the final bit and an activation schedule needs separate review.How Has This Been Tested?
macOS arm64, depends build,
make -j1.sigopcount_tests:GetSigOpCountDataSigs:CHECKDATASIG CHECKDATASIGVERIFY CHECKSIGcounts 1 by default and 3 withcount_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:AreInputsStandardaccepts a redeem script with 15CHECKDATASIGVERIFYand rejects one with 16. With the baseline policy line restored, the 16-signature case is accepted and the test fails.sigopcount_tests/block_sigop_limit_ignores_data_sigs_while_dormantandblock_sigop_limit_counts_data_sigs_once_active(-vbparams=signature_work:-1:-1). Each connects a real block whose transaction output holds one moreOP_CHECKDATASIGthan the block sigop limit.CheckBlockdoesn't count data signatures, so only the gatedConnectBlockcount can reject it. The block connects while the gate is dormant and is rejected withbad-blk-sigopsonce it is active. With theConnectBlockgate forced off, the active-case test fails.versionbits_tests/signature_work_is_dormant:NEVER_ACTIVE.IsValidMNActivation(18, t)still accepts at time 0, at genesis time and atINT64_MAX.ALWAYS_ACTIVEoverride 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 completesigopcount_testssuite passes six cases, including both new cases; the broader suites were not repeated.test/functional/mempool_accept.pyandtest/functional/rpc_blockchain.py: pass.git diff --check,lint-whitespace.py,lint-circular-dependencies.py,lint-includes.py,lint-logs.py: clean.Limits:
CreateNewBlockcoinbase count wiring was checked by reading.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:
🤖 Generated with Claude Code