Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

No free relay under the cluster-mempool rules

Proved
BitcoinFeerateDiagram.no_free_relay_diagram

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

bitcoincluster-mempoolfeefracfeerate-diagramformal-verificationmathlibmempoolpolicyrbf

If the old and new diagrams' totals are a common FFF plus the evicted fees and plus the replacement's fee, and both ImprovesFeerateDiagram and the replacement mission's PaysForRBF rate R hold: the new diagram is strictly better and its total fee exceeds the old by at least rate.getFee R.new.vsize. The replacement mission's no-free-relay theorems therefore hold at the pinned revision's actual rules.

Preamble
import Definitions.Def_BitcoinFeerateDiagram
open BitcoinFeerateDiagram BitcoinReplacement
Formal statement
theorem BitcoinFeerateDiagram.no_free_relay_diagram (rate : FeeRate) (R : Replacement)
    (old new : List FeeFrac) (F : ℤ) (hold : SizesPos old) (hnew : SizesPos new)
    (hfold : diagramFee old = F + totalFee R.evicted) (hfnew : diagramFee new = F + R.new.fee)
    (himp : ImprovesFeerateDiagram old new) (hpay : PaysForRBF rate R) :
    StrictlyBetter new old ∧ diagramFee old + rate.getFee R.new.vsize ≤ diagramFee new := by sorry
Source
Bitcoin Core a773e1e33b349dc819b5a0edc1c7a4839dc73b48: util/feefrac.h (FeeFrac :20, MulFallback :25-30, DivFallback :40-59, Mul/Div :64-82, operator+/- :120-131, EvaluateFee :147-175, ByRatio :217-240), util/overflow.h (CeilDiv :70-74), util/feefrac.cpp (CompareChunks :12-75), policy/rbf.cpp (ImprovesFeerateDiagram :127-140, PaysForRBF :100-125): https://github.com/bitcoin/bitcoin/blob/a773e1e33b349dc819b5a0edc1c7a4839dc73b48/src/util/feefrac.cpp; test vectors from src/test/rbf_tests.cpp (feerate_chunks_utilities) and src/test/feefrac_tests.cpp
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: BitcoinFeerateDiagram.no_free_relay_diagram

Statement. Let

  • rrr be a FeeRate (natural numbers fee(r)≥0\mathrm{fee}(r) \ge 0fee(r)≥0, size(r)>0\mathrm{size}(r) > 0size(r)>0),
  • RRR be a Replacement (a new transaction R.newR.\mathrm{new}R.new with natural-number fee and positive natural-number vsize, a multiset R.evictedR.\mathrm{evicted}R.evicted of transactions, and a sub-multiset R.direct≤R.evictedR.\mathrm{direct} \le R.\mathrm{evicted}R.direct≤R.evicted),
  • old\mathit{old}old and new\mathit{new}new be arbitrary finite lists of FeeFracs (possibly empty),
  • FFF be an arbitrary integer,

and assume

  1. SizesPos(old)\mathrm{SizesPos}(\mathit{old})SizesPos(old) and SizesPos(new)\mathrm{SizesPos}(\mathit{new})SizesPos(new): every chunk of either list has strictly positive size;
  2. diagramFee(old)=F+totalFee(R.evicted)\mathrm{diagramFee}(\mathit{old}) = F + \mathrm{totalFee}(R.\mathrm{evicted})diagramFee(old)=F+totalFee(R.evicted) (the natural-number total fee regarded as an integer);
  3. diagramFee(new)=F+fee(R.new)\mathrm{diagramFee}(\mathit{new}) = F + \mathrm{fee}(R.\mathrm{new})diagramFee(new)=F+fee(R.new) (regarded as an integer);
  4. ImprovesFeerateDiagram(old,new)\mathrm{ImprovesFeerateDiagram}(\mathit{old}, \mathit{new})ImprovesFeerateDiagram(old,new), i.e. compareChunks(new,old)=greater\mathrm{compareChunks}(\mathit{new}, \mathit{old}) = \mathsf{greater}compareChunks(new,old)=greater;
  5. PaysForRBF(r,R)\mathrm{PaysForRBF}(r, R)PaysForRBF(r,R), i.e. totalFee(R.evicted)≤fee(R.new)\mathrm{totalFee}(R.\mathrm{evicted}) \le \mathrm{fee}(R.\mathrm{new})totalFee(R.evicted)≤fee(R.new) and getFee(r,vsize(R.new))≤fee(R.new)−totalFee(R.evicted)\mathrm{getFee}(r, \mathrm{vsize}(R.\mathrm{new})) \le \mathrm{fee}(R.\mathrm{new}) - \mathrm{totalFee}(R.\mathrm{evicted})getFee(r,vsize(R.new))≤fee(R.new)−totalFee(R.evicted).

