The SIGHASH_SINGLE bug returns the hash 1
ProvedBitcoinSig.sigHash_single_bugFor every script code, transaction, input index and hash type with and : the legacy signature hash is uint256::ONE — the historical quirk by which such a signature commits to nothing.
import Definitions.Def_BitcoinSig open BitcoinSig BitcoinSer
theorem BitcoinSig.sigHash_single_bug (scriptCode : Bytes) (tx : Tx) (nIn hashType : Nat)
(h1 : hashType &&& 0x1f = BitcoinSig.SIGHASH_SINGLE) (h2 : tx.vout.length ≤ nIn) :
BitcoinSig.sigHashLegacy scriptCode tx nIn hashType = BitcoinSig.uint256One := by sorryRead-back
What the Lean code literally says, in plain math · claude-fable-5-1 (independent sub-agent, blind: Lean code + auditor instructions only)
Read-back: BitcoinSig.sigHash_single_bug
Binders and hypothesis. Universally quantified over a byte string , a transaction , and natural numbers and (the latter unbounded, not restricted to one byte). Two hypotheses:
- : , i.e. the low five bits of (bitwise AND on natural numbers with
0x1f) equal the constantSIGHASH_SINGLE; the remaining bits, in particular the ANYONECANPAY bit and any bits above the eighth, are unconstrained; - : , the input index is at least the number of outputs (so there is no output at position ; this includes the case of a transaction with no outputs at all, for every ).
Conclusion.
where uint256One is the 32-byte string consisting of the byte followed by 31 zero bytes.
Unfolding. sigHashLegacy is defined as: if and then uint256One, else the double SHA-256 of the legacy serialization followed by the 4-byte hash type. The two hypotheses are literally the two conjuncts of the guard, so the conclusion is the first branch of the definition. The script code, the inputs, version, lock time, and the number of inputs play no role; need not be a valid input index either.
Edge cases. With the conclusion holds for every including . With exactly, the bound is met (it is , not ). Hash types , (), , , etc. all satisfy .
What is not said. The statement does not say what the hash is when or when the low five bits are not . It does not say that uint256One is "the number one" in any particular reading: as a byte string it begins with the byte ; read big-endian by pubkeyVerify it is the scalar — the theorem asserts only equality of byte strings. It does not say anything about whether a signature over this value verifies, nor about checkECDSASignature or checkSigPreTapscript. It does not say the BIP143 hash has any analogous behaviour (by its definition it does not; it uses a zero hashOutputs instead). It does not assert that this is a "bug" despite the theorem's name — the name is not part of the statement.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.