Skip to content

Fix trivial underflow/overflow issues#940

Open
benthecarman wants to merge 3 commits into
lightningdevkit:mainfrom
benthecarman:over-underflows
Open

Fix trivial underflow/overflow issues#940
benthecarman wants to merge 3 commits into
lightningdevkit:mainfrom
benthecarman:over-underflows

Conversation

@benthecarman

Copy link
Copy Markdown
Contributor

A bunch of small issues found by project-loupe. Can drop any commits that we don't think are worth it (the electrum fee one might be a bit much).

@ldk-reviews-bot

ldk-reviews-bot commented Jun 12, 2026

Copy link
Copy Markdown

I've assigned @tnull as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@ldk-reviews-bot ldk-reviews-bot requested a review from tnull June 12, 2026 20:59
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

Comment thread src/payment/unified.rs
&self, amount_sats: u64, description: &str, expiry_sec: u32,
) -> Result<String, Error> {
let onchain_address = self.onchain_payment.new_address()?;
let amount_msats = amount_sats.checked_mul(1_000).ok_or(Error::InvalidAmount)?;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than doing this here, shouldn't we rather do the check in BOLT11/BOLT12 receive methods, as this method is just meant to forward to them, with as little custom logic on top as possible. Apart from that we might also be okay to punt on it as we intend to switch to an LightningAmount type soon everywhere, that should enforce such checks at conversion time across the board.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we wanted to do this check in the bolt11/12 functions then we'd have to have those take sats rather than msats. I think this is the right location for this. LightningAmount is the correct choice eventually.

Comment thread src/chain/electrum.rs

@tnull tnull left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also include This finding was discovered by Project Loupe in the commit messages, just so we can keep track of how many reported things were fixed.

Return InvalidAmount when converting the requested satoshi amount to
millisatoshis would overflow. This keeps debug and release behavior
consistent and avoids producing a URI whose on-chain amount differs from
its Lightning payment amount.

This commit was created with assistance from OpenAI Codex.

This finding was discovered by Project Loupe
Use saturating arithmetic when accounting for skimmed JIT-channel fees
while validating manually claimed payments. This prevents an oversized
skimmed fee from underflowing the expected claimable amount.

This commit was created with assistance from OpenAI Codex.

This finding was discovered by Project Loupe
Track registered transaction IDs in a set so repeated filter
registrations do not grow the collection or slow block-connected checks.
This keeps the wallet's registered-transaction lookup bounded by unique
transaction IDs.

This commit was created with assistance from OpenAI Codex.

This finding was discovered by Project Loupe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants