Checks Bitcoin transactions' signatures from their raw bytes and the outputs they spend, as a
public Esplora API serves them (mempool.space by default), with no node and no library. For each
input, btc-sig-check:
- tells what it spends from the spent output's script: P2PKH, P2WPKH, P2WPKH inside P2SH, multisig in P2WSH, in P2WSH inside P2SH or in P2SH, or a Taproot key;
- rebuilds what was signed, by that output's rules: the legacy signature hash, BIP143's for SegWit v0, or BIP341's for Taproot, under the signature's own hash type;
- verifies the signature: ECDSA through Node's crypto, BIP-340 Schnorr in its own BigInt secp256k1, since Node has none.
Inputs it doesn't check, like Taproot script paths and scripts other than multisig, are counted with why. It exits 1 if a signature doesn't verify.
A block explorer shows that a transaction was signed. Checking the signature takes knowing what
was signed, and that changes with each output type: three signature hash algorithms, six hash
types, and which parts of the transaction each one covers. btc-sig-check rebuilds them all from
the bytes, and shows what each covers on real transactions:
- Legacy signatures don't cover the amount spent. Changing a P2PKH input's amount leaves its signature valid, which is why SegWit's BIP143 added the amount to what's signed.
- A Taproot signature covers every input's amount, not only its own: change any input's, and every Taproot signature without ANYONECANPAY fails, while an ANYONECANPAY one still verifies.
- SINGLE|ANYONECANPAY sells one input for one output: the hash type that ordinals listings sign with, found on Taproot, P2WPKH and P2SH-P2WPKH inputs.
- Pay-to-anchor outputs are everywhere: in block 977,916, 393 of the 2,200 transactions spent a BIP431 pay-to-anchor output, which anyone can spend to bump a transaction's fee. It has no signature.
- Most scripts are multisig: of that block's 176 P2WSH and P2SH script inputs, 151 were plain multisig, 2-of-3 mostly, and every one verified. The other 25 were conditional scripts like Lightning's.
Needs Node 24 or later, and nothing else.
git clone https://github.com/Urthella/btc-sig-check && cd btc-sig-check node src/main.ts --block 977916 --txs 10000
the first 2,200 of block 977,916's 2,200 transactions, 0000000000000000000165a200059fb955efb8bac81fdb1c718b254b2b5c8ea5: 9,601 inputs
P2WPKH: 5,009 of 5,009 inputs verify (ALL 5,008, ALL|ANYONECANPAY 1)
Taproot key path: 1,607 of 1,607 inputs verify (DEFAULT 1,077, ALL 518, SINGLE|ANYONECANPAY 12)
P2PKH: 1,546 of 1,546 inputs verify (ALL 1,545, ALL|ANYONECANPAY 1)
P2WPKH in P2SH: 701 of 701 inputs verify (ALL 701)
P2WSH multisig: 71 of 71 inputs verify (ALL 71)
P2WSH multisig in P2SH: 70 of 70 inputs verify (ALL 70)
P2SH multisig: 10 of 10 inputs verify (ALL 10)
not checked: 393 × a pay-to-anchor output has no signature; 169 × a Taproot script path spend isn't checked; 25 × a P2WSH script other than multisig isn't checked
check: 9,014 of 9,014 inputs verify
--block HEIGHT|HASHpicks the block: the newest by default.--txs Nchecks its first N transactions, 25 to a page of the API: 100 by default, up to 10,000, enough for any block.--tx TXIDchecks transactions by ID instead; repeat it for more.--api URLpicks the Esplora API:https://mempool.space/apiby default.--jsonprints the report as JSON.
Exit codes: 0 when every signature checked verifies, 1 when one doesn't, and 2 when it couldn't check: bytes that don't hash to the transaction asked for, or bad arguments.
- Reads the block's raw bytes, and the outputs each transaction spends from the API's
transaction list. With
--tx, a transaction's raw bytes must hash to its ID. - P2PKH: the scriptSig pushes a signature and a key, the key must hash to the output's key hash, and the signature covers the legacy hash: the transaction with this input's script code and no other input's script. ALL and ALL|ANYONECANPAY are checked.
- P2WPKH, bare or inside P2SH: the witness holds a signature and a key that must hash to the program (inside P2SH, the redeem script must hash to the output's hash too, and be the scriptSig's one push, as BIP141 says), and the signature covers BIP143's hash: the input's own amount, the prevouts, sequences and outputs as the hash type says. ALL, ALL|ANYONECANPAY and SINGLE|ANYONECANPAY are checked.
- Taproot key paths: the witness's one item is a 64-byte signature, DEFAULT, or 65 bytes with its hash type. It's checked against the output's key, over BIP341's tagged hash of every spent amount and script, the transaction and its outputs, as the hash type says. DEFAULT, ALL and SINGLE|ANYONECANPAY are checked; a type BIP341 doesn't define fails.
- Multisig,
OP_m <key>... OP_n OP_CHECKMULTISIG, asOP_CHECKMULTISIGruns it:- an empty dummy item, then m signatures, each verifying against a key after the last one that did, so they must come in the keys' order, and no key counts twice; an empty signature fails;
- in P2WSH, the witness script must hash to the output's program and signatures cover BIP143's hash of it; inside P2SH, the redeem script must hash to the output's hash first, and be the scriptSig's one push;
- in legacy P2SH, the redeem script is the last push and signatures cover the legacy hash. Items under the dummy are allowed, since only a witness script must leave a clean stack, and a dummy that isn't empty, which blocks before SegWit's, 481,824, allowed, is counted as not checked;
- the report counts inputs, not signatures: a multisig input's signatures pass or fail together.
- Only the hash types real signatures showed: each algorithm is checked under the types found on mainnet, so a real signature backs every path. Any other type is counted as not checked.
- Not checked, and counted: Taproot script paths, scripts other than multisig, pay-to-anchor outputs, a Taproot annex, a legacy multisig dummy that isn't empty, and the hash types above.
- The building blocks:
- BIP-340's test vectors, a key off the curve, and a signature built here whose R has an odd y, which must fail though its x matches;
- ECDSA over the double SHA-256 of a preimage, with compressed and uncompressed keys.
- Real transactions, saved with their spent outputs by
scripts/fetch-fixtures.ts: one of each kind and hash type found by scanning blocks 820,000 to 820,002 and 977,914 to 977,916, and the first 25 of block 977,915.- Every saved transaction parses to its own ID, and every signature of a kind this checks verifies.
- Then they're changed: a signature, an empty one, a key or redeem script that doesn't hash to the output, an amount, a 65-byte signature with hash type 0. Each fails where its algorithm says it should, and only there.
- A hash type no mainnet input showed, like NONE or plain SINGLE, is reported as not checked, and one BIP341 doesn't define fails.
- Multisig, 2-of-2, 2-of-3 and 3-of-7, bare, inside P2SH and legacy, verifies. Then: two signatures swapped, one used twice, one too few, one empty, one forged, a dummy that isn't empty, a witness script that doesn't hash to its output, an extra item under the dummy. Each fails, but the extra item still verifies in legacy P2SH, which allows it.
- Inside P2SH, a SegWit program pushed with OP_PUSHDATA1 or after another push fails, and a redeem script other than the three stays unchecked.
- End to end: the CLI runs against a fake Esplora API serving those transactions:
- a block's first transactions, or ones by
--tx, are checked; - a signature that doesn't verify exits 1, and bytes that don't hash to the transaction asked for exit 2;
- a rate-limited API is asked again;
- bad arguments and an unreachable API exit 2.
- a block's first transactions, or ones by
- Mutation testing: forty-eight deliberate bugs were planted one at a time, and the tests caught every one.
- Live, on 2026-11-28: all 9,014 inputs of block 977,916 that this checks verified.
- Signatures, and multisig, only. It doesn't run scripts, so a script other than multisig, or a Taproot script path, isn't checked, and neither are timelocks, whether an output was already spent, or a witness on an input that shouldn't have one.
- The spent outputs come from the API. A legacy signature doesn't commit to the spent amount, but SegWit and Taproot signatures do, so a wrong amount from the API fails them.
- Mainnet's hash types as found: NONE, plain SINGLE, Taproot ALL|ANYONECANPAY and the annex are left unchecked until a real input shows them. In blocks 820,000 to 820,002 and 977,914 to 977,916, none did.
MIT