Then both of the following hold:

  • StrictlyBetter(new,old)\mathrm{StrictlyBetter}(\mathit{new}, \mathit{old})StrictlyBetter(new,old): diagram(old,x)≤diagram(new,x)\mathrm{diagram}(\mathit{old}, x) \le \mathrm{diagram}(\mathit{new}, x)diagram(old,x)≤diagram(new,x) for every rational x≥0x \ge 0x≥0, and diagram(old,x)<diagram(new,x)\mathrm{diagram}(\mathit{old}, x) < \mathrm{diagram}(\mathit{new}, x)diagram(old,x)<diagram(new,x) for some rational x≥0x \ge 0x≥0;
  • diagramFee(old)+getFee(r,vsize(R.new))≤diagramFee(new)\displaystyle \mathrm{diagramFee}(\mathit{old}) + \mathrm{getFee}\big(r, \mathrm{vsize}(R.\mathrm{new})\big) \le \mathrm{diagramFee}(\mathit{new})diagramFee(old)+getFee(r,vsize(R.new))≤diagramFee(new) (in Z\mathbb ZZ), where getFee(r,v)=(fee(r) v+size(r)−1)/size(r)\mathrm{getFee}(r, v) = \big(\mathrm{fee}(r)\,v + \mathrm{size}(r) - 1\big) \mathbin{/} \mathrm{size}(r)getFee(r,v)=(fee(r)v+size(r)−1)/size(r) with natural-number floor division.

Binders and edge cases. The chunk lists are tied to RRR only through hypotheses 2 and 3, i.e. through their total fees and the common integer offset FFF; nothing relates the chunks' sizes to vsize(R.new)\mathrm{vsize}(R.\mathrm{new})vsize(R.new) or to the evicted transactions' vsizes, nothing relates individual chunks to individual transactions, and R.directR.\mathrm{direct}R.direct plays no role. FFF may be any integer (including negative). Chunk fees are arbitrary integers; the lists are not assumed sorted by feerate; either list may be empty (total fee 000). R.evictedR.\mathrm{evicted}R.evicted may be the empty multiset (total fee 000). The fee rate rrr may have fee(r)=0\mathrm{fee}(r) = 0fee(r)=0, in which case getFee=0\mathrm{getFee} = 0getFee=0. Argument order: ImprovesFeerateDiagram takes old\mathit{old}old first and runs compareChunks with new\mathit{new}new first.

Definitions used, unfolded

