Bitcoin Sighash Types: How Transaction Signing Authorization Works Under the Hood
SIGHASH_ALL, SIGHASH_NONE, SIGHASH_SINGLE, and ANYONECANPAY: what each flag commits to and how they enable advanced transaction patterns.
Every Bitcoin transaction requires at least one digital signature to authorize spending. But a signature does not blindly commit to the entire transaction: a one-byte flag called the sighash type controls exactly which parts of the transaction the signature covers. Changing this flag changes what a signer authorizes, and what remains open for others to modify.
Most wallets default to SIGHASH_ALL, which locks down every input and output. That is the right choice for simple payments. But Bitcoin supports six sighash combinations (seven with Taproot), and the less common flags unlock powerful multi-party transaction patterns: crowdfunding, collaborative swaps, modular fee bumping, and the pre-signed transaction trees that underpin Layer 2 protocols like Spark and the Lightning Network.
What Signing Actually Means in Bitcoin
A Bitcoin signature does not sign the raw transaction bytes. Instead, the wallet constructs a sighash preimage: a serialized byte string representing the parts of the transaction the signer wants to commit to. This preimage is hashed (double SHA-256 for legacy and SegWit transactions, or a tagged hash for Taproot), and the resulting digest is signed with the private key using ECDSA or Schnorr.
The sighash type byte is appended to the end of the signature in the witness or scriptSig. When a node validates the transaction, it reconstructs the same preimage using the same sighash flag, hashes it, and verifies the signature against the public key. If any committed field has changed, the hash will not match, and the signature fails.
Why not sign everything, always? Signing every field (SIGHASH_ALL) is the safest default, but it makes the transaction rigid. If you want multiple independent parties to contribute inputs, or allow outputs to be added after signing, you need a sighash type that leaves those fields uncommitted. The flag system gives signers granular control over what they authorize.
The Three Base Sighash Types
Bitcoin defines three base sighash types, each identified by a single byte. They differ in which outputs the signature commits to. By default, all three commit to every inputin the transaction.
SIGHASH_ALL (0x01)
The default and most common type. The signature commits to all inputs and all outputs. Any modification to any part of the transaction invalidates it. Virtually every standard Bitcoin payment uses this flag.
- Commits to: all inputs, all outputs
- Leaves open: nothing
- Use case: standard payments where the signer wants complete control
SIGHASH_NONE (0x02)
The signature commits to all inputs but no outputs at all. After signing, anyone who holds the partially signed transaction can attach any outputs they choose. This is functionally a "blank check" on the signed UTXO: the signer authorizes spending the coin but does not specify where it goes.
- Commits to: all inputs
- Leaves open: all outputs
- Use case: delegating destination choice to a co-signer or coordinator
Caution: SIGHASH_NONE is rarely safe in practice. Anyone who intercepts the signed transaction can redirect the funds to their own address. It is primarily useful in multi-party protocols where another participant adds a constrained output before broadcast.
SIGHASH_SINGLE (0x03)
The signature commits to all inputs and exactly one output: the output at the same index as the input being signed. Other outputs can be freely added or modified.
- Commits to: all inputs, one output (same index as the signed input)
- Leaves open: all other outputs
- Use case: swap-style transactions where each party cares only about their own payout
SIGHASH_SINGLE is the foundation of atomic swap constructions. Alice signs input 0 committing to output 0 (her payout), and Bob signs input 1 committing to output 1 (his payout). Neither can alter the other's output, but the transaction only becomes valid when both signatures are present.
The ANYONECANPAY Modifier
ANYONECANPAY (0x80) is not a standalone sighash type. It is a modifier bit that combines with any of the three base types via bitwise OR. When set, the signature commits to only the single input being signed, rather than all inputs. Other participants can add their own inputs without invalidating existing signatures.
This yields three additional combinations, for a total of six sighash types in pre-Taproot Bitcoin:
| Sighash Type | Hex Value | Inputs Committed | Outputs Committed |
|---|---|---|---|
| ALL | 0x01 | All | All |
| NONE | 0x02 | All | None |
| SINGLE | 0x03 | All | Same-index only |
| ALL|ANYONECANPAY | 0x81 | Signed input only | All |
| NONE|ANYONECANPAY | 0x82 | Signed input only | None |
| SINGLE|ANYONECANPAY | 0x83 | Signed input only | Same-index only |
Real-World Use Cases for Each Combination
Crowdfunding with ALL|ANYONECANPAY (0x81)
This is the most practical use of ANYONECANPAY. A fundraiser creates a transaction with fixed outputs (e.g., 1 BTC to a project address) but only one input. Each pledger adds their own input signed with ALL|ANYONECANPAY, which locks the outputs while allowing new inputs. Once total inputs cover the outputs plus fees, anyone can broadcast.
This pattern was proposed for Bitcoin assurance contracts as early as 2012. Mike Hearn's Lighthouse project implemented it, and Armory's wallet supported a similar workflow. The mechanism is trustless: pledgers commit funds only if the total target is reached, because the transaction is invalid until inputs cover outputs.
Fee Bumping with NONE|ANYONECANPAY (0x82)
A signer commits to a single input and no outputs. A coordinator or co-signer can then attach any output and additional inputs. This pattern is niche but appears in protocols where one party provides funds and another determines the destination: for example, a payment processor that batches customer deposits.
In practice, NONE|ANYONECANPAY is the most dangerous combination. The signer has committed to spending a specific coin but has specified neither where it goes nor what other coins are involved. It should only be used within controlled, multi-step signing protocols.
Modular Swaps with SINGLE|ANYONECANPAY (0x83)
Each participant signs one input committing to one output (their own payout), leaving everything else open. Multiple such signed fragments can be assembled into a single transaction. This enables modular, composable transaction construction where parties only need to agree on their own input-output pair.
The PayJoin (BIP 78) protocol leverages similar patterns. Sender and receiver each contribute inputs, making the resulting transaction indistinguishable from a standard multi-input payment: a significant privacy improvement through transaction structure obfuscation.
How the Sighash Preimage Is Constructed
The exact fields included in the preimage depend on both the sighash type and the script version. Bitcoin has three distinct signing algorithms: the legacy algorithm (pre-SegWit), the BIP 143 algorithm (SegWit v0), and the BIP 341 algorithm (Taproot/SegWit v1).
Legacy Signing (Pre-SegWit)
The original algorithm serializes a modified copy of the entire transaction. For each input being signed, the scriptSig of other inputs is replaced with an empty script, and the script of the input being signed is replaced with the scriptPubKey of the UTXO being spent. The sighash type is appended as a 4-byte little-endian integer, and the whole blob is double-SHA256 hashed.
This approach has a critical flaw: hashing cost scales quadratically with the number of inputs. For a transaction with n inputs, each signature requires hashing a preimage that includes all n inputs, producing O(n²) total hash operations. Attackers exploited this to construct transactions that took minutes to validate, motivating the BIP 143 redesign.
BIP 143 Signing (SegWit v0)
BIP 143, authored by Johnson Lau and Pieter Wuille, fixes quadratic hashing by pre-computing three cacheable hash values that can be reused across all inputs in the same transaction:
- hashPrevouts: double SHA-256 of all input outpoints (or zeros if ANYONECANPAY)
- hashSequence: double SHA-256 of all input sequence values (or zeros if ANYONECANPAY, NONE, or SINGLE)
- hashOutputs: double SHA-256 of all outputs (or just the same-index output for SINGLE, or zeros for NONE)
The preimage then serializes these hashes alongside the transaction version, the specific outpoint, scriptCode, input value, sequence number, locktime, and sighash type. Because the three intermediate hashes are computed once and cached, total hashing cost drops from O(n²) to O(n).
BIP 143 also introduced a critical safety improvement: the input value (amount being spent) is included in the signed message. Under legacy signing, the amount was absent, meaning a hardware wallet could be tricked into signing a transaction that spent a larger UTXO than displayed, with the excess going to miner fees.
BIP 341 Signing (Taproot)
BIP 341 further refines the algorithm for Taproot (SegWit v1) spends. The preimage uses tagged hashes (SHA-256 with a domain-separating tag, as defined in BIP 340) under the tag TapSighash. It begins with an epoch byte (currently 0x00), allowing future soft forks to introduce new sighash algorithms without ambiguity.
Key improvements over BIP 143:
- All input amounts and all input scriptPubKeys are committed (not just the current input's), preventing fee-manipulation attacks across inputs
- The spend type byte encodes whether the spend is key-path or script-path, and whether an annex is present
- Tagged hashing eliminates the possibility of cross-protocol hash collisions
- SIGHASH_DEFAULT (0x00) is added, behaving identically to ALL but allowing the sighash byte to be omitted from the signature for a 1-byte savings (64 bytes instead of 65)
| Feature | Legacy | BIP 143 (SegWit v0) | BIP 341 (Taproot) |
|---|---|---|---|
| Hash algorithm | Double SHA-256 | Double SHA-256 | Tagged hash (single SHA-256) |
| Hashing complexity | O(n²) | O(n) | O(n) |
| Signs input amount | No | Current input only | All input amounts |
| Signs input scriptPubKey | No | No | All input scriptPubKeys |
| Epoch/versioning | None | None | Epoch byte (0x00) |
| Default sighash | ALL (0x01) | ALL (0x01) | DEFAULT (0x00) or ALL (0x01) |
| Signature scheme | ECDSA | ECDSA | Schnorr (BIP 340) |
SIGHASH_DEFAULT: Taproot's Implicit Flag
Taproot introduces a seventh sighash value: SIGHASH_DEFAULT (0x00). It is semantically identical to SIGHASH_ALL: the signature commits to all inputs and all outputs. The difference is purely encoding: when using the default, the sighash byte is omitted from the 64-byte Schnorr signature. If any other sighash type is used, the signature is 65 bytes with the type appended.
This optimization saves one byte per signature, which adds up in transactions with many inputs. It also makes the common case simpler: a bare 64-byte signature unambiguously means "I signed everything." BIP 341 restricts the valid Taproot sighash values to 0x00, 0x01, 0x02, 0x03, 0x81, 0x82, and 0x83. Any other value causes validation failure.
The SIGHASH_SINGLE Bug
A notorious historical quirk deserves mention. In the legacy signing algorithm, if a signer uses SIGHASH_SINGLE on an input whose index is greater than or equal to the number of outputs, the hash function returns the constant value 1 (the 256-bit integer 1, left-padded with zeros). Any valid signature for the hash of that constant is accepted by consensus.
This was first reported on the Bitcoin development mailing list in 2012 by Matt Corallo. Because fixing it would constitute a hard fork (invalidating previously valid transactions), the behavior was preserved. Instead, wallet software and the raw transaction API were patched to reject such constructions before broadcast. BIP 143 and BIP 341 both resolve this by explicitly handling the out-of-range case, making it impossible in SegWit and Taproot transactions.
Sighash Types in Layer 2 Protocols
Off-chain protocols rely heavily on pre-signed transactions to enforce rules without broadcasting to the blockchain. The sighash type determines what each pre-signed transaction commits to, and choosing the right flag is fundamental to protocol security.
Lightning Network
Lightning commitment transactions use SIGHASH_ALL to lock both parties' balances into specific outputs. When a channel state updates, both parties exchange signatures on a new commitment transaction. The anchor outputs pattern uses SIGHASH_SINGLE|ANYONECANPAY on certain outputs, allowing either party to attach additional inputs for fee bumping via CPFP without invalidating the commitment signature.
Statechains and Spark
Statechains use pre-signed exit transactions to guarantee that the current owner can always withdraw on-chain. These exit transactions typically use SIGHASH_ALL: they commit to a fixed output paying the current owner, and their timelocks establish a priority ordering so that the most recent owner's exit transaction has the shortest delay.
Spark extends the statechain model with a tree of off-chain transactions. Each leaf in Spark's transaction tree is a pre-signed transaction whose sighash commitments ensure that only the current owner (in combination with the Spark operators via FROST threshold signatures) can authorize spending. The rigid signing provided by SIGHASH_ALL is what prevents previous owners from redirecting funds after a transfer.
Future Sighash Proposals: ANYPREVOUT
SIGHASH_ANYPREVOUT (proposed in BIP 118) would add a new modifier that excludes the outpoint (the specific UTXO being spent) from the signed message. This would allow a single pre-signed transaction to be valid against multiple different UTXOs, enabling the eltoo/LN-Symmetry channel update mechanism where any state can replace any prior state without penalty transactions. ANYPREVOUT would also simplify statechain implementations by eliminating the need for new signatures on every transfer.
Security Implications for Developers
Choosing the wrong sighash type can lead to loss of funds. Here are the key considerations:
Never Use SIGHASH_NONE for Standalone Payments
A SIGHASH_NONE signature on a normal payment lets any intermediary redirect your coins. Only use it within tightly controlled multi-step protocols where another signer adds the constrained output.
Verify Sighash Types in PSBT Workflows
Partially Signed Bitcoin Transactions (PSBTs) pass unsigned or partially signed transactions between parties. Hardware wallets and signing devices should always display the sighash type to the user. A hardware wallet that silently accepts SIGHASH_NONE could enable theft if the PSBT is crafted maliciously.
Be Explicit About Sighash in Library Code
Most Bitcoin libraries default to SIGHASH_ALL, but relying on implicit defaults is risky when building multi-party signing flows. Always explicitly set the sighash type in your signing code. For Taproot key-path spends, prefer SIGHASH_DEFAULT (0x00) for the 1-byte savings unless your protocol requires distinguishing between DEFAULT and ALL.
Sighash Types at a Glance
| Type | Hex | What It Authorizes | Primary Use Case |
|---|---|---|---|
| ALL | 0x01 | Exact transaction, no changes allowed | Standard payments |
| NONE | 0x02 | Spending the inputs, destination open | Multi-party protocols (rare) |
| SINGLE | 0x03 | One input-output pair, rest open | Swaps and atomic trades |
| ALL|ANYONECANPAY | 0x81 | Fixed outputs, one input, others can join | Crowdfunding and assurance contracts |
| NONE|ANYONECANPAY | 0x82 | One input, everything else open | Blank check (dangerous outside protocols) |
| SINGLE|ANYONECANPAY | 0x83 | One input-output pair, composable | Modular transaction assembly |
| DEFAULT (Taproot) | 0x00 | Same as ALL, implicit encoding | Taproot key-path spends (saves 1 byte) |
Building with Sighash Awareness
Understanding sighash types is not just academic: it is a prerequisite for working with any Bitcoin protocol that goes beyond simple send-and-receive. Pre-signed transaction trees, channel update mechanisms, collaborative transaction construction, and fee-bumping strategies all depend on choosing the correct sighash flag for each signature.
For developers building on Bitcoin Layer 2 protocols, the Spark documentation provides details on how Spark's off-chain transaction tree uses signing constructs to maintain self-custody guarantees. The Bitcoin Script programmability deep dive covers how sighash flags interact with opcodes like OP_CHECKSIG and OP_CHECKSIGADD. And for a complete picture of how transactions move from construction to confirmation, see the Bitcoin transaction lifecycle walkthrough.
This article is for educational purposes only. It does not constitute financial or investment advice. Bitcoin and Layer 2 protocols involve technical and financial risk. Always do your own research and understand the tradeoffs before using any protocol.

