This repository has been archived by the owner on Nov 24, 2024. It is now read-only.
serial-coder - Updating the startBlock
state variable without affecting existing pools leads to incorrect points/rewards distributions
#171
Labels
Duplicate
A valid issue that is a duplicate of an issue with `Has Duplicates` label
Medium
A valid Medium severity issue
Reward
A payout will be made for this issue
Sponsor Disputed
The sponsor disputed this issue's validity
serial-coder
medium
Updating the
startBlock
state variable without affecting existing pools leads to incorrect points/rewards distributionsSummary
The
SophonFarming::setStartBlock()
updates thestartBlock
state variable without affecting existing pools. Consequently, theSophonFarming
contract will incorrectly distribute points/rewards to users who stake in those existing pools.Vulnerability Detail
The
startBlock
state variable is initialized in theSophonFarming::initialize()
. Then, the function creates the predefined pools (sDAI
,wstETH
, andweETH
) by executing theSophonFarming::add()
.@1 -- The startBlock state variable gets initialized in the initialize()
: https://github.com/sherlock-audit/2024-05-sophon/blob/05059e53755f24ae9e3a3bb2996de15df0289a6c/farming-contracts/contracts/farm/SophonFarming.sol#L118@2.1 -- The initialize() creates sDAI pool by executing the add()
: https://github.com/sherlock-audit/2024-05-sophon/blob/05059e53755f24ae9e3a3bb2996de15df0289a6c/farming-contracts/contracts/farm/SophonFarming.sol#L131@2.2 -- The initialize() creates wstETH pool by executing the add()
: https://github.com/sherlock-audit/2024-05-sophon/blob/05059e53755f24ae9e3a3bb2996de15df0289a6c/farming-contracts/contracts/farm/SophonFarming.sol#L135@2.3 -- The initialize() creates weETH pool by executing the add()
: https://github.com/sherlock-audit/2024-05-sophon/blob/05059e53755f24ae9e3a3bb2996de15df0289a6c/farming-contracts/contracts/farm/SophonFarming.sol#L139The
add()
initializes thelastRewardBlock
variable based on the currentblock.number
or thestartBlock
variable (depending on which is greater). ThelastRewardBlock
variable is finally assigned to the created pool.@3 -- The add() initializes the lastRewardBlock variable based on the current block.number or the startBlock (depending on which is greater)
: https://github.com/sherlock-audit/2024-05-sophon/blob/05059e53755f24ae9e3a3bb2996de15df0289a6c/farming-contracts/contracts/farm/SophonFarming.sol#L163-L164@4 -- The lastRewardBlock is assigned to the created pool
: https://github.com/sherlock-audit/2024-05-sophon/blob/05059e53755f24ae9e3a3bb2996de15df0289a6c/farming-contracts/contracts/farm/SophonFarming.sol#L178The vulnerability resides in the
SophonFarming::setStartBlock()
, which updates thestartBlock
state variable without affecting existing pools.In other words, the updated
startBlock
state variable will affect only new pools created after. However, this state variable should be globally shared with all pools. Therefore, theSophonFarming
contract will distribute points/rewards to users staking in existing pools incorrectly (more or less than the actual depending on the difference between the new and old values of thestartBlock
variable).@5 -- In the setStartBlock(), the startBlock state variable is updated without taking effect on existing pools
: https://github.com/sherlock-audit/2024-05-sophon/blob/05059e53755f24ae9e3a3bb2996de15df0289a6c/farming-contracts/contracts/farm/SophonFarming.sol#L279Coded PoC
The coded PoC is presented below.
Please place the code in the test file:
farming-contracts/test/SophonFarming.t.sol
. To run the code, execute the command:forge test -vvv --match-test test_PocSettingNewStartBlockNotEffectiveToExistingPools
.The PoC proves that the
setStartBlock()
updates thestartBlock
state variable without affecting existing pools.Impact
The
setStartBlock()
updates thestartBlock
state variable without affecting existing pools. Consequently, theSophonFarming
contract will incorrectly distribute points/rewards to users staking in existing pools.In more detail, the updated
startBlock
state variable will affect only new pools created after. However, this state variable should be globally shared with all pools. Therefore, theSophonFarming
contract will distribute points/rewards to users staking in existing pools incorrectly (more or less than the actual depending on the difference between the new and old values of thestartBlock
variable).Code Snippet
https://github.com/sherlock-audit/2024-05-sophon/blob/05059e53755f24ae9e3a3bb2996de15df0289a6c/farming-contracts/contracts/farm/SophonFarming.sol#L118
https://github.com/sherlock-audit/2024-05-sophon/blob/05059e53755f24ae9e3a3bb2996de15df0289a6c/farming-contracts/contracts/farm/SophonFarming.sol#L131
https://github.com/sherlock-audit/2024-05-sophon/blob/05059e53755f24ae9e3a3bb2996de15df0289a6c/farming-contracts/contracts/farm/SophonFarming.sol#L135
https://github.com/sherlock-audit/2024-05-sophon/blob/05059e53755f24ae9e3a3bb2996de15df0289a6c/farming-contracts/contracts/farm/SophonFarming.sol#L139
https://github.com/sherlock-audit/2024-05-sophon/blob/05059e53755f24ae9e3a3bb2996de15df0289a6c/farming-contracts/contracts/farm/SophonFarming.sol#L163-L164
https://github.com/sherlock-audit/2024-05-sophon/blob/05059e53755f24ae9e3a3bb2996de15df0289a6c/farming-contracts/contracts/farm/SophonFarming.sol#L178
https://github.com/sherlock-audit/2024-05-sophon/blob/05059e53755f24ae9e3a3bb2996de15df0289a6c/farming-contracts/contracts/farm/SophonFarming.sol#L279
Tool used
Manual Review
Recommendation
Apply the updated
startBlock
state variable on all existing pools in thesetStartBlock()
.Duplicate of #108
The text was updated successfully, but these errors were encountered: