Skip to content

Materialize exact raw bytes from canonical ScriptNums - #313

Merged
RobinLinus merged 1 commit into
solving-bitcoin:mainfrom
brenorb:codex/raw-scriptnum-byte-adapter
Nov 9, 2026
Merged

RobinLinus merged 1 commit into
solving-bitcoin:mainfrom
brenorb:codex/raw-scriptnum-byte-adapter

Conversation

@brenorb

@brenorb brenorb commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Result

Adds arithmetic::byte_encoding::numeric_to_raw_byte(). It verifies a canonical ScriptNum in 0 through 255 and returns exactly one raw byte. Values from 129 through 255 use the canonical negative result of 128 - x. The two zero-magnitude cases select explicit raw literals for 00 and 80.

Numeric input Schedule Native-hash leaf bytes Serialized data witness bytes Ordinary items Hint items Combined peak Executed non-push ops
0x00 Sign-magnitude 72 2 1 0 4 20
0x00 High-half table 391 2 1 0 4 19
0xc8 Sign-magnitude 72 4 1 0 4 22
0xc8 High-half table 391 4 1 0 129 86

Both complete leaves hash the raw output with native SHA-256, check the same expected digest, and leave true. Witness bytes exclude script, control block, annex and transaction. Evidence is locally reproduced with unclassified execution.

All 256 values are checked by exact output equality and an independent host digest under both local profiles. Directly hashing the numeric representations of 0, 128 or 255 fails the one-byte digest predicates. Other tests check malformed witnesses and the combined-stack frontier.

Verification

  • Focused exhaustive byte and hash checks and metric tests
  • python3 tools/kb.py validate and cargo fmt --all -- --check
  • cargo test --locked -- --skip fields::

@brenorb
brenorb marked this pull request as ready for review November 6, 2026 09:10
@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:16:21.352064Z 81f98fa 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 cd6b801 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