Unknown witness versions are accepted
ProvedBitcoinVerify.unknown_witness_versionWith the WITNESS flag, an output OP_v <program> with , or with a program that is not 32 bytes (including pay-to-anchor), spent with an empty scriptSig and any witness, verifies exactly when the program is true as a script value. This is the future-soft-fork compatibility rule: such outputs are anyone-can-spend, except that an all-zero program fails the base evaluation.
import Definitions.Def_BitcoinVerify import Definitions.Def_BitcoinScript open BitcoinVerify BitcoinSer BitcoinSig open BitcoinScript hiding Bytes Byte
theorem BitcoinVerify.unknown_witness_version (tap : TaprootHandler) (c : Ctx) (v : Nat) (prog : Bytes)
(w : List Bytes) (hf : c.flags.witness = true) (hv : v ≤ 16)
(hu : 2 ≤ v ∨ (v = 1 ∧ prog.length ≠ 32)) (h2 : 2 ≤ prog.length) (h40 : prog.length ≤ 40) :
BitcoinVerify.verifyScript tap c [] (BitcoinVerify.witnessBytes v prog) w = BitcoinScript.castToBool prog := 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.unknown_witness_version
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 with consensus flags c.flags, transaction c.tx, input index c.nIn, integer amount c.amount; , a natural number; prog, a byte string; , a list of byte strings (the witness). Five hypotheses:
hf:c.flags.witness = true;hv: ;hu: , or ( and );h2: ;h40: .
Together hv and hu give , excluding entirely and excluding the single combination with a 32-byte program.
Conclusion. With (the opcode OP_v, a direct-push length byte, then the program; ):
This is an equality of Booleans: the verification succeeds exactly when the program bytes cast to true, and fails exactly when they cast to false (all zero bytes, or all zero but a final ).
Unfolding the left-hand side. The empty scriptSig evaluates to the empty stack. is evaluated with version base: the opcode byte is OP_v, which pushes the minimal encoding of the number ; the push adds prog. The top-first stack is and topTrue is ; when it is false verifyScript returns false, matching the right side. Otherwise, since the witness flag is on (hf), the native branch computes isWitnessProgram π: length in by h2, h40; first byte in by hv and ; second byte ; so it yields with . The scriptSig is empty, so the verdict is verifyWitnessProgram tap c w v prog false.
Unfolding verifyWitnessProgram. , so the version-0 arm is skipped. The Taproot arm requires and and not-P2SH; hypothesis hu rules out the first two together. The remaining arm returns true both when isPayToAnchor v prog holds ( and ) and when it does not. So the verdict is true, the witness being ignored entirely — it may be empty or arbitrary. Combining: the left side is .
Logical content. For every handler, every context with the witness flag on, every version and every program of bytes except the (version , 32-byte) case, and every witness, the full verification with an empty scriptSig succeeds iff the program bytes cast to true. The handler tap and the taproot, p2sh and other flags do not affect the result; neither does the content of .
What is not said. Nothing about (P2WSH/P2WPKH, where lengths matter); nothing about with a 32-byte program (the Taproot case, which depends on c.flags.taproot and tap); nothing about (where witnessBytes is not a witness program); nothing when the witness flag is off; nothing for a non-empty scriptSig; nothing about P2SH-wrapped programs. The theorem does not say the outcome is "true": for a program of all zero bytes it asserts the verification is false.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.