AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Moderate 62 Bitcoin

Merge rust-bitcoin/rust-bitcoin#6884: units: Fix div_by_fee_rate_floor precision

Public commit record

What the developer wrote

Authored by Andrew Poelstra

91/100 · Strong
Merge rust-bitcoin/rust-bitcoin#6884: units: Fix div_by_fee_rate_floor precision

1b067e90f3dad98d727edf2c709c96e25925e04b units: Test div_by_fee_rate_floor precision (Jamil Lambert, PhD)
5970d84abd8bac00f4e4c6398bb253b2a33e9dac units: Fix div_by_fee_rate_floor precision (Jamil Lambert, PhD)

Pull request description:

`div_by_fee_rate_floor` divided by the sat/kwu rate rounded up, understating the maximum affordable weight. Divide by the sat/MvB rate with a widened intermediate, as done for `div_by_weight_*` in #4675.

Closes project-loupe/audit-rust-bitcoin#81


ACKs for top commit:
apoelstra:
ACK 1b067e90f3dad98d727edf2c709c96e25925e04b; successfully ran local tests
tcharding:
ACK 1b067e90f3dad98d727edf2c709c96e25925e04b


Tree-SHA512: 6cc01c973f8a8cb8253e3e6c90ea5d17d47eaa01aee1683db312535715efc27c7da8561c7a9921a94689b1553e2e872a4f17d5006baa6c8a458d9ca71f05e596
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This commit fixes a precision bug in a Rust Bitcoin library function that calculates how much transaction weight a given amount of money can afford at a given fee rate. The old code rounded the fee rate up to a coarser unit (satoshis per kilo-weight-unit), which could make the result slightly too small, understating the affordable weight. The fix uses a wider intermediate calculation with satoshis per million virtual bytes, matching a previous fix for related functions. It also now properly reports overflow when the result exceeds the maximum representable weight.

Recommended action

Review downstream callers of `div_by_fee_rate_floor` to determine whether the previously understated weight values could have caused incorrect transaction construction, fee estimation, or coin-selection logic. Update to the patched version and run the new regression test. Consider auditing related `div_by_weight_*` functions for similar precision issues if not already addressed.

Security signals we found

01

Incorrect fee-rate-to-weight conversion leading to understated affordable weight

02

Integer rounding direction (ceil) used as divisor in floor division causing off-by-one or larger precision loss

03

Addition of overflow handling for Weight::MAX

04

Fix explicitly closes an audit issue (project-loupe/audit-rust-bitcoin#81)

Risk score

Why this scored 62/100

Our methodology →
Potential impact 18/30
Exploitability 12/25
Stealth signal 10/15
Affected reach 10/15
Confidence 8/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.