Division conventions. Three kinds of division occur.

  • Default integer division n/dn \mathbin{/} dn/d with remainder n mod dn \bmod dnmodd (Euclidean convention). For d>0d > 0d>0: n/d=⌊n/d⌋n / d = \lfloor n/d \rfloorn/d=⌊n/d⌋ and n mod d=n−d⌊n/d⌋∈[0,d)n \bmod d = n - d\lfloor n/d \rfloor \in [0, d)nmodd=n−d⌊n/d⌋∈[0,d), also for negative nnn (e.g. −7/2=−4-7/2 = -4−7/2=−4, −7 mod 2=1-7 \bmod 2 = 1−7mod2=1). For d<0d < 0d<0: n/d=−⌊n/∣d∣⌋n / d = -\lfloor n/|d| \rfloorn/d=−⌊n/∣d∣⌋ and n mod d∈[0,∣d∣)n \bmod d \in [0, |d|)nmodd∈[0,∣d∣). For d=0d = 0d=0: n/0=0n / 0 = 0n/0=0 and n mod 0=nn \bmod 0 = nnmod0=n.
  • Truncated division tdiv⁡(n,d)\operatorname{tdiv}(n,d)tdiv(n,d) with remainder tmod⁡(n,d)=n−d⋅tdiv⁡(n,d)\operatorname{tmod}(n,d) = n - d\cdot\operatorname{tdiv}(n,d)tmod(n,d)=n−d⋅tdiv(n,d): the quotient is rounded toward zero, so the remainder is 000 or has the sign of nnn, with ∣tmod⁡(n,d)∣<∣d∣|\operatorname{tmod}(n,d)| < |d|∣tmod(n,d)∣<∣d∣ (e.g. tdiv⁡(−7,2)=−3\operatorname{tdiv}(-7,2) = -3tdiv(−7,2)=−3, tmod⁡(−7,2)=−1\operatorname{tmod}(-7,2) = -1tmod(−7,2)=−1). For d=0d = 0d=0: tdiv⁡(n,0)=0\operatorname{tdiv}(n,0) = 0tdiv(n,0)=0, tmod⁡(n,0)=n\operatorname{tmod}(n,0) = ntmod(n,0)=n.
  • Rational division in Q\mathbb QQ, with the convention q/0=0q / 0 = 0q/0=0. For q∈Qq \in \mathbb Qq∈Q, ⌊q⌋\lfloor q \rfloor⌊q⌋ is the greatest integer ≤q\le q≤q and ⌈q⌉\lceil q \rceil⌈q⌉ the least integer ≥q\ge q≥q.

Below, [P][P][P] denotes 111 if the condition PPP holds and 000 otherwise.

FeeFrac. A FeeFrac is a pair X=(fee(X),size(X))X = (\mathrm{fee}(X), \mathrm{size}(X))X=(fee(X),size(X)) of two arbitrary integers. Nothing constrains them: either component may be zero or negative, and no machine-word bounds are imposed. Addition and subtraction are componentwise,

X±Y=(fee(X)±fee(Y), size(X)±size(Y)),X \pm Y = \big(\mathrm{fee}(X) \pm \mathrm{fee}(Y),\ \mathrm{size}(X) \pm \mathrm{size}(Y)\big),X±Y=(fee(X)±fee(Y), size(X)±size(Y)),

and the zero FeeFrac is (0,0)(0,0)(0,0). A chunk list is a finite list c=[c1,…,cn]c = [c_1, \dots, c_n]c=[c1​,…,cn​] of FeeFracs; the empty list (n=0n = 0n=0) is allowed.

byRatioCmp. For FeeFracs X,YX, YX,Y, byRatioCmp(X,Y)\mathrm{byRatioCmp}(X, Y)byRatioCmp(X,Y) is the three-way comparison of the two integers fee(X)⋅size(Y)\mathrm{fee}(X)\cdot\mathrm{size}(Y)fee(X)⋅size(Y) and fee(Y)⋅size(X)\mathrm{fee}(Y)\cdot\mathrm{size}(X)fee(Y)⋅size(X):

