Skip to content

Decode canonical CompactSize from separate raw byte items - #324

Merged
RobinLinus merged 1 commit into
solving-bitcoin:mainfrom
brenorb:codex/compactsize-raw-decoder
Nov 9, 2026
Merged

RobinLinus merged 1 commit into
solving-bitcoin:mainfrom
brenorb:codex/compactsize-raw-decoder

Conversation

@brenorb

@brenorb brenorb commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Decode canonical CompactSize values through 65,535 when the token already occupies separate raw byte items. The fragment verifies exact byte shape and minimal wire form, preserves caller state, and returns a canonical ScriptNum. It uses no hints.

The comparison keeps dispatch, decoded output, and the complete leaf predicate fixed. The numeric-byte baseline uses canonical ScriptNums for the logical bytes. Witness bytes below count the data-item count and length-prefixed data only. The stack column includes the main and alt stacks. Executed non-push operations include control delimiters processed by the pinned local interpreter.

Value Byte items Leaf bytes Data witness bytes Data items Hint items Peak Executed
0 Raw 139 3 1 0 3 38
0 Numeric 77 2 1 0 4 16
128 Raw 141 3 1 0 3 40
128 Numeric 79 4 1 0 4 16
253 Raw 141 7 3 0 5 67
253 Numeric 79 8 3 0 5 42
32,768 Raw 142 7 3 0 5 64
32,768 Numeric 80 8 3 0 5 42
65,535 Raw 142 7 3 0 5 72
65,535 Numeric 80 10 3 0 5 42

Each raw leaf adds 62 bytes. The largest measured data-witness saving is three bytes, and raw zero is one byte larger. Raw 80 directly interpreted as a ScriptNum is negative zero and loses its wire value. The separate negative-result page covers that counterexample and the size tradeoff. The pinned Bitcoin Core v30.3 reader supplies the minimal-encoding rule. #313 converts in the other direction, and #317 accounts for witness serialization.

Evidence is locally reproduced with unclassified execution. The local tests compare all 65,536 accepted values with host serialization, exercise representative boundary values under both local profiles, reject malformed tokens, and check the exact 1,000-item combined frontier. Focused tests, metric snapshots, knowledge validation, formatting, and diff checks passed. The required full non-field suite also passed on this exact commit.

@brenorb
brenorb marked this pull request as ready for review November 6, 2026 11:12
@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-06T11:16:25.791387Z c2209b7 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.

@RobinLinus
RobinLinus merged commit 8737dda 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