P2PKH is correct against Core's concrete signature checker
ProvedBitcoinSig.p2pkh_concreteFor every flag setting, transaction, input index, amount and signature version, and every signature, key and hash within the 520-byte push limit:
where the oracle is Core's RIPEMD-160∘SHA-256 and the pre-tapscript checker. Composed with checkSig_base_iff, the right-hand side is: valid encodings, a valid key, and ECDSA verification of the legacy sighash. This instantiates the Script mission's abstract P2PKH theorem with the concrete cryptography and sighash of the pinned source.
import Definitions.Def_BitcoinSig import Definitions.Def_BitcoinScript import Definitions.Def_BitcoinSer open BitcoinSig BitcoinSer
theorem BitcoinSig.p2pkh_concrete (f : SigFlags) (fl : BitcoinScript.Flags) (tx : Tx) (nIn : Nat) (amount : Int)
(v : SigVersion) (sig pk h : Bytes)
(hsig : sig.length ≤ BitcoinScript.MAX_SCRIPT_ELEMENT_SIZE)
(hpk : pk.length ≤ BitcoinScript.MAX_SCRIPT_ELEMENT_SIZE)
(hh : h.length ≤ BitcoinScript.MAX_SCRIPT_ELEMENT_SIZE) :
BitcoinScript.verifyScriptPlain fl (BitcoinSig.legacyOracle f tx nIn amount v (BitcoinSig.p2pkhBytes h))
[.push sig, .push pk] (BitcoinScript.p2pkhScript h) = true ↔
BitcoinSer.hash160 pk = h ∧
BitcoinSig.checkSigPreTapscript f tx nIn amount v (BitcoinSig.p2pkhBytes h) sig pk = some 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.p2pkh_concrete
Binders and hypothesis. Universally quantified over: a signature-layer flag record (Booleans dersig, lowS, strictenc, witnessPubkeyType); an interpreter flag record (Booleans cltv, csv, nulldummy); a transaction ; a natural number ; an integer ; a signature version ; and three byte strings , , . Three hypotheses, each bounding a length by MAX_SCRIPT_ELEMENT_SIZE :
- : ;
- : ;
- : .
Nothing else is assumed: may be out of range, may be negative, need not have length 20, may be
witnessV0even though the interpreter being run is the legacy one.
Conclusion. Let denote the oracle legacyOracle (p2pkhBytes ): the record whose hash functions are the serialization file's RIPEMD-160, SHA-1, SHA-256, Hash160 (RIPEMD-160 of SHA-256) and Hash256 (double SHA-256), whose checkSig is checkSigPreTapscript (p2pkhBytes ) , and whose lock-time and sequence checks are checkLockTime and checkSequence . Then
if and only if
Unfolding the left side. verifyScriptPlain evaluates the script on the empty stack; if that fails ("none") the result is false; otherwise it evaluates on the resulting stack; if that fails or leaves an empty stack the result is false; otherwise the result is castToBool of the top element (some byte is non-zero, except that a lone 0x80 after zeros counts as false). Evaluation starts from the state (main stack , alt stack , condition stack , op count ) and processes instructions in order; at the end the condition stack must be empty (it is, since no OP_IF occurs). Stacks are written top-first.
Script 1: push — fails if (excluded by ), else pushes; stack . push — likewise; stack . The 1000-element stack limit is never approached.
Script 2: p2pkhScript is (OP_DUP, OP_HASH160, the push, OP_EQUALVERIFY, OP_CHECKSIG). Each opcode byte exceeds OP_16 and so is counted toward the 201-op limit (reaching 4, far below); none is disabled. OP_DUP duplicates the top: . OP_HASH160 replaces the top by of it, i.e. BitcoinSer.hash160 : . push — fails if (excluded by ): . OP_EQUALVERIFY pops two elements , and succeeds (removing both) exactly when as byte strings, failing the whole script otherwise: . OP_CHECKSIG pops and and calls = checkSigPreTapscript (p2pkhBytes ) : "none" fails the script; "some " pushes if is true, or if false. Final stack: or ; castToBool gives true exactly for . So the left side is true precisely when the equality check passed and the oracle returned "some true".
Unfolding the right side's second conjunct. checkSigPreTapscript with script code p2pkhBytes : if = base the script code first has every raw-byte occurrence of pushBytes at instruction boundaries deleted (findAndDelete); if = witnessV0 it is used unchanged. The result is "none" if checkSignatureEncoding or checkPubKeyEncoding fails, else "some" of checkECDSASignature : false unless pubkeyValid and non-empty; otherwise, with the last byte of and the rest, the signature hash is sigHashLegacy (for base) or sigHashWitnessV0 (for witnessV0, with "false" if ), and the verdict is pubkeyVerify .
What is not said. The statement does not say anything if any of the three lengths exceeds 520 (then the left side is false by a push failure while the right side may still hold; the hypotheses are what make the backward direction true). It does not say the interpreter flags matter — they are never consulted on this script path (no CLTV, CSV or multisig), and the statement quantifies over them without using them. It does not restrict to base: for witnessV0 the oracle still runs the legacy interpreter but hashes with the BIP143 algorithm, and the statement covers that combination too. It does not say . It does not say that p2pkhBytes is the byte serialization of p2pkhScript (that is a separate statement), nor that the script code passed to the oracle "is" the executed script in any sense beyond the way was built. It does not distinguish the script-error outcome "none" of the signature check from "some false": both make the left side false and the right side false. It does not say anything about OP_CODESEPARATOR, about the findAndDelete step altering p2pkhBytes (it can, if pushBytes happens to occur in it), or about the cryptographic meaning of the verdict.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.