Submitted by shaflow2, also found by 0xlookman, 13u9, Agontuk, ATH, GEEKS, and p0wd3r
https://github.com/code-423n4/2025-01-pump-science/blob/768ef58478724bf6b464c9f0952e3e5a3b2a2613/programs/pump-science/src/state/bonding_curve/curve.rs#L103
In the last buy process, the protocol automatically adjusts the price to fit the curve, ensuring precise SOL fundraising. This results in a change in the transaction price, which also alters the amount of SOL paid by the user. However, since the swap fee is calculated beforehand, this can lead to an incorrect fee calculation. And if the actual amount of SOL to be paid increases, we should recheck that ctx.accounts.user.get_lamports() >= exact_in_amount.checked_add(min_rent).unwrap() to ensure sufficient remaining funds and prevent the account from being closed.
The transaction fee is calculated before entering the apply_buy function, based on the exact_in_amount provided as input.
However, if it is the last buy, the price adjustment will cause the actual amount of SOL the user needs to pay (as reflected in buy_result) to change, leading to incorrect protocol fee calculation.
After the apply_buy call is completed, check whether the actual SOL paid by the user in buy_result matches buy_amount_applied. If they do not match, recalculate fee_lamports. Additionally, revalidate that ctx.accounts.user.get_lamports() >= exact_in_amount.checked_add(min_rent).unwrap().
It is also recommended to add a new slippage parameter to control the maximum SOL input.
Kulture (Pump Science) confirmed
