Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Pinning: descendants attached to a transaction raise the cost of replacing it by their total fee

Proved
BitcoinReplacement.pinning_cost

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

bip125bitcoinfee-marketformal-verificationmathlibmempoolpinningpolicyrbf

For a valid replacement RRR, a transaction ttt and a multiset DDD with t::mD≤t ::ₘ D \let::m​D≤ R.evicted: 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. Whoever attaches descendants of total fee FFF to ttt forces any replacement of ttt to pay at least FFF more.

Preamble
import Definitions.Def_BitcoinReplacement
Formal statement
theorem BitcoinReplacement.pinning_cost (rate : BitcoinReplacement.FeeRate)
    (t : BitcoinReplacement.Tx) (D : Multiset BitcoinReplacement.Tx)
    (R : BitcoinReplacement.Replacement) (hR : BitcoinReplacement.Valid rate R)
    (hD : t ::ₘ D ≤ R.evicted) :
    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

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 Valid⁡(r,R)\operatorname{Valid}(r, R)Valid(r,R) holds (all three conditions above) and such that

t::mD  ≤  R.evictedt ::_m D \;\le\; R.\mathrm{evicted}t::m​D≤R.evicted

as multisets (every transaction value occurs in t::mDt ::_m Dt::m​D at most as often as in R.evictedR.\mathrm{evicted}R.evicted; in particular ttt occurs in R.evictedR.\mathrm{evicted}R.evicted at least once more than it occurs in DDD), the following inequality of natural numbers holds:

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. DDD may be empty, in which case the hypothesis says only that ttt occurs in R.evictedR.\mathrm{evicted}R.evicted and the conclusion reads fee⁡(t)+getFee⁡r(vsize⁡(R.new))≤fee⁡(R.new)\operatorname{fee}(t) + \operatorname{getFee}_r(\operatorname{vsize}(R.\mathrm{new})) \le \operatorname{fee}(R.\mathrm{new})fee(t)+getFeer​(vsize(R.new))≤fee(R.new). t::mDt ::_m Dt::m​D need not be all of R.evictedR.\mathrm{evicted}R.evicted; the inequality is only ≤\le≤, with the fees of any remaining evicted elements not appearing on the left. Nothing relates ttt or DDD to R.directR.\mathrm{direct}R.direct. No positivity assumption is made on rfeer_{\mathrm{fee}}rfee​; if rfee=0r_{\mathrm{fee}} = 0rfee​=0 the getFee⁡\operatorname{getFee}getFee term is 000.

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