Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

With DERSIG a non-DER signature is a script error

Proved
BitcoinSig.checkSig_dersig

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

bitcoinbitcoin-mainnetconsensusderecdsaformal-verificationschnorrsecp256k1sighash

If the DERSIG flag is set, a non-empty signature failing IsValidSignatureEncoding makes checkSigPreTapscript return none (the script fails), for every transaction, key and script code.

Preamble
import Definitions.Def_BitcoinSig
open BitcoinSig BitcoinSer
Formal statement
theorem BitcoinSig.checkSig_dersig (f : SigFlags) (tx : Tx) (nIn : Nat) (amount : Int) (v : SigVersion)
    (scriptCode sig pk : Bytes) (hf : f.dersig = true) (hne : sig ≠ [])
    (hder : BitcoinSig.isValidSignatureEncoding sig = false) :
    BitcoinSig.checkSigPreTapscript f tx nIn amount v scriptCode sig pk = none := 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.checkSig_dersig

Binders and hypothesis. Universally quantified: a flag record fff (Booleans dersig, lowS, strictenc, witnessPubkeyType); a transaction txtxtx; a natural number nInnInnIn; an integer amountamountamount; a signature version vvv (either base or witnessV0); and byte strings scriptCodescriptCodescriptCode, sigsigsig, pkpkpk. Three hypotheses:

  • hfhfhf: the dersig flag of fff is true;
  • hnehnehne: sigsigsig is not the empty byte string;
  • hderhderhder: isValidSignatureEncoding sigsigsig = false. Unfolded, this means at least one of the following holds for ℓ=∣sig∣\ell = |sig|ℓ=∣sig∣ (with out-of-range bytes read as 000): ℓ<9\ell < 9ℓ<9; ℓ>73\ell > 73ℓ>73; byte 0 is not 0x30; byte 1 is not ℓ−3\ell - 3ℓ−3; with lenRlenRlenR = byte 3, ℓ≤5+lenR\ell \leq 5 + lenRℓ≤5+lenR; with lenSlenSlenS = byte 5+lenR5 + lenR5+lenR, lenR+lenS+7≠ℓlenR + lenS + 7 \neq \elllenR+lenS+7=ℓ; byte 2 is not 0x02; lenR=0lenR = 0lenR=0; byte 4 is ≥\geq≥ 0x80; lenR>1lenR > 1lenR>1 and byte 4 is 000 and byte 5 is <<< 0x80; byte lenR+4lenR + 4lenR+4 is not 0x02; lenS=0lenS = 0lenS=0; byte lenR+6lenR + 6lenR+6 is ≥\geq≥ 0x80; or lenS>1lenS > 1lenS>1 and byte lenR+6lenR+6lenR+6 is 000 and byte lenR+7lenR+7lenR+7 is <<< 0x80.

Conclusion.

checkSigPreTapscript f tx nIn amount v scriptCode sig pk=none.\text{checkSigPreTapscript}\ f\ tx\ nIn\ amount\ v\ scriptCode\ sig\ pk = \text{none}.checkSigPreTapscript f tx nIn amount v scriptCode sig pk=none.

That is, the pre-tapscript signature check reports a script error (the "none" outcome), as opposed to a verdict "some true" or "some false".

Unfolding. checkSigPreTapscript first computes a script code scscsc (for base, scriptCodescriptCodescriptCode with the push of sigsigsig deleted; for witnessV0, scriptCodescriptCodescriptCode itself) — this is irrelevant to the conclusion. It then returns "none" if checkSignatureEncoding f sigf\,sigfsig is false or checkPubKeyEncoding f v pkf\,v\,pkfvpk is false. checkSignatureEncoding f sigf\,sigfsig is: true if sigsigsig is empty (excluded by hnehnehne); otherwise false if (fff.dersig ∨\lor∨ fff.lowS ∨\lor∨ fff.strictenc) and not isValidSignatureEncoding sigsigsig. With hfhfhf the disjunction is true and with hderhderhder the encoding check is false, so this branch fires and the whole result is "none" regardless of txtxtx, nInnInnIn, amountamountamount, vvv, scriptCodescriptCodescriptCode, pkpkpk, and regardless of the other three flags.

What is not said. The statement does not say that the dersig flag is necessary for this outcome: the same "none" would follow from lowS or strictenc alone, but the theorem only covers the case fff.dersig = true. It does not say anything when sigsigsig is empty (where checkSignatureEncoding is unconditionally true and the result would be "some false" or "none" depending on the key encoding). It does not say anything about valid encodings. It does not say the public key is examined at all — it is not: the key-encoding check is short-circuited by the signature-encoding failure in the sense that the disjunction is already satisfied. It does not say anything about checkECDSASignature, the signature hash, or the elliptic-curve verification, none of which are reached. It does not characterize which structural defect sigsigsig has.

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