Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

A push is never a proper prefix of another push

Proved
BitcoinUniqueness.pushBytes_prefix

by pitimespi · Oct 29, 2026 · Mathlib 0df444a (Lean v4.33.1)

bip30bip34bitcoinbitcoin-mainnetcoinbaseconsensusformal-verificationuniqueness

For byte strings d,d′d, d'd,d′ shorter than 2322^{32}232: if the canonical push of ddd is a prefix of the canonical push of d′d'd′ then d=d′d = d'd=d′. The first byte fixes the encoding class (direct, PUSHDATA1/2/4) and, with the length field, the length.

Preamble
import Definitions.Def_BitcoinUniqueness
import Definitions.Def_BitcoinSer
import Definitions.Def_BitcoinSig
open BitcoinUniqueness BitcoinSer BitcoinBlockV2
Formal statement
theorem BitcoinUniqueness.pushBytes_prefix (d d' : BitcoinSer.Bytes) (hd : d.length < 2 ^ 32) (hd' : d'.length < 2 ^ 32)
    (h : (BitcoinSig.pushBytes d).isPrefixOf (BitcoinSig.pushBytes d') = true) : d = d' := by sorry
Source
Bitcoin Core a773e1e33b349dc819b5a0edc1c7a4839dc73b48: ConnectBlock (fEnforceBIP30, BIP34_IMPLIES_BIP30_LIMIT), ContextualCheckBlock (the BIP34 height push), src/validation.cpp: https://github.com/bitcoin/bitcoin/blob/a773e1e33b349dc819b5a0edc1c7a4839dc73b48/src/validation.cpp; CScript::push_int64, CScriptNum::serialize (script/script.h); BIP30, BIP34
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: BitcoinUniqueness.pushBytes_prefix

Statement. For all byte strings ddd and d′d'd′ (finite lists of 8-bit words) such that

  • ∣d∣<232|d| < 2^{32}∣d∣<232 and
  • ∣d′∣<232|d'| < 2^{32}∣d′∣<232,

if pushBytes(d)\mathrm{pushBytes}(d)pushBytes(d) is a prefix (initial segment, possibly the whole string) of pushBytes(d′)\mathrm{pushBytes}(d')pushBytes(d′), then d=d′d = d'd=d′.

Formally:

∀d,d′∈Bytes,∣d∣<232 ∧ ∣d′∣<232 ∧ pushBytes(d)⊑pushBytes(d′) ⟹ d=d′,\forall d, d' \in \mathrm{Bytes},\quad |d| < 2^{32} \ \wedge\ |d'| < 2^{32} \ \wedge\ \mathrm{pushBytes}(d) \sqsubseteq \mathrm{pushBytes}(d') \ \Longrightarrow\ d = d',∀d,d′∈Bytes,∣d∣<232 ∧ ∣d′∣<232 ∧ pushBytes(d)⊑pushBytes(d′) ⟹ d=d′,

where x⊑yx \sqsubseteq yx⊑y means y=x+ ⁣ ⁣+zy = x \mathbin{+\!\!+} zy=x++z for some byte string zzz.

What pushBytes says

For a byte string ddd with length ℓ=∣d∣\ell = |d|ℓ=∣d∣:

pushBytes(d)={[ℓ]+ ⁣ ⁣+dℓ<76 (0x4c),[0x4c, ℓ]+ ⁣ ⁣+d76≤ℓ≤255,[0x4d]+ ⁣ ⁣+le2(ℓ)+ ⁣ ⁣+d256≤ℓ≤65535,[0x4e]+ ⁣ ⁣+le4(ℓ)+ ⁣ ⁣+dℓ≥65536,\mathrm{pushBytes}(d) = \begin{cases} [\ell] \mathbin{+\!\!+} d & \ell < 76 \ (\mathtt{0x4c}),\\ [\mathtt{0x4c},\ \ell] \mathbin{+\!\!+} d & 76 \le \ell \le 255,\\ [\mathtt{0x4d}] \mathbin{+\!\!+} \mathrm{le}_2(\ell) \mathbin{+\!\!+} d & 256 \le \ell \le 65535,\\ [\mathtt{0x4e}] \mathbin{+\!\!+} \mathrm{le}_4(\ell) \mathbin{+\!\!+} d & \ell \ge 65536,\end{cases}pushBytes(d)=⎩⎨⎧​[ℓ]++d[0x4c, ℓ]++d[0x4d]++le2​(ℓ)++d[0x4e]++le4​(ℓ)++d​ℓ<76 (0x4c),76≤ℓ≤255,256≤ℓ≤65535,ℓ≥65536,​

where [ℓ][\ell][ℓ] and [0x4c,ℓ][\mathtt{0x4c}, \ell][0x4c,ℓ] write ℓ\ellℓ as one byte (reduced modulo 256, which is lossless in those branches), and lek(ℓ)\mathrm{le}_k(\ell)lek​(ℓ) is the kkk-byte little-endian encoding of ℓ mod 28k\ell \bmod 2^{8k}ℓmod28k. In the last branch the length is encoded modulo 2322^{32}232; the hypotheses ∣d∣,∣d′∣<232|d|, |d'| < 2^{32}∣d∣,∣d′∣<232 make that encoding lossless.

Edge cases and scope

  • d=[ ]d = [\,]d=[]: pushBytes([ ])=[0x00]\mathrm{pushBytes}([\,]) = [\mathtt{0x00}]pushBytes([])=[0x00]; the claim then says no non-empty d′d'd′ (of length below 2322^{32}232) has a push beginning with the byte 0x00\mathtt{0x00}0x00.
  • The prefix relation is reflexive, so d=d′d = d'd=d′ trivially satisfies the hypothesis; the content is the converse direction only.
  • The two length bounds are hypotheses on the claim's scope; pushBytes\mathrm{pushBytes}pushBytes is defined for every byte string. The theorem says nothing about strings of length ≥232\ge 2^{32}≥232.
  • The statement concerns only the canonical push encoding of two byte strings; no script parsing, block or chain state is involved.
Human review
  • Endorsed by Shuze Chen · Oct 29, 2026

    Confirmed by the moderator at approval.

  • Endorsed by pitimespi · Oct 29, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me