Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

The BIP143 sighash ignores scriptSigs and witnesses

Proved
BitcoinSig.sigHashWitnessV0_skeleton

by pitimespi · Oct 26, 2026 · Mathlib 0df444a (Lean v4.33.1)

bitcoinbitcoin-mainnetconsensusderecdsaformal-verificationschnorrsecp256k1sighash

For every script code, index, hash type and amount, two transactions with the same skeleton have the same BIP143 signature hash.

Preamble
import Definitions.Def_BitcoinSig
open BitcoinSig BitcoinSer
Formal statement
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 sorry
Source
Bitcoin Core a773e1e33b349dc819b5a0edc1c7a4839dc73b48: IsValidSignatureEncoding, IsLowDERSignature, IsCompressedOrUncompressedPubKey, IsCompressedPubKey, IsDefinedHashtypeSignature, CheckSignatureEncoding, CheckPubKeyEncoding, FindAndDelete, CTransactionSignatureSerializer, SignatureHash (BASE and WITNESS_V0), EvalChecksigPreTapscript, GenericTransactionSignatureChecker::CheckECDSASignature/CheckLockTime/CheckSequence, src/script/interpreter.cpp: https://github.com/bitcoin/bitcoin/blob/a773e1e33b349dc819b5a0edc1c7a4839dc73b48/src/script/interpreter.cpp; GetScriptOp, src/script/script.cpp; CPubKey::IsValid/Verify/CheckLowS and ecdsa_signature_parse_der_lax, src/pubkey.cpp and pubkey.h; secp256k1_eckey_pubkey_parse (src/secp256k1/src/eckey_impl.h), secp256k1_ecdsa_sig_verify (ecdsa_impl.h), secp256k1_schnorrsig_verify (modules/schnorrsig/main_impl.h); BIP66, BIP143, BIP340 at bips revision 100ba872c808946155b1eeb8c4568058f2eea0a7
Read-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 scriptCodescriptCodescriptCode, two transactions txtxtx and tx′tx'tx′, natural numbers nInnInnIn and hashTypehashTypehashType (unbounded), and an integer amountamountamount (any integer, including negative). One hypothesis hhh: sameSkeleton tx tx′tx\,tx'txtx′, i.e.

tx′.version=tx.version,tx′.vout=tx.vout,tx′.nLockTime=tx.nLockTime,tx'.\text{version} = tx.\text{version},\quad tx'.\text{vout} = tx.\text{vout},\quad tx'.\text{nLockTime} = tx.\text{nLockTime},tx′.version=tx.version,tx′.vout=tx.vout,tx′.nLockTime=tx.nLockTime,

and the list of pairs (prevout,nSequence)(\text{prevout}, \text{nSequence})(prevout,nSequence) taken over tx′.vintx'.\text{vin}tx′.vin equals the same list taken over tx.vintx.\text{vin}tx.vin (so the input counts agree and prevouts and sequence numbers agree position-wise), while scriptSigs and witness stacks are unconstrained.

Conclusion.

sigHashWitnessV0 scriptCode tx′ nIn hashType amount=sigHashWitnessV0 scriptCode tx nIn hashType amount.\text{sigHashWitnessV0}\ scriptCode\ tx'\ nIn\ hashType\ amount = \text{sigHashWitnessV0}\ scriptCode\ tx\ nIn\ hashType\ amount .sigHashWitnessV0 scriptCode tx′ nIn hashType amount=sigHashWitnessV0 scriptCode tx nIn hashType amount.

Unfolding. With acpacpacp := (hashType&128≠0hashType \mathbin{\&} 128 \neq 0hashType&128=0), singlesinglesingle := (hashType&31=3hashType \mathbin{\&} 31 = 3hashType&31=3), nonenonenone := (hashType&31=2hashType \mathbin{\&} 31 = 2hashType&31=2) and zerozerozero := 32 zero bytes, sigHashWitnessV0 sc t nIn ht asc\,t\,nIn\,ht\,asctnInhta is the double SHA-256 of the concatenation, in this order, of:

  1. the 4-byte little-endian t.versiont.\text{version}t.version;
  2. hashPrevoutshashPrevoutshashPrevouts: if not acpacpacp, the double SHA-256 of the concatenation over all inputs of serOutPoint (prevout hash bytes then 4-byte index); else zerozerozero;
  3. hashSequencehashSequencehashSequence: if not acpacpacp and not singlesinglesingle and not nonenonenone, the double SHA-256 of the concatenation over all inputs of the 4-byte sequence; else zerozerozero;
  4. serOutPoint of the prevout of input nInnInnIn (or of the default input with empty hash and index 0, giving just 4 zero bytes, if out of range);
  5. serBytes scscsc — the script code verbatim with a compact-size prefix (no OP_CODESEPARATOR removal);
  6. the 8-byte two's-complement little-endian aaa;
  7. the 4-byte sequence of input nInnInnIn (or 000 for the default);
  8. hashOutputshashOutputshashOutputs: if neither singlesinglesingle nor nonenonenone, the double SHA-256 of the concatenation of serTxOut over all outputs; else if singlesinglesingle and nIn<∣t.vout∣nIn < |t.\text{vout}|nIn<∣t.vout∣ (strict), the double SHA-256 of serTxOut of output nInnInnIn; else zerozerozero;
  9. the 4-byte t.nLockTimet.\text{nLockTime}t.nLockTime;
  10. the 4-byte little-endian ht mod 232ht \bmod 2^{32}htmod232. Every transaction field consulted — version, all prevouts, all sequences, the output list, the lock time — is equated by hhh, position by position, and scscsc, nInnInnIn, hththt, aaa 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 amountamountamount in any particular way, only that an equal amountamountamount is used on both sides; a negative amountamountamount 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 hhh but is not stated separately). It does not say anything about which differences between txtxtx and tx′tx'tx′ 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.

Human review
  • Endorsed by Shuze Chen · Oct 26, 2026

    Confirmed by the moderator at approval.

  • Endorsed by pitimespi · Oct 26, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me