Because of missing slippage parameter, mintForToken() can be front-runned
The mintForToken() function lacks a slippage parameter, allowing a frontrunner to manipulate the pool's reserves so that the transferred token appears more valuable, causing users to receive less USSD than expected.
Source: https://github.com/sherlock-audit/2023-05-USSD-judging/issues/97
Found by
0xRobocop, Aymen0909, GimelSec, Kose, cryptostellar5, qbs, shealtielanz
Summary
Missing slippage parameter in mintForToken() makes it vulnerable to front-run attacks and exposes users to unwanted slippage.
Vulnerability Detail
The current implementation of the mintForToken() function lacks a parameter for controlling slippage, which makes it vulnerable to front-run attacks. Transactions involving large volumes are particularly at risk, as the minting process can be manipulated, resulting in price impact. This manipulation allows the reserves of the pool to be controlled, enabling a frontrunner to make the transferred token to appear more valuable than its actual worth. Consequently, when users mint USSD, they may receive USSD that are worth significantly less than the value of their real worth. This lack of slippage control resembles a swap without a limit on value manipulation.
Impact
User will be vulnerable to front-run attacks and receive less USSD from their expectation.
Code Snippet
/// Mint specific AMOUNT OF STABLE by giving token
function mintForToken(
address token,
uint256 tokenAmount,
address to
) public returns (uint256 stableCoinAmount) {
require(hasCollateralMint(token), "unsupported token");
IERC20Upgradeable(token).safeTransferFrom(
msg.sender,
address(this),
tokenAmount
);
stableCoinAmount = calculateMint(token, tokenAmount);
_mint(to, stableCoinAmount);
emit Mint(msg.sender, to, token, tokenAmount, stableCoinAmount);
}
Tool used
Manual Review
Recommendation
Consider adding a minAmountOut parameter.
Discussion
sherlock-admin
Removed: comment left for traceability I think this is not a valid medium. As the mintForToken function uses oracle prices, which return a weighted average price, it should not be that easy manipulated by Frontrunning.
You've deleted an escalation for this issue.
kosedogus
Escalate for 10USDC I think this is not a valid medium. As the mintForToken function uses oracle prices, which return a weighted average price, it should not be that easy manipulated by Frontrunning.
Weighted average prices does not guarantee that trades (minting in this case) executed based on the average price will be free from slippage. TWAP's are obviously vulnerable to slippage attacks. I also would like to remind that there is another valid issue due to the lack of slippage parameter in uniRouter. (That function also uses TWAP)
Shogoki
Okay, I think you are right. I removed the escalation
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 mintForToken() function calculates the minted amount using current pool reserves without allowing the caller to specify a minimum acceptable output, making it susceptible to price manipulation.
Impact
Users could receive less USSD than expected due to front-running, though the text notes that oracle prices may make manipulation less easy.
What the attacker needed
Attacker can front-run transactions; large volume transactions
The fix
The function should be fixed by adding a minAmountOut parameter to let users specify the minimum acceptable USSD output.
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.
When you mint a stablecoin by depositing another token, the amount you get back depends on the pool's current reserves. Without a minimum amount you are willing to accept, someone can trade just before you to change those reserves and make your mint less favourable. This is called front-running and can cost you money.
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.