Closed sherlock-admin2 closed 5 months ago
1 comment(s) were left on this issue during the judging contest.
0xmystery commented:
invalid because it would require the admin to make a mistake by inputting a false boolean
The protocol team fixed this issue in the following PRs/commits: https://github.com/sophon-org/farming-contracts/commit/6d117397d57a39a865cee0621cabf9154fb6fd71
The Lead Senior Watson signed off on the fix.
0xShoonya
high
Improper reward points calculation (withUpdate)
Summary
The add() and set() functions in the Sophon contract present a vulnerability due to the improper handling of reward points calculation when the totalAllocPoint variable is modified without updating the pending reward points first. If the _withUpdate parameter is set to false, the massUpdatePools() function, responsible for updating pending rewards, is not called. Consequently, the reward calculation for each pool may become incorrect.
Vulnerability Detail
The
totalAllocPoint
variable is used to determine the portion that each pool would get from the total reward pints minted, so it is one of the main factors used in the reward points calculation. Therefore, whenever thetotalAllocPoint
variable is modified without updating the pending reward points first, the reward of each pool will be incorrectly calculated.In the
add()
andset()
functions shown below, if_withUpdate
is set to false, thetotalAllocPoint
variable will be modified without updating the rewards(massUpdatePools())
.Impact
This vulnerability can lead to inaccurate reward distribution among pools, potentially causing unfairness and inconsistency in the rewards received by users. Pools with updated allocation points may receive more rewards than intended, while pools with outdated allocation points may receive fewer rewards than expected.
Code Snippet
https://github.com/sherlock-audit/2024-05-sophon/blob/05059e53755f24ae9e3a3bb2996de15df0289a6c/farming-contracts/contracts/farm/SophonFarming.sol#L153-L187 https://github.com/sherlock-audit/2024-05-sophon/blob/05059e53755f24ae9e3a3bb2996de15df0289a6c/farming-contracts/contracts/farm/SophonFarming.sol#L195-L216
Tool used
Manual Review
Recommendation
Remove the
_withUpdate
variable in theadd()
andset()
functions and always call themassUpdatePools()
function before updatingtotalAllocPoint
variable.