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.keypath_annex
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); sig,annex,q : byte strings.
Hypotheses.
- (annex0), the first byte of annex read as a natural (default 0 if annex is empty), equals 0x50=80 (the constant
ANNEX_TAG);
- annex=[].
Conclusion (an equality of Booleans).
taprootHandler(spent)(c,[sig,annex],q)=checkSchnorrSignature(c.tx,spent,c.nIn,sig,q,false,(true,SHA256(serBytes(annex)),[],0xFFFFFFFF)),
where serBytes(annex)=CompactSize(∣annex∣)∥annex and the last argument is the ExecData record with annexPresent =true, annexHash =SHA256(serBytes(annex)), empty tapleafHash, and codeseparatorPos =232−1.
The left side, unfolded. taprootHandler(spent)(c,W,q): false if W=[]; otherwise hasAnnex(W) is "∣W∣≥2 and the last element of W is non-empty with first byte 0x50"; when it holds the annex is the last element and the stack is W minus its last element, otherwise there is no annex and the stack is W; e0 is (annex present, SHA256(serBytes(annex)) if present else [], [], 0xFFFFFFFF); if the stack has exactly one element x the result is checkSchnorrSignature(c.tx,spent,c.nIn,x,q,false,e0); otherwise the script path is taken (control block and script from the end of the stack, control size checks, commitment check, Tapscript execution or acceptance of an unknown leaf version). For W=[sig,annex]: ∣W∣=2, and by hypotheses 1–2 the last element annex is non-empty with first byte 0x50, so hasAnnex holds, the stack is [sig] of length 1, e0=(true,SHA256(serBytes(annex)),[],0xFFFFFFFF), and the key path is taken. Neither c.flags.taproot nor c.amount is consulted.
The signature check, unfolded. checkSchnorrSignature(tx,S,i,sig,pk,τ,e) (with S the spent-output list, i the input index, τ the tapscript flag, e the ExecData) is the Boolean computed as follows: if ∣sig∣=64 and ∣sig∣=65, false; otherwise let t:= the last byte of sig as a natural if ∣sig∣=65, else t:=0, and sig′:=sig without its last byte if ∣sig∣=65, else sig; if ∣sig∣=65 and t=0, false; otherwise compute sigHashSchnorr(tx,S,i,t,τ,e) — if that is none, false; if it is some(h), the result is schnorrVerify(pk,h,sig′).
schnorrVerify(pk,m,σ) is: false if ∣pk∣=32 or ∣σ∣=64; let r:=BE(σ[0:32]) and s:=BE(σ[32:64]) (big-endian values); false if p≤r or n≤s (p=2256−232−977 the field prime, n the secp256k1 group order); let P:=liftX(BE(pk)), which is none if BE(pk)≥p, and otherwise, with x:=BE(pk) and y:=(x3+7)(p+1)/4modp, is the point (x,y) if y is even, or (x,p−y) if y is odd, provided y2≡x3+7(modp), and none otherwise; false if P is none; let c:=BE(tagged("BIP0340/challenge",σ[0:32]∥pk∥m))modn; let R:=s⋅G+((n−c)modn)⋅P computed with the bundle's affine addition/doubling formulas (with the point at infinity as none) and a 257-step double-and-add; false if R is none; otherwise true iff yR is even and xR=r.
sigHashSchnorr(tx,S,i,t,τ,e), with e=(a,A,L,κ) (annex present, annex hash, tapleaf hash, code-separator position), is: none unless t∈{0,1,2,3,0x81,0x82,0x83}; let o:=1 if t=0 else t&3; ι:=t&0x80; ς:=2[τ]+[a] (so 0, 1, 2 or 3); I:= the i-th input of tx, or, if i≥∣vin∣, the default input (prevout with empty hash and index 0, empty scriptSig, sequence 0, empty witness); if o=3 then single:= none when ∣vout∣≤i and otherwise SHA256(serTxOut(vouti)), else single:=[]; if single is none the result is none; otherwise the result is some of
tagged("TapSighash", [0x00,tmod256]∥le32(version)∥le32(nLockTime)∥Hin∥Hout∥[ς]∥D∥(A if a else [])∥single∥(L∥[0x00]∥le32(κ) if τ else []))
where Hin is empty if ι=0x80 and otherwise is the concatenation of four SHA-256 digests: of all inputs' serialized outpoints (hash ∥ le32 index), of all elements of S's values as 8-byte little-endian two's complement, of all elements of S's scriptPubKeys each prefixed by its CompactSize length, and of all inputs' le32 sequences; Hout is the SHA-256 of all outputs serialized (le64 two's-complement value ∥ CompactSize-prefixed script) if o=1, and empty otherwise; D is serOutPoint(I.prevout)∥serTxOut(Si or the default output (−1,[]) if i≥∣S∣)∥le32(I.nSequence) if ι=0x80, and le32(i) otherwise. tagged(T,m)=SHA256(SHA256(T)∥SHA256(T)∥m) with T the UTF-8 bytes of the tag; le32(x) is the 4-byte little-endian encoding of xmod232; CompactSize is 1 byte below 253, else 0xfd + 2 bytes up to 0xffff, else 0xfe + 4 bytes up to 0xffffffff, else 0xff + 8 bytes. All SHA-256 computations are the bundle's own implementation.
In this instance τ=false and a=true, so ς=1, the message contains SHA256(serBytes(annex)) right after the per-input data, and no tapscript extension.
Edge cases the quantifiers include. Hypothesis 2 is implied by hypothesis 1 (an empty annex would give first byte 0=80), so it adds nothing; annex=[0x50] (one byte); sig of any length (both sides false unless 64 or 65 with non-zero last byte); q of any length; c.nIn out of range (default input and default output (−1,[]) in the hash); spent of any length; arbitrary flags.
Confirmed by the moderator at approval.