Native P2WSH characterized
ProvedBitcoinVerify.p2wsh_correctWith the WITNESS flag, the output OP_0 <SHA256(script)> spent with an empty scriptSig and witness ws ++ [script] verifies iff the program is true as a script value and the witness script, run under witness v0 on the stack of the remaining elements (last on top), leaves exactly one true element.
import Definitions.Def_BitcoinVerify import Definitions.Def_BitcoinSer import Definitions.Def_BitcoinScript open BitcoinVerify BitcoinSer BitcoinSig open BitcoinScript hiding Bytes Byte
theorem BitcoinVerify.p2wsh_correct (tap : TaprootHandler) (c : Ctx) (ws : List Bytes) (script : Bytes)
(hf : c.flags.witness = true) :
BitcoinVerify.verifyScript tap c [] (BitcoinVerify.witnessBytes 0 (BitcoinSer.sha256 script)) (ws ++ [script]) = true ↔
BitcoinScript.castToBool (BitcoinSer.sha256 script) = true ∧
BitcoinVerify.executeWitnessScriptV0 c ws.reverse script = 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.p2wsh_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 (consensus flags c.flags, transaction c.tx, input index c.nIn, integer amount c.amount); ws, a list of byte strings; script, a byte string. One hypothesis hf: c.flags.witness = true. There are no size hypotheses on ws, its elements, or script.
Conclusion. Let (32 bytes) and (34 bytes). Then
The witness is the list ws with script appended as its last element.
Unfolding the left-hand side. The empty scriptSig evaluates to the empty stack. evaluates (version base) to the top-first stack (the byte pushes the empty string, then the 32-byte push). topTrue is : if the SHA-256 digest is all zeros or zeros followed by a final , verifyScript returns false. Otherwise, with the witness flag on (hf), isWitnessProgram π (length , first byte , second byte ), and the scriptSig is empty, so verifyScript returns exactly verifyWitnessProgram tap c (ws ++ [script]) 0 P false.
Unfolding verifyWitnessProgram. Version , (the script-hash size): the last element of the witness, getLast? (ws ++ [script]), is script (the witness is non-empty by construction); the test fails to trigger since is defined as that hash; so the result is executeWitnessScriptV0 c ((ws ++ [script]).dropLast.reverse) script executeWitnessScriptV0 c (reverse ws) script. The witness elements other than the script are reversed, so the element of ws that was last in serialized order becomes the interpreter's top.
Unfolding executeWitnessScriptV0 (the right-hand side). executeWitnessScriptV0 c (reverse ws) script is: false if some element of ws is longer than 520 bytes; otherwise evalBytes c witnessV0 (reverse ws) script — false if , false if script fails the byte-level parse, false if the interpreter (flags scriptFlagsOf c.flags; oracle with signature check checkSigPreTapscript (sigFlagsOf c.flags) c.tx c.nIn c.amount witnessV0 script, script code the whole script) fails; otherwise true iff the final stack has exactly one element and that element casts to true. The script element itself is not subject to the 520-byte test (it was removed by dropLast), only to the -byte test.
Logical content. For every handler, context with the witness flag on, witness prefix ws and script, the full verification of an empty scriptSig against the native version-0 32-byte program equals the conjunction of (i) the program bytes casting to true and (ii) the witness-script execution verdict on the reversed remaining witness. Both directions are asserted.
What is not said. Nothing when the witness flag is off; nothing for a non-empty scriptSig; nothing about witnesses whose last element does not hash to the program (the statement fixes the program as the hash of the last element); nothing about P2SH-wrapped P2WSH; no size constraints are asserted — they are absorbed into executeWitnessScriptV0 on the right; no clean-stack condition beyond the one-element rule inside executeWitnessScriptV0; the handler tap, the taproot and p2sh flags are not consulted on this path and the theorem is silent about them. It does not unfold what the interpreter does with script.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.