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.bandwidth_paid_real
Setting (unfolded from the preamble). All declarations live in a namespace BitcoinReplacement. A transaction t is a pair of natural numbers (fee(t),vsize(t)) together with a proof that vsize(t)>0; fee(t) may be 0. Two transactions are equal exactly when their fees and virtual sizes agree. A fee rate r is a pair of natural numbers (rfee,rsize) together with a proof that rsize>0; rfee may be 0, and nothing identifies (1,2) with (2,4). For a fee rate r and a natural number v,
getFeer(v)=⌊rsizerfee⋅v+(rsize−1)⌋,
computed with natural-number (rounding-down) division; since rsize≥1 the inner subtraction rsize−1 is exact, and the value equals ⌈rfeev/rsize⌉. In particular getFeer(0)=0, and getFeer(v)=0 for every v whenever rfee=0.
A replacement R consists of a transaction R.new, a multiset of transactions R.evicted, a multiset of transactions R.direct, and a proof that R.direct≤R.evicted as multisets (every transaction value occurs in R.direct at most as many times as it occurs in R.evicted). Either multiset may be empty, R.new may itself occur in R.evicted, and no other relation between the three components is imposed. For a multiset s of transactions, totalFee(s)=∑u∈sfee(u), summed with multiplicity, so totalFee(∅)=0.
R is valid at rate r (written Valid(r,R)) when all three of the following hold:
- (PaysMoreThanConflicts(R)) for every transaction value u occurring in R.direct, fee(u)⋅vsize(R.new)<fee(R.new)⋅vsize(u) (a strict cross-multiplied comparison in N; vacuously true when R.direct is empty; nothing is required of elements of R.evicted that do not occur in R.direct);
- (PaysForRBF(r,R), first conjunct) totalFee(R.evicted)≤fee(R.new);
- (PaysForRBF(r,R), second conjunct) getFeer(vsize(R.new))≤fee(R.new)−˙totalFee(R.evicted), where −˙ is truncated natural-number subtraction (it returns 0 when the subtrahend exceeds the minuend; under item 2 it coincides with ordinary subtraction).
A list [R1,…,Rn] of replacements (n≥0) is a chain at rate r from t0 (written IsChain(r,t0,[R1,…,Rn])) when, writing ti=Ri.new for 1≤i≤n, for every i with 1≤i≤n: Ri is valid at rate r, and the transaction value ti−1 occurs in the multiset Ri.evicted. Membership is by value: any element of Ri.evicted with the same fee and virtual size as ti−1 counts; it is not required that ti−1 occur in Ri.direct, nor that Ri.evicted contain nothing else. The empty list is a chain from any t0 at any rate. The chain end chainEnd(t0,[R1,…,Rn]) is tn=Rn.new when n≥1 and is t0 itself when n=0 (it depends only on the last replacement). The chain vsizes chainVsizes([R1,…,Rn]) is the list [vsize(t1),…,vsize(tn)], empty when n=0. Below, tn always denotes chainEnd(t0,[R1,…,Rn]), i.e. it is t0 when n=0.
Statement. For every fee rate r, every transaction t0, and every list of replacements [R1,…,Rn] (n≥0) such that IsChain(r,t0,[R1,…,Rn]) holds, the following inequality of rational numbers holds:
fee(t0)+rsizerfee⋅i=1∑nvsize(ti)≤fee(tn),
where ti=Ri.new; here fee(t0), rfee, rsize and fee(tn) are natural numbers cast into Q, the quotient rfee/rsize is exact rational division (well defined because rsize>0, so no division-by-zero convention is involved), and ∑i=1nvsize(ti) is the natural-number sum of the list chainVsizes([R1,…,Rn]), cast into Q after summation. No rounding function appears in the statement itself.
Edge cases. When n=0 the sum is 0 and tn=t0, so the claim reads fee(t0)≤fee(t0) in Q. When rfee=0 the claim reads fee(t0)≤fee(tn). The relation ≤ is non-strict.
Confirmed by the moderator at approval.