Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

EvaluateFeeUp is the ceiling, on both code paths

Proved
BitcoinFeerateDiagram.evaluateFeeUp_eq_ceil

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

bitcoincluster-mempoolfeefracfeerate-diagramformal-verificationmathlibmempoolpolicyrbf

As above with the ceiling.

Preamble
import Definitions.Def_BitcoinFeerateDiagram
open BitcoinFeerateDiagram BitcoinReplacement
Formal statement
theorem BitcoinFeerateDiagram.evaluateFeeUp_eq_ceil (f : FeeFrac) (atSize : ℤ)
    (hs : 0 < f.size) (_ha : 0 ≤ atSize) :
    FeeFrac.evaluateFeeUp f atSize = ⌈((f.fee * atSize : ℤ) : ℚ) / f.size⌉ := 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.evaluateFeeUp_eq_ceil

Statement. For every FeeFrac fff (a pair of integers (fee(f),size(f))(\mathrm{fee}(f), \mathrm{size}(f))(fee(f),size(f))) and every integer ttt (the "at size"), assuming

size(f)>0andt≥0,\mathrm{size}(f) > 0 \qquad\text{and}\qquad t \ge 0,size(f)>0andt≥0,

we have

evaluateFeeUp(f,t)=⌈fee(f)⋅tsize(f)⌉,\mathrm{evaluateFeeUp}(f, t) = \left\lceil \frac{\mathrm{fee}(f)\cdot t}{\mathrm{size}(f)} \right\rceil,evaluateFeeUp(f,t)=⌈size(f)fee(f)⋅t​⌉,

where the product fee(f)⋅t\mathrm{fee}(f)\cdot tfee(f)⋅t is formed in Z\mathbb ZZ, then divided exactly in Q\mathbb QQ by size(f)\mathrm{size}(f)size(f), and the ceiling is taken.

Binders and edge cases. fee(f)\mathrm{fee}(f)fee(f) is an arbitrary integer (negative, zero, or ≥233\ge 2^{33}≥233 all allowed), so all three branches of evaluateFee are in scope (here with ρ\rhoρ false: the ceilDiv branch for 0≤fee(f)<2330 \le \mathrm{fee}(f) < 2^{33}0≤fee(f)<233 and the div branch otherwise). The hypothesis t≥0t \ge 0t≥0 carries a name beginning with an underscore, which only signals that the name is not referred to; it is nevertheless a hypothesis of the theorem, so the statement says nothing about negative ttt. t=0t = 0t=0 is allowed. No word-size bounds are imposed on fee, size or ttt.

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.

mul. mul(a,b)=a⋅b\mathrm{mul}(a, b) = a \cdot bmul(a,b)=a⋅b, the exact product of two integers.

div. For integers n,dn, dn,d and a boolean ρ\rhoρ ("round down"), with q=tdiv⁡(n,d)q = \operatorname{tdiv}(n,d)q=tdiv(n,d) and r=tmod⁡(n,d)r = \operatorname{tmod}(n,d)r=tmod(n,d) (truncated division):

div(n,d,ρ)=q+[ r>0 ]−[ r≠0 and ρ ].\mathrm{div}(n, d, \rho) = q + [\,r > 0\,] - [\,r \neq 0 \text{ and } \rho\,].div(n,d,ρ)=q+[r>0]−[r=0 and ρ].

Case by case: if r=0r = 0r=0 the result is qqq; if r>0r > 0r>0 it is qqq when ρ\rhoρ is true and q+1q + 1q+1 when ρ\rhoρ is false; if r<0r < 0r<0 it is q−1q - 1q−1 when ρ\rhoρ is true and qqq when ρ\rhoρ is false. The definition places no condition on ddd: for d=0d = 0d=0 it gives q=0q = 0q=0, r=nr = nr=n, hence [n>0]−[n≠0 and ρ][n > 0] - [n \ne 0 \text{ and } \rho][n>0]−[n=0 and ρ]; for d<0d < 0d<0 the remainder still carries the sign of nnn.

ceilDiv. For integers n,dn, dn,d, with default (Euclidean) integer division:

ceilDiv(n,d)=n/d+[ n mod d≠0 ].\mathrm{ceilDiv}(n, d) = n / d + [\,n \bmod d \ne 0\,].ceilDiv(n,d)=n/d+[nmodd=0].

The definition is stated for all integers (not only nonnegative ones); for d=0d = 0d=0 it gives [ n≠0 ][\,n \ne 0\,][n=0].

evaluateFee, evaluateFeeDown, evaluateFeeUp. For a FeeFrac XXX, an integer ttt ("at size") and a boolean ρ\rhoρ:

evaluateFee(X,t,ρ)={(fee(X)⋅t)/size(X)if 0≤fee(X)<233 and ρ is true,ceilDiv(fee(X)⋅t, size(X))if 0≤fee(X)<233 and ρ is false,div(mul(fee(X),t), size(X), ρ)otherwise (fee(X)<0 or fee(X)≥233),\mathrm{evaluateFee}(X, t, \rho) = \begin{cases} \big(\mathrm{fee}(X)\cdot t\big) \mathbin{/} \mathrm{size}(X) & \text{if } 0 \le \mathrm{fee}(X) < 2^{33} \text{ and } \rho \text{ is true},\\ \mathrm{ceilDiv}\big(\mathrm{fee}(X)\cdot t,\ \mathrm{size}(X)\big) & \text{if } 0 \le \mathrm{fee}(X) < 2^{33} \text{ and } \rho \text{ is false},\\ \mathrm{div}\big(\mathrm{mul}(\mathrm{fee}(X), t),\ \mathrm{size}(X),\ \rho\big) & \text{otherwise (} \mathrm{fee}(X) < 0 \text{ or } \mathrm{fee}(X) \ge 2^{33}\text{)},\end{cases}evaluateFee(X,t,ρ)=⎩⎨⎧​(fee(X)⋅t)/size(X)ceilDiv(fee(X)⋅t, size(X))div(mul(fee(X),t), size(X), ρ)​if 0≤fee(X)<233 and ρ is true,if 0≤fee(X)<233 and ρ is false,otherwise (fee(X)<0 or fee(X)≥233),​

where 233=85899345922^{33} = 8589934592233=8589934592, the "///" in the first line is the default (Euclidean) integer division, and mul(a,b)=ab\mathrm{mul}(a,b) = abmul(a,b)=ab. Then evaluateFeeDown(X,t)=evaluateFee(X,t,true)\mathrm{evaluateFeeDown}(X, t) = \mathrm{evaluateFee}(X, t, \text{true})evaluateFeeDown(X,t)=evaluateFee(X,t,true) and evaluateFeeUp(X,t)=evaluateFee(X,t,false)\mathrm{evaluateFeeUp}(X, t) = \mathrm{evaluateFee}(X, t, \text{false})evaluateFeeUp(X,t)=evaluateFee(X,t,false). The definition itself imposes no condition on size(X)\mathrm{size}(X)size(X) or ttt.

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