Leak of Value in yield function, slippage check is not effective
The yield function uses the output of sellBasePreview as a slippage check but performs no validation on it, so the check is equivalent to setting the value to zero. An attacker could exploit this to cause the protocol to accept unfavourable trades.
Originally disclosed on Code4rena
Submitted by Alex the Entreprenerd
The function yield is using the input from sellBasePreview and then using it.
function yield(
address u,
address y,
uint256 a,
address r
) internal returns (uint256) {
// preview exact swap slippage on yield
uint128 returned = IYield(y).sellBasePreview(Cast.u128(a));
// send the remaing amount to the given yield pool
Safe.transfer(IERC20(u), y, a);
// lend out the remaining tokens in the yield pool
IYield(y).sellBase(r, returned);
The output of sellBasePreview is meant to be used off-chain to avoid front-running and price changes, additionally no validation is performed on this value (is it zero, is it less than 95% of amount) meaning the check is equivalent to setting returned = 0
I’d recommend to add checks, or ideally have a trusted keeper bulk sellBase with an additional slippage check as the function parameter
sourabhmarathe (Illuminate) 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
The function uses the output of sellBasePreview as a slippage limit without validating it, so any value (including zero) is accepted.
Impact
The slippage check is ineffective, so trades could execute at unfavourable prices, potentially causing a loss of value.
What the attacker needed
None
The fix
Add validation on the previewed amount (for example, reject zero or values below a threshold) or have a trusted keeper perform the swap with an explicit slippage parameter.
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 slippage check is meant to stop a trade from going through at a much worse price than expected. Here the code asks a pool for a preview of the trade result but never checks whether that preview is reasonable, so the protection does nothing. An attacker could make the trade happen at a bad price.
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.