Bonding Curve Invariant Check Incorrectly Validates SOL Balance Due to Rent Inclusion
The bonding curve invariant check compares the escrow account's raw lamport balance, which includes rent, against the tracked real SOL reserves, which exclude rent. This lets the invariant pass when the escrow actually holds less spendable SOL than the reserves require.
Submitted by Evo
The bonding curve invariant check fails to account for rent when comparing SOL balances, leading to incorrect validation of the protocol’s core invariant. Since sol_escrow_lamports includes rent while real_sol_reserves doesn’t, the invariant check could pass when it should fail.
Proof of Concept
The issue exists in the bonding curve invariant check in curve.rs:L306:
// Get raw lamports which includes rent
let sol_escrow_lamports = sol_escrow.lamports();
// Ensure real sol reserves are equal to bonding curve pool lamports
if sol_escrow_lamports < bonding_curve.real_sol_reserves {
msg!(
"real_sol_r:{}, bonding_lamps:{}",
bonding_curve.real_sol_reserves,
sol_escrow_lamports
);
msg!("Invariant failed: real_sol_reserves != bonding_curve_pool_lamports");
return Err(ContractError::BondingCurveInvariant.into());
}
The issue arises because:
sol_escrow_lamportsis retrieved usinglamports()which returns the total balance including rent- This is compared directly against
real_sol_reserveswhich tracks only the actual SOL reserves without rent - The comparison
sol_escrow_lamports < bonding_curve.real_sol_reserveswill incorrectly pass whensol_escrow_lamportshas insufficient SOL (excluding rent) but the rent amount makes up the difference
For example:
- If
real_sol_reserves= 100 SOL (100,000,000,000 lamports) - And actual available SOL = 99.99795072 SOL (99,997,960,720 lamports)
- And rent = 0.00204928 SOL (2,039,280 lamports)
- Then
sol_escrow_lamports= 100 SOL (100,000,000,000 lamports) - The check 100 < 100 is false, so the invariant passes
- But it should fail since the actual available SOL (99.99795072) is less than required (100)
Evidence of the original intent to handle rent can be seen in the commented out code:
// let rent_exemption_balance: u64 =
// Rent::get()?.minimum_balance(8 + BondingCurve::INIT_SPACE as usize);
// let bonding_curve_pool_lamports: u64 = lamports - rent_exemption_balance;
Which will cause the issue.
Recommended Mitigation Steps
Subtract the rent-exemption amount from sol_escrow_lamports before comparing to real_sol_reserves in the invariant check.
Kulture (Pump Science) confirmed
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the invariant compares a rent-inclusive lamport balance against a rent-exclusive reserve figure, without subtracting the rent-exemption amount.
Impact
The core invariant could pass when the escrow holds less spendable SOL than required, so the protocol's accounting check may not catch a real shortfall.
What the attacker needed
None
The fix
The rent-exemption amount should be subtracted from the escrow lamport balance before it is compared with the real SOL reserves.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A Solana account must hold a small minimum balance, called rent, just to exist. The code checked the account's whole balance, rent included, against the amount the pool was supposed to hold, so the rent could hide a shortfall and the safety check would wrongly pass.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.