Skip to content

feat(script): check a serialized witness-data byte cap - #317

Merged
RobinLinus merged 1 commit into
solving-bitcoin:mainfrom
brenorb:codex/witness-data-byte-cap
Nov 9, 2026
Merged

RobinLinus merged 1 commit into
solving-bitcoin:mainfrom
brenorb:codex/witness-data-byte-cap

Conversation

@brenorb

@brenorb brenorb commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Result

Adds support::witness_data_size::verify_data_witness_size_at_most(items, cap). It measures a fixed opaque data suffix as a standalone serialized witness vector and preserves both caller stacks. If the public cap is below CompactSizeWidth(items) + items + 253, every accepted item must have a one-byte length prefix, so the generated script can omit all long-prefix checks.

Items Cap Data fixture Selected leaf / executed ops / peak Always conditional leaf / executed ops / peak Data witness bytes Hint items
32 161 Four bytes each 199 / 146 / 35 487 / 274 / 36 161 0
32 286 Four bytes each 455 / 306 / 36 487 / 274 / 36 161 0
32 1062 Lengths 252, 253, 520, then empty 455 / 306 / 36 487 / 276 / 36 1062 0
253 256 Empty items 1763 / 1141 / 256 4040 / 2153 / 257 256 0

All leaves include the cap check and identical cleanup. Witness bytes exclude the leaf, control block, annex and transaction. Executed non-push counts include visited branch delimiters. The evidence is locally reproduced with unclassified execution.

The weak short-prefix-only schedule accepts a 258-byte vector at cap 256. The final exact schedule rejects it at 256 and 257. The tests also pin the 997-item tight and 996-item exact combined-stack frontiers.

Verification

  • Focused CompactSize, hostile witness, and combined-stack checks
  • Exact metric snapshots, python3 tools/kb.py validate, cargo fmt --all -- --check, and git diff --check
  • cargo test --locked -- --skip fields::

@brenorb
brenorb marked this pull request as ready for review November 6, 2026 09:50
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T09:58:17.939391Z 41d0f09 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 41d0f09078

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread knowledge/catalog.json
"bip-144",
"bitcoin-core-v30.3-regtest",
"bitcoin-script-locked",
"bitcoin-scriptexec-locked"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Reference the interpreter actually used for the new measurements

The new tests resolve the patched interpreter at a09e87af (Cargo.lock:312–314), but this source ID points to historical ba96bc2 in knowledge/references/sources.json:111–115. That version is documented in NR-043 as missing witness-entry and transient-push resource checks exercised by this primitive's boundary tests, so it is not valid provenance for the reported strict-stack evidence. Replace it with the existing bitcoin-scriptexec-csv-20260920 reference to meet AGENTS.md's immutable-source recording requirement.

AGENTS.md reference: AGENTS.md:L52-L52

Useful? React with 👍 / 👎.

@RobinLinus
RobinLinus merged commit 23243d9 into solving-bitcoin:main Nov 9, 2026
3 checks passed
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.

2 participants