The serializer always produces a minimal encoding
ProvedBitcoinScript.serialize_minimalFor every integer , : the output of CScriptNum::serialize never has a final byte without value bits that the previous byte could absorb. Consequently the interpreter's own numeric results always pass the MINIMALDATA test.
import Definitions.Def_BitcoinScript
theorem BitcoinScript.serialize_minimal (n : Int) : BitcoinScript.nonMinimal (BitcoinScript.serialize n) = false := 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.serialize_minimal
Binders and hypothesis. One universally quantified variable , an integer (of either sign, any magnitude, including ). No hypotheses.
Conclusion. The Boolean
is equal to false. Since nonMinimal returns true to signal a non-minimal encoding, the claim is: the byte list produced by serialize from any integer is never flagged as non-minimal by nonMinimal.
Unfolding serialize. For , . For : let , the little-endian bytes of the absolute value with no trailing zero bytes (so is non-empty and its last byte is non-zero). If the last byte of has bit set, the output is followed by one extra byte, when and when . Otherwise, the output is with bit set on its last byte when , and itself when .
Unfolding nonMinimal. Given a byte list : if , the result is false. Otherwise let be the final byte and consider the byte before it, if any. The result is
That is, is "non-minimal" when the last byte is or and either has length one or the preceding byte has its top bit clear.
The claim, case by case (as the code determines it). The theorem asserts that for every integer , the output of serialize falls outside the "non-minimal" pattern:
- : the output is , on which
nonMinimalis false by its first clause. - with no extra byte appended: the last byte is the last byte of (non-zero, top bit clear), possibly with its top bit set by
setTop; in either case its low seven bits are non-zero, so the first conjunct fails. - with an extra byte or appended: the last byte has zero low bits, so the first conjunct holds, and the claim is that the second conjunct fails: the preceding byte (the last byte of ) has its top bit set. The theorem states the conclusion for all at once; the above is merely the shape the definitions give it.
Edge cases included. ; (one byte, and ); ; (two bytes with an appended sign/padding byte); , ; arbitrarily large magnitudes (there is no bound on and the output may be arbitrarily long — longer than the 4- and 5-byte limits that toNum enforces elsewhere).
What is not said. The theorem does not say that serialize produces the shortest encoding in any sense other than the specific predicate nonMinimal; it does not say that serialize is injective, nor that (that is a separate theorem in this bundle). It does not say anything about nonMinimal on lists that are not in the image of serialize, nor that every list on which nonMinimal is false is in the image of serialize (e.g. nothing is claimed about versus beyond what serialize produces). It does not bound the length of , and so says nothing about whether toNum with its size limit would accept the result. It does not involve toNum's requireMinimal flag directly, the interpreter, flags, or the oracle.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.