CastToBool is 'nonzero as a script number'
ProvedBitcoinScript.castToBool_iffFor every byte list , . In particular both encodings of zero — all-zero bytes, and zero bytes followed by 0x80 (negative zero) — are false, and every other byte list is true, whatever its length.
import Definitions.Def_BitcoinScript
theorem BitcoinScript.castToBool_iff (v : Bytes) : BitcoinScript.castToBool v = true ↔ BitcoinScript.setVch v ≠ 0 := by sorry
Read-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: BitcoinScript.castToBool_iff
Binders and hypothesis. There is a single universally quantified variable , a finite list of bytes (8-bit words), of any length including zero. There are no hypotheses, no flags, no oracle, and no other parameters.
Conclusion. The statement is a biconditional between two Boolean/propositional facts about :
Unfolding the left-hand side. is the recursive function with ; for a single byte; and when is non-empty. Spelled out: is true exactly when there is some byte of that is non-zero, except in the special case where every byte before the last is and the last byte is exactly , which is false. In particular , , , and are all false, while , and are true.
Unfolding the right-hand side. is the integer
where is the little-endian unsigned value (, ) and clears bit of the last byte only. Hence exactly when every byte of is after ignoring the sign bit of the last byte — i.e. when is empty, or all-zero, or all-zero except that its last byte is . The right-hand side is the negation of that: some byte of has a bit set other than the sign bit of the final byte.
The claim, in words. For every byte list , the truthiness test (some non-zero byte, with "negative zero" counted as false) coincides with the numeric value under the sign-magnitude little-endian reading being non-zero. Both directions are asserted: whenever the Boolean test is true the integer is non-zero, and whenever the integer is non-zero the Boolean test is true. Equivalently, if and only if .
Edge cases included by the quantifier. (both sides false: and ). (both sides false: the single-byte clause excludes , and ). Lists of arbitrary length, including lists far longer than any numeric size limit used elsewhere in the file (4 or 5 bytes): the statement does not restrict length, so it concerns on lists of, say, 1000 bytes just as much as on short ones. Lists with trailing zero bytes such as (both sides true) and non-minimal encodings are all included.
What is not said. The theorem does not mention toNum, minimal encodings, nonMinimal, or any size limit; it says nothing about how was produced, and nothing about serialize. It does not assert that equals or any round-trip property. It does not say which non-zero value takes, only that it is non-zero; in particular it does not relate the sign or magnitude of to anything. It does not state the contrapositive form separately, though that follows logically from the biconditional. It makes no claim about the interpreter (execOp, step, run) or about how the result of castToBool is used by OP_IF, OP_VERIFY, OP_IFDUP or verifyScriptPlain; in particular it does not assert that a script's final truth value is determined by a numeric value. It does not involve any oracle or flags.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.