FlashLoanLiquidate.JOJOFlashLoan has no slippage control when swapping USDC
The FlashLoanLiquidate.JOJOFlashLoan function lacks slippage control when swapping USDC, unlike similar functions that use a user-supplied minReceive parameter. This could expose users to sandwich attacks during the swap.
Source: https://github.com/sherlock-audit/2023-04-jojo-judging/issues/373
Found by
0x52, 0xStalin, Aymen0909, Bauer, Nyx, T1MOH, cccz, peakbolt, rvierdiiev
Summary
FlashLoanLiquidate.JOJOFlashLoan has no slippage control when swapping USDC
Vulnerability Detail
In both GeneralRepay.repayJUSD and FlashLoanRepay.JOJOFlashLoan, the user-supplied minReceive parameter is used for slippage control when swapping USDC.
function JOJOFlashLoan(
address asset,
uint256 amount,
address to,
bytes calldata param
) external {
(address approveTarget, address swapTarget, uint256 minReceive, bytes memory data) = abi
.decode(param, (address, address, uint256, bytes));
IERC20(asset).approve(approveTarget, amount);
(bool success, ) = swapTarget.call(data);
if (success == false) {
assembly {
let ptr := mload(0x40)
let size := returndatasize()
returndatacopy(ptr, 0, size)
revert(ptr, size)
}
}
uint256 USDCAmount = IERC20(USDC).balanceOf(address(this));
require(USDCAmount >= minReceive, "receive amount is too small");
...
function repayJUSD(
address asset,
uint256 amount,
address to,
bytes memory param
) external {
IERC20(asset).safeTransferFrom(msg.sender, address(this), amount);
uint256 minReceive;
if (asset != USDC) {
(address approveTarget, address swapTarget, uint256 minAmount, bytes memory data) = abi
.decode(param, (address, address, uint256, bytes));
IERC20(asset).approve(approveTarget, amount);
(bool success, ) = swapTarget.call(data);
if (success == false) {
assembly {
let ptr := mload(0x40)
let size := returndatasize()
returndatacopy(ptr, 0, size)
revert(ptr, size)
}
}
minReceive = minAmount;
}
uint256 USDCAmount = IERC20(USDC).balanceOf(address(this));
require(USDCAmount >= minReceive, "receive amount is too small");
However, this is not done in FlashLoanLiquidate.JOJOFlashLoan, and the lack of slippage control may expose the user to sandwich attacks when swapping USDC.
Impact
The lack of slippage control may expose the user to sandwich attacks when swapping USDC.
Code Snippet
Tool used
Manual Review
Recommendation
Consider making FlashLoanLiquidate.JOJOFlashLoan use the minReceive parameter for slippage control when swapping USDC.
Discussion
JoscelynFarr
fix link: https://github.com/JOJOexchange/JUSDV1/commit/b0e7d27cf484d9406a267a1b38ac253113101e8e
IAm0x52
Fix looks good. JOJOFlashloan now validates minReceived when swapping
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 FlashLoanLiquidate.JOJOFlashLoan function does not use a minReceive parameter to enforce a minimum output amount when swapping USDC, unlike other similar functions.
What the attacker needed
None
The fix
The fix was applied to make FlashLoanLiquidate.JOJOFlashLoan validate minReceived when swapping.
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 a contract swaps one token for another, it should check that it receives at least a minimum amount to protect against price manipulation. Here, one function forgot this check, so an attacker could manipulate the price and cause the user to get less than expected.
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.