Skip to content

Followups to #405 #409

Open
Open

Description

@KyrylR

To reduce the scope of #405 and have a discussion on some of the points, I have decided to created an issue describing the leftovers

  1. Add a padding helper for Bitcoin.

#405 only pads with an annex (Cost::get_padding, Cost::get_annex_padding_size).
The draft TapSimplicity rules (BIN-2026-0003) instead pad with one all-zero item at the bottom of the witness stack, which must be minimal.
One byte longer is invalid, and an empty item is valid.
The helper should take the whole witness, say where the item goes, and be selected by name rather than by Cargo features (1 2).

  1. Don't rely on elements implying bitcoin in src/analysis.rs.

U32Weight, its conversions, and now Cost::is_budget_valid and Cost::get_annex_padding_size are all gated on bitcoin only.

The generated simplicity_sys::c_jets::jets_wrapper functions are safe pub fns that dereference raw pointers, so they can be crashed without unsafe (e.g. a CFrameItem with a null edge).
They should be unsafe fn, or not public.

Release simplicity-sys before the next simplicity-lang, and bump the dependency.
simplicity-lang uses the Bitcoin jets_wrapper functions (already on master) and, in its tests, simplicity_sys::tests::BITCOIN_PRIMITIVE_JET_NODE_INC.


Would like to get comments on all of those if possible

Activity

  1. KyrylR commented on Nov 19, 2026

    @KyrylR
    CollaboratorAuthor

    In regard to the (commit TBD):

    // The environment hashes of `Fixture::new()`.
    const TX_HASH: &str = "1032104862fdcc0a976cad6da0fbb47ddd67930a1f83cc7d69a4d5cf6addea69";
    const TAP_ENV_HASH: &str = "c744c712ef26db826c3904d7471bf4d5d1a53fdf7c663a9a5e4d681026f6c06f";
    const SIG_ALL_HASH: &str = "c65d5cff65c29c1417783930350af2045e0ec92d6dfa7f0ff02a4826453c7c8b";

    These were computed outside this crate and outside the C library, by hashing the preimages the C code hashes (bitcoin/env.c, bitcoin/txEnv.c and bitcoin/ops.c) with Python's hashlib.

        import hashlib
    
        H = lambda *parts: hashlib.sha256(b"".join(parts)).digest()
        u32 = lambda n: n.to_bytes(4, "big")
        u64 = lambda n: n.to_bytes(8, "big")
        seq = lambda start: bytes(range(start, start + 32))
        txouts = lambda outs: H(H(*(u64(v) for v, _ in outs)), H(*(H(spk) for _, spk in outs)))
    
        ins = [(seq(0x10), 2, 0xFFFFFFFE), (seq(0x20), 0, 0xFFFFFFFF), (seq(0x30), 1, 0xFFFFFFFD)]
        utxos = [(30000, b"\x51"), (10000, b"\x52" * 2), (20000, b"\x53" * 3)]
        outs = [(25000, b"\x6a"), (34000, b"\x6a" * 2)]
        key = bytes.fromhex("50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0")
    
        inputs = H(
            H(*(txid + u32(vout) for txid, vout, _ in ins)),
            H(*(u32(sequence) for _, _, sequence in ins)),
            H(bytes(len(ins))),  # one zero byte per input without an annex
        )
        tx_hash = H(u32(4), u32(700000), inputs, txouts(outs), txouts(utxos))  # version, lock time
    
        tag = H(b"TapLeaf")
        tapleaf = H(tag, tag, bytes([0xBE, 32]), seq(0xC0))  # leaf version, CMR
        tap_env_hash = H(tapleaf, H(seq(0x70), seq(0x90)), key)  # merkle path
        sig_all_hash = H(tx_hash, tap_env_hash, u32(1))  # input index
        print(tx_hash.hex(), tap_env_hash.hex(), sig_all_hash.hex(), sep="\n")

    Not sure whether we should include it into the code comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions