Platform: Code4rena
Start Date: 28/09/2023
Pot Size: $36,500 USDC
Total HM: 5
Participants: 115
Period: 6 days
Judge: 0xDjango
Total Solo HM: 1
Id: 290
League: ETH
Rank: 107/115
Findings: 1
Award: $4.37
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: Bauchibred
Also found by: 0x3b, 0xDetermination, 0xMosh, 0xScourgedev, 0xTheC0der, 0xTiwa, 0xWaitress, 0xdice91, 0xfusion, 0xpiken, 0xprinc, 0xweb3boy, ArmedGoose, Aymen0909, Breeje, Brenzee, Daniel526, DavidGiladi, DeFiHackLabs, Flora, Fulum, HChang26, Hama, IceBear, J4X, Krace, KrisApostolov, Maroutis, Mirror, MohammedRizwan, Norah, PwnStars, SPYBOY, TangYuanShen, Testerbot, ThreeSigma, Tricko, al88nsk, alexweb3, ast3ros, berlin-101, bin2chen, blutorque, btk, d3e4, deth, e0d1n, ether_sky, ge6a, gkrastenov, glcanvas, hals, imare, inzinko, jkoppel, jnforja, joaovwfreire, josephdara, kutugu, lotux, lsaudit, mahdirostami, merlin, n1punp, nadin, neumo, nisedo, nobody2018, oakcobalt, orion, peanuts, pep7siup, pina, ptsanev, rokinot, rvierdiiev, said, santipu_, sashik_eth, seerether, squeaky_cactus, terrancrypt, tonisives, twicek, vagrant, xAriextz, y4y
4.3669 USDC - $4.37
The sweepToken
function lacks a crucial check to determine whether a token is being tracked and has pending accruals, which can lead to discrepancies in the tokenAmountAccrued
mapping and subsequent issues in the accrueTokens
and releaseFunds
functions.
The sweepToken
function allows the contract owner to transfer a specified amount of any token from the contract to another address. However, it does not verify whether the token is being tracked or has pending accruals by the contract. Consequently, if sweepToken
is used to withdraw tokens that are pending to be accrued, it can create a situation where the tokenAmountAccrued
mapping reflects an amount greater than the actual token balance of the contract. This discrepancy can lead to an underflow in the accrueTokens
function and cause the releaseFunds
function to revert due to insufficient balance.
function sweepToken(IERC20Upgradeable token_, address to_, uint256 amount_) external onlyOwner { uint256 balance = token_.balanceOf(address(this)); if (amount_ > balance) { revert InsufficientBalance(amount_, balance); } emit SweepToken(address(token_), to_, amount_); token_.safeTransfer(to_, amount_); }
The absence of a check for tracked tokens in the sweepToken
function can disrupt the normal operation of the contract by creating a mismatch between the actual token balance and the tokenAmountAccrued
mapping. This can lead to underflows in arithmetic operations within the accrueTokens
function and reverts in the releaseFunds
function due to insufficient funds, thereby potentially locking funds and halting the normal operation of the contract.
If sweepToken
is utilised to withdraw tokens that are being tracked and have pending accruals, the actual balance of the contract for that token will be reduced without updating the tokenAmountAccrued
mapping. This will create a situation where tokenAmountAccrued[token_]
is greater than the actual balance, causing the subtraction in accrueTokens
to underflow and the ERC20 transfer in releaseFunds
to revert due to insufficient funds.
Manual analysis was performed.
Introduce a check in the sweepToken
function to prevent the withdrawal of tokens that are being tracked and have pending accruals. This could be achieved by maintaining a mapping of tracked tokens and checking against it in the sweepToken
function. Alternatively, directly check whether tokenAmountAccrued[token_]
is greater than 0, and if it is, revert the transaction to prevent the sweeping of tokens that are pending accrual.
Example mitigation in sweepToken
function:
function sweepToken(IERC20Upgradeable token_, address to_, uint256 amount_) external onlyOwner { require(tokenAmountAccrued[address(token_)] == 0, "Cannot sweep tracked token with pending accruals"); uint256 balance = token_.balanceOf(address(this)); require(amount_ <= balance, "Insufficient balance"); emit SweepToken(address(token_), to_, amount_); token_.safeTransfer(to_, amount_); }
This mitigation ensures that tokens with pending accruals cannot be swept, thereby preventing the described vulnerability. Ensure to thoroughly test the contract after implementing changes to validate that the solution works as intended and does not introduce new issues.
Invalid Validation
#0 - c4-pre-sort
2023-10-05T01:10:22Z
0xRobocop marked the issue as duplicate of #42
#1 - c4-judge
2023-10-31T17:09:53Z
fatherGoose1 changed the severity to QA (Quality Assurance)
#2 - c4-judge
2023-11-03T01:42:42Z
fatherGoose1 marked the issue as grade-b