P2SH-wrapped P2WPKH is correct
ProvedBitcoinVerify.p2sh_p2wpkh_correctWith both flags, the output OP_HASH160 <Hash160(OP_0 <h>)> OP_EQUAL spent with scriptSig <OP_0 <h>> and witness [sig, pk] verifies iff is true as a script value, and the BIP143 signature check on the implied P2PKH script accepts.
import Definitions.Def_BitcoinVerify import Definitions.Def_BitcoinScript import Definitions.Def_BitcoinSig import Definitions.Def_BitcoinSer open BitcoinVerify BitcoinSer BitcoinSig open BitcoinScript hiding Bytes Byte
theorem BitcoinVerify.p2sh_p2wpkh_correct (tap : TaprootHandler) (c : Ctx) (sig pk h : Bytes)
(hp : c.flags.p2sh = true) (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 (BitcoinSig.pushBytes (BitcoinVerify.witnessBytes 0 h))
(BitcoinVerify.p2shBytes (BitcoinSer.hash160 (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.p2sh_p2wpkh_correct
Binders and hypothesis. Universally quantified: tap, a Taproot handler (an arbitrary function from a context, a list of byte strings and a byte string to a Boolean); , a verification context with consensus flags c.flags, transaction c.tx, input index c.nIn, integer amount c.amount; sig, pk, , byte strings. Five hypotheses:
hp:c.flags.p2sh = true;hf:c.flags.witness = true;hh: ;hsig: ;hpk: .
Conclusion. Let (the 22-byte redeem script), (23 bytes), and (23 bytes, since hash160 yields 20 bytes). Then
with and .
Unfolding the left-hand side, outer evaluations. evaluated on the empty stack (version base) is a single push of : stackSig . Then on : OP_HASH160 → ; push → ; OP_EQUAL → ; topTrue is true. The native branch: isWitnessProgram π is nothing ( starts with ), so native = none. With hp and isPayToScriptHash π true, the P2SH branch runs. isPushOnly σ holds (one canonical push). stackSig is , so redeem and the remainder is the empty stack. Then evalBytes c base [] r runs: parses as a push of the empty string and a push of , giving stack2 with topTrue — false (and the verification false) if is twenty zero bytes or nineteen zero bytes followed by . Next, since c.flags.witness is true (hf), isWitnessProgram r is (length 22, first byte 0, second byte 20); the check holds by construction; the verdict is verifyWitnessProgram tap c [sig, pk] 0 h true.
Unfolding verifyWitnessProgram and executeWitnessScriptV0. Version , : the witness must have exactly two elements (it does), and the result is executeWitnessScriptV0 c [pk, sig] (p2pkhBytes h) — the witness list reversed, pk on top. The isP2sh = true argument plays no role in the version-0 arm. executeWitnessScriptV0 requires every stack element at most 520 bytes (hsig, hpk), then runs evalBytes c witnessV0 [pk, sig] (p2pkhBytes h): OP_DUP, OP_HASH160, push , OP_EQUALVERIFY (fails unless , leaving ), then OP_CHECKSIG pops pk (pubkey) and sig and consults the oracle checkSigPreTapscript F c.tx c.nIn c.amount witnessV0 (p2pkhBytes h) sig pk: "nothing" fails the script (an encoding check failed — only dersig can be on), some ok pushes or the empty string. Exactly one element remains and the verdict is ok. So the left side is true iff , and the oracle returns some true, i.e. the right side. Under version witnessV0 the script code is p2pkhBytes h unaltered; the ECDSA check uses the digest with c.amount and is false when c.amount < 0.
What is not said. Nothing for a scriptSig other than exactly the canonical push of (any other encoding of the same push, or extra pushes, is outside the statement); nothing for a witness other than exactly [sig, pk]; nothing when either the p2sh or witness flag is off; nothing when or elements exceed 520 bytes. checkSigPreTapscript is left unexpanded on the right — the theorem does not spell out the signature-hash or the elliptic-curve verification. The handler tap and the taproot flag are never consulted on this path and the theorem says nothing about them. The theorem does not say that the two sides are both true, only that they are equivalent.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.