What the Lean code literally says, in plain math · claude-fable-5-1 (independent sub-agent, blind: Lean code + auditor instructions only)
Read-back: BitcoinAnchors.received_p2wsh_spend
Declaration. For every Taproot handler tap (an arbitrary function from (context, witness list, program) to Booleans, unconstrained), every verification context c (a seven-Boolean flag record c.flags with fields p2sh,witness,taproot,dersig,cltv,csv,nulldummy; a transaction c.tx; an input index c.nIn∈N; an amount c.amount∈Z), all byte strings H (revHash), R (remoteKey), L (localKey), P (payHash), every integer e (expiry), and every list of byte strings ws, under the hypotheses c.flags.witness=true (hf), ∣H∣≤520 (hrev), ∣R∣≤520 (hrem), ∣L∣≤520 (hloc), ∣P∣≤520 (hpay) and ∣e∣<232 (hd, absolute value; e may be negative or zero), the following biconditional holds. Let X=receivedBytes(H,R,L,P,e), the byte string spelled out in part P (containing numBytes(e)).
Left. verifyScript(tap,c,[],witnessBytes(0,SHA256(X)), ws++[X])=true: the procedure of part B with empty scriptSig, scriptPubKey [0x00,0x20]++SHA256(X) and witness list ws followed by X. By part B this is: castToBool(SHA256(X))=true, every element of ws is at most 520 bytes, X is at most 10000 bytes and parses, and evalScript(scriptFlagsOf(c.flags),oX,reverse(ws),parseScript(X)) is some of a one-element, castToBool-true stack.
Right. The conjunction of
- castToBool(SHA256(X))=true;
- every element e′ of ws satisfies ∣e′∣≤520;
- ReceivedSpend(scriptFlagsOf(c.flags), oX, H,R,L,P,e, reverse(ws)), with oX=legacyOracle(sigFlagsOf(c.flags),c.tx,c.nIn,c.amount,witnessV0,X) the concrete oracle of part B: o.hash160 is ripemd160∘SHA256, o.checkSig is the concrete ECDSA/BIP143 check with script code X, f.nulldummy is c.flags.nulldummy, CsvPasses(f,o,1) is "c.flags.csv=false or checkSequence(c.tx,c.nIn,1)=true", and CltvPasses(f,o,e) is "c.flags.cltv=false or (0≤e and checkLockTime(c.tx,c.nIn,e)=true)", the latter unfolded in part B (same side of the 500000000 threshold, e≤c.tx.nLockTime, and the input's nSequence not 0xffffffff). Explicitly, with st=reverse(ws): (1) st=[pk,σ], hash160(pk)=H, oX.checkSig(σ,pk)=some true; or (2) st=[x,σL,σR,d], hash160(x)=H, ∣x∣=32, hash160(x)=P, oX.checkSig(σL,L)=some true and oX.checkSig(σR,R)=some true, (c.flags.nulldummy=true⇒d=[]), CSV-1 condition; or (3) st=[x,σ], hash160(x)=H, ∣x∣=32, CLTV-e condition, oX.checkSig(σ,R)=some true, CSV-1 condition.
Only c.flags.witness is fixed; c.flags.csv, cltv, nulldummy, dersig, p2sh, taproot are unconstrained and enter the right side through scriptFlagsOf and sigFlagsOf; c.tx, c.nIn (possibly out of range) and c.amount (possibly negative) are unconstrained. The witness list ws may be empty or of any length, and its elements are reversed on the right side: the last element of ws is the top of the stack reverse(ws).
Common unfolded definitions, part A: the script interpreter
Everything below is a literal unfolding of the definitions the statement depends on. Nothing here is a claim about the theorem; it only says what the symbols mean.
Bytes and stacks. A byte is an 8-bit word, i.e. a value in {0,…,255}. A byte string is a finite list of bytes; ∣v∣ is its length and [] is the empty byte string. A stack is a finite list of byte strings written top first: in [a,b,c] the element a is on top. The constants are MAX_SCRIPT_ELEMENT_SIZE=520, MAX_STACK_SIZE=1000, MAX_OPS_PER_SCRIPT=201, MAX_PUBKEYS_PER_MULTISIG=20.
Truth value of a byte string, castToBool(v): [] is false; a one-byte string [b] is true iff b=0 and b=0x80; a string b::r of length at least two is true iff b=0 or castToBool(r). Equivalently, v is true iff some byte of v is nonzero, except that a string consisting of zero bytes followed by a final byte 0x80 is false.
boolBytes: boolBytes(true)=[0x01] (the single byte 1) and boolBytes(false)=[] (the empty byte string).
Stack literals used in the statements. [[1]] is the stack with exactly one element, the one-byte string 0x01; [[16]] is the stack with exactly one element, the one-byte string 0x10 (decimal 16); [[]] is the stack with exactly one element, the empty byte string; [] is the empty stack. A stack written [σ] has exactly one element σ; [x,σ] has exactly two, x on top.
Flags f: a record of three Booleans f.cltv, f.csv, f.nulldummy. No other verification flag exists in this model. Where f is a parameter of a theorem, all three values are unconstrained.
Oracle o: a record of arbitrary functions with no axioms relating them to each other or to anything else: five byte-string-to-byte-string functions o.ripemd160, o.sha1, o.sha256, o.hash160, o.hash256; a function o.checkSig(σ,k) from pairs of byte strings (first the signature, second the key) to the three values none, some true, some false; and two functions o.checkLockTime,o.checkSequence:Z→{true,false}. In particular, in a theorem that takes o as a parameter, o.hash160 is an arbitrary function (its outputs need not be 20 bytes long, it need not be injective, and it has no relation to o.sha256), and o.checkSig is an arbitrary three-valued function.
Script numbers. serialize(v) for v∈Z: [] if v=0; otherwise the little-endian bytes of ∣v∣ with no trailing zero byte, after which: if the last byte has its top bit (0x80) set, one extra byte is appended (0x80 if v<0, 0x00 if v>0); otherwise, if v<0, the top bit of the last byte is set. Thus serialize(1)=[0x01], serialize(2)=[0x02], serialize(16)=[0x10], serialize(32)=[0x20]. The decoding setVch(v) is 0 for [], and otherwise the little-endian value of v with the top bit of the last byte removed and read as a minus sign. toNum(false,m,v) is none if m<∣v∣ and somesetVch(v) otherwise (no minimal-encoding check is made).
Instructions and scripts. An instruction is either a push push(d) of a byte string d, or an opcode op(c) for a byte c. A script is a finite list of instructions. Opcode bytes that occur: OP_1NEGATE =0x4f, OP_1 =0x51, OP_2 =0x52, OP_16 =0x60, OP_IF =0x63, OP_NOTIF =0x64, OP_ELSE =0x67, OP_ENDIF =0x68, OP_IFDUP =0x73, OP_DROP =0x75, OP_DUP =0x76, OP_SWAP =0x7c, OP_SIZE =0x82, OP_EQUAL =0x87, OP_EQUALVERIFY =0x88, OP_HASH160 =0xa9, OP_CHECKSIG =0xac, OP_CHECKSIGVERIFY =0xad, OP_CHECKMULTISIG =0xae, OP_CHECKLOCKTIMEVERIFY =0xb1, OP_CHECKSEQUENCEVERIFY =0xb2.
numInstr(n) for n∈Z: if n=−1 or 1≤n≤16, the opcode op(n+0x50) (so numInstr(1)=op(OP_1), numInstr(2)=op(OP_2), numInstr(16)=op(OP_16), numInstr(−1)=op(0x4f)); otherwise the push push(serialize(n)) (so numInstr(32)=push([0x20]) and numInstr(0)=push([])).
The parsed scripts of the anchors file, for arbitrary byte strings K (funding key), R (remote key), L (local key), H (revocation hash), P (payment hash) and an integer e (expiry):
toRemoteScript(R)=[push(R), op(OP_CHECKSIGVERIFY), op(OP_1), op(OP_CHECKSEQUENCEVERIFY)].
anchorScript(K)=[push(K), op(OP_CHECKSIG), op(OP_IFDUP), op(OP_NOTIF), op(OP_16), op(OP_CHECKSEQUENCEVERIFY), op(OP_ENDIF)].
offeredScript(H,R,L,P) is the 30-instruction list: OP_DUP, OP_HASH160, push(H), OP_EQUAL, OP_IF, OP_CHECKSIG, OP_ELSE, push(R), OP_SWAP, OP_SIZE, push([0x20]), OP_EQUAL, OP_NOTIF, OP_DROP, OP_2, OP_SWAP, push(L), OP_2, OP_CHECKMULTISIG, OP_ELSE, OP_HASH160, push(P), OP_EQUALVERIFY, OP_CHECKSIG, OP_ENDIF, OP_1, OP_CHECKSEQUENCEVERIFY, OP_DROP, OP_ENDIF.
receivedScript(H,R,L,P,e) is the 32-instruction list: OP_DUP, OP_HASH160, push(H), OP_EQUAL, OP_IF, OP_CHECKSIG, OP_ELSE, push(R), OP_SWAP, OP_SIZE, push([0x20]), OP_EQUAL, OP_IF, OP_HASH160, push(P), OP_EQUALVERIFY, OP_2, OP_SWAP, push(L), OP_2, OP_CHECKMULTISIG, OP_ELSE, OP_DROP, numInstr(e), OP_CHECKLOCKTIMEVERIFY, OP_DROP, OP_CHECKSIG, OP_ENDIF, OP_1, OP_CHECKSEQUENCEVERIFY, OP_DROP, OP_ENDIF.
Execution state: a main stack, an alt stack, a condition stack vfExec (a list of Booleans) and an op counter. The initial state for a stack st has main stack st, empty alt stack, empty vfExec, counter 0. The machine is executing when every entry of vfExec is true (vacuously, when vfExec is empty).
evalScript(f,o,st,S): starting from the initial state of st, apply step to the instructions of S in order; if any step returns none the result is none; after the last instruction the result is none if vfExec is non-empty and otherwise some of the final main stack. So the value is either none (script failure) or somest′ for a stack st′ (the alt stack and the counter are discarded).
step on push(d): none if 520<∣d∣; otherwise, if executing, d is placed on top of the main stack (if not executing, nothing changes); then none if the main-stack size plus the alt-stack size exceeds 1000, else the new state.
step on op(c): c is counted when 0x60<c; if counted and the counter plus one exceeds 201, none; otherwise the counter is incremented when counted; none if c is one of the fifteen disabled opcodes (none of the opcodes listed above is disabled); otherwise, if executing or 0x63≤c≤0x68 (the conditionals), execOp is applied and the result is none if it is none or if the stack-size sum then exceeds 1000; otherwise (not executing, not a conditional) the state is unchanged, again subject to the size check.
execOp(f,o,fExec,c,s) for the opcodes that occur ("none" means script failure; "no change" means the state is returned unchanged):
- OP_1NEGATE, OP_1, …, OP_16: push serialize(c−0x50); so OP_1 pushes [0x01], OP_2 pushes [0x02], OP_16 pushes [0x10]. These bytes are ≤0x60, so they are not counted.
- OP_CHECKLOCKTIMEVERIFY: if f.cltv=false, no change. Otherwise none on an empty stack; else with top t (not popped): none if ∣t∣>5; with n=setVch(t), none if n<0, none if o.checkLockTime(n)=false, else no change.
- OP_CHECKSEQUENCEVERIFY: if f.csv=false, no change. Otherwise none on an empty stack; else with top t (not popped): none if ∣t∣>5; with n=setVch(t), none if n<0; no change if bit 31 of n is set (precisely: max(n,0)&231=0); else none if o.checkSequence(n)=false, else no change.
- OP_IF / OP_NOTIF: if executing, none on an empty stack; else the top t is popped, v=castToBool(t) (negated for OP_NOTIF) and v is pushed onto vfExec. If not executing, false is pushed onto vfExec and the stack is untouched.
- OP_ELSE: none if vfExec is empty; else its top entry is negated.
- OP_ENDIF: none if vfExec is empty; else its top entry is removed.
- OP_IFDUP: none on an empty stack; else if castToBool of the top is true the top is duplicated, otherwise no change.
- OP_DROP: none on an empty stack; else the top is removed. OP_DUP: none on an empty stack; else the top is duplicated. OP_SWAP: none with fewer than two elements; else the top two are exchanged. OP_SIZE: none on an empty stack; else serialize(∣t∣) is pushed above the top t, which stays.
- OP_EQUAL / OP_EQUALVERIFY: none with fewer than two elements; else the top a and the next b are popped and eq is the proposition "a and b are the same byte string"; OP_EQUAL pushes boolBytes(eq); OP_EQUALVERIFY pushes nothing and is none when eq is false.
- OP_HASH160: none on an empty stack; else the top t is replaced by o.hash160(t).
- OP_CHECKSIG / OP_CHECKSIGVERIFY: none with fewer than two elements; else the top k (the key) and the next σ (the signature) are popped and o.checkSig(σ,k) is consulted: none gives none; someok: OP_CHECKSIG pushes boolBytes(ok), while OP_CHECKSIGVERIFY pushes nothing and is none when ok=false.
- OP_CHECKMULTISIG: none on an empty stack; the top nk is popped and decoded by toNum(false,4,⋅) (none if longer than 4 bytes); none if nk<0 or 20<nk; the counter becomes counter +nk, none if that exceeds 201; the next nk elements are the keys (none if fewer remain); the next element ns is popped (none if none remains) and decoded likewise, none if ns<0 or nk<ns; the next ns elements are the signatures (none if fewer remain); multisigLoop(o,sigs,keys) is computed: none gives none; someok: none if no element remains, else one more element dummy is popped, none if f.nulldummy=true and dummy=[], else boolBytes(ok) is pushed.
multisigLoop(o,sigs,keys) (both lists top first): some true if sigs is empty; some false if sigs is non-empty and keys is empty; otherwise, with σ the first signature and k the first key, o.checkSig(σ,k): none gives none; some true gives some false if fewer keys than signatures remain after removing both, else the loop on the remaining signatures and remaining keys; some false gives some false if the remaining keys are fewer than all the current signatures, else the loop on the same signatures and the remaining keys. For the only instance that occurs, multisigLoop(o,[σL,σR],[L,R]) unfolds to: none if o.checkSig(σL,L)=none; some false if o.checkSig(σL,L)=some false; and, if o.checkSig(σL,L)=some true, the value o.checkSig(σR,R) itself. Hence it equals some true iff o.checkSig(σL,L)=some true and o.checkSig(σR,R)=some true; the signature σR is never checked against L, nor σL against R.
CsvPasses(f,o,d) for d∈Z:
f.csv=false ∨ (0≤d ∧ (max(d,0)&231=0 ∨ o.checkSequence(d)=true)).
For d=1 and d=16 the bit-31 disjunct is false (1&231=0 and 16&231=0), so CsvPasses(f,o,1)⟺f.csv=false∨o.checkSequence(1)=true and CsvPasses(f,o,16)⟺f.csv=false∨o.checkSequence(16)=true. When f and o are arbitrary parameters, o.checkSequence is an arbitrary function of an integer.
CltvPasses(f,o,e) for e∈Z: f.cltv=false ∨ (0≤e ∧ o.checkLockTime(e)=true).
topTrue(st): false for the empty stack; castToBool of the top element otherwise.
The spend predicates of the anchors file (all stacks top first; σ,σL,σR,pk,x,d range over byte strings):
ToRemoteSpend(f,o,R,st): there is σ with st=[σ], o.checkSig(σ,R)=some true and CsvPasses(f,o,1).
AnchorSpend(f,o,K,st): there is σ with st=[σ] and either o.checkSig(σ,K)=some true, or both o.checkSig(σ,K)=some false and CsvPasses(f,o,16).
OfferedSpend(f,o,H,R,L,P,st) is the disjunction of
- there are pk,σ with st=[pk,σ], o.hash160(pk)=H and o.checkSig(σ,pk)=some true;
- there are x,σ with st=[x,σ], o.hash160(x)=H, ∣x∣=32, o.hash160(x)=P, o.checkSig(σ,R)=some true and CsvPasses(f,o,1);
- there are x,σL,σR,d with st=[x,σL,σR,d], o.hash160(x)=H, ∣x∣=32, multisigLoop(o,[σL,σR],[L,R])=some true, (f.nulldummy=true⇒d=[]) and CsvPasses(f,o,1).
ReceivedSpend(f,o,H,R,L,P,e,st) is the disjunction of
- there are pk,σ with st=[pk,σ], o.hash160(pk)=H and o.checkSig(σ,pk)=some true;
- there are x,σL,σR,d with st=[x,σL,σR,d], o.hash160(x)=H, ∣x∣=32, o.hash160(x)=P, multisigLoop(o,[σL,σR],[L,R])=some true, (f.nulldummy=true⇒d=[]) and CsvPasses(f,o,1);
- there are x,σ with st=[x,σ], o.hash160(x)=H, ∣x∣=32, CltvPasses(f,o,e), o.checkSig(σ,R)=some true and CsvPasses(f,o,1).
Common unfolded definitions, part P: byte-level scripts and parsing
Canonical push, pushBytes(d) for a byte string d: if ∣d∣<76 (= 0x4c), the single byte ∣d∣ followed by d; else if ∣d∣≤255, the bytes 0x4c, ∣d∣, then d; else if ∣d∣≤65535, the byte 0x4d, the two little-endian bytes of ∣d∣, then d; else the byte 0x4e, the four little-endian bytes of ∣d∣, then d.
numBytes(n) for n∈Z: if n=−1 or 1≤n≤16, the single byte n+0x50 (so numBytes(1)=[0x51], numBytes(2)=[0x52], numBytes(16)=[0x60]); otherwise pushBytes(serialize(n)) (so numBytes(32)=[0x01,0x20] and numBytes(0)=[0x00], the empty push).
The serialized scripts of the anchors file (byte strings, ++ is concatenation):
toRemoteBytes(R)=pushBytes(R)++[0xad]++[0x51]++[0xb2].
anchorBytes(K)=pushBytes(K)++[0xac,0x73,0x64]++[0x60]++[0xb2,0x68].
offeredBytes(H,R,L,P)=[0x76,0xa9]++pushBytes(H)++[0x87,0x63,0xac,0x67]++pushBytes(R)++[0x7c,0x82]++[0x01,0x20]++[0x87,0x64,0x75]++[0x52]++[0x7c]++pushBytes(L)++[0x52]++[0xae,0x67,0xa9]++pushBytes(P)++[0x88,0xac,0x68]++[0x51]++[0xb2,0x75,0x68].
receivedBytes(H,R,L,P,e)=[0x76,0xa9]++pushBytes(H)++[0x87,0x63,0xac,0x67]++pushBytes(R)++[0x7c,0x82]++[0x01,0x20]++[0x87,0x63,0xa9]++pushBytes(P)++[0x88]++[0x52]++[0x7c]++pushBytes(L)++[0x52]++[0xae,0x67,0x75]++numBytes(e)++[0xb1,0x75,0xac,0x68]++[0x51]++[0xb2,0x75,0x68].
getOp(s), one instruction off the front of a byte string: none if s is empty. Otherwise let c be the first byte and r the rest. If c≤0x4e: the push size is c itself when c<0x4c; the next byte when c=0x4c (none if r is empty); the little-endian value of the next two bytes when c=0x4d (none if fewer than two remain); the little-endian value of the next four bytes when c=0x4e (none if fewer than four remain); then, with the size bytes removed from r, none if fewer than size bytes remain, else the pair (push of the next size bytes, the remainder). If c>0x4e: the pair (op(c), r).
parseScript(s): an auxiliary recursion with fuel ∣s∣: on the empty string, some[]; with fuel 0 and a non-empty string, none; otherwise getOp (none propagates) and the instruction is prepended to the parse of the remainder with one less fuel. The value is either none or some of a list of instructions.
Common unfolded definitions, part B: the verification layer
Concrete hashes. sha256 (written here SHA256) is a fixed, concrete implementation of SHA-256 on byte strings, producing a 32-byte string; ripemd160 likewise is concrete RIPEMD-160 (20 bytes); hash160=ripemd160∘SHA256; hash256=SHA256∘SHA256. These are the only places where hashing is concrete; nothing is assumed about them beyond their definitions.
Consensus flags c.flags: a record of seven Booleans p2sh,witness,taproot,dersig,cltv,csv,nulldummy. scriptFlagsOf(F) is the interpreter flag record ⟨F.cltv,F.csv,F.nulldummy⟩; sigFlagsOf(F) is the signature-layer flag record ⟨dersig=F.dersig, lowS=false, strictenc=false, witnessPubkeyType=false⟩.
Context c: a record with c.flags as above, a transaction c.tx, an input index c.nIn∈N and an amount c.amount∈Z. A transaction tx has tx.version∈N, a list of inputs tx.vin, a list of outputs tx.vout and tx.nLockTime∈N; an input has a previous outpoint, a scriptSig, nSequence∈N and a witness list. No range bounds (e.g. below 232) are imposed on version, nSequence or nLockTime unless a hypothesis states one, and c.nIn may exceed the number of inputs.
inputSequence(tx,n): the nSequence of the n-th input (0-based) of tx, or 0 when n is not a valid index (the default input has nSequence=0).
Taproot handler tap: an arbitrary function from (context, witness list, program bytes) to Booleans; it is a parameter with no hypotheses.
witnessBytes(0,prog): the byte 0x00 followed by pushBytes(prog). For a 32-byte prog this is the 34-byte string [0x00,0x20]++prog.
checkSequence(tx,n,q) for q∈Z: let τ=inputSequence(tx,n); false if tx.version<2; false if τ&231=0; otherwise with mask m=222∣0xffff, τm=τ&m and qm=max(q,0)&m: false unless (τm<222 and qm<222) or (222≤τm and 222≤qm); false if τm<qm; else true. For q=16: qm=16, so checkSequence(tx,n,16)=true iff 2≤tx.version, bit 31 of τ is clear, bit 22 of τ is clear, and 16≤τ&0xffff. For q=1: likewise with 1≤τ&0xffff.
checkLockTime(tx,n,t) for t∈Z: false unless (tx.nLockTime<500000000 and t<500000000) or (500000000≤tx.nLockTime and 500000000≤t); false if tx.nLockTime<t; false if inputSequence(tx,n)=0xffffffff; else true.
Signature check with the flags sigFlagsOf(c.flags), version witnessV0, script code X: checkSigPreTapscript(σ,k) is none iff c.flags.dersig=true, σ=[] and σ fails the strict-DER test isValidSignatureEncoding (the public-key encoding check always passes because strictenc and witnessPubkeyType are off); otherwise it is some of checkECDSASignature(c.tx,c.nIn,c.amount,witnessV0,σ,k,X), which is: false if k is not a public key of valid declared length (first byte 2 or 3 with ∣k∣=33, or 4, 6 or 7 with ∣k∣=65); false if σ=[]; otherwise, with the last byte of σ as the hash type and σ′ the rest, false if c.amount<0, else the ECDSA verification (lax DER parse of σ′, low-S normalization, secp256k1 verification) of the BIP143 signature hash of c.tx at input c.nIn with script code X, amount c.amount and that hash type, under key k. In particular the empty signature [] always yields some false, never none.
legacyOracle(sigFlagsOf(c.flags),c.tx,c.nIn,c.amount,witnessV0,X): the oracle whose five hash functions are the concrete ripemd160,sha1,SHA256,hash160,hash256, whose checkSig is the function just described (with script code X unchanged, no FindAndDelete), whose checkLockTime is checkLockTime(c.tx,c.nIn,⋅) and whose checkSequence is checkSequence(c.tx,c.nIn,⋅). Below this oracle is written oX.
evalBytes(c,v,st,s): none if 10000<∣s∣; else none if parseScript(s)=none; else evalScript(scriptFlagsOf(c.flags), legacyOracle(sigFlagsOf(c.flags),c.tx,c.nIn,c.amount,v,s), st, parseScript(s)).
isWitnessProgram(s): none if ∣s∣<4 or 42<∣s∣; with b0 the first byte, none if b0=0 and (b0<0x51 or 0x60<b0); some(version, s without its first two bytes) if the second byte plus 2 equals ∣s∣, where version is 0 for b0=0 and b0−0x50 otherwise; none otherwise.
executeWitnessScriptV0(c,st,X): false if some element of st is longer than 520 bytes; else evalBytes(c,witnessV0,st,X): none gives false; somest′ gives (∣st′∣=1 and topTrue(st′)).
verifyWitnessProgram(tap,c,w,version,prog,isP2sh), for version 0 and ∣prog∣=32: false if w is empty; else with X the last element of w, false if SHA256(X)=prog, else executeWitnessScriptV0(c, reverse(w without its last element), X). (Version 0 with a 20-byte program is the P2WPKH case; other version-0 lengths give false; version 1 with a 32-byte non-P2SH program gives true if c.flags.taproot is off and tap(c,w,prog) otherwise; everything else gives true.)
verifyScript(tap,c,scriptSig,scriptPubKey,w): evaluate evalBytes(c,base,[],scriptSig) (none gives false) to a stack st1; evaluate evalBytes(c,base,st1,scriptPubKey) (none gives false) to a stack st2; false if topTrue(st2) is false. Then, if c.flags.witness is true and isWitnessProgram(scriptPubKey)=some(version,prog): the result is false if scriptSig=[] and otherwise verifyWitnessProgram(tap,c,w,version,prog,false). Otherwise (witness flag off, or not a witness program) the P2SH branch applies: if c.flags.p2sh and scriptPubKey is 0xa9 ⟨20 bytes⟩ 0x87, the redeem script is run (details omitted here as they do not arise for the statements' arguments); else false if c.flags.witness is on and w is non-empty, else true.
Unfolding on the arguments of this statement (scriptSig =[], scriptPubKey =witnessBytes(0,SHA256(X)) for a script byte string X, witness list w=ws++[X], and c.flags.witness=true): evalBytes of the empty scriptSig yields the empty stack; the scriptPubKey [0x00,0x20]++SHA256(X) parses to [push([]),push(SHA256(X))] and evaluates to the stack [SHA256(X),[]], whose topTrue is castToBool(SHA256(X)) (true iff the 32-byte digest is not all zero bytes and is not 31 zero bytes followed by 0x80); isWitnessProgram of that 34-byte string is some(0,SHA256(X)); the last element of w is X and SHA256(X)=SHA256(X), so the verdict is executeWitnessScriptV0(c,reverse(ws),X): false if some element of ws exceeds 520 bytes, false if ∣X∣>10000 or X does not parse, and otherwise "evalScript(scriptFlagsOf(c.flags),oX,reverse(ws),parseScript(X)) is some of a one-element stack whose element is castToBool-true".
Confirmed by the moderator at approval.