Closed sherlock-admin3 closed 1 month ago
1 comment(s) were left on this issue during the judging contest.
0xmystery commented:
valid because lastRewardBlock for each pool should indeed sync with the latest startBlock
The protocol team fixed this issue in the following PRs/commits: https://github.com/sophon-org/farming-contracts/commit/1f8d4e5ccec63052fcaf751b867294472e2d20a7
0xAadi
medium
Incorrect Reward Calculation Due to Unupdated
lastRewardBlock
WhenstartBlock
is Reduced or IncreasedSummary
The
SophonFarming
contract has a vulnerability where reducing/Increasing thestartBlock
after pools have been created does not update thelastRewardBlock
for those pools. This can lead to incorrect reward calculations, as the_getBlockMultiplier
function will use the outdatedlastRewardBlock
.Vulnerability Detail
When the
startBlock
is reduced, thelastRewardBlock
for existing pools is not updated to reflect the newstartBlock
. This misalignment causes the_getBlockMultiplier
function to calculate rewards based on an outdatedlastRewardBlock
, leading to incorrect reward distribution.Impact
startBlock
andlastRewardBlock
and Similarly Protocol can loss rewards if the thestartBlock
is increased.Code Snippet
The issue lies in the
setStartBlock
function:https://github.com/sherlock-audit/2024-05-sophon/blob/05059e53755f24ae9e3a3bb2996de15df0289a6c/farming-contracts/contracts/farm/SophonFarming.sol#L272C1-L280C6
Tool used
Manual Review
Recommendation
Update the
lastRewardBlock
for all pools when thestartBlock
is changed. Here is a suggested fix:Duplicate of #108