What the Lean code literally says, in plain math · claude-fable-5-1 (independent sub-agent, blind: Lean code + auditor instructions only)
Read-back: BitcoinTaproot.scriptpath_commitment
Binders. spent : a list of transaction outputs; c : a verification context BitcoinVerify.Ctx (fields flags — Booleans p2sh, witness, taproot, dersig, cltv, csv, nulldummy —, tx, nIn∈N, amount∈Z); stack : a list of byte strings; script,control,q : byte strings.
Throughout, W:=stack∥[script,control] denotes the witness list consisting of the elements of stack followed by script and then control (so ∣W∣≥2 and control is last).
Hypotheses.
- hasAnnex(W)=false. Unfolded: hasAnnex(W) is "∣W∣≥2 and the last element of W is non-empty with first byte equal to 0x50"; since ∣W∣≥2 holds, the hypothesis says exactly that control is empty or its first byte is not 0x50.
- taprootHandler(spent)(c,W,q)=true.
Conclusion.
verifyTaprootCommitment(control,q,tapleafHash(⟨control0&0xfe⟩8, script))=true,
where control0 is the first byte of control as a natural (default 0 if control is empty), & is bitwise AND, ⟨⋅⟩8 converts a natural to an 8-bit value (mod 256), and tapleafHash(v,s)=tagged("TapLeaf",[v]∥CompactSize(∣s∣)∥s).
verifyTaprootCommitment, unfolded. verifyTaprootCommitment(control,q,ℓ)=checkTapTweak(q, control[1:33], taprootMerkleRoot(control,ℓ), [control0 is odd]), where control[1:33] is "drop the first byte, then take up to 32 bytes" (shorter if control is shorter than 33 bytes), and the parity bit is the low bit of the first control byte (default 0). taprootMerkleRoot(control,ℓ) is the left fold h0=ℓ, hj+1=tapbranchHash(hj,Nj) over the k=⌊(∣control∣−˙33)/32⌋ consecutive 32-byte chunks Nj of control after its first 33 bytes; tapbranchHash(x,y)=tagged("TapBranch",minlex(x,y)∥maxlex(x,y)) with the file's lexicographic order (ties concatenate y∥x, which equals x∥y). checkTapTweak(q,int,m,π) is: let P:=liftX(BE(int)) — none if BE(int)≥p or if x3+7 is not a square mod p, else the point with abscissa x=BE(int) and even ordinate; false if P is none; otherwise xonlyTweakAddCheck(q,π,P,tapTweakHash(int,m)), where tapTweakHash(int,m)=tagged("TapTweak",int∥m), and xonlyTweakAddCheck(q,π,P,T) is: let t:=BE(T); false if n≤t; let Q:=P+t⋅G (bundle's affine formulas, t⋅G being none when t=0 so that Q=P); false if Q is the point at infinity; else true iff the 32-byte big-endian encoding of xQmod2256 equals q and (yQ is odd) =π. tagged(T,m)=SHA256(SHA256(T)∥SHA256(T)∥m), T the UTF-8 bytes of the tag.
Hypothesis 2, unfolded. taprootHandler(spent)(c,W,q): W is non-empty; by hypothesis 1 there is no annex, so the working stack is W itself; its length is ∣stack∣+2=1, so the key path is not taken. The script path pops the last element as the control block (=control), then the last remaining element as the script (=script), leaving stack. It returns false if ∣control∣<33, or ∣control∣>4129 (=33+32⋅128), or (∣control∣−33)mod32=0. Otherwise, with leaf version v:=control0&0xfe and ℓ:=tapleafHash(⟨v⟩8,script), it returns false if verifyTaprootCommitment(control,q,ℓ) is false; otherwise, if v=0xc0 it returns executeTapscript of the Tapscript context (flags cltv, csv, nulldummy from c.flags, c.tx, spent, c.nIn), the ExecData (false,[],ℓ,0xFFFFFFFF), the reversed stack, script, and the initial weight (serialized size of the whole witness W as a CompactSize-prefixed list of CompactSize-prefixed elements) +50; and if v=0xc0 it returns true. Hence hypothesis 2 entails that the size checks pass and that the commitment check in the conclusion evaluates to true (plus either successful Tapscript execution or an unknown leaf version), and the theorem extracts the commitment part.
Edge cases the quantifiers include. stack=[] (witness of exactly two elements); control empty or shorter than 33 bytes — then hypothesis 2 is false and the statement is vacuous for those; control with first byte 0x50 is excluded by hypothesis 1 (first byte 0x51 is allowed, giving the same leaf version 0x50); q of length =32 makes the commitment false, hence hypothesis 2 false; leaf versions other than 0xc0, where hypothesis 2 reduces to the size and commitment checks alone; script empty; c.flags.taproot and c.amount unused.
Confirmed by the moderator at approval.