byRatioCmp(X,Y)={ltif fee(X) size(Y)<fee(Y) size(X),eqif they are equal,gtif fee(X) size(Y)>fee(Y) size(X).\mathrm{byRatioCmp}(X,Y) = \begin{cases}\mathrm{lt} & \text{if } \mathrm{fee}(X)\,\mathrm{size}(Y) < \mathrm{fee}(Y)\,\mathrm{size}(X),\\ \mathrm{eq} & \text{if they are equal},\\ \mathrm{gt} & \text{if } \mathrm{fee}(X)\,\mathrm{size}(Y) > \mathrm{fee}(Y)\,\mathrm{size}(X).\end{cases}byRatioCmp(X,Y)=⎩⎨⎧​lteqgt​if fee(X)size(Y)<fee(Y)size(X),if they are equal,if fee(X)size(Y)>fee(Y)size(X).​

No sign condition on the sizes is part of the definition. In particular, byRatioCmp(X,(0,1))\mathrm{byRatioCmp}(X, (0,1))byRatioCmp(X,(0,1)) is the comparison of fee(X)\mathrm{fee}(X)fee(X) with 000, independent of size(X)\mathrm{size}(X)size(X).

PartialOrdering and boolCompare. PartialOrdering\mathrm{PartialOrdering}PartialOrdering is a four-element type with values less\mathsf{less}less, equivalent\mathsf{equivalent}equivalent, greater\mathsf{greater}greater, unordered\mathsf{unordered}unordered. For booleans β0,β1\beta_0, \beta_1β0​,β1​:

boolCompare(false,false)=equivalent,boolCompare(false,true)=less,boolCompare(true,false)=greater,boolCompare(true,true)=equivalent.\mathrm{boolCompare}(\text{false},\text{false}) = \mathsf{equivalent},\quad \mathrm{boolCompare}(\text{false},\text{true}) = \mathsf{less},\quad \mathrm{boolCompare}(\text{true},\text{false}) = \mathsf{greater},\quad \mathrm{boolCompare}(\text{true},\text{true}) = \mathsf{equivalent}.boolCompare(false,false)=equivalent,boolCompare(false,true)=less,boolCompare(true,false)=greater,boolCompare(true,true)=equivalent.

sweep. sweep(R0,R1,A0,A1,β0,β1)∈PartialOrdering\mathrm{sweep}(R_0, R_1, A_0, A_1, \beta_0, \beta_1) \in \mathrm{PartialOrdering}sweep(R0​,R1​,A0​,A1​,β0​,β1​)∈PartialOrdering, where R0,R1R_0, R_1R0​,R1​ are lists of FeeFracs, A0,A1A_0, A_1A0​,A1​ are FeeFracs and β0,β1\beta_0, \beta_1β0​,β1​ are booleans, is defined by recursion (each recursive call shortens R0R_0R0​ or R1R_1R1​, so it terminates) as follows.

  1. Both lists empty (R0=R1=[ ]R_0 = R_1 = [\,]R0​=R1​=[]): the result is boolCompare(β0,β1)\mathrm{boolCompare}(\beta_0, \beta_1)boolCompare(β0​,β1​).
  2. R0=c0::R0′R_0 = c_0 :: R_0'R0​=c0​::R0′​ nonempty, R1=[ ]R_1 = [\,]R1​=[]: put P=c0+A0P = c_0 + A_0P=c0​+A0​ and κ=byRatioCmp(P−A1,(0,1))\kappa = \mathrm{byRatioCmp}(P - A_1, (0,1))κ=byRatioCmp(P−A1​,(0,1)), i.e. the comparison of fee(P)−fee(A1)=fee(c0)+fee(A0)−fee(A1)\mathrm{fee}(P) - \mathrm{fee}(A_1) = \mathrm{fee}(c_0) + \mathrm{fee}(A_0) - \mathrm{fee}(A_1)fee(P)−fee(A1​)=fee(c0​)+fee(A0​)−fee(A1​) with 000 (sizes play no role). Set β0′=β0∨(κ=gt)\beta_0' = \beta_0 \lor (\kappa = \mathrm{gt})β0′​=β0​∨(κ=gt), i.e. β0\beta_0β0​ or fee(P)>fee(A1)\mathrm{fee}(P) > \mathrm{fee}(A_1)fee(P)>fee(A1​); and β1′=β1∨(κ=lt)\beta_1' = \beta_1 \lor (\kappa = \mathrm{lt})β1′​=β1​∨(κ=lt), i.e. β1\beta_1β1​ or fee(P)<fee(A1)\mathrm{fee}(P) < \mathrm{fee}(A_1)fee(P)<fee(A1​). If β0′\beta_0'β0′​ and β1′\beta_1'β1′​ are both true, the result is unordered\mathsf{unordered}unordered; otherwise it is sweep(R0′,[ ],P,A1,β0′,β1′)\mathrm{sweep}(R_0', [\,], P, A_1, \beta_0', \beta_1')sweep(R0′​,[],P,A1​,β0′​,β1′​).
  3. R0=[ ]R_0 = [\,]R0​=[], R1=c1::R1′R_1 = c_1 :: R_1'R1​=c1​::R1′​ nonempty (mirror image): put P=c1+A1P = c_1 + A_1P=c1​+A1​ and κ=\kappa = κ= comparison of fee(P)−fee(A0)\mathrm{fee}(P) - \mathrm{fee}(A_0)fee(P)−fee(A0​) with 000. Set β1′=β1∨(fee(P)>fee(A0))\beta_1' = \beta_1 \lor (\mathrm{fee}(P) > \mathrm{fee}(A_0))β1′​=β1​∨(fee(P)>fee(A0​)) and β0′=β0∨(fee(P)<fee(A0))\beta_0' = \beta_0 \lor (\mathrm{fee}(P) < \mathrm{fee}(A_0))β0′​=β0​∨(fee(P)<fee(A0​)). If both are true, the result is unordered\mathsf{unordered}unordered; otherwise it is sweep([ ],R1′,A0,P,β0′,β1′)\mathrm{sweep}([\,], R_1', A_0, P, \beta_0', \beta_1')sweep([],R1′​,A0​,P,β0′​,β1′​).
  4. Both nonempty, R0=c0::R0′R_0 = c_0 :: R_0'R0​=c0​::R0′​, R1=c1::R1′R_1 = c_1 :: R_1'R1​=c1​::R1′​: put P0=c0+A0P_0 = c_0 + A_0P0​=c0​+A0​ and P1=c1+A1P_1 = c_1 + A_1P1​=c1​+A1​.
    • (a) If size(P0)>size(P1)\mathrm{size}(P_0) > \mathrm{size}(P_1)size(P0​)>size(P1​): κ=byRatioCmp(P1−A0, P0−A0)\kappa = \mathrm{byRatioCmp}(P_1 - A_0,\ P_0 - A_0)κ=byRatioCmp(P1​−A0​, P0​−A0​), i.e. the comparison of
