Repository navigation
Use saturating math for reserve and LSPS amounts - #1185
Open
benthecarman wants to merge 2 commits into
Open
benthecarman wants to merge 2 commits into
benthecarman wants to merge 2 commits into
Conversation
Setting AnchorChannelsConfig::per_channel_reserve_sats to u64::MAX is a natural way to say "never open or accept anchor channels with untrusted peers", since no wallet can cover that reserve. However, the reserve sums used unchecked arithmetic: multiplying it by the number of existing anchor channels, or adding the reserve for a new channel, overflowed and panicked in debug builds. Values close to a power of two could also wrap to a tiny reserve in release builds. Use saturating arithmetic so an oversized reserve is treated as unsatisfiable instead. This was found by Project Loupe. This change was made with the help of Claude Code.
The LSPS2 service computed the JIT channel size by multiplying the intercepted HTLC amount by the configured over-provisioning rate, and the LSPS1 client summed the caller-provided channel balances, both with unchecked arithmetic. Oversized inputs overflowed, panicking in debug builds and wrapping to a bogus channel size in release builds. Use saturating arithmetic so such inputs fall through to the existing insufficient-funds and LSP-limit checks. This was found by Project Loupe. This change was made with the help of Claude Code.
|
I've assigned @tnull as a reviewer! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some reserve and channel size calculations used unchecked math. Large
inputs, such as
per_channel_reserve_sats = u64::MAX, panic in debugbuilds and can wrap in release builds.
Use saturating math so these hit the normal insufficient-funds checks
instead.
Found by Project Loupe.