Research·Protocol

What a Bitcoin Signature Actually Commits To

Signing a Bitcoin input does not sign the transaction. It signs a digest built from a chosen subset of it, and the chooser is the signer. That subset is what makes assurance contracts and collaborative transactions possible, and getting it wrong is how people hand over blank cheques.

Level
Advanced
Reading
8 min
Published
2026-11-24
Reviewed
2026-11-24

A Bitcoin signature authorises a specific set of facts about a transaction, and the signer picks which facts. That choice is encoded in one byte appended to the signature, and almost every interesting multi-party construction in Bitcoin depends on it — as do several of the more spectacular ways to lose money.

What does the flag select?

Which inputs and which outputs are covered by the digest the signature authorises.

Four behaviours matter. ALL covers every input and every output: the transaction is fixed, and any change invalidates the signature. This is the default and what almost every payment uses.

NONE covers the inputs and none of the outputs. The signer is saying “these coins may be spent” and nothing about where they go. Whoever holds the partially signed transaction may direct the money anywhere.

SINGLE covers the inputs and exactly one output — the one at the same index as the input being signed. The signer fixes their own payment and leaves the rest open.

ANYONECANPAY is a modifier combined with any of the above. It restricts the input coverage to just this one input, so others may be added freely.

Taproot adds a fifth value, DEFAULT, which behaves as ALL but is encoded as the absence of a byte. It saves one byte per signature and is what a normal Taproot spend uses.

What are the strange ones for?

Collaborative transactions where participants commit at different times.

SINGLE combined with ANYONECANPAY is the classic assurance contract. A contributor signs “my input funds this one output” and nothing else, so any number of contributors can add their own input-output pairs, and the transaction becomes valid only when the total is sufficient. Nobody has to trust a coordinator with their money, and a contributor who changes their mind simply never broadcasts.

The same pattern underlies collaborative funding of channels and coinjoin-style constructions where each participant guarantees their own contribution without constraining the others.

NONE is the one with almost no legitimate use. A signature that covers no outputs is an instruction that the coins may be moved anywhere by whoever holds the transaction, which is a blank cheque unless the surrounding protocol constrains it by other means. It exists because the original design enumerated the combinations.

What does the digest actually contain?

A serialisation of the selected fields, hashed twice, with the flag byte appended at the end.

For a SegWit input the components are explicit and worth listing, because they show what a signature is and is not promising: the transaction version, a hash of all input outpoints, a hash of all input sequence numbers, the specific outpoint being spent, the script code of that input, the amount of the output being spent, that input’s sequence number, a hash of all outputs, the lock time, and the flag.

Which of those are included depends on the flag. ANYONECANPAY drops the hashes of all outpoints and all sequences, since only one input is covered. NONE and SINGLE replace the hash of all outputs with either nothing or a hash of one.

The flag byte is appended to the digest before hashing and appended to the signature on the wire, which is how a verifier knows which digest to reconstruct. That is why the last byte of a signature tells you the flag, and why altering it invalidates the signature rather than reinterpreting it.

What is the SIGHASH_SINGLE bug?

A case where the legacy algorithm signs a known constant instead of a transaction, and anyone can then spend the input.

In the original signature hash algorithm, SINGLE signs the output at the same index as the input. If the input’s index is greater than the number of outputs, there is no such output — and rather than failing, the legacy code returns a digest of the integer 1.

The result is a signature over a fixed, publicly known value. Anyone who sees it can reuse it in a transaction of their own construction, because the signature does not commit to anything specific. Coins have been lost to this.

It survives because fixing it in the original script system would have required a consensus change for a case that only bites people who construct transactions by hand. BIP 143 removed it for SegWit inputs by defining the digest differently, and Taproot removed it again. Legacy inputs still behave the old way, which is one of the small permanent hazards in Bitcoin’s history.

Why did SegWit need a new digest?

Two defects: validation cost that grew quadratically, and a digest that did not include the amount.