(fee(P1)−fee(A0))(size(P0)−size(A0))with(fee(P0)−fee(A0))(size(P1)−size(A0)).\big(\mathrm{fee}(P_1) - \mathrm{fee}(A_0)\big)\big(\mathrm{size}(P_0) - \mathrm{size}(A_0)\big) \quad\text{with}\quad \big(\mathrm{fee}(P_0) - \mathrm{fee}(A_0)\big)\big(\mathrm{size}(P_1) - \mathrm{size}(A_0)\big).(fee(P1​)−fee(A0​))(size(P0​)−size(A0​))with(fee(P0​)−fee(A0​))(size(P1​)−size(A0​)).
 Set $\beta_1' = \beta_1 \lor (\kappa = \mathrm{gt})$ and $\beta_0' = \beta_0 \lor (\kappa = \mathrm{lt})$. If both are true, the result is $\mathsf{unordered}$; otherwise it is $\mathrm{sweep}(c_0 :: R_0',\ R_1',\ A_0,\ P_1,\ \beta_0', \beta_1')$ (list $0$ and $A_0$ unchanged; the head of list $1$ is consumed and $A_1$ becomes $P_1$).
  • (b) Otherwise (size(P0)≤size(P1)\mathrm{size}(P_0) \le \mathrm{size}(P_1)size(P0​)≤size(P1​)): κ=byRatioCmp(P0−A1, P1−A1)\kappa = \mathrm{byRatioCmp}(P_0 - A_1,\ P_1 - A_1)κ=byRatioCmp(P0​−A1​, P1​−A1​), i.e. the comparison of
