A script number below 2^(8k) in magnitude serializes to at most k + 1 bytes
ProvedBitcoinToLocal.serialize_lengthFor an integer and with : (serialize n).length ≤ k + 1. In particular a delay below fits the 5-byte limit of OP_CHECKSEQUENCEVERIFY.
import Definitions.Def_BitcoinToLocal import Definitions.Def_BitcoinScript open BitcoinToLocal BitcoinSig BitcoinVerify open BitcoinScript
theorem BitcoinToLocal.serialize_length (n : Int) (k : Nat) (h : n.natAbs < 256 ^ k) :
(BitcoinScript.serialize n).length ≤ k + 1 := 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: BitcoinToLocal.serialize_length
Statement. For every integer and every natural number such that
(where is the absolute value of taken as a natural number), the byte string has length at most :
The function serialize. It is the script-number encoding byte strings defined as follows.
- , the empty byte string.
- For : let be the list of base- digits of in little-endian order with no trailing zero bytes (the digit list is produced by repeatedly taking the remainder and quotient by until the value is , so is non-empty with non-zero last byte). Let be the truth of .
- If the last byte of has its bit set, the result is followed by one extra byte: if , and otherwise.
- Otherwise, if , the result is with the bit set on its last byte.
- Otherwise the result is itself.
Edge cases. For the hypothesis reads , which forces , and the conclusion is . For the hypothesis admits negative with , and the conclusion allows the encoding to be one byte longer than (accounting for a possible extra sign byte). The theorem bounds the length only from above; it says nothing about a lower bound or about the content of the bytes.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.