The first is the serious one. The legacy algorithm re-serialises the transaction for every signature it checks, so a transaction with many inputs does work proportional to the square of its size. BIP 143 cites the measured case: a one-megabyte block normally verified in about two seconds on 2015 hardware, while a one-megabyte transaction with 5,569 signature operations took around twenty-five seconds. That transaction was constructed and mined, and it has a CVE.

BIP 143 fixes it by precomputing reusable midstates — hashes of all inputs, all sequences and all outputs — so each signature reuses that work and the cost becomes linear.

The second defect is quieter and shaped hardware wallets. The legacy digest does not include the value of the output being spent, so a signing device could not know how much it was authorising. It had to be given the full parent transactions to work the amounts out, which for an air-gapped device meant transferring megabytes to sign a payment. Including the amount in the digest means a device can be told the value by an untrusted source: a wrong value produces an invalid signature, so the worst case is a failed transaction rather than a stolen one.

That is the small change behind every modern hardware wallet showing you a fee it can actually vouch for.

What did Taproot change again?

The digest got wider, and the encoding got cheaper.

A Taproot signature commits to more of the context than BIP 143 did, including the amounts and scripts of every input rather than only the one being signed. That closes a class of attack in which a signer is misled about the other inputs of a transaction it is participating in — relevant exactly when multiple parties are involved, which is when sighash flags are interesting in the first place.

The digest also uses tagged hashes, so a value computed for one purpose cannot be reinterpreted as another, and DEFAULT removes the flag byte for the overwhelmingly common case.

The practical rule for anyone building on this: the flag is part of your protocol’s security argument, not a serialisation detail. Silent payments break outright under ANYONECANPAY, because the recipient’s output is derived from the set of inputs and that set must not change after signing. Several other protocols have the same dependency and state it less clearly.

Why is ALL almost always right?

Because anything else leaves part of the transaction open, and open parts need a reason.

A signature with ALL is a complete statement: these coins, to these destinations, with this fee, or nothing. Every other flag removes one of those guarantees in exchange for flexibility that only a multi-party protocol can use. For an ordinary payment there is no counterparty waiting to add anything, so the flexibility buys nothing and the removed guarantee is real.

The failure mode is specific. A signature that does not commit to the outputs commits to a fee of whatever is left over, which means whoever assembles the final transaction decides how much the miner receives — out of your coins. A signature that does not commit to the other inputs can be combined with inputs you never saw, in a transaction you would not have approved.

So the sensible default is the strictest flag that lets the protocol work, chosen deliberately rather than inherited from an example. Wallets get this right by never offering the choice.

Check it yourself

The flag is the last byte of a legacy or SegWit signature. Decode any transaction and look at the end of a signature in the witness or scriptSig:

bitcoin-cli getrawtransaction <txid> true | grep -A4 txinwitness

A signature ending in 01 is ALL — which is nearly all of them. 02 is NONE, 03 is SINGLE, and the high bit set (81, 82, 83) adds ANYONECANPAY. A Taproot key-path signature of exactly 64 bytes has no flag byte at all, which is DEFAULT.

Counting the non-01 signatures across a few recent blocks is a quick way to see how rare the exotic flags are in practice, and how much of Bitcoin’s flexibility goes unused.

What remains uncertain

Whether new flags arrive. SIGHASH_ANYPREVOUT has been specified for years to enable channel designs that re-bind a signature to a different previous output, and it has not activated. Proposals for group-signing flags exist in draft. Each would widen what collaborative protocols can express, and each is waiting behind the same activation question as everything else.

Whether legacy hazards get retired. The SINGLE bug and the quadratic digest both remain reachable through legacy inputs. The consensus cleanup proposal addresses the validation cost; nothing proposes invalidating the bug, and coins sitting in legacy outputs keep the option open indefinitely.

How much of this is understood by the people using it. Wallet software hides the flag entirely and chooses correctly. Protocol developers choose deliberately. The gap is in between — in scripts and tooling written by people who copied a flag from an example — and nothing surfaces the mistake until it costs something.

Sources

Nearby