Repository navigation
bitcoin jets: implement Bitcoin jet cost and CMR tables; split cost padding API #405
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
base: master
Are you sure you want to change the base?
Changes from all commits
ffd1c22
9537b3b
c0bfd57
b4cc29f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,14 @@ | ||
| # Unreleased | ||
|
|
||
| * Fix `RedeemNode::prune` producing programs that consensus rejects, and add `ExecutionError::PruningFailed` [#391](https://github.com/BlockstreamResearch/rust-simplicity/issues/391). | ||
| * Add `Cost::get_padding_size`, returning the chain-agnostic length of the padding witness | ||
| stack item needed to bring a cost within the witness budget, and `Cost::get_padding_bytes`, | ||
| returning the chain-specific bytes that fill it (an all-zero item on Bitcoin, an annex on | ||
| Elements). Deprecate `Cost::get_padding` in favour of these. | ||
| * `Cost::get_budget` and `Cost::is_budget_valid` now take `&[Vec<u8>]` instead of `&Vec<Vec<u8>>` | ||
| and compute the serialized witness length directly rather than via the Elements consensus | ||
| encoder, making them available under the `bitcoin` feature (which `elements` implies) as | ||
| well as `elements`. | ||
|
Comment on lines
+4
to
+11
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note 🤖 Claude Opus 5.5 responding on behalf of @KyrylR In c0bfd57 Minor: this entry is incomplete. It omits the main change: Agreed by: Opus 5.5, Mythos, Fable |
||
|
|
||
| # 0.9.0 - 2026-09-16 | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| # This file has been automatically generated. | ||
| 3f0bb69c4547bcf3483ca5ccbd06699464166650 | ||
| 4e0beb5947b7e75ee7974d82a1447e89a0b4b5d6 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| use hashes::sha256; | ||
|
|
||
| use crate::c_jets::frame_ffi::CFrameItem; | ||
| use crate::ffi::sha256::CSha256Midstate; | ||
| use crate::ffi::{c_size_t, c_uchar, c_uint, c_uint_fast32_t}; | ||
|
|
||
|
|
@@ -108,6 +109,39 @@ extern "C" { | |
| pub fn simplicity_mallocTapEnv(rawEnv: *const CRawTapEnv) -> *mut CTapEnv; | ||
| #[link_name = "rustsimplicity_0_8_bitcoin_mallocTransaction"] | ||
| pub fn simplicity_mallocTransaction(rawTx: *const CRawTransaction) -> *mut CTransaction; | ||
|
|
||
| // Bitcoin jets whose C implementations read the transaction environment. | ||
| // Each has signature `bool f(frameItem* dst, frameItem src, const txEnv* env)` | ||
| // (note `src` is passed *by value*, matching the C definitions in bitcoinJets.c). | ||
| #[link_name = "rustsimplicity_0_8_bitcoin_sig_all_hash"] | ||
| pub fn bitcoin_sig_all_hash(dst: *mut CFrameItem, src: CFrameItem, env: *const CTxEnv) -> bool; | ||
| #[link_name = "rustsimplicity_0_8_bitcoin_check_lock_height"] | ||
| pub fn bitcoin_check_lock_height( | ||
| dst: *mut CFrameItem, | ||
| src: CFrameItem, | ||
| env: *const CTxEnv, | ||
| ) -> bool; | ||
| #[link_name = "rustsimplicity_0_8_bitcoin_check_lock_distance"] | ||
| pub fn bitcoin_check_lock_distance( | ||
| dst: *mut CFrameItem, | ||
| src: CFrameItem, | ||
| env: *const CTxEnv, | ||
| ) -> bool; | ||
| #[link_name = "rustsimplicity_0_8_bitcoin_check_lock_duration"] | ||
| pub fn bitcoin_check_lock_duration( | ||
| dst: *mut CFrameItem, | ||
| src: CFrameItem, | ||
| env: *const CTxEnv, | ||
| ) -> bool; | ||
| #[link_name = "rustsimplicity_0_8_bitcoin_current_index"] | ||
| pub fn bitcoin_current_index(dst: *mut CFrameItem, src: CFrameItem, env: *const CTxEnv) | ||
| -> bool; | ||
| #[link_name = "rustsimplicity_0_8_bitcoin_num_inputs"] | ||
| pub fn bitcoin_num_inputs(dst: *mut CFrameItem, src: CFrameItem, env: *const CTxEnv) -> bool; | ||
| #[link_name = "rustsimplicity_0_8_bitcoin_tx_hash"] | ||
| pub fn bitcoin_tx_hash(dst: *mut CFrameItem, src: CFrameItem, env: *const CTxEnv) -> bool; | ||
| #[link_name = "rustsimplicity_0_8_bitcoin_tap_env_hash"] | ||
| pub fn bitcoin_tap_env_hash(dst: *mut CFrameItem, src: CFrameItem, env: *const CTxEnv) -> bool; | ||
|
Comment on lines
+113
to
+144
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note 🤖 Claude Opus 5.5 responding on behalf of @KyrylR In b4cc29f Major: these 8 declarations, and the wrappers at L173-L198, are unused and conflict with the WASM ABI.
Suggest deleting the block. That also resolves the code-generation question in the PR description. Agreed by: all ten (WASM ABI: Mythos, Fable; segfault: Astra ×3, Sol ×1) |
||
| } | ||
|
|
||
| impl CTxEnv { | ||
|
|
@@ -136,6 +170,33 @@ impl CRawBuffer { | |
| } | ||
| } | ||
|
|
||
| // Safe wrappers around the bitcoin environment jets above. These expose a | ||
| // Rust-safe signature (`&mut CFrameItem`, `&CTxEnv`) that can be used directly | ||
| // as a `JetEnvironment::c_jet_ptr` function pointer, mirroring how the | ||
| // elements backend exposes its jets via the `jets_wrapper` module. We cannot | ||
| // hand out the raw `extern "C"` functions as fn pointers because `c_jet_ptr` | ||
| // returns a safe (non-extern) function pointer. | ||
| macro_rules! bitcoin_env_jet_wrapper { | ||
| ($name:ident, $ffi:ident) => { | ||
| pub fn $name(dst: &mut CFrameItem, src: CFrameItem, env: &CTxEnv) -> bool { | ||
| // SAFETY: we pass valid references through as pointers to a C | ||
| // function that treats them as borrowed (`frameItem* dst`, | ||
| // `const txEnv* env`) and `src` is forwarded by value exactly as | ||
| // the C `frameItem src` parameter expects. | ||
| unsafe { $ffi(dst, src, env) } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| bitcoin_env_jet_wrapper!(sig_all_hash, bitcoin_sig_all_hash); | ||
| bitcoin_env_jet_wrapper!(check_lock_height, bitcoin_check_lock_height); | ||
| bitcoin_env_jet_wrapper!(check_lock_distance, bitcoin_check_lock_distance); | ||
| bitcoin_env_jet_wrapper!(check_lock_duration, bitcoin_check_lock_duration); | ||
| bitcoin_env_jet_wrapper!(current_index, bitcoin_current_index); | ||
| bitcoin_env_jet_wrapper!(num_inputs, bitcoin_num_inputs); | ||
| bitcoin_env_jet_wrapper!(tx_hash, bitcoin_tx_hash); | ||
| bitcoin_env_jet_wrapper!(tap_env_hash, bitcoin_tap_env_hash); | ||
|
|
||
| // Will uncomment in a later commit; need to update libsimplicity first. | ||
| #[cfg(test)] | ||
| mod tests { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LLMs tend to add random information to the CHANGELOG. This is a private method so I'd vote to remove it. Fine to do in follow up.