rust-bitcoin / rust-bitcoin/rust-miniscript

API improvements suggestions

Open
#545 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
426
Forks
200
Avg merge
7d 17h
Merged PRs (30d)
8

Description

We used miniscript to identify which M of N PubKeys correspond to the M signatures in a spent M of N multisig output, for the P2SH, P2WSH and P2TR (script path) outputs.

I wanted to make two suggestions about potential Miniscript API improvements:

  1. The interpreter.verify_sig() function requires prevouts argument, that is a vector of all outpoints corresponding to all the transaction’s inputs. Only in the case of Taproot the signed message commits to the scriptPubKeys of all outputs spent by the transaction, per BIP 341. Even for the Witness case per BIP 143, only the amount from a single outpoint corresponding to the input being verified is required (and not the whole vector). For the legacy P2SH or bare script cases, no outpoints are required. Preparing this prevouts Vec for all legacy cases is an unnecessary computation in the program that is using the miniscript API.
    We suggest either:

    • making the prevouts argument an enum with three variants: ALL(& [T]) (for taproot), ONE(T) (for witness) or NONE (for legacy)
    • or replacing the interpreter.verify_sig function with three functions interpreter.verify_sig_taproot(), interpreter.verify_sig_witness(), interpreter.verify_sig_legacy().
  2. interpreter.verify_sig() returns false instead of a concrete error. For example, we mistakenly passed a prevouts vector that did not correspond to inputs length. The Error::PrevoutsSize that cache.taproot_script_spend_signature_hash() returned was transformed into false here, and returned.
    It would be desirable to return a Result<bool, sighash::Error> from interpreter.verify_sig(), instead of bool.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/interpreter/mod.rs, especially interpreter.verify_sig() and the linked cache.taproot_script_spend_signature_hash() call. Compare the proposed prevouts API alternatives and Result<bool, sighash::Error> behavior across legacy, witness, and Taproot cases. Done means an agreed API design addresses both suggestions without converting concrete errors into false.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design, cryptography
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.