Strict DER accepts the canonical layout
ProvedBitcoinSig.derEncode_validFor minimal big-endian integers (non-empty, top bit clear, no leading zero unless needed) with and any hash-type byte, isValidSignatureEncoding (derEncode r s ht) = true.
import Definitions.Def_BitcoinSig open BitcoinSig BitcoinSer
theorem BitcoinSig.derEncode_valid (r s : Bytes) (ht : Byte) (hr : BitcoinSig.minimalInt r)
(hs : BitcoinSig.minimalInt s) (hlen : r.length + s.length ≤ 66) :
BitcoinSig.isValidSignatureEncoding (BitcoinSig.derEncode r s ht) = true := 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: BitcoinSig.derEncode_valid
Binders and hypothesis. Universally quantified over byte strings and and a byte , with three hypotheses:
- :
minimalInt, i.e. , the first byte of is0x80, and if and the first byte of is then the second byte of is0x80; - :
minimalInt, the same three conditions for ; - : . Since both strings are non-empty, each has length between and .
Conclusion.
Unfolding the encoding. derEncode is the byte string , of total length , which under lies in . Under all the "mod 256" reductions are identities.
Unfolding the check. isValidSignatureEncoding on this string examines, in order (with byte meaning the -th byte, if out of range): (true); (true by ); byte 0 is 0x30 (true); byte 1 equals (true); := byte 3 , and (true since ); := byte , which is the byte right after 's tag, i.e. , and (true); byte 2 is 0x02 (true); (true by ); byte 4 — the first byte of — is 0x80 (true by ); it is not the case that and 's first byte is and 's second byte (byte 5) is 0x80 (true by ); byte — the tag after — is 0x02 (true); (true by ); byte — the first byte of — is 0x80 (true by ); not ( and 's first byte is and 's second byte is 0x80) (true by ). The final byte is never inspected. Hence the check returns true.
What is not said. The statement does not say anything when (then the encoded length exceeds 73 and the check would fail, but the theorem is silent). It does not say anything about non-minimal or empty or . It does not say that the hash-type byte is a "defined" hash type, nor that it is examined — the encoding check ignores it. It does not say that or read as integers are non-zero, below , or low (the byte string is a valid minimalInt, and the string 0x7f followed by 64 0xff bytes is too). It does not say that parseDerLax accepts the encoding, that checkLowS holds, or anything about checkSignatureEncoding with any flags (which additionally depends on lowS and strictenc). It does not state the converse decomposition; that is the separate completeness statement.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.