Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

A chunking with non-increasing feerates has a concave diagram

Proved
BitcoinFeerateDiagram.diagram_concave

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

bitcoincluster-mempoolfeefracfeerate-diagramformal-verificationmathlibmempoolpolicyrbf

For positive sizes and non-increasing feerates, diagram cs is concave on [0,diagramSize][0, \text{diagramSize}][0,diagramSize].

Preamble
import Definitions.Def_BitcoinFeerateDiagram
open BitcoinFeerateDiagram BitcoinReplacement
Formal statement
theorem BitcoinFeerateDiagram.diagram_concave (cs : List FeeFrac) (hpos : SizesPos cs)
    (hsort : FeeratesNonIncreasing cs) :
    ConcaveOn ℚ (Set.Icc 0 (diagramSize cs : ℚ)) (diagram cs) := 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.diagram_concave

Statement. Let c=[c1,…,cn]c = [c_1, \dots, c_n]c=[c1​,…,cn​] be any finite list of FeeFracs such that

  • SizesPos(c)\mathrm{SizesPos}(c)SizesPos(c): size(ci)>0\mathrm{size}(c_i) > 0size(ci​)>0 for every iii; and
  • FeeratesNonIncreasing(c)\mathrm{FeeratesNonIncreasing}(c)FeeratesNonIncreasing(c): fee(ci+1)⋅size(ci)≤fee(ci)⋅size(ci+1)\mathrm{fee}(c_{i+1})\cdot\mathrm{size}(c_i) \le \mathrm{fee}(c_i)\cdot\mathrm{size}(c_{i+1})fee(ci+1​)⋅size(ci​)≤fee(ci​)⋅size(ci+1​) for every pair of adjacent chunks.

Let I={x∈Q:0≤x≤diagramSize(c)}I = \{x \in \mathbb Q : 0 \le x \le \mathrm{diagramSize}(c)\}I={x∈Q:0≤x≤diagramSize(c)}, the closed interval of rationals from 000 to the total size diagramSize(c)=∑isize(ci)\mathrm{diagramSize}(c) = \sum_i \mathrm{size}(c_i)diagramSize(c)=∑i​size(ci​). Then the function x↦diagram(c,x)x \mapsto \mathrm{diagram}(c, x)x↦diagram(c,x) is concave on III over the scalar field Q\mathbb QQ, which means:

  1. III is convex (as a subset of Q\mathbb QQ), and
  2. for all x,y∈Ix, y \in Ix,y∈I and all rationals λ,μ≥0\lambda, \mu \ge 0λ,μ≥0 with λ+μ=1\lambda + \mu = 1λ+μ=1,
λ diagram(c,x)+μ diagram(c,y)≤diagram(c,λx+μy).\lambda\,\mathrm{diagram}(c, x) + \mu\,\mathrm{diagram}(c, y) \le \mathrm{diagram}(c, \lambda x + \mu y).λdiagram(c,x)+μdiagram(c,y)≤diagram(c,λx+μy).

Binders and edge cases. Fees are arbitrary integers (zero or negative allowed). Concavity is asserted only on [0,diagramSize(c)][0, \mathrm{diagramSize}(c)][0,diagramSize(c)], not on the whole half-line x≥0x \ge 0x≥0 and not for negative xxx; only rational points and rational weights are involved. For the empty list, diagramSize=0\mathrm{diagramSize} = 0diagramSize=0 and I={0}I = \{0\}I={0}, so the claim reduces to diagram([ ],0)≤diagram([ ],0)\mathrm{diagram}([\,], 0) \le \mathrm{diagram}([\,], 0)diagram([],0)≤diagram([],0). For a single chunk the sortedness hypothesis is vacuous. The sortedness hypothesis compares only adjacent chunks, by integer cross-multiplication.

Definitions used, unfolded

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.

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.

FeeratesNonIncreasing. FeeratesNonIncreasing(c)\mathrm{FeeratesNonIncreasing}(c)FeeratesNonIncreasing(c) means: for every pair of adjacent chunks ci,ci+1c_i, c_{i+1}ci​,ci+1​,

fee(ci+1)⋅size(ci)≤fee(ci)⋅size(ci+1)\mathrm{fee}(c_{i+1})\cdot\mathrm{size}(c_i) \le \mathrm{fee}(c_i)\cdot\mathrm{size}(c_{i+1})fee(ci+1​)⋅size(ci​)≤fee(ci​)⋅size(ci+1​)

(integer cross-multiplication). It holds automatically for lists of length 000 or 111.

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