Skip to content

bitcoin jets: implement Bitcoin jet cost and CMR tables; split cost padding API - #405

Open
delta1 wants to merge 5 commits into
BlockstreamResearch:masterfrom
delta1:pr/bitcoin-jets-cost-padding-cjetptr
Open

delta1 wants to merge 5 commits into
BlockstreamResearch:masterfrom
delta1:pr/bitcoin-jets-cost-padding-cjetptr

Conversation

@delta1

@delta1 delta1 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Includes and supercedes #386 #387 #388

Implements the rest of the Bitcoin jet environment from #331: the cost() and cmr() stubs for Bitcoin jets are replaced with full tables derived from the canonical primitiveJetNode.inc in libsimplicity, covering all 428 jets in the Bitcoin jet set.

Splits Cost::get_padding into a chain-agnostic get_padding_size plus a chain-specific get_padding_bytes. While Elements uses an annex item ([0x50] + zeros), Bitcoin must pad with a plain all-zero stack item.

Also declares the FFI bindings for the env-context Bitcoin jets (with tests exercising them against a real transaction environment) and drops the now-unnecessary Arcs in environments.

Closes the remaining gaps in RedeemNode::prune(): the Rust Bit Machine can now execute Bitcoin jets against a real CTxEnv in order to rewrite dead case branches into asserts.

Draft until I figure out how to resolve this with upstream code generation for simplicity-sys/src/c_jets/c_env/bitcoin.rs

@delta1
delta1 force-pushed the pr/bitcoin-jets-cost-padding-cjetptr branch from a717ac1 to b4cc29f Compare November 10, 2026 10:19
@delta1
delta1 marked this pull request as ready for review November 10, 2026 10:25
@delta1

delta1 commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Rebased to revendor libsimplicity

@stringhandler stringhandler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

utACK b4cc29f

Comment thread src/analysis.rs Resolved
Comment thread CHANGELOG.md Resolved
@stringhandler

Copy link
Copy Markdown
Contributor

ACK b4cc29f; Ran through local tests and fuzzing

@KyrylR KyrylR left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Note

🤖 Claude Opus 5.5 responding on behalf of @KyrylR

Superseded by the inline review: #405 (review)

@KyrylR

KyrylR commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Ran some of my AIs on the PR

This is a pilot test, so if you think that this "batch" is bad and distributing or you would like to see it in a different way, pls let me know for the future

@KyrylR KyrylR left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Note

🤖 Claude Opus 5.5 responding on behalf of @KyrylR

@KyrylR authorized posting this review. It was written by AI reviewers: ten independent reviews of b4cc29f, each in its own worktree. Each inline comment ends with an "Agreed by" line naming the AI reviewers that reported it independently. Opus 5.5 = Claude Opus 5.5 (×2), Mythos = Claude Mythos 5.2, Fable = Claude Fable 5.2, Astra = GPT-6 Astra (×3), Sol = GPT-6.1 Sol (×3).

The generated Bitcoin CMR and cost tables are correct; the padding API and the hand-written FFI block need changes, as described in the 9 inline comments.

Checked and correct:

  • All 428 CMRs and costs match the vendored bitcoin/primitiveJetNode.inc, with 0 mismatches across independent parsers.
  • 3f0bb69..4e0beb5 changes only GenRustJets.hs, and update_jets.sh --check passes.
  • Elements budget and padding results are identical to the old encoder-based code.
  • Tests pass for every feature combination and on MSRV 1.74; clippy -D warnings, fmt and docs are clean.

The tables commit (ffd1c22) could land on its own.

Comment thread src/analysis.rs Resolved
Comment thread src/analysis.rs Resolved
Comment thread src/jet/bitcoin/spec_tests.rs Resolved
Comment thread src/jet/bitcoin/tests.rs Resolved
Comment thread src/analysis.rs Resolved
Comment thread src/analysis.rs Resolved
Comment thread CHANGELOG.md Resolved
Comment thread src/analysis.rs Resolved
@delta1

delta1 commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Pushed some updates for the review comments, feel free to pick this up @KyrylR thanks

@KyrylR KyrylR mentioned this pull request Nov 19, 2026
delta1 and others added 3 commits November 19, 2026 18:09
Update the vendored libsimplicity to 4e0beb5947b7e75ee7974d82a1447e89a0b4b5d6 and regenerate the jet files with update_jets.sh
Co-authored-by: Kyryl R <kyryl.ryabov@gmail.com>
Co-authored-by: Kyryl R <kyryl.ryabov@gmail.com>
@KyrylR
KyrylR force-pushed the pr/bitcoin-jets-cost-padding-cjetptr branch from 43bd4ed to 4c2d1b4 Compare November 19, 2026 16:11
@KyrylR

KyrylR commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

To simplify the scope, I decided to create this #409

Comment thread src/analysis.rs
/// The budget is the serialized size of the witness stack, in weight units, plus 50 weight units.
/// Bitcoin and Elements serialize a witness stack the same way.
/// A CompactSize item count, then each item with a CompactSize length prefix.
#[cfg(feature = "bitcoin")]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It is like so, because in Cargo.toml we have this:
elements = ["dep:elements", "bitcoin"]

delta1 and others added 2 commits November 19, 2026 18:19
Co-authored-by: Kyryl R <kyryl.ryabov@gmail.com>
Co-authored-by: Kyryl R <kyryl.ryabov@gmail.com>
@KyrylR
KyrylR force-pushed the pr/bitcoin-jets-cost-padding-cjetptr branch from 4c2d1b4 to 0d5ffb1 Compare November 19, 2026 16:19
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.

3 participants