Native P2WPKH is correct
ProvedBitcoinVerify.p2wpkh_correctWith the WITNESS flag, for a 20-byte and signature and key within 520 bytes:
where the signature check is the signature mission's checker under witness v0 (BIP143 sighash, DERSIG from the flags) on the implied script DUP HASH160 <h> EQUALVERIFY CHECKSIG. The first conjunct records that an all-zero key hash is unspendable: the base evaluation of OP_0 <h> leaves on top and requires it true.
Formalization Note. verifyScript is the full VerifyScript control flow with the consensus flags; the equivalence holds for every flag set with WITNESS on, every transaction and amount, and every Taproot handler.
import Definitions.Def_BitcoinVerify import Definitions.Def_BitcoinScript import Definitions.Def_BitcoinSer import Definitions.Def_BitcoinSig open BitcoinVerify BitcoinSer BitcoinSig open BitcoinScript hiding Bytes Byte
theorem BitcoinVerify.p2wpkh_correct (tap : TaprootHandler) (c : Ctx) (sig pk h : Bytes)
(hf : c.flags.witness = true) (hh : h.length = 20)
(hsig : sig.length ≤ BitcoinScript.MAX_SCRIPT_ELEMENT_SIZE)
(hpk : pk.length ≤ BitcoinScript.MAX_SCRIPT_ELEMENT_SIZE) :
BitcoinVerify.verifyScript tap c [] (BitcoinVerify.witnessBytes 0 h) [sig, pk] = true ↔
BitcoinScript.castToBool h = true ∧ BitcoinSer.hash160 pk = h ∧
BitcoinSig.checkSigPreTapscript (BitcoinVerify.sigFlagsOf c.flags) c.tx c.nIn c.amount .witnessV0
(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: BitcoinVerify.p2wpkh_correct
Binders and hypothesis. Universally quantified: tap, a Taproot handler (any function from a context, a list of byte strings and a byte string to a Boolean); , a verification context with fields c.flags (consensus flags), c.tx (a transaction), c.nIn (a natural number), c.amount (an integer); sig, pk, , byte strings. Four hypotheses:
hf:c.flags.witness = true;hh: ;hsig: ;hpk: .
Conclusion. With (22 bytes) and witness stack (serialized order, pk last):
where and .
Unfolding the left-hand side. The scriptSig is empty: evalBytes c base [] [] parses to no instructions and yields the empty stack. Then is evaluated on it with version base: the byte parses as a push of the empty string, and as a push of ; the resulting top-first stack is . topTrue of it is : false when all 20 bytes are zero, or all zero except a final ; so the verification is false in that case. Otherwise the native branch: c.flags.witness is true (hf); isWitnessProgram π is (length , first byte , second byte ); the scriptSig is empty, so the verdict is verifyWitnessProgram tap c [sig, pk] 0 h false and verifyScript returns exactly that Boolean (no P2SH branch, no further witness check).
Unfolding verifyWitnessProgram here. Version and (the keyhash size), so the witness must have exactly elements (it does), and the result is executeWitnessScriptV0 c [pk, sig] (p2wpkhExec h): the witness is reversed, so pk is the interpreter's top and sig is beneath it, and p2wpkhExec h = p2pkhBytes h.
Unfolding executeWitnessScriptV0. No stack element may exceed 520 bytes (hsig, hpk ensure this); then evalBytes c witnessV0 [pk, sig] (p2pkhBytes h) runs: the 26-byte script passes the test and parses as OP_DUP, OP_HASH160, push , OP_EQUALVERIFY, OP_CHECKSIG. The interpreter (flags scriptFlagsOf c.flags, oracle legacyOracle F c.tx c.nIn c.amount witnessV0 (p2pkhBytes h)) does: OP_DUP → ; OP_HASH160 → ; push → ; OP_EQUALVERIFY → fails unless , else ; OP_CHECKSIG pops pubkey pk and signature sig and consults the oracle, which is checkSigPreTapscript F c.tx c.nIn c.amount witnessV0 (p2pkhBytes h) sig pk: a result of "nothing" (an encoding check failed: dersig on and sig not valid DER, the other encoding flags being off) fails the script; some ok pushes if ok else the empty string. The final stack has exactly one element and topTrue of it equals ok. Hence the left side is true iff , , and the oracle returns some true — which is the right side. In checkSigPreTapscript with version witnessV0, the script code is p2pkhBytes h unchanged, and the ECDSA check uses the BIP143-style digest with c.amount and returns false when c.amount < 0.
What is not said. Nothing about any witness stack other than exactly two elements in the order [sig, pk]; nothing when the witness flag is off; nothing about ; nothing about elements over 520 bytes; nothing about what checkSigPreTapscript means cryptographically — it appears unexpanded on the right; nothing about the handler tap or the taproot, p2sh flags, which are not consulted on this path. The theorem does not claim the key is compressed or that the signature is low-S (those flags are hard-wired off by sigFlagsOf).
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.