Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

SIGHASH_SINGLE without an output fails

Proved
BitcoinTaproot.sighash_single_missing

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

bip341bip342bitcoinbitcoin-mainnetconsensusformal-verificationschnorrtaproottapscript

For a valid hash type whose output type is SIGHASH_SINGLE and an input index with no corresponding output, sigHashSchnorr is none: unlike the legacy sighash there is no uint256::ONE quirk in BIP341.

Preamble
import Definitions.Def_BitcoinTaproot
open BitcoinTaproot BitcoinSer BitcoinSig BitcoinVerify
open BitcoinScript hiding Bytes Byte
Formal statement
theorem BitcoinTaproot.sighash_single_missing (tx : Tx) (spent : List TxOut) (inPos hashType : Nat) (tapscript : Bool) (ed : ExecData)
    (hv : hashType ≤ 3 ∨ (0x81 ≤ hashType ∧ hashType ≤ 0x83)) (h3 : hashType &&& 3 = 3) (hout : tx.vout.length ≤ inPos) :
    BitcoinTaproot.sigHashSchnorr tx spent inPos hashType tapscript ed = none := by sorry
Source
Bitcoin Core a773e1e33b349dc819b5a0edc1c7a4839dc73b48: VerifyWitnessProgram (version 1), ExecuteWitnessScript, EvalScript under SigVersion::TAPSCRIPT, EvalChecksigTapscript, CheckSchnorrSignature, SignatureHashSchnorr, ComputeTapleafHash, ComputeTapbranchHash, ComputeTaprootMerkleRoot, VerifyTaprootCommitment, src/script/interpreter.cpp: https://github.com/bitcoin/bitcoin/blob/a773e1e33b349dc819b5a0edc1c7a4839dc73b48/src/script/interpreter.cpp; XOnlyPubKey::CheckTapTweak, ComputeTapTweakHash, src/pubkey.cpp; secp256k1_xonly_pubkey_tweak_add_check, src/secp256k1/src/modules/extrakeys/main_impl.h; IsOpSuccess, src/script/script.cpp; BIP340, BIP341, BIP342 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: BitcoinTaproot.sighash_single_missing

Binders. tx\mathrm{tx}tx : a transaction (natural version, list of inputs vin\mathrm{vin}vin, list of outputs vout\mathrm{vout}vout, natural lock time); spent\mathrm{spent}spent : a list of outputs; inPos,hashType\mathrm{inPos}, \mathrm{hashType}inPos,hashType : natural numbers; tapscript\mathrm{tapscript}tapscript : a Boolean; ed\mathrm{ed}ed : an ExecData record (annexPresent : Boolean, annexHash, tapleafHash : byte strings, codeseparatorPos : natural).

Hypotheses.

  1. hashType≤3  ∨  (0x81≤hashType∧hashType≤0x83)\mathrm{hashType} \le 3 \;\lor\; (0x81 \le \mathrm{hashType} \land \mathrm{hashType} \le 0x83)hashType≤3∨(0x81≤hashType∧hashType≤0x83);
  2. hashType & 3=3\mathrm{hashType} \,\&\, 3 = 3hashType&3=3 (bitwise AND on naturals);
  3. ∣tx.vout∣≤inPos|\mathrm{tx}.\mathrm{vout}| \le \mathrm{inPos}∣tx.vout∣≤inPos.

Conclusion.

sigHashSchnorr(tx,spent,inPos,hashType,tapscript,ed)=none.\mathrm{sigHashSchnorr}(\mathrm{tx}, \mathrm{spent}, \mathrm{inPos}, \mathrm{hashType}, \mathrm{tapscript}, \mathrm{ed}) = \mathrm{none}.sigHashSchnorr(tx,spent,inPos,hashType,tapscript,ed)=none.

Unfolded: sigHashSchnorr\mathrm{sigHashSchnorr}sigHashSchnorr first tests the guard of hypothesis 1 (it passes). It then sets the output type o:=1o := 1o:=1 if hashType=0\mathrm{hashType} = 0hashType=0, else o:=hashType & 3o := \mathrm{hashType} \,\&\, 3o:=hashType&3. By hypothesis 2, hashType≠0\mathrm{hashType} \neq 0hashType=0 (since 0 & 3=00 \,\&\, 3 = 00&3=0) and o=3o = 3o=3, the file's SIGHASH_SINGLE. Combined with hypothesis 1 this means hashType∈{3,0x83}\mathrm{hashType} \in \{3, 0x83\}hashType∈{3,0x83}. When o=3o = 3o=3 the function computes the "single output" component as: none\mathrm{none}none if ∣vout∣≤inPos|\mathrm{vout}| \le \mathrm{inPos}∣vout∣≤inPos, otherwise the SHA-256 of the serialized output voutinPos\mathrm{vout}_{\mathrm{inPos}}voutinPos​. When that component is none\mathrm{none}none the whole function returns none\mathrm{none}none without computing the tagged hash. Hypothesis 3 makes that component none\mathrm{none}none.

Edge cases the quantifiers include. vout\mathrm{vout}vout empty (then every inPos\mathrm{inPos}inPos qualifies); inPos\mathrm{inPos}inPos also beyond vin\mathrm{vin}vin (irrelevant, the default input is never reached); spent\mathrm{spent}spent of any length; the Boolean tapscript\mathrm{tapscript}tapscript and the record ed\mathrm{ed}ed are arbitrary and unused.

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

    Confirmed by the moderator at approval.

  • Endorsed by pitimespi · Oct 27, 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