fix: use checked_add for total_fee_requested in process_delegation_cleanup#180
fix: use checked_add for total_fee_requested in process_delegation_cleanup#180amathxbt wants to merge 1 commit intomagicblock-labs:mainfrom
Conversation
…eanup
In process_delegation_cleanup the per-commit fee (already protected by
checked_mul) was added to SESSION_FEE_LAMPORTS with a plain + operator:
let total_fee_requested = commit_fee + SESSION_FEE_LAMPORTS;
For a long-lived delegation with a very large commit_count the result of
COMMIT_FEE_LAMPORTS * commit_count can approach u64::MAX. Adding the
constant SESSION_FEE_LAMPORTS on top of such a value overflows, wrapping
around to a small number and causing the protocol to charge far less than
it should, letting the validator escape paying the session fee.
Fix: use checked_add(...).ok_or(DlpError::Overflow) consistent with every
other arithmetic operation in this file.
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 0/1 reviews remaining, refill in 59 minutes and 49 seconds.Comment |
Summary
Fixes an unchecked arithmetic overflow in
process_delegation_cleanup(src/processor/fast/undelegate.rs).Bug — Plain
+oncommit_fee + SESSION_FEE_LAMPORTScan overflowThe per-commit fee multiplication is correctly protected with
checked_mul, but the subsequent addition of the constantSESSION_FEE_LAMPORTSuses a plain+operator. For a long-lived delegation with a very largecommit_count,commit_feecan approachu64::MAX. AddingSESSION_FEE_LAMPORTSon top then overflows, wrapping around to a small value. This causes the protocol to collect far less than the intended fee, letting the validator escape the session fee entirely.Example: If
COMMIT_FEE_LAMPORTS * commit_count = u64::MAX - 1andSESSION_FEE_LAMPORTS = 5000, the result wraps to4998instead of the expected value, andtotal_fee_requested.min(total_lamports)silently charges the wrong amount.Fix
Consistent with every other arithmetic operation in this codebase.
Impact
delegation-program / src/processor/fast/undelegate.rs