Skip to content

consensus: close algo-review C-H1–C-H4 and C-M1–C-M7 - #247

Merged
reardencode merged 14 commits into
masterfrom
consensus/algo-review
Aug 25, 2026
Merged

consensus: close algo-review C-H1–C-H4 and C-M1–C-M7#247
reardencode merged 14 commits into
masterfrom
consensus/algo-review

Conversation

@rearden-grok

@rearden-grok rearden-grok Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes every consensus finding in docs/algo-review.md (C-H1–C-H4, C-M1–C-M7). Each ID is moved to §11 in the same commit as the fix.

High

  • C-H2. script_sigop_count stops on truncated PUSHDATA2/4 ([0x4d, 0xac] → 0).
  • C-H1. BIP342 tapscript validation-weight budget (50 + witness size, −50 per nonempty CHECKSIG*).
  • C-H3. P2SH scriptSig is eval_script + IsPushOnly (OP_1NEGATE accepted; >10 000-byte scriptSig rejected).
  • C-H4. Testnet 20-minute min-difficulty + walk-back to last non-powLimit bits.

Medium

  • C-M1. Empty coinbase vout rejected (no outputs).
  • C-M2. Regtest subsidy halves every 150 blocks.
  • C-M3. P2SH sigops abort on scriptSig opcode > OP_16.
  • C-M7. Witness sigops counted only when segwit is active.
  • C-M4. assemble_run enforces future-time + BIP34/66/65 nVersion on every block (not only headers-first validate_header).
  • C-M6. Signet uses last exact 38-byte BIP141 commitment and Core BLOCK_SCRIPT_VERIFY_FLAGS (P2SH|WITNESS|DERSIG|NULLDUMMY, no CLEANSTACK).
  • C-M5. Script-pool failed is Acquire/Release.

Test plan

  • Targeted cargo test -p rbitcoin-consensus --lib pins named in docs/algo-review.md §11
  • Required GHA: fmt, deny, clippy, test, windows, macos, multinode, coverage

Made with Cursor

rearden-grok Bot added a commit that referenced this pull request Aug 25, 2026
§11 placeholders pointed at this PR; fill the number now that it exists.

Co-authored-by: Cursor <cursoragent@cursor.com>
rearden-grok Bot added a commit that referenced this pull request Aug 25, 2026
PR #247 is dirty against master (#244#246). Take the spent.idx pin
path and other algo-review closures; keep this branch's consensus
fixes.

Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	docs/algo-review.md
rearden-grok Bot and others added 13 commits August 25, 2026 15:11
Core GetOp fails when PUSHDATA2/4 lacks a length field; leftover
bytes must not be counted as CHECKSIG. Matches C-H2.

Co-authored-by: Cursor <cursoragent@cursor.com>
Charge 50 per executed nonempty CHECKSIG/CHECKSIGADD against
50 + witness serialized size. Negative remaining fails, matching
Core EvalChecksigTapscript (C-H1).

Co-authored-by: Cursor <cursoragent@cursor.com>
EvalScript the scriptSig (10k / 520 / 1000 limits) then IsPushOnly,
so OP_1NEGATE is a valid push and oversized scriptSig is rejected
(C-H3). Nested SegWit reuses the same collector.

Co-authored-by: Cursor <cursoragent@cursor.com>
Off-interval headers with time > prev + 2×spacing use powLimit bits;
otherwise walk back to the last non-min-diff block, matching Core
GetNextWorkRequired (C-H4).

Co-authored-by: Cursor <cursoragent@cursor.com>
CheckTransaction requires vout nonempty for every tx including the
coinbase (C-M1). Structure and assemble both enforce it.

Co-authored-by: Cursor <cursoragent@cursor.com>
Core nSubsidyHalvingInterval is 150 on regtest, 210000 elsewhere.
block_subsidy now uses ChainParams (C-M2).

Co-authored-by: Cursor <cursoragent@cursor.com>
Core GetSigOpCount(scriptSig) returns 0 if any opcode is > OP_16.
last_script_push no longer skips those opcodes (C-M3).

Co-authored-by: Cursor <cursoragent@cursor.com>
Core GetTransactionSigOpCost adds BIP141 witness sigops only when
SCRIPT_VERIFY_WITNESS is on. We always added them, so a P2WPKH-shaped
prevout inflated block sigop cost by 1 before the segwit height.

Co-authored-by: Cursor <cursoragent@cursor.com>
Pipelined assemble_run only ran MTP/bits/pow, so a tip-ahead or
multi-block confirm could skip BIP34/66/65 version floors and the
2-hour future-time cap that validate_header already enforced.

Co-authored-by: Cursor <cursoragent@cursor.com>
Signet picked the first OP_RETURN containing aa21a9ed and evaluated
the challenge as Base with CLEANSTACK. Core uses the last exact
38-byte 6a24aa21a9ed output and BLOCK_SCRIPT_VERIFY_FLAGS
(P2SH|WITNESS|DERSIG|NULLDUMMY).

Co-authored-by: Cursor <cursoragent@cursor.com>
Relaxed loads of Wave::failed could let a worker enter after the
publisher observed in_wave == 0 on ARM. Pair Acquire loads with the
Release store; increment-then-check was already in place.

Co-authored-by: Cursor <cursoragent@cursor.com>
§11 placeholders pointed at this PR; fill the number now that it exists.

Co-authored-by: Cursor <cursoragent@cursor.com>
Signet challenge now goes through verify_job_all_inputs, so EvalContext::new
and eval_script_sig_pushes are test-only. Clippy -D warnings rejects the
lib build and the min-diff walk's `h % interval != 0`.

Co-authored-by: Cursor <cursoragent@cursor.com>
@rearden-grok
rearden-grok Bot force-pushed the consensus/algo-review branch from b7c30ba to 700fc71 Compare August 25, 2026 22:16
generate_to_script(300) hit coinbase excess value after C-M2 because
mine_regtest_paying always paid 50 BTC. Use block_subsidy.

Co-authored-by: Cursor <cursoragent@cursor.com>
@reardencode
reardencode merged commit 64b5070 into master Aug 25, 2026
13 checks passed
@rearden-grok
rearden-grok Bot deleted the consensus/algo-review branch August 25, 2026 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant