Skip to content
Business logic Audit finding Intermediate

Rewards might get stuck when approved actor renews a position

When an approved actor renews or extends a staking position, the rewards are sent to the approved actor instead of the position owner. This could cause reward tokens to be lost or sent to the wrong user, especially if the approved actor is a smart contract.

0xAnmol Follow with BlockBusters, ChinmayF and 2 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-06-magicsea-judging/issues/207

Found by

0xAnmol, BlockBusters, ChinmayF, HonorLt, ydlee

Summary

When an approved actor calls the harvest function, the rewards get sent to the user (staker). However, when the approved actor renews the user’s position, they receive the rewards instead.

If the approved actor is a smart contract (e.g., a keeper), the funds might get stuck forever or go to the wrong user, such as a Chainlink keeper.

Vulnerability Detail

Suppose Alice mints an NFT by creating a position and approves Bob to use it.

  • When Bob calls harvestPosition with Alice’s tokenId, Alice will receive the rewards (as intended)
  • When Bob calls renewLockPosition with Alice’s tokenId, Bob will receive the rewards. The internal function _lockPosition, which is called by renewLockPosition, also harvests the position before updating the lock duration. Unlike the harvest function, _lockPosition sends the rewards to msg.sender instead of the token owner.

This bug exists in both renewLockPosition and extendLockPosition, as they both call _lockPosition, which includes the wrong receiver.

PoC

To run this test, add it into MlumStaking.t.sol.

Solidity
function testVuln_ApprovedActorReceivesRewardsWhenRenewingPosition() public {
    // setup pool
    uint256 _amount = 100e18;
    uint256 lockTime = 1 days;

    _rewardToken.mint(address(_pool), 100_000e6);
    _stakingToken.mint(ALICE, _amount);

    // alice creates new position
    vm.startPrank(ALICE);
    _stakingToken.approve(address(_pool), _amount);
    _pool.createPosition(_amount, lockTime);
    vm.stopPrank();

    // alice approves bob
    vm.prank(ALICE);
    _pool.approve(BOB, 1);

    skip(1 hours);

    // for simplicity of the PoC we use a static call
    // IMlumStaking doesn't include `renewLockPosition(uint256)`
    uint256 bobBefore = _rewardToken.balanceOf(BOB);
    vm.prank(BOB);
    address(_pool).call(abi.encodeWithSignature("renewLockPosition(uint256)", 1));

    // Bob receivew the rewards, instead of alice
    assertGt(_rewardToken.balanceOf(BOB), bobBefore);
}

Impact

Possible loss of reward tokens

Code Snippet

https://github.com/sherlock-audit/2024-06-magicsea/blob/main/magicsea-staking/src/MlumStaking.sol#L710

Tool used

Manual Review, Foundry

Recommendation

Change _lockPosition() in MlumStaking.sol to use the owner of the position instead of msg.sender.

Solidity
function _lockPosition(uint256 tokenId, uint256 lockDuration, bool resetInitial) internal {
    ...
-   _harvestPosition(tokenId, msg.sender);
+   _harvestPosition(tokenId, _ownerOf(tokenId));
    ...
}

Discussion

0xSmartContract

Calling the renewLockPosition and extendLockPosition functions may result in rewards being sent to the wrong address.

When an approved actor calls the renewLockPosition or extendLockPosition functions, the rewards go to the approved actor who made the call, not the Position Owner.

0xHans1

PR: https://github.com/metropolis-exchange/magicsea-staking/pull/8

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/metropolis-exchange/magicsea-staking/pull/8

sherlock-admin2

The Lead Senior Watson signed off on the fix.

The original report as published on Sherlock, by 0xAnmol. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Impact

Reward tokens could be lost or sent to the wrong user, especially if the approved actor is a smart contract.

What the attacker needed

Position owner approves another actor; approved actor calls renew or extend

The fix

The protocol team fixed this issue by changing `_lockPosition` to send rewards to the position owner instead of `msg.sender`.

How it was found

  1. Alice creates a position and approves Bob to manage it.
  2. Bob calls `renewLockPosition` with Alice's tokenId.
  3. The internal `_lockPosition` function harvests rewards and sends them to Bob (msg.sender) instead of Alice.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

In a staking system, users can approve someone else to manage their staked position. Normally, when rewards are collected, they should go to the position owner. Here, if the approved manager renews the lock, the rewards go to the manager instead, which is unfair and could lose funds if the manager is a contract.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by 0xAnmol

View all

7 more disclosed reports, best first.

More from MagicSea - the native DEX on the IotaEVM

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.