You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update not getting called right after a WETH reward addition to Staking.sol will make old stakers lose a portion of their staked amounts.
Vulnerability Details
Staking.sol relies on a measuring system that factors in how many indexes ago a user has staked. When update() gets called after WETH gets added to the system index gets updated with an amount that is going to get distributed to each and every user based on how much they have staked. The formula used to determine the multiplier for each user's staked tokens is the following: amount of new weth * 1e18 / current supply of staking tokens.
Then based on that multiplier the following calculation gets done for each address when updateFor() gets called on it: amount supplied * the current multiplier amount / 1e18.
The issue arises due to update() on Staking.sol not getting called right after WETH gets sent from Fees.sol's sellProfits(). The reward calculations only give users the right amount if balances got updated right after WETH being deposited. This opens the door for such cases:
WETH gets sent to Staking.sol. update() doesn't get called.
Someone depositing tokens into Staking.sol.
then WETH getting sent again, right after that update update() getting called.
This will make everyone's who deposited before the new depositor get less rewards because the total supply of tokens in the contract being different than when update should have been called.
[ESCALATE] This is duplicate of #1223 See Recommendations for both.
I believe the only similarity between the two findings is them recommending update on Staking.sol be called in Fees.sol's WETH transfer function.
Though the recommendation is the same the root cause of the two issues isn't the same.
update() not getting called right after a WETH amount has been sent will cause users to lose staking rewards
Severity
High Risk
Relevant GitHub Links
https://github.com/Cyfrin/2023-07-beedle/blob/main/src/Staking.sol#L61
https://github.com/Cyfrin/2023-07-beedle/blob/main/src/Fees.sol#L26
Summary
Update not getting called right after a WETH reward addition to
Staking.sol
will make old stakers lose a portion of their staked amounts.Vulnerability Details
Staking.sol
relies on a measuring system that factors in how many indexes ago a user has staked. Whenupdate()
gets called after WETH gets added to the systemindex
gets updated with an amount that is going to get distributed to each and every user based on how much they have staked. The formula used to determine the multiplier for each user's staked tokens is the following:amount of new weth * 1e18 / current supply of staking tokens
.Then based on that multiplier the following calculation gets done for each address when
updateFor()
gets called on it:amount supplied * the current multiplier amount / 1e18
.The issue arises due to
update()
onStaking.sol
not getting called right after WETH gets sent fromFees.sol
'ssellProfits()
. The reward calculations only give users the right amount if balances got updated right after WETH being deposited. This opens the door for such cases:Staking.sol
.update()
doesn't get called.Staking.sol
.update()
getting called.This will make everyone's who deposited before the new depositor get less rewards because the total supply of tokens in the contract being different than when update should have been called.
Here is a PoC demonstrating the issue:
https://gist.github.com/CrisCodesCrap/a312eded3c4b57231af1a1df71f7a3be
Impact
Stakers, who have staked before the new staker will lose a portion of their tokens due to the offset staking token balance.
Tools Used
Manual Review
Recommendations
Consider calling
Staking.sol
's update inFees.sol
'ssellProfits()
.The text was updated successfully, but these errors were encountered: