Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Undefined hash types are rejected

Proved
BitcoinTaproot.sighash_type_invalid

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

bip341bip342bitcoinbitcoin-mainnetconsensusformal-verificationschnorrtaproottapscript

For a hash type outside {0,1,2,3}∪{0x81,0x82,0x83}\{0,1,2,3\} \cup \{0x81,0x82,0x83\}{0,1,2,3}∪{0x81,0x82,0x83}, sigHashSchnorr is none (the signature check fails).

Preamble
import Definitions.Def_BitcoinTaproot
open BitcoinTaproot BitcoinSer BitcoinSig BitcoinVerify
open BitcoinScript hiding Bytes Byte
Formal statement
theorem BitcoinTaproot.sighash_type_invalid (tx : Tx) (spent : List TxOut) (inPos hashType : Nat) (tapscript : Bool) (ed : ExecData)
    (h : ¬ (hashType ≤ 3 ∨ (0x81 ≤ hashType ∧ hashType ≤ 0x83))) :
    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_type_invalid

Binders. tx\mathrm{tx}tx : a transaction (record with a natural-number version, a list of inputs, a list of outputs, a natural-number lock time); spent\mathrm{spent}spent : a list of transaction outputs (each an integer value and a byte-string script); inPos,hashType\mathrm{inPos}, \mathrm{hashType}inPos,hashType : natural numbers; tapscript\mathrm{tapscript}tapscript : a Boolean; ed\mathrm{ed}ed : an ExecData record (a Boolean annexPresent, byte strings annexHash and tapleafHash, a natural codeseparatorPos).

Hypothesis. ¬(hashType≤3  ∨  (0x81≤hashType∧hashType≤0x83))\neg\big(\mathrm{hashType} \le 3 \;\lor\; (0x81 \le \mathrm{hashType} \land \mathrm{hashType} \le 0x83)\big)¬(hashType≤3∨(0x81≤hashType∧hashType≤0x83)), i.e. hashType∉{0,1,2,3,0x81,0x82,0x83}\mathrm{hashType} \notin \{0,1,2,3,0x81,0x82,0x83\}hashType∈/{0,1,2,3,0x81,0x82,0x83}.

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 returns an optional byte string; its very first step is the test "if not (hashType≤3\mathrm{hashType} \le 3hashType≤3 or 0x81≤hashType≤0x830x81 \le \mathrm{hashType} \le 0x830x81≤hashType≤0x83) then none\mathrm{none}none", and only otherwise does it compute the tagged hash tagged("TapSighash",⋅)\mathrm{tagged}(\texttt{"TapSighash"}, \cdot)tagged("TapSighash",⋅) of the BIP341-style message (epoch byte, hash-type byte, version, lock time, the optional four prevout/amount/scriptPubKey/sequence hashes, the optional outputs hash, the spend-type byte, the per-input data or input index, the optional annex hash, the optional single-output hash, and the optional tapscript extension). The hypothesis is exactly the negation of that guard, so the conclusion is that the first branch is taken.

Edge cases the quantifiers include. hashType=0x80\mathrm{hashType} = 0x80hashType=0x80 (excluded by the guard and therefore covered by this theorem); any hashType≥0x84\mathrm{hashType} \ge 0x84hashType≥0x84 including values above 255255255; tx\mathrm{tx}tx with no inputs or outputs; inPos\mathrm{inPos}inPos beyond the input list; spent\mathrm{spent}spent of any length, all irrelevant since the guard fails first.

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