Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

PaysForRBF is one inequality

Proved
BitcoinReplacement.paysForRBF_iff

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

bip125bitcoinfee-marketformal-verificationmathlibmempoolpinningpolicyrbf

For any rate and replacement: PaysForRBF rate R iff totalFee R.evicted + rate.getFee R.new.vsize ≤ R.new.fee.

Preamble
import Definitions.Def_BitcoinReplacement
Formal statement
theorem BitcoinReplacement.paysForRBF_iff (rate : BitcoinReplacement.FeeRate)
    (R : BitcoinReplacement.Replacement) :
    BitcoinReplacement.PaysForRBF rate R ↔
      BitcoinReplacement.totalFee R.evicted + 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.paysForRBF_iff

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).

Statement. For every fee rate rrr and every replacement RRR (with no validity or other hypothesis), the following two conditions are equivalent:

  • Left side: PaysForRBF⁡(r,R)\operatorname{PaysForRBF}(r, R)PaysForRBF(r,R), i.e. the conjunction
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),

where −˙\dot-−˙​ is truncated natural-number subtraction;

  • Right side: the single natural-number inequality
totalFee⁡(R.evicted)+getFee⁡r(vsize⁡(R.new))≤fee⁡(R.new).\operatorname{totalFee}(R.\mathrm{evicted}) + \operatorname{getFee}_r(\operatorname{vsize}(R.\mathrm{new})) \le \operatorname{fee}(R.\mathrm{new}).totalFee(R.evicted)+getFeer​(vsize(R.new))≤fee(R.new).

Edge cases and scope. The condition PaysMoreThanConflicts⁡(R)\operatorname{PaysMoreThanConflicts}(R)PaysMoreThanConflicts(R) (the strict fee-rate comparison against R.directR.\mathrm{direct}R.direct) plays no role on either side; R.directR.\mathrm{direct}R.direct is not mentioned. If R.evictedR.\mathrm{evicted}R.evicted is empty then totalFee⁡(R.evicted)=0\operatorname{totalFee}(R.\mathrm{evicted}) = 0totalFee(R.evicted)=0 and both sides reduce to getFee⁡r(vsize⁡(R.new))≤fee⁡(R.new)\operatorname{getFee}_r(\operatorname{vsize}(R.\mathrm{new})) \le \operatorname{fee}(R.\mathrm{new})getFeer​(vsize(R.new))≤fee(R.new). If rfee=0r_{\mathrm{fee}} = 0rfee​=0 then getFee⁡r(⋅)=0\operatorname{getFee}_r(\cdot) = 0getFeer​(⋅)=0 and both sides reduce to totalFee⁡(R.evicted)≤fee⁡(R.new)\operatorname{totalFee}(R.\mathrm{evicted}) \le \operatorname{fee}(R.\mathrm{new})totalFee(R.evicted)≤fee(R.new). The equivalence is a biconditional, in both directions.

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