This repository has been archived by the owner on Mar 3, 2024. It is now read-only.
xiaoming90 - Immediately start getting rewards belonging to others after staking #603
Labels
Has Duplicates
A valid issue with 1+ other issues describing the same vulnerability
High
A valid High severity issue
Reward
A payout will be made for this issue
Sponsor Confirmed
The sponsor acknowledged this issue is valid
xiaoming90
high
Immediately start getting rewards belonging to others after staking
Summary
Malicious users could abuse the accounting error to immediately start getting rewards belonging to others after staking, leading to a loss of reward tokens.
Vulnerability Detail
Assume a new user called Bob mints 100 LMPVault or DV shares. The ERC20's
_mint
function will be called, which will first increase Bob's balance at Line 267 and then trigger the_afterTokenTransfer
hook at Line 271.https://github.com/OpenZeppelin/openzeppelin-contracts/blob/0457042d93d9dfd760dbaa06a4d2f1216fdbe297/contracts/token/ERC20/ERC20.sol#L259
The
_afterTokenTransfer
hook will automatically stake the newly minted shares to the rewarder contracts on behalf of Bob.https://github.com/sherlock-audit/2023-06-tokemak/blob/main/v2-core-audit-2023-07-14/src/vault/LMPVault.sol#L854
Within the
MainRewarder.stake
function, it will first call the_updateReward
function at Line 87 to take a snapshot of accumulated rewards. Since Bob is a new user, his accumulated rewards should be zero. However, this turned out to be false due to the bug described in this report.https://github.com/sherlock-audit/2023-06-tokemak/blob/main/v2-core-audit-2023-07-14/src/rewarders/MainRewarder.sol#L86
When the
_updateReward
function is executed, it will compute Bob's earned rewards. It is important to note that at this point, Bob's balance has already been updated to 100 shares in thestakeTracker
contract, anduserRewardPerTokenPaid[Bob]
is zero.Bob's earned reward will be as follows, where$r$ is the
rewardPerToken()
:Bob immediately accumulated a reward of$100r$ upon staking into the rewarder contract, which is incorrect. Bob could withdraw $100r$ reward tokens that do not belong to him.
https://github.com/sherlock-audit/2023-06-tokemak/blob/main/v2-core-audit-2023-07-14/src/rewarders/AbstractRewarder.sol#L128
Impact
Loss of reward tokens for the vault shareholders.
Code Snippet
https://github.com/sherlock-audit/2023-06-tokemak/blob/main/v2-core-audit-2023-07-14/src/vault/LMPVault.sol#L854
https://github.com/sherlock-audit/2023-06-tokemak/blob/main/v2-core-audit-2023-07-14/src/rewarders/MainRewarder.sol#L86
https://github.com/sherlock-audit/2023-06-tokemak/blob/main/v2-core-audit-2023-07-14/src/rewarders/AbstractRewarder.sol#L128
Tool used
Manual Review
Recommendation
Ensure that the balance of the users in the rewarder contract is only incremented after the
_updateReward
function is executed.One option is to track the balance of the staker and total supply internally within the rewarder contract and avoid reading the states in the
stakeTracker
contract, commonly seen in many reward contracts.The text was updated successfully, but these errors were encountered: