The BIP143 sighash ignores scriptSigs and witnesses
ProvedBitcoinSig.sigHashWitnessV0_skeletonFor every script code, index, hash type and amount, two transactions with the same skeleton have the same BIP143 signature hash.
import Definitions.Def_BitcoinSig open BitcoinSig BitcoinSer
theorem BitcoinSig.sigHashWitnessV0_skeleton (scriptCode : Bytes) (tx tx' : Tx) (nIn hashType : Nat) (amount : Int)
(h : BitcoinSig.sameSkeleton tx tx') :
BitcoinSig.sigHashWitnessV0 scriptCode tx' nIn hashType amount =
BitcoinSig.sigHashWitnessV0 scriptCode tx nIn hashType amount := 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.sigHashWitnessV0_skeleton
Binders and hypothesis. Universally quantified over a byte string , two transactions and , natural numbers and (unbounded), and an integer (any integer, including negative). One hypothesis : sameSkeleton , i.e.
and the list of pairs taken over equals the same list taken over (so the input counts agree and prevouts and sequence numbers agree position-wise), while scriptSigs and witness stacks are unconstrained.
Conclusion.
Unfolding. With := (), := (), := () and := 32 zero bytes, sigHashWitnessV0 is the double SHA-256 of the concatenation, in this order, of:
- the 4-byte little-endian ;
- : if not , the double SHA-256 of the concatenation over all inputs of
serOutPoint(prevout hash bytes then 4-byte index); else ; - : if not and not and not , the double SHA-256 of the concatenation over all inputs of the 4-byte sequence; else ;
serOutPointof the prevout of input (or of the default input with empty hash and index 0, giving just 4 zero bytes, if out of range);serBytes— the script code verbatim with a compact-size prefix (noOP_CODESEPARATORremoval);- the 8-byte two's-complement little-endian ;
- the 4-byte sequence of input (or for the default);
- : if neither nor , the double SHA-256 of the concatenation of
serTxOutover all outputs; else if and (strict), the double SHA-256 ofserTxOutof output ; else ; - the 4-byte ;
- the 4-byte little-endian . Every transaction field consulted — version, all prevouts, all sequences, the output list, the lock time — is equated by , position by position, and , , , are shared; so the preimages and the hashes coincide.
What is not said. The statement does not say the converse. It does not say the hash depends on in any particular way, only that an equal is used on both sides; a negative is not excluded by this statement (the rejection of negative amounts lives elsewhere, in the checker). It does not assert the number of inputs is the same (it follows from but is not stated separately). It does not say anything about which differences between and are tolerated beyond "anything outside the skeleton". It does not mention any flag, encoding check, or verification. It does not compare the witness-v0 hash with the legacy hash.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.