Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

A push-only scriptSig satisfies IsPushOnly

Proved
BitcoinVerify.isPushOnly_pushes

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

bip141bitcoinbitcoin-mainnetconsensusformal-verificationp2shsegwitverifyscript

For elements each within 520 bytes, isPushOnly (pushesBytes ps) = true.

Preamble
import Definitions.Def_BitcoinVerify
import Definitions.Def_BitcoinScript
open BitcoinVerify BitcoinSer BitcoinSig
open BitcoinScript hiding Bytes Byte
Formal statement
theorem BitcoinVerify.isPushOnly_pushes (ps : List Bytes) (hp : ∀ p ∈ ps, p.length ≤ BitcoinScript.MAX_SCRIPT_ELEMENT_SIZE) :
    BitcoinVerify.isPushOnly (BitcoinVerify.pushesBytes ps) = true := by sorry
Source
Bitcoin Core a773e1e33b349dc819b5a0edc1c7a4839dc73b48: VerifyScript, VerifyWitnessProgram, ExecuteWitnessScript, src/script/interpreter.cpp: https://github.com/bitcoin/bitcoin/blob/a773e1e33b349dc819b5a0edc1c7a4839dc73b48/src/script/interpreter.cpp; CScript::IsPayToScriptHash, IsWitnessProgram, IsPushOnly, IsPayToAnchor, DecodeOP_N, src/script/script.cpp and script.h; MAX_SCRIPT_SIZE, WITNESS_V0_SCRIPTHASH_SIZE, WITNESS_V0_KEYHASH_SIZE, WITNESS_V1_TAPROOT_SIZE; BIP16, BIP141, BIP143 at bips revision 100ba872c808946155b1eeb8c4568058f2eea0a7
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: BitcoinVerify.isPushOnly_pushes

Binders and hypothesis. One universally quantified variable pspsps, a finite list of byte strings (each byte string a finite list of 8-bit bytes). One hypothesis hp: for every element ppp of the list pspsps, ∣p∣≤520|p| \le 520∣p∣≤520 (the constant MAX_SCRIPT_ELEMENT_SIZE). The list may be empty, in which case the hypothesis is vacuous.

Conclusion.

isPushOnly(pushesBytes(ps))=true.\mathrm{isPushOnly}\big(\mathrm{pushesBytes}(ps)\big) = \mathrm{true}.isPushOnly(pushesBytes(ps))=true.

Unfolding pushesBytes. pushesBytes ps is the concatenation, in list order, of pushBytes p for each p∈psp \in psp∈ps, where pushBytes p is the canonical push encoding of ppp: if ∣p∣<76|p| < 76∣p∣<76, the length byte ∣p∣|p|∣p∣ followed by ppp (for p=[]p = []p=[] this is the single byte 0x00\mathtt{0x00}0x00); if 76≤∣p∣≤25576 \le |p| \le 25576≤∣p∣≤255, the byte 0x4c\mathtt{0x4c}0x4c (OP_PUSHDATA1), one length byte, then ppp; if 256≤∣p∣≤65535256 \le |p| \le 65535256≤∣p∣≤65535, the byte 0x4d\mathtt{0x4d}0x4d (OP_PUSHDATA2), two little-endian length bytes, then ppp; otherwise 0x4e\mathtt{0x4e}0x4e (OP_PUSHDATA4), four little-endian length bytes, then ppp. Under the hypothesis ∣p∣≤520|p| \le 520∣p∣≤520, only the first three forms occur. For the empty list, pushesBytes [] = [].

Unfolding isPushOnly. isPushOnly s runs isPushOnlyAux with fuel ∣s∣|s|∣s∣ on sss. The auxiliary returns true on the empty string; false when the fuel is 000 and the string is non-empty; otherwise it calls the byte-level parser getOp on the string: if getOp fails (a push opcode whose declared length exceeds the remaining bytes, or a PUSHDATA prefix with too few length bytes), the result is false; if it returns a push instruction, the auxiliary recurses on the remaining bytes with one less fuel; if it returns a non-push opcode ccc, the result is false when 0x60<c\mathtt{0x60} < c0x60<c (opcodes above OP_16) and otherwise recurses. getOp consumes at least one byte per call, so fuel ∣s∣|s|∣s∣ never runs out before the string is exhausted.

What the theorem therefore says. For every list of byte strings each of at most 520 bytes, the concatenation of their canonical pushes, when parsed instruction by instruction, consists only of instructions that are data pushes (or opcodes ≤0x60\le \mathtt{0x60}≤0x60, which cannot arise from pushBytes), and the parse never fails. In particular the parser re-finds exactly the push boundaries written by pushBytes.

What is not said. The theorem does not state the converse (that every push-only byte string is of the form pushesBytes ps); it does not say anything about lists containing an element longer than 520 bytes (the statement is silent, not negative, for those — isPushOnly itself has no size test, but the theorem's hypothesis excludes them); it says nothing about the number of elements or the total length (no MAX_SCRIPT_SIZE or MAX_STACK_SIZE bound appears); it does not say that evaluating pushesBytes ps succeeds or produces any particular stack; and it does not relate isPushOnly to parseScript or to verifyScript.

Human review
  • Endorsed by Shuze Chen · Oct 27, 2026

    Confirmed by the moderator at approval.

  • Endorsed by pitimespi · Oct 27, 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