The legacy checker unfolded
ProvedBitcoinSig.checkSig_base_iffcheckSigPreTapscript f tx nIn amount BASE scriptCode sig pk = some true iff CheckSignatureEncoding and CheckPubKeyEncoding pass, the key is valid, and with pubkeyVerify pk (sigHashLegacy (FindAndDelete scriptCode ⟨sig⟩) tx nIn ht) sig': the signature check is ECDSA verification of the legacy sighash of the signature-deleted script code, under the hash type given by the last byte.
import Definitions.Def_BitcoinSig open BitcoinSig BitcoinSer
theorem BitcoinSig.checkSig_base_iff (f : SigFlags) (tx : Tx) (nIn : Nat) (amount : Int)
(scriptCode sig pk : Bytes) :
BitcoinSig.checkSigPreTapscript f tx nIn amount .base scriptCode sig pk = some true ↔
BitcoinSig.checkSignatureEncoding f sig = true ∧ BitcoinSig.checkPubKeyEncoding f .base pk = true ∧
BitcoinSig.pubkeyValid pk = true ∧
∃ (sig' : Bytes) (ht : Byte), sig = sig' ++ [ht] ∧
BitcoinSig.pubkeyVerify pk
(BitcoinSig.sigHashLegacy (BitcoinSig.findAndDelete scriptCode (BitcoinSig.pushBytes sig)).1 tx nIn ht.toNat)
sig' = true := by sorryRead-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_base_iff
Binders and hypothesis. The statement is universally quantified over: a flag record (four Booleans: dersig, lowS, strictenc, witnessPubkeyType); a transaction (fields: natural-number version, list of inputs vin, list of outputs vout, natural-number nLockTime); a natural number (an input index, not required to be in range); an integer ; and three byte strings , , . There are no hypotheses: the statement is an unconditional biconditional.
Conclusion. The following two statements are equivalent.
Left side. The pre-tapscript signature check in base mode, namely checkSigPreTapscript , returns the value "some true". Unfolding that definition: let be the first component of findAndDelete (pushBytes ), i.e. with every raw-byte occurrence of the canonical push encoding of removed at instruction boundaries (the push encoding is the length byte followed by when , and the 0x4c/0x4d/0x4e forms for longer data; for the empty signature it is the single byte 0x00). The result is "none" if checkSignatureEncoding is false or checkPubKeyEncoding is false; otherwise it is "some" of checkECDSASignature , which is: false if pubkeyValid fails or is empty; otherwise, writing with the last byte, the Boolean pubkeyVerify (sigHashLegacy ) . In base mode the amount is never consulted.
Right side. The conjunction of four things:
checkSignatureEncoding= true — which holds vacuously if is empty, and otherwise requires: strict DER structure (isValidSignatureEncoding) whenever any of .dersig, .lowS, .strictenc is set; additionally low- of the signature without its final byte (isLowDERSignature) when .lowS is set; additionally that the last byte masked with0x7flies in when .strictenc is set;checkPubKeyEncoding= true — i.e. if .strictenc then is 65 bytes starting with0x04or 33 bytes starting with0x02/0x03; thewitnessPubkeyTypeflag has no effect inbasemode;pubkeyValid= true — is non-empty and its length equals the length its first byte announces (33 for0x02/0x03, 65 for0x04/0x06/0x07, otherwise an impossible 0);- there exist a byte string and a byte with and
where is exactly the findAndDelete result described above and is used as the natural number in it denotes.
Further unfolding of the verification. pubkeyVerify is: false unless pubkeyValid ; false unless parsePubkey yields an affine point (compressed keys are lifted from the abscissa with the announced parity; uncompressed/hybrid keys must have both coordinates below , satisfy , and for hybrid tags the announced parity); false unless the lax DER parser accepts with some pair (overflowing or over-long integers give rather than rejection); otherwise the raw ECDSA check with message (big-endian value of ) , with , and with replaced by whenever : false if or is or , else must be finite with . sigHashLegacy is the constant uint256One (byte 1 followed by 31 zero bytes) if and , and otherwise the double SHA-256 of the legacy signature serialization of with script code (with OP_CODESEPARATOR instructions removed) at input under hash type , followed by the 4-byte little-endian .
What is not said. The statement does not say anything about witnessV0 mode. It does not say that matters (it is bound but inert). It does not assert that the existential decomposition is unique (though it is, since is the last byte). It does not say what happens when the left side is "none" versus "some false": both are lumped into "not some true", so the right side being false does not distinguish an encoding failure from a failed verification. It does not say that the findAndDelete step leaves unchanged, nor that any of the four conjuncts is independent of the others (e.g. conjunct 3 is already implied by conjunct 4's pubkeyVerify). It does not relate the result to any notion of a "correct" signature; it is a restatement of the checker's control flow as a conjunction.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.