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
{{ message }}
This repository has been archived by the owner on Jan 12, 2025. It is now read-only.
DuplicateA valid issue that is a duplicate of an issue with `Has Duplicates` labelMediumA Medium severity issue.RewardA payout will be made for this issue
Rewards can be stolen in MlumStaking.sol by frontrunning
Summary
Rewards can be stolen in MlumStaking.sol by frontrunning
Vulnerability Detail
MlumStaking receives rewardToken and distribute it among the stakers, who are staking. An attacker can frontrun the rewardToken deposit to receive rewards and withdraw immediately after receiving rewards, successfully stealing other users reward
function createPosition(uint256amount, uint256lockDuration) externaloverride nonReentrant {
// no new lock can be set if the pool has been unlockedif (isUnlocked()) {
require(lockDuration ==0, "locks disabled");
}
_updatePool();
// handle tokens with transfer tax
amount =_transferSupportingFeeOnTransfer(stakedToken, msg.sender, amount);
require(amount !=0, "zero amount"); // createPosition: amount cannot be null// mint NFT position tokenuint256 currentTokenId =_mintNextTokenId(msg.sender);
// calculate bonusesuint256 lockMultiplier =getMultiplierByLockDuration(lockDuration);
uint256 amountWithMultiplier = amount * (lockMultiplier +1e4) /1e4;
// create position
_stakingPositions[currentTokenId] =StakingPosition({
initialLockDuration: lockDuration,
amount: amount,
rewardDebt: amountWithMultiplier * (_accRewardsPerShare) / (PRECISION_FACTOR),
lockDuration: lockDuration,
startLockTime: _currentBlockTimestamp(),
lockMultiplier: lockMultiplier,
amountWithMultiplier: amountWithMultiplier,
totalMultiplier: lockMultiplier
});
// update total lp supply
_stakedSupply = _stakedSupply + amount;
_stakedSupplyWithMultiplier = _stakedSupplyWithMultiplier + amountWithMultiplier;
emitCreatePosition(currentTokenId, amount, lockDuration);
}
Attacker will create position that has 0 lock duration before the rewardToken deposit and due to 0 lock duration attacker will be able to withdraw immediately after staking along with rewards
All this happening due to _accRewardsPerShare which increases due to increase in rewardToken, so everytime there is rewardToken deposited, it increases the _accRewardsPerShare and an attacker can take advantage of that
sherlock-admin4
changed the title
Joyful Arctic Aardvark - Rewards can be stolen in MlumStaking.sol by frontrunning
utsav - Rewards can be stolen in MlumStaking.sol by frontrunning
Jul 29, 2024
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
DuplicateA valid issue that is a duplicate of an issue with `Has Duplicates` labelMediumA Medium severity issue.RewardA payout will be made for this issue
utsav
Medium
Rewards can be stolen in MlumStaking.sol by frontrunning
Summary
Rewards can be stolen in MlumStaking.sol by frontrunning
Vulnerability Detail
MlumStaking receives rewardToken and distribute it among the stakers, who are staking. An attacker can frontrun the rewardToken deposit to receive rewards and withdraw immediately after receiving rewards, successfully stealing other users reward
Attacker will create position that has 0 lock duration before the rewardToken deposit and due to 0 lock duration attacker will be able to withdraw immediately after staking along with rewards
All this happening due to
_accRewardsPerShare
which increases due toincrease
in rewardToken, so everytime there is rewardTokendeposited
, it increases the _accRewardsPerShare and an attacker can take advantage of thatImpact
Rewards will be stolen
Code Snippet
https://github.com/sherlock-audit/2024-06-magicsea/blob/main/magicsea-staking/src/MlumStaking.sol#L354C4-L391C1
https://github.com/sherlock-audit/2024-06-magicsea/blob/main/magicsea-staking/src/MlumStaking.sol#L574C4-L592C1
https://github.com/sherlock-audit/2024-06-magicsea/blob/main/magicsea-staking/src/MlumStaking.sol#L496C5-L503C1
Tool used
VS code
Recommendation
Add some delay when a user creates position or use time based calculation
Duplicate of #74
The text was updated successfully, but these errors were encountered: