Pay-to-public-key-hash is correct
ProvedBitcoinScript.p2pkh_correctFor every flag setting and oracle, signature , public key and hash each of at most bytes,
Here verifyScriptPlain evaluates the scriptSig and then the scriptPubKey on the same stack with the transcribed EvalScript — element-size, operation-count and stack-size checks included — and requires a true top; hash160 and checkSig are the oracle's. The template that carries most of Bitcoin's history therefore enforces exactly "the key hashes to and the signature verifies", in both directions, for every oracle.
Formalization Note. The 520-byte bounds are the MAX_SCRIPT_ELEMENT_SIZE push checks; no assumption is made on the oracle, on the flags, or on the length of beyond the push limit.
import Definitions.Def_BitcoinScript
theorem BitcoinScript.p2pkh_correct (f : Flags) (o : Oracle) (sig pubkey h : Bytes)
(hsig : sig.length ≤ BitcoinScript.MAX_SCRIPT_ELEMENT_SIZE)
(hpk : pubkey.length ≤ BitcoinScript.MAX_SCRIPT_ELEMENT_SIZE)
(hh : h.length ≤ BitcoinScript.MAX_SCRIPT_ELEMENT_SIZE) :
BitcoinScript.verifyScriptPlain f o [.push sig, .push pubkey] (BitcoinScript.p2pkhScript h) = true ↔
o.hash160 pubkey = h ∧ o.checkSig sig pubkey = 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: BitcoinScript.p2pkh_correct
Binders and hypothesis. Universally quantified: , a flags record (three arbitrary Booleans); , an oracle (hash functions ripemd160, sha1, sha256, hash160, hash256 from byte lists to byte lists, checkSig from two byte lists to an optional Boolean, and two integer predicates — all arbitrary); and three byte lists , , . (Here is a byte list, the hash value embedded in the output script, not a hypothesis.) Three hypotheses:
- : ;
- : ;
- : .
No other constraint: any of the three may be empty, need not have any particular length such as , and need not be a well-formed key.
Conclusion. A biconditional:
Unfolding the scripts. with bytes . The scriptSig is the two pushes, first then .
Unfolding verifyScriptPlain, step by step. First evaluation, from the empty stack: push (size check passes by ), push (by ); the condition stack is empty throughout; the result is (public key on top). Second evaluation, from the fresh state with operation count reset to :
- (counted; count ): stack .
- (count ): top replaced by ; stack . No size check on the hash output.
- : size check by ; stack (4 elements ).
- (count ): with on top and second, , byte-list equality. If , both are removed, stack ; otherwise the step fails and verification is false.
- (count ): with on top and second, evaluate ; none failure, false; stack .
- End: condition stack empty, success;
verifyScriptPlainreturns , which is .
The claim, in words. Under the three length hypotheses, verification succeeds exactly when both (a) the oracle's hash160 of is, as a byte list, equal to , and (b) the oracle's checkSig on returns . In the forward direction, a true verification yields both facts; in the backward direction, both facts yield a true verification. Failure of (a) makes verification false regardless of (b); if (a) holds and checkSig returns or none, verification is false. The flags play no role.
What is not said. Nothing is claimed if any of the three lengths exceeds . The oracle is uninterpreted: the theorem does not say hash160 is RIPEMD160∘SHA256, that its output has bytes, or that checkSig is ECDSA on a signature hash; it only relates verification to whatever these functions return on the given inputs. There is no claim about the order of evaluation of (a) and (b) beyond what the biconditional expresses (in particular the theorem does not say that checkSig is not called when the hash mismatches). The scriptSig is fixed to exactly two pushes in the order , ; a scriptSig with extra elements, extra opcodes, or reversed order is not covered. No pay-to-script-hash, witness, CLEANSTACK, push-only, NULLFAIL, or minimal-encoding condition exists in the statement. The final stack contents and the operation count are not described. Nothing is said about whether determines uniquely (collisions in the oracle's hash160 are not excluded and would simply be covered by the "" on the right-hand side).
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.