Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

The pinning bound is exactly rule 4

Proved
BitcoinReplacement.pinning_cost_tight

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

bip125bitcoinfee-marketformal-verificationmathlibmempoolpinningpolicyrbf

If R.evicted = t ::ₘ D then PaysForRBF rate R iff t.fee+totalFee(D)+getFee(vsize R.new)≤R.new.feet.\text{fee} + \text{totalFee}(D) + \text{getFee}(\text{vsize } R.\text{new}) \le R.\text{new}.\text{fee}t.fee+totalFee(D)+getFee(vsize R.new)≤R.new.fee: the bound of pinning_cost is attained, so the pinning cost is neither more nor less than the descendants' fees plus the incremental fee.

Preamble
import Definitions.Def_BitcoinReplacement
Formal statement
theorem BitcoinReplacement.pinning_cost_tight (rate : BitcoinReplacement.FeeRate)
    (t : BitcoinReplacement.Tx) (D : Multiset BitcoinReplacement.Tx)
    (R : BitcoinReplacement.Replacement) (hE : R.evicted = t ::ₘ D) :
    BitcoinReplacement.PaysForRBF rate R ↔
      t.fee + BitcoinReplacement.totalFee D + rate.getFee R.new.vsize ≤ R.new.fee := by sorry
Source
Bitcoin Core a773e1e33b349dc819b5a0edc1c7a4839dc73b48: PaysForRBF (src/policy/rbf.cpp: https://github.com/bitcoin/bitcoin/blob/a773e1e33b349dc819b5a0edc1c7a4839dc73b48/src/policy/rbf.cpp), CFeeRate::GetFee = FeePerVSize::EvaluateFeeUp (policy/feerate.cpp, util/feefrac.h), DEFAULT_INCREMENTAL_RELAY_FEE (policy/policy.h); PaysMoreThanConflicts as last present in policy/rbf.cpp at v29.0; BIP125
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: BitcoinReplacement.pinning_cost_tight

Setting (unfolded from the preamble). All declarations live in a namespace BitcoinReplacement. A transaction ttt is a pair of natural numbers (fee⁡(t),vsize⁡(t))(\operatorname{fee}(t), \operatorname{vsize}(t))(fee(t),vsize(t)) together with a proof that vsize⁡(t)>0\operatorname{vsize}(t) > 0vsize(t)>0; fee⁡(t)\operatorname{fee}(t)fee(t) may be 000. Two transactions are equal exactly when their fees and virtual sizes agree. A fee rate rrr is a pair of natural numbers (rfee,rsize)(r_{\mathrm{fee}}, r_{\mathrm{size}})(rfee​,rsize​) together with a proof that rsize>0r_{\mathrm{size}} > 0rsize​>0; rfeer_{\mathrm{fee}}rfee​ may be 000, and nothing identifies (1,2)(1,2)(1,2) with (2,4)(2,4)(2,4). For a fee rate rrr and a natural number vvv,

getFee⁡r(v)  =  ⌊rfee⋅v+(rsize−1)rsize⌋,\operatorname{getFee}_r(v) \;=\; \left\lfloor \frac{r_{\mathrm{fee}}\cdot v + (r_{\mathrm{size}} - 1)}{r_{\mathrm{size}}} \right\rfloor ,getFeer​(v)=⌊rsize​rfee​⋅v+(rsize​−1)​⌋,

computed with natural-number (rounding-down) division; since rsize≥1r_{\mathrm{size}} \ge 1rsize​≥1 the inner subtraction rsize−1r_{\mathrm{size}}-1rsize​−1 is exact, and the value equals ⌈rfee v/rsize⌉\lceil r_{\mathrm{fee}}\, v / r_{\mathrm{size}}\rceil⌈rfee​v/rsize​⌉. In particular getFee⁡r(0)=0\operatorname{getFee}_r(0) = 0getFeer​(0)=0, and getFee⁡r(v)=0\operatorname{getFee}_r(v) = 0getFeer​(v)=0 for every vvv whenever rfee=0r_{\mathrm{fee}} = 0rfee​=0.

A replacement RRR consists of a transaction R.newR.\mathrm{new}R.new, a multiset of transactions R.evictedR.\mathrm{evicted}R.evicted, a multiset of transactions R.directR.\mathrm{direct}R.direct, and a proof that R.direct≤R.evictedR.\mathrm{direct} \le R.\mathrm{evicted}R.direct≤R.evicted as multisets (every transaction value occurs in R.directR.\mathrm{direct}R.direct at most as many times as it occurs in R.evictedR.\mathrm{evicted}R.evicted). Either multiset may be empty, R.newR.\mathrm{new}R.new may itself occur in R.evictedR.\mathrm{evicted}R.evicted, and no other relation between the three components is imposed. For a multiset sss of transactions, totalFee⁡(s)=∑u∈sfee⁡(u)\operatorname{totalFee}(s) = \sum_{u \in s} \operatorname{fee}(u)totalFee(s)=∑u∈s​fee(u), summed with multiplicity, so totalFee⁡(∅)=0\operatorname{totalFee}(\varnothing) = 0totalFee(∅)=0.

RRR is valid at rate rrr (written Valid⁡(r,R)\operatorname{Valid}(r,R)Valid(r,R)) when all three of the following hold:

  1. (PaysMoreThanConflicts⁡(R)\operatorname{PaysMoreThanConflicts}(R)PaysMoreThanConflicts(R)) for every transaction value uuu occurring in R.directR.\mathrm{direct}R.direct, fee⁡(u)⋅vsize⁡(R.new)<fee⁡(R.new)⋅vsize⁡(u)\operatorname{fee}(u)\cdot\operatorname{vsize}(R.\mathrm{new}) < \operatorname{fee}(R.\mathrm{new})\cdot\operatorname{vsize}(u)fee(u)⋅vsize(R.new)<fee(R.new)⋅vsize(u) (a strict cross-multiplied comparison in N\mathbb{N}N; vacuously true when R.directR.\mathrm{direct}R.direct is empty; nothing is required of elements of R.evictedR.\mathrm{evicted}R.evicted that do not occur in R.directR.\mathrm{direct}R.direct);
  2. (PaysForRBF⁡(r,R)\operatorname{PaysForRBF}(r,R)PaysForRBF(r,R), first conjunct) totalFee⁡(R.evicted)≤fee⁡(R.new)\operatorname{totalFee}(R.\mathrm{evicted}) \le \operatorname{fee}(R.\mathrm{new})totalFee(R.evicted)≤fee(R.new);
  3. (PaysForRBF⁡(r,R)\operatorname{PaysForRBF}(r,R)PaysForRBF(r,R), second conjunct) getFee⁡r(vsize⁡(R.new))≤fee⁡(R.new)−˙totalFee⁡(R.evicted)\operatorname{getFee}_r(\operatorname{vsize}(R.\mathrm{new})) \le \operatorname{fee}(R.\mathrm{new}) \mathbin{\dot-} \operatorname{totalFee}(R.\mathrm{evicted})getFeer​(vsize(R.new))≤fee(R.new)−˙​totalFee(R.evicted), where −˙\dot-−˙​ is truncated natural-number subtraction (it returns 000 when the subtrahend exceeds the minuend; under item 2 it coincides with ordinary subtraction).

For a transaction ttt and a multiset DDD of transactions, t::mDt ::_m Dt::m​D denotes the multiset obtained from DDD by adding one further copy of ttt.

Statement. For every fee rate rrr, every transaction ttt, every multiset DDD of transactions, and every replacement RRR such that

R.evicted  =  t::mDR.\mathrm{evicted} \;=\; t ::_m DR.evicted=t::m​D

as an equality of multisets (so R.evictedR.\mathrm{evicted}R.evicted is nonempty and consists exactly of one copy of ttt together with the elements of DDD), the following two conditions are equivalent:

  • Left side: PaysForRBF⁡(r,R)\operatorname{PaysForRBF}(r, R)PaysForRBF(r,R), i.e.
totalFee⁡(R.evicted)≤fee⁡(R.new)andgetFee⁡r(vsize⁡(R.new))≤fee⁡(R.new)−˙totalFee⁡(R.evicted),\operatorname{totalFee}(R.\mathrm{evicted}) \le \operatorname{fee}(R.\mathrm{new}) \quad\text{and}\quad \operatorname{getFee}_r(\operatorname{vsize}(R.\mathrm{new})) \le \operatorname{fee}(R.\mathrm{new}) \mathbin{\dot-} \operatorname{totalFee}(R.\mathrm{evicted}),totalFee(R.evicted)≤fee(R.new)andgetFeer​(vsize(R.new))≤fee(R.new)−˙​totalFee(R.evicted),

with −˙\dot-−˙​ truncated natural-number subtraction;

  • Right side:
fee⁡(t)+totalFee⁡(D)+getFee⁡r(vsize⁡(R.new))  ≤  fee⁡(R.new).\operatorname{fee}(t) + \operatorname{totalFee}(D) + \operatorname{getFee}_r(\operatorname{vsize}(R.\mathrm{new})) \;\le\; \operatorname{fee}(R.\mathrm{new}).fee(t)+totalFee(D)+getFeer​(vsize(R.new))≤fee(R.new).

Edge cases and scope. No validity hypothesis is assumed: PaysMoreThanConflicts⁡(R)\operatorname{PaysMoreThanConflicts}(R)PaysMoreThanConflicts(R) is neither assumed nor part of either side, and R.directR.\mathrm{direct}R.direct is not mentioned (it is constrained only by the built-in requirement R.direct≤R.evictedR.\mathrm{direct} \le R.\mathrm{evicted}R.direct≤R.evicted). DDD may be empty. Under the hypothesis, totalFee⁡(R.evicted)=fee⁡(t)+totalFee⁡(D)\operatorname{totalFee}(R.\mathrm{evicted}) = \operatorname{fee}(t) + \operatorname{totalFee}(D)totalFee(R.evicted)=fee(t)+totalFee(D). If rfee=0r_{\mathrm{fee}} = 0rfee​=0 the getFee⁡\operatorname{getFee}getFee term is 000. The equivalence is a biconditional.

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