An input spending a native witness program has an empty scriptSig when its script verifies
ProvedBitcoinMalleability.native_scriptSig_emptyFor script flags with WITNESS set, a ledger and a transaction whose CheckInputScripts succeeds: every input whose spent output is a native witness program has scriptSig = []. (VerifyScript returns SCRIPT_ERR_WITNESS_MALLEATED otherwise; the VerifyScript mission's native_witness_malleated lifted to the block mission's per-input loop.)
import Definitions.Def_BitcoinMalleability import Definitions.Def_BitcoinActivation import Definitions.Def_BitcoinSer import Definitions.Def_BitcoinVerify open BitcoinMalleability BitcoinSer BitcoinBlockV2
theorem BitcoinMalleability.native_scriptSig_empty (f : BitcoinActivation.ScriptFlags) (u : Ledger)
(tx : BitcoinSer.Tx) (hf : f.witness = true) (h : BitcoinBlockV2.inputScriptsOk f u tx = true) :
∀ i ∈ tx.vin, BitcoinVerify.isWitnessProgram (BitcoinBlockV2.accessCoin u i.prevout).out.scriptPubKey ≠ none →
i.scriptSig = [] := 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: BitcoinMalleability.native_scriptSig_empty
Statement in words
For every consensus flag set , every ledger and every transaction , if the witness flag of is on and every input script of verifies against under (in the sense of , unfolded below), then every input occurring in whose spent output script (looked up in ) is a witness program has an empty .
Binders and hypotheses
Universally quantified, with no other constraints than those listed:
- : a record of seven Booleans . Only is constrained (below); the other six are arbitrary.
- : a ledger, i.e. a finite association list of pairs (outpoint, coin), where an outpoint is with a byte string of any length and , and a coin is with . Keys need not be distinct.
- : a transaction , where each input is (outpoint, byte string, natural number, list of byte strings) and each output is . No well-formedness is assumed.
- Hypothesis : .
- Hypothesis : .
Conclusion
Membership "" is list membership: the input equals some element of the list (its position does not matter).
The notions, unfolded
Lookup. is the coin of the first pair in whose outpoint equals , or, if there is none, the dummy coin , whose output script is empty.
Witness program. For a byte string of length , is defined iff , the first byte is or in , and ; it then yields with if else , and (length to ). The empty string is not a witness program, so the conclusion's antecedent fails for any input whose outpoint is absent from .
Input scripts OK. Let and . Then means: for every index with , writing ,
where is a verification context (flags, spending transaction, input index, amount ; for a missing coin, ), and is the Taproot handler of the Taproot file for the spent-output list (described below). When the condition is vacuously true.
verifyScript for a handler , context , scriptSig , scriptPubKey and witness stack (a list of byte strings in serialized order, last element on top) is the Boolean computed as follows:
- Evaluate with signature version base on the empty stack: . If this fails, the result is false; otherwise let be the resulting stack (top first).
- Evaluate on : . If this fails, false; otherwise let be the resulting stack. If is empty or its top element is "false" under (a byte string is true iff some byte is non-zero, except that a string whose only non-zero byte is a final is false), the result is false.
- Native witness branch, taken only if is on and is defined: the result is false if , and otherwise is . This verdict is final.
- Otherwise, if is on and is pay-to-script-hash (, , , ): false unless is push-only (every instruction of parses and is a data push or an opcode ); false if is empty; otherwise with ( the top), evaluate ; false on failure or on a non-true top; then, if is on and : false unless , else ; if is on and is not a witness program: false if , else true; if the witness flag is off: true.
- Otherwise (neither branch): false if is on and ; else true.
Here ("evalBytes") is: undefined if ; undefined if does not parse into a sequence of script instructions; otherwise the final stack (top first) of the Script interpreter run from stack on the parsed , with interpreter flags and the legacy signature/lock-time oracle built from , , , , , script code ; undefined if the interpreter fails. is the canonical push of : a length byte then if ; , one length byte, if ; , two little-endian length bytes, if ; else , four little-endian length bytes, .
verifyWitnessProgram : if and : false if is empty; else with the last element of , false if , else "execute witness script" with the reversed remaining elements as stack and script . If and : false unless , else execute with stack reversed and the implied script . If and : false. If , and : true when is off, else . Every other case (other versions, version-1 programs of other lengths, version 1 inside P2SH, pay-to-anchor) is true. "Execute witness script" with stack and script is: false if any element of exceeds bytes; else must be defined, leave exactly one element, and that element must be true.
The Taproot handler : false if is empty; otherwise an annex (a last element starting with byte when ) is split off; if one element remains it is checked as a Schnorr key-path signature for over , and ; otherwise the last element is a control block whose length must be for some , the element before it is the leaf script, the control block must commit to the leaf, and for leaf version the tapscript is executed on the remaining elements with a validation-weight budget; other leaf versions give true. (The handler is consulted only in the case , , not P2SH, taproot flag on.)
Edge cases made explicit
- If is empty, both and the conclusion hold vacuously.
- The hypothesis ranges over inputs by position (with the amount and context index ), while the conclusion ranges over inputs by membership; an input occurring twice in is verified at both positions.
- requires every input to verify, including inputs spending non-witness-program outputs and inputs whose outpoint is absent from (then the output script is and the amount is ); the conclusion speaks only of inputs whose looked-up script is a witness program.
- Any witness version – and program length – counts as a witness program in the conclusion.
- No well-formedness of or , no distinctness of ledger keys, no coinbase exclusion, and no constraint on , , , , , is assumed.
- The statement says nothing about witnesses, sequence numbers, outputs, or the transaction identifier.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.