(fee(P0)−fee(A1))(size(P1)−size(A1))with(fee(P1)−fee(A1))(size(P0)−size(A1)).\big(\mathrm{fee}(P_0) - \mathrm{fee}(A_1)\big)\big(\mathrm{size}(P_1) - \mathrm{size}(A_1)\big) \quad\text{with}\quad \big(\mathrm{fee}(P_1) - \mathrm{fee}(A_1)\big)\big(\mathrm{size}(P_0) - \mathrm{size}(A_1)\big).(fee(P0​)−fee(A1​))(size(P1​)−size(A1​))with(fee(P1​)−fee(A1​))(size(P0​)−size(A1​)).
 Set $\beta_0' = \beta_0 \lor (\kappa = \mathrm{gt})$ and $\beta_1' = \beta_1 \lor (\kappa = \mathrm{lt})$. If both are true, the result is $\mathsf{unordered}$. Otherwise, if $\mathrm{size}(P_1) = \mathrm{size}(P_0)$ the result is $\mathrm{sweep}(R_0', R_1', P_0, P_1, \beta_0', \beta_1')$ (both heads consumed); and if $\mathrm{size}(P_0) < \mathrm{size}(P_1)$ it is $\mathrm{sweep}(R_0',\ c_1 :: R_1',\ P_0,\ A_1,\ \beta_0', \beta_1')$.

The flags only ever change from false to true, and the function returns unordered\mathsf{unordered}unordered at the first step at which both become true; a recursive call is made only when at most one of them is true. The case boolCompare(true,true)=equivalent\mathrm{boolCompare}(\text{true},\text{true}) = \mathsf{equivalent}boolCompare(true,true)=equivalent can therefore be reached only if sweep is entered with both flags already true and both lists empty. The definition makes no assumption on signs of fees or sizes, nor on the order of the chunks; zero or negative sizes simply enter the comparisons above.

compareChunks. For chunk lists c0,c1c^0, c^1c0,c1:

compareChunks(c0,c1)=sweep(c0,c1,(0,0),(0,0),false,false).\mathrm{compareChunks}(c^0, c^1) = \mathrm{sweep}\big(c^0, c^1, (0,0), (0,0), \text{false}, \text{false}\big).compareChunks(c0,c1)=sweep(c0,c1,(0,0),(0,0),false,false).

Edge cases: compareChunks([ ],[ ])=equivalent\mathrm{compareChunks}([\,],[\,]) = \mathsf{equivalent}compareChunks([],[])=equivalent; when one list is (or becomes) exhausted, only the fees of the remaining cumulative points versus the other side's accumulated fee are compared (case 2/3 of sweep).

ImprovesFeerateDiagram. For chunk lists old\mathit{old}old and new\mathit{new}new (in this argument order),

ImprovesFeerateDiagram(old,new)  ⟺  compareChunks(new,old)=greater,\mathrm{ImprovesFeerateDiagram}(\mathit{old}, \mathit{new}) \iff \mathrm{compareChunks}(\mathit{new}, \mathit{old}) = \mathsf{greater},ImprovesFeerateDiagram(old,new)⟺compareChunks(new,old)=greater,

i.e. the second argument is passed first to compareChunks.

diagram. For a chunk list ccc and x∈Qx \in \mathbb Qx∈Q, diagram(c,x)∈Q\mathrm{diagram}(c, x) \in \mathbb Qdiagram(c,x)∈Q is defined recursively:

