Wrong lastBuyBackPrice
The buyBack function calculates lastBuyBackPrice using the first two amounts returned by a token swap, but these amounts depend on the swap path. If a path with more than two tokens is used, the price is incorrect, leading to wrong rebase amounts and effectiveYetiTokenBalance updates.
Submitted by cmichel
The sYETIToken.lastBuyBackPrice is set in buyBack and hardcoded as:
function buyBack(address routerAddress, uint256 YUSDToSell, uint256 YETIOutMin, address[] memory path) external onlyOwner {
require(YUSDToSell > 0, "Zero amount");
require(lastBuybackTime + 69 hours < block.timestamp, "Must have 69 hours pass before another buyBack");
yusdToken.approve(routerAddress, YUSDToSell);
uint256[] memory amounts = IRouter(routerAddress).swapExactTokensForTokens(YUSDToSell, YETIOutMin, path, address(this), block.timestamp + 5 minutes);
lastBuybackTime = block.timestamp;
// amounts[0] is the amount of YUSD that was sold, and amounts[1] is the amount of YETI that was gained in return. So the price is amounts[0] / amounts[1]
// @audit this hardcoded lastBuybackPrice is wrong when using a different path (think path length 3)
lastBuybackPrice = div(amounts[0].mul(1e18), amounts[1]);
emit BuyBackExecuted(YUSDToSell, amounts[0], amounts[1]);
}
It divides the first and second return amounts of the swap, however, these amounts depend on the swap path parameter that is used by the caller. If a swap path of length 3 is used, then this is obviously wrong. It also assumes that each router sorts the pairs the same way (which is true for Uniswap/Sushiswap).
Impact
The lastBuyBackPrice will be wrong when using a different path. This will lead rebases using a different yeti amount and the effectiveYetiTokenBalance being updated wrong.
Recommended Mitigation Steps
Verify the first and last element of the path are YETI/YUSD and use the first and last amount parameter.
kingyetifinance (Yeti finance) confirmed and disagreed with severity
@LilYeti: The idea was that on launch we will likely use a curve pool to route through so this contract would change slightly. However it is valid and some more checks would be good to add. Moving to level 1 issue.
A medium severity rating is warranted.
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 code assumes the swap path always has exactly two tokens, so it uses the first two amounts from the swap return without checking the path length or the tokens involved.
Impact
The lastBuyBackPrice will be wrong when using a different path, leading to incorrect rebase amounts and effectiveYetiTokenBalance updates.
What the attacker needed
Owner calls buyBack; swap path length > 2
The fix
The code should verify that the first and last tokens in the path are YETI and YUSD, and use the first and last amounts from the swap return.
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.
This report is about a smart contract that buys back its own token. It records the price of the buyback by dividing two numbers from the trade, but those numbers only make sense if the trade goes directly from one token to another. If the trade goes through an extra token, the recorded price is wrong, which can mess up later calculations for everyone's balance.
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.