Skip to content

Update libsimplicity to latest version; add Bitcoin transaction environment - #331

Draft
apoelstra wants to merge 9 commits into
BlockstreamResearch:masterfrom
apoelstra:2025-12/update-libsimplicity
Draft

apoelstra wants to merge 9 commits into
BlockstreamResearch:masterfrom
apoelstra:2025-12/update-libsimplicity

Conversation

@apoelstra

Copy link
Copy Markdown
Collaborator

Draft until BlockstreamResearch/simplicity#324 merges

This updates libsimplicity to the newest version, which has several changes:

  • new Core benchmarks leading to CMR/IMR changes for Core programs
  • a new Bitcoin jet set and transaction environment
  • several improvements to the Jet trait, which need to happen simultaneously in GenRustJets (from libsimplicity) and here

Don't actually build bitcoin yet; just refactor build.rs
For dumb "C polymorphism" reasons we have two structures in the C code named
txEnv. We can call the corresponding Rust structures different things, but
we need to access them from the C file env.c, which provides some C wrappers
for FFI stuff.

Since you can't have two different structs with the same name in one compilation
unit, split it into two.
When we update libsimplicity we will use a new type for the Core environment
rather than directly using (). Then we will need to use CoreEnv::EMPTY as the
value everywhere.

To minimize the later diff, do this change now, where for now we just set
CoreEnv::EMPTY equal to ().
This is the more correct trait. When we update the Jet trait we will
be forced to pick one, and we will pick Borrow.
Updates to BlockstreamResearch/simplicity#324

This PR does a couple things simultaneously:

* Runs vendor-simplicity.sh and update-jets.sh
* Updates the `Jet` trait to have associated transaction and environment types,
  and for the environment to be paramterized by the transaction type.
* Changes the Core environment from () to CoreEnv::<Infallible>
* Updates some fixed Core CMR/IHR vectors (this update to libsimplicity changes
  the benchmarks for the Core jets and thus changes these vectors)
* Uncomments the commented-out symbols in simplicity-sys/src/c_jets/c_env/bitcoin.rs
* Adds the "build bitcoin" lines to simplicity-sys/build.rs

The update to the `Jet` trait is a bit noisy but ultimately mechanical: everywhere
that we're generic over all J: Jet, we now also have to be generic over all
T: Borrow<J::Transaction>, which leads to some extra line noise especially in
unit tests where we have assert_* helper functions.

The last four points are tiny diffs, thanks to the previous preparatory commits.

The use of CoreEnv::<Infallible> as the core environment type is kinda fun. It
means that it is impossible to execute any code which attempts to access the
transaction in the environment. (No such code exists, since it would be nonsensical,
but now we have some assurance that it won't exist by accident in the future.)

Unfortunately this mixes mechanical and non-mechanical things in one commit. But
the mechanical changes are exclusively in simplicity-sys/depend/ and src/jet/init/
and the non-mechanical changes are exclusively outside of those files, so it
should be possible to review this.
Now that we've updated the Jet trait to allow the transactions in environments
to be arbitrary T: Borrow<Transaction>, we don't need to use Arc everywhere.
In many cases we can use normal references.
This is a Rust type which can be used, among other things, to construct
the transaction environment needed by C jets.

Also provides accessors for the underlying transaction and input index,
both of which are used (in the Elements version of this struct) in the
policy satisfier.
@apoelstra
apoelstra marked this pull request as draft December 18, 2025 17:31
@apoelstra

Copy link
Copy Markdown
Collaborator Author

cc @roconnor-blockstream this is a bit Rust-heavy but I think you can usefully review it.

cc @canndrew

This is a draft but I don't expect it to change other than maybe the commit ID of libsimplicity that I use.

delta1 added a commit to delta1/rust-simplicity that referenced this pull request Feb 4, 2026
@delta1 delta1 mentioned this pull request Feb 24, 2026
apoelstra added a commit that referenced this pull request Oct 23, 2026
579d1f9 bitcoin: extract annex per BIP341 instead of Witness::taproot_annex (Byron Hambly)
9aa64bb jet: populate annexes in Bitcoin environment (Andrew Poelstra)
61593d5 jet: implement Rust bitcoin environment (Andrew Poelstra)
738f01c jet: drop unnecessary Arcs in environments (Andrew Poelstra)
09220af jet: generalize JetEnvironment impls to use Borrow<T> (Byron Hambly)
b5e0cbe simplicity-sys: update libsimplicity to 3f0bb69c (Byron Hambly)
f48c90a jet: switch from Deref to Borrow for transaction environments (Andrew Poelstra)
40838c1 simplicity-sys: define bitcoin transaction environment (Andrew Poelstra)
46528e5 simplicity-sys: split env.c into bitcoin_env.c (Byron Hambly)

Pull request description:

  Redux of  #331. 
  
  Covers the same ground: vendoring the bitcoin-env libsimplicity branch and adding the Rust `BitcoinEnv`/`JetEnvironment` plumbing.
  
  Why a new branch instead of updating #331:
  
  - Vendored libsimplicity rev differs: this PR pins `ba967b1a` (the rev shipped with simplicity-lang 0.9.0, already on `master`); 
  - Symbol version differs as a direct consequence: this PR's C/FFI layer targets `rustsimplicity_0_8_*`.
  - `CoreEnv::EMPTY` (added in `b0a25c2`) is not needed or referenced by this series and is intentionally omitted.
  
  Three additional PRs stack on this one: #386 #387 #388


ACKs for top commit:
  stringhandler:
    ACK 579d1f9
  apoelstra:
    ACK 579d1f9; successfully ran local tests


Tree-SHA512: b5618d0cbc85d989da0e6423fcc36dce6bfe7379f6519acdf6bc54759cbc967e434e52e03de20041c56753880c30fbbcfa6847ed7f00183a4045dc96732767e3
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