Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

The validation-weight budget

Proved
BitcoinTaproot.sigops_budget

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

bip341bip342bitcoinbitcoin-mainnetconsensusformal-verificationschnorrtaproottapscript

An executed OP_CHECKSIG with a non-empty signature when fewer than 50 weight units remain is a script error (SCRIPT_ERR_TAPSCRIPT_VALIDATION_WEIGHT), before any key or signature is examined.

Preamble
import Definitions.Def_BitcoinTaproot
import Definitions.Def_BitcoinScript
open BitcoinTaproot BitcoinSer BitcoinSig BitcoinVerify
open BitcoinScript hiding Bytes Byte
Formal statement
theorem BitcoinTaproot.sigops_budget (c : TapCtx) (ed : ExecData) (ts : TapState) (pubkey sig : Bytes) (rest : List Bytes)
    (hs : ts.st.stack = pubkey :: sig :: rest) (hsig : sig ≠ []) (hw : ts.weightLeft < BitcoinTaproot.VALIDATION_WEIGHT_PER_SIGOP_PASSED) :
    BitcoinTaproot.tapExecOp c ed true BitcoinScript.OP_CHECKSIG ts = 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.sigops_budget

Binders. ccc : a TapCtx record (flags; transaction tx\mathrm{tx}tx; list spent\mathrm{spent}spent; index nIn\mathrm{nIn}nIn); ed\mathrm{ed}ed : an ExecData record; ts\mathrm{ts}ts : a TapState record (st\mathrm{st}st : interpreter state; weightLeft∈Z\mathrm{weightLeft} \in \mathbb{Z}weightLeft∈Z; codeseparatorPos,opcodePos∈N\mathrm{codeseparatorPos}, \mathrm{opcodePos} \in \mathbb{N}codeseparatorPos,opcodePos∈N); pubkey,sig\mathrm{pubkey}, \mathrm{sig}pubkey,sig : byte strings; rest\mathrm{rest}rest : a list of byte strings.

Hypotheses.

  1. ts.st.stack=pubkey::sig::rest\mathrm{ts}.\mathrm{st}.\mathrm{stack} = \mathrm{pubkey} :: \mathrm{sig} :: \mathrm{rest}ts.st.stack=pubkey::sig::rest (main stack, top first);
  2. sig≠[ ]\mathrm{sig} \neq [\,]sig=[];
  3. ts.weightLeft<50\mathrm{ts}.\mathrm{weightLeft} < 50ts.weightLeft<50 as integers (the constant VALIDATION_WEIGHT_PER_SIGOP_PASSED, which is the integer 505050).

Conclusion.

tapExecOp(c,ed,true,0xac,ts)=none,\mathrm{tapExecOp}(c, \mathrm{ed}, \mathrm{true}, \texttt{0xac}, \mathrm{ts}) = \mathrm{none},tapExecOp(c,ed,true,0xac,ts)=none,

where 0xac\texttt{0xac}0xac is OP_CHECKSIG.

Unfolded. For OP_CHECKSIG, tapExecOp\mathrm{tapExecOp}tapExecOp requires the stack shape of hypothesis 1 (else none\mathrm{none}none) and calls evalChecksigTapscript(c,ed′,sig,pubkey,ts.weightLeft)\mathrm{evalChecksigTapscript}(c, \mathrm{ed}', \mathrm{sig}, \mathrm{pubkey}, \mathrm{ts}.\mathrm{weightLeft})evalChecksigTapscript(c,ed′,sig,pubkey,ts.weightLeft), where ed′\mathrm{ed}'ed′ is ed\mathrm{ed}ed with codeseparatorPos replaced by ts.codeseparatorPos\mathrm{ts}.\mathrm{codeseparatorPos}ts.codeseparatorPos. In that function success:=(sig≠[ ])=true\mathrm{success} := (\mathrm{sig} \neq [\,]) = \mathrm{true}success:=(sig=[])=true by hypothesis 2, so weight:=weightLeft−50\mathrm{weight} := \mathrm{weightLeft} - 50weight:=weightLeft−50 (integer subtraction); the first test "if success∧weight<0\mathrm{success} \land \mathrm{weight} < 0success∧weight<0 then none\mathrm{none}none" fires because weightLeft<50\mathrm{weightLeft} < 50weightLeft<50 gives weight<0\mathrm{weight} < 0weight<0. This test precedes the public-key length tests (∣pubkey∣=0⇒none|\mathrm{pubkey}| = 0 \Rightarrow \mathrm{none}∣pubkey∣=0⇒none; ∣pubkey∣=32⇒|\mathrm{pubkey}| = 32 \Rightarrow∣pubkey∣=32⇒ Schnorr check; other lengths ⇒\Rightarrow⇒ accept) and the signature verification, none of which are reached. A none\mathrm{none}none from evalChecksigTapscript\mathrm{evalChecksigTapscript}evalChecksigTapscript makes tapExecOp\mathrm{tapExecOp}tapExecOp return none\mathrm{none}none.

Edge cases the quantifiers include. pubkey\mathrm{pubkey}pubkey of any length, including empty or non-32-byte; sig\mathrm{sig}sig of any non-zero length (not only 64/65); weightLeft\mathrm{weightLeft}weightLeft negative or exactly 494949; rest\mathrm{rest}rest empty; arbitrary ccc and ed\mathrm{ed}ed (never consulted).

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