Skip to content

update libsimplicity to cad9a63292ea8fdd5c1615e0322986f6f996d42f #296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

apoelstra
Copy link
Collaborator

Updates libsimplicity for the recent refactorings for the elements/bitcoin split, and also to a commit that uses the new Haskell deps so that I can run my local CI on it.

@apoelstra apoelstra force-pushed the 2025-07/libsimplicity branch from 1940dab to ad7a60b Compare July 10, 2025 20:50
@apoelstra
Copy link
Collaborator Author

The clippy CI failure is expected and is because we're running clippy on an unpinned stable version. I will fix this in a followup commit (but I need to do this one first because my nix-based test infrastructure is not working, because I updated nixpkgs to no longer contain the Haskell deps for the old version of upstream, and I need those in order to build upstream to check that the vendored files are checked in correctly).

No other CI failures are expected (if you see any you can wait til I fix them).

@apoelstra
Copy link
Collaborator Author

I will need a couple of hours -- the current failures are because our fuzztests now use multiple incompatible versions of simplicity-sys, and we haven't separated their symbol names properly.

There are actually only two changes here:

* In vendor-simplicity.sh I added a couple `sed` lines to search-and-replace
  simplicity_ symbols with rustsimplicity_X_y_ ones, then re-ran the script.
* In src/tests/ffi.rs I added a bunch of #[link_name] attributes to compensate.

One way to test this is to rename all the 0_4s to 0_3s e.g. with

    find . -exec sed -i s/_0_4_/_0_3_/g {} \;

Then re-run vendor-simplicity.sh and see that your `git diff` has become empty.
@apoelstra apoelstra force-pushed the 2025-07/libsimplicity branch from ad7a60b to ff51b90 Compare July 14, 2025 22:18
@apoelstra
Copy link
Collaborator Author

Will open a separate PR with the first several commits of this. But want to get CI passing here first.

The process here was:

* Manually replace c_X with c_v0_3_X everywhere (actually only in two files,
  wrapper.h and jets_ffi.rs)
* Run update_jets.sh and make sure it changes all the 0_3s to 0_4s.

Note that now both update_jets.sh and vendor-simplicity.sh update wrapper.h.
This is fine since the change is idempotent. But we really should clean up
and combine these two scripts one of these days..

The 0_3 test is easy to do during review, though if you are on NixOS then replace
the cabal build/exec lines by first nix-building the `haskell` target in Simplicity
and then directly calling result/bin/GenRustJets in there.
As before, I first manually added _0_3_ version numbers, modified the vendoring
script, ran it, and made sure that the resulting diff added 0_4s and worked.
This field tells Cargo what library we're linking in, and helps it
provide sane error messages (rather than linker spew) when somebody
tries to compile multiple versions of the library that link the
same thing.

When we provide a links field we should also provide a build field.
This is set to build.rs by default, but crate2nix seems to get confused
when one is present but not the other.
Here I did the bare minimum renaming in the rest of the library to get
things to compile. This was in three files:

* in simplicity-sys/build.rs I had to tweak some paths
* In simplicity-sys/depend/jets_wrapper.c I had to tweak a path
* In simplicity-sys/depend/env.c tweaked some paths, added typedefs, and
  updated the signature of c_set_txEnv based on the same function in env.c
  from Haskell/cbits in libsimpliciity.

THEN in order for the tests to pass and not segfault, I had to implement
three API changes in simplicity-sys/src/tests/ffi.rs (and update the call
sites in simplicity-sys/src/tests/mod.rs):

* simplicity_decodeMallocDag now takes a callback
* simplicity_mallocTypeInference now takes a callback (and defining this
  callback required adding bindings for a bunch of aux types, annoyingly)
* SimplicityErr adds a new OVERWEIGHT variant (and extends the unit tests
  to hit this)

Rust being extremely agressive about UB in unsafe code, by dropping any
of the three of these you can get very weird-looking segfaults (e.g. an
immediate jump to a null address with no backtrace, for the missing enum
variant but a unit test that creates in from C code).

Anyway, I tried to minimize this diff but wasn't totally successful. The
next commits do the "rest" of the upgrade work, which consists of a bunch
of mechanical renaming.
We leave txEnv alone because that's what's done in Haskell/cbits. When
we add the 'bitcoin' feature we will figure out exactly what we're
supposed to do here.
@apoelstra apoelstra force-pushed the 2025-07/libsimplicity branch from f6a8a32 to 421d47d Compare July 21, 2025 03:16
@apoelstra apoelstra marked this pull request as draft July 21, 2025 12:35
@apoelstra
Copy link
Collaborator Author

Blocked on BlockstreamResearch/simplicity#304

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