Closed sherlock-admin3 closed 5 months ago
1 comment(s) were left on this issue during the judging contest.
0xmystery commented:
invalid because an admin action can break certain assumptions about the functioning of the code
@mystery0x ,Thank you for your judgement.
However , i disagree with the decision .
The point is the user who owed more tokens before the change MUST receive same tokens after the change and this new change should be applied to new users. That's how a lot of standard systems work.
However if a Person has deposited for a long time and they have EARNED 1 Million rewards , the admin has no rights to decrease his rewards by a major amount .
The point here is that this is not malicious behaviour by admin , but it is about the insufficiency of the code to handle the rewards accrual and retaining those rewards for existing users in time of block points per change because existing users who has staked for so long bearing in mind the points they will get based on the config of the protocol at their time of deposit , and withdraw , they MUST receive same amount of tokens otherwise the system is just bricked for users and their trust and will cause huge losses to users.
This is clearly a valid medium according to sherlock rules because their are Definite loss of funds involved but due to some external conditions.
Actually, there's no issue here. massUpdatePools()
is triggered before having pointsPerBlock
assigned a new value:
function setPointsPerBlock(uint256 _pointsPerBlock) public onlyOwner {
if (isFarmingEnded()) {
revert FarmingIsEnded();
}
massUpdatePools();
pointsPerBlock = _pointsPerBlock;
}
pool.accPointsPerShare
for each _pid
is updated before the change, that could also possibly increase instead of just decrease pointsPerBlock
, ensuring fair reward accumulation for all existing users.
0xreadyplayer1
medium
Delayed withdraw transaction will lead to accruing less rewards/points to users when the points per block has been changed in the meanwhile
Summary
If a user initiates their withdraw transaction , the transaction gets delayed to next block but the transactions like decreasing the
points per block by admin succeeds , the user will incur a huge loss of rewards/points that effectively will decrease amount of
airdrop tokens amount the user is entitled to get.
Vulnerability Detail
The Withdraw and deposit transactions rely on the block multiplier and points per block to calculate the amount of rewards/points
settled for user . These rewards will be later used for deciding the exact amount of tokens the owner of the airdrop tokens
will send to the user and regarded as activity.
However , if a user initiates their withdraw transaction at Block X , and their transaction is delayed upto X+Y blocks where Y >=1
But in the same block X , there are set of owner only transactions that alter the state of farming contracts especially points per block
Then the user , when withdraw transaction is executed will incur a loss of funds compared to their anticipated rewards calculation.
The transaction delays are well known on ETH Mainnet & can occur due to following reasons :
and some other miscellaneous factors.
Please read the well-detailed-documented PoC
PoC
Exploit Scenario
Code
Please insert this test inside
test/SophonFarming.t.sol
and run test usingPoC output
This test demonstrates how this small delay in witdraw tx can lead to user losing their 8.33e18 Tokens which is huge amount of rewards.
The issue might escalate when their is a big price change in pointsPerBlock and transaction delays for more blocks like 5 or 10
in the time of high network demand.
Impact
Loss of user's rewards/points which effectively means loss of token funds as they will determine the amount of airdrop tokens users will receive.
Code Snippet
https://github.com/sherlock-audit/2024-05-sophon/blob/main/farming-contracts/contracts/farm/SophonFarming.sol#L699
Tool used
Manual Review
Recommendation
There can be multiple steps to minimize ( as fixing is very hard - would require revamping entire implementation )