Rent Collection Exploit Remediation
How to fix rent collection exploit patterns.
Rent Collection Exploit Remediation
Overview
Related Detector: Rent Collection Exploit
Incorrect rent handling leads to account deletion. The fix is to always calculate rent-exempt minimums dynamically and verify balances stay above the threshold after any lamport withdrawal.
Recommended Fix
let rent = Rent::get()?;
let min_balance = rent.minimum_balance(account.data_len());
// Before any withdrawal
require!(account.lamports() - amount >= min_balance, BelowRentExempt);
Common Mistakes
Mistake: Hardcoding Rent Values
// WRONG: rent requirements can change
const RENT_EXEMPT: u64 = 890_880;
Always use Rent::get()?.minimum_balance(data_len) for dynamic calculation.