diagram([ ],x)=0,diagram(c1::c′,x)={fee(c1)⋅x/size(c1)if x≤size(c1),fee(c1)+diagram(c′,x−size(c1))if x>size(c1),\mathrm{diagram}([\,], x) = 0, \qquad \mathrm{diagram}(c_1 :: c', x) = \begin{cases} \mathrm{fee}(c_1)\cdot x / \mathrm{size}(c_1) & \text{if } x \le \mathrm{size}(c_1),\\ \mathrm{fee}(c_1) + \mathrm{diagram}\big(c', x - \mathrm{size}(c_1)\big) & \text{if } x > \mathrm{size}(c_1),\end{cases}diagram([],x)=0,diagram(c1​::c′,x)={fee(c1​)⋅x/size(c1​)fee(c1​)+diagram(c′,x−size(c1​))​if x≤size(c1​),if x>size(c1​),​

with rational division (⋅/0=0\cdot/0 = 0⋅/0=0). It is defined for every rational xxx, including negative xxx. For the empty list it is identically 000. When every size is positive, writing Sk=∑i≤ksize(ci)S_k = \sum_{i \le k}\mathrm{size}(c_i)Sk​=∑i≤k​size(ci​) and Fk=∑i≤kfee(ci)F_k = \sum_{i \le k}\mathrm{fee}(c_i)Fk​=∑i≤k​fee(ci​) (with S0=F0=0S_0 = F_0 = 0S0​=F0​=0) for c=[c1,…,cn]c = [c_1,\dots,c_n]c=[c1​,…,cn​], n≥1n \ge 1n≥1, the recursion unfolds to: diagram(c,x)=fee(c1) x/size(c1)\mathrm{diagram}(c,x) = \mathrm{fee}(c_1)\,x/\mathrm{size}(c_1)diagram(c,x)=fee(c1​)x/size(c1​) for all x≤S1x \le S_1x≤S1​ (including negative xxx); Fk−1+fee(ck)(x−Sk−1)/size(ck)F_{k-1} + \mathrm{fee}(c_k)(x - S_{k-1})/\mathrm{size}(c_k)Fk−1​+fee(ck​)(x−Sk−1​)/size(ck​) for Sk−1≤x≤SkS_{k-1} \le x \le S_kSk−1​≤x≤Sk​; and FnF_nFn​ for x≥Snx \ge S_nx≥Sn​ — the piecewise-linear function through (0,0),(S1,F1),…,(Sn,Fn)(0,0), (S_1,F_1), \dots, (S_n,F_n)(0,0),(S1​,F1​),…,(Sn​,Fn​), horizontal to the right. If a size is zero or negative the recursion still evaluates but need not have this shape (e.g. a chunk with size(c1)<0\mathrm{size}(c_1) < 0size(c1​)<0 gives diagram(c,0)=fee(c1)+diagram(c′,−size(c1))\mathrm{diagram}(c, 0) = \mathrm{fee}(c_1) + \mathrm{diagram}(c', -\mathrm{size}(c_1))diagram(c,0)=fee(c1​)+diagram(c′,−size(c1​)); a chunk with size 000 contributes a jump of fee(c1)\mathrm{fee}(c_1)fee(c1​) just after x=0x = 0x=0).

diagramFee, diagramSize. For c=[c1,…,cn]c = [c_1,\dots,c_n]c=[c1​,…,cn​]: diagramFee(c)=∑i=1nfee(ci)∈Z\mathrm{diagramFee}(c) = \sum_{i=1}^n \mathrm{fee}(c_i) \in \mathbb ZdiagramFee(c)=∑i=1n​fee(ci​)∈Z and diagramSize(c)=∑i=1nsize(ci)∈Z\mathrm{diagramSize}(c) = \sum_{i=1}^n \mathrm{size}(c_i) \in \mathbb ZdiagramSize(c)=∑i=1n​size(ci​)∈Z (both 000 for the empty list).

SizesPos. SizesPos(c)\mathrm{SizesPos}(c)SizesPos(c) means size(ci)>0\mathrm{size}(c_i) > 0size(ci​)>0 for every chunk cic_ici​ in ccc (vacuously true for the empty list). It says nothing about fees, which may be zero or negative.

Dominates, BetterSomewhere, StrictlyBetter. For chunk lists c0,c1c^0, c^1c0,c1:

  • Dominates(c0,c1)\mathrm{Dominates}(c^0, c^1)Dominates(c0,c1): for every rational x≥0x \ge 0x≥0, diagram(c1,x)≤diagram(c0,x)\mathrm{diagram}(c^1, x) \le \mathrm{diagram}(c^0, x)diagram(c1,x)≤diagram(c0,x).
  • BetterSomewhere(c0,c1)\mathrm{BetterSomewhere}(c^0, c^1)BetterSomewhere(c0,c1): there is a rational x≥0x \ge 0x≥0 with diagram(c1,x)<diagram(c0,x)\mathrm{diagram}(c^1, x) < \mathrm{diagram}(c^0, x)diagram(c1,x)<diagram(c0,x).
  • StrictlyBetter(c0,c1)\mathrm{StrictlyBetter}(c^0, c^1)StrictlyBetter(c0,c1): Dominates(c0,c1)\mathrm{Dominates}(c^0, c^1)Dominates(c0,c1) and BetterSomewhere(c0,c1)\mathrm{BetterSomewhere}(c^0, c^1)BetterSomewhere(c0,c1).

Only x≥0x \ge 0x≥0 is quantified over (negative xxx is excluded; x=0x = 0x=0 is included), and xxx ranges over all nonnegative rationals, including points beyond both total sizes.

FeeRate and getFee (from the imported replacement file). A FeeRate rrr consists of natural numbers fee(r)≥0\mathrm{fee}(r) \ge 0fee(r)≥0 and size(r)\mathrm{size}(r)size(r) with the built-in requirement size(r)>0\mathrm{size}(r) > 0size(r)>0. For v∈Nv \in \mathbb Nv∈N,

getFee(r,v)=(fee(r)⋅v+(size(r)−1))/size(r)\mathrm{getFee}(r, v) = \big(\mathrm{fee}(r)\cdot v + (\mathrm{size}(r) - 1)\big) \mathbin{/} \mathrm{size}(r)getFee(r,v)=(fee(r)⋅v+(size(r)−1))/size(r)

computed in the natural numbers with floor division (size(r)−1≥0\mathrm{size}(r) - 1 \ge 0size(r)−1≥0 since size(r)>0\mathrm{size}(r) > 0size(r)>0).

Tx, Replacement, totalFee, PaysForRBF (from the imported replacement file). A transaction ttt is a pair of natural numbers fee(t)≥0\mathrm{fee}(t) \ge 0fee(t)≥0, vsize(t)\mathrm{vsize}(t)vsize(t) with vsize(t)>0\mathrm{vsize}(t) > 0vsize(t)>0. A Replacement RRR consists of a transaction R.newR.\mathrm{new}R.new, a finite multiset R.evictedR.\mathrm{evicted}R.evicted of transactions, and a finite multiset R.directR.\mathrm{direct}R.direct of transactions with R.direct≤R.evictedR.\mathrm{direct} \le R.\mathrm{evicted}R.direct≤R.evicted (sub-multiset, counting multiplicity); the multisets may be empty. totalFee(s)=∑t∈sfee(t)∈N\mathrm{totalFee}(s) = \sum_{t \in s}\mathrm{fee}(t) \in \mathbb NtotalFee(s)=∑t∈s​fee(t)∈N, summed with multiplicity (000 for the empty multiset). For a FeeRate rrr,

PaysForRBF(r,R)  ⟺  totalFee(R.evicted)≤fee(R.new)  and  getFee(r,vsize(R.new))≤fee(R.new)−totalFee(R.evicted),\mathrm{PaysForRBF}(r, R) \iff \mathrm{totalFee}(R.\mathrm{evicted}) \le \mathrm{fee}(R.\mathrm{new}) \ \text{ and }\ \mathrm{getFee}\big(r, \mathrm{vsize}(R.\mathrm{new})\big) \le \mathrm{fee}(R.\mathrm{new}) - \mathrm{totalFee}(R.\mathrm{evicted}),PaysForRBF(r,R)⟺totalFee(R.evicted)≤fee(R.new)  and  getFee(r,vsize(R.new))≤fee(R.new)−totalFee(R.evicted),

where the subtraction is truncated subtraction of natural numbers (by the first conjunct it equals the ordinary difference).

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

    Confirmed by the moderator at approval.

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