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: 75/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
PrimeLiquidityProvider.sol
may cause accounting issues in token accrual logicIf an underlying token is mistakenly sent to the PrimeLiquidityProvider.sol
, The accrueTokens
function may miscalculate the token accrual because of using the contract balance for accounting .
if (deltaBlocks > 0) { uint256 distributionSpeed = tokenDistributionSpeeds[token_]; uint256 balance = IERC20Upgradeable(token_).balanceOf(address(this)); //<----here
However if mistakenly sent tokens are sent back to the actual user through sweepToken
function there's a possibility to temporary dos of the accrueTokens
function cause it assumes the contract balance to be bigger than accrued amount of tokens .
if (deltaBlocks > 0) { uint256 distributionSpeed = tokenDistributionSpeeds[token_]; uint256 balance = IERC20Upgradeable(token_).balanceOf(address(this)); uint256 balanceDiff = balance - tokenAmountAccrued[token_]; //<----here
If the balance drops below the amount of accrued tokens , this will underflow and revert because of solidity 0.8.13
This may result in temporary dos'ed state of releaseFunds
function in PrimeLiquidityProvider.sol
and _claimInterest
function in Prime.sol
Unsure about the mitigation . One way can be tracking the valid txns to the PrimeLiquidityProvider.sol
in a variable and using that instead of balanceOf(address(this))
for accounting in accrueTokens
function .
The protocol uses solidity version 0.8.13 which is vulnerable to a reported optimizer bug . https://github.com/code-423n4/2023-09-venus/blob/main/contracts/Tokens/Prime/PrimeLiquidityProvider.sol#L2
Switching to a more stable version of solidity like 0.8.18 / 0.8.19 is recommended .
As the current implementation of Prime anyone can call the claimInterest
funcition an claim in behalf of an user . Tokens are then sent to the actual user . This may invoke certain scenarios where an user may forcefully receive the interest accrued by him even he didnot want to collect it
https://github.com/code-423n4/2023-09-venus/blob/main/contracts/Tokens/Prime/Prime.sol#L443
Remove function claimInterest(address vToken, address user)
L2's like arbitrum's blocks are not consistant . That's why Using `block.number' for token accrual accounting may result in different rewards for the same amount of token staked in different chains . https://github.com/code-423n4/2023-09-venus/blob/main/contracts/Tokens/Prime/PrimeLiquidityProvider.sol#L254
function accrueTokens(address token_) public { _ensureZeroAddress(token_); _ensureTokenInitialized(token_); uint256 blockNumber = getBlockNumber(); uint256 deltaBlocks = blockNumber - lastAccruedBlock[token_]; //<---here
Using block.timstamp is a better choice for consistant accounting in all chains .
_ensureZeroAddress
function is to make sure the input address is not zero . But the naming is not correct according to its functionality .
https://github.com/code-423n4/2023-09-venus/blob/main/contracts/Tokens/Prime/PrimeLiquidityProvider.sol#L344
Naming should be _ensureNotZeroAddress
.
#0 - 0xRobocop
2023-10-07T01:58:37Z
L-01 dup of #42 L-04 dup of #132
#1 - c4-pre-sort
2023-10-07T01:58:48Z
0xRobocop marked the issue as low quality report
#2 - c4-judge
2023-11-03T02:47:02Z
fatherGoose1 marked the issue as grade-b