Skip to content
Business logic Audit finding Beginner

Retroactive lock period changes affect existing stakes

The staking contract stores only a deposit timestamp per stake and validates withdrawals against a single global minimum stake period that the owner can change at any time. If the owner increases that period after a deposit, existing stakers are blocked from withdrawing until the new longer period elapses.

Another Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

57799 sc low retroactive lock period changes affect existing stakes

Submitted on Oct 28th 2025 at 23:16:49 UTC by @Another for Audit Comp | Belong

Description

Brief/Intro

The setMinStakePeriod function allows the contract owner to change the minimum stake period, which retroactively affects all existing stakes.

Vulnerability Details

The setMinStakePeriod function allows the contract owner to change the minimum stake period:

{% code title="Staking.sol — setMinStakePeriod" %}

Solidity
    /// @dev Reverts if `period == 0`.
    /// @param period New minimum stake period in seconds.
    function setMinStakePeriod(uint256 period) external onlyOwner {
        require(period > 0, MinStakePeriodShouldBeGreaterThanZero());
        minStakePeriod = period;/
        emit MinStakePeriodSet(period);
    }

{% endcode %}

Each stake recorded in the deposit function only sets a timestamp without storing the minStakePeriod that was in effect at deposit time. During withdrawal, the _consumeUnlockedSharesOrRevert function uses the current global minStakePeriod for all stake validation:

{% code title="Staking.sol — deposit & withdraw hooks" %}

Solidity
    function _deposit(address by, address to, uint256 assets, uint256 shares) internal override {
        super._deposit(by, to, assets, shares);
        // lock freshly minted shares
        stakes[to].push(Stake({shares: shares, timestamp: block.timestamp}));
    }

    /// @dev Gas-efficient withdrawal with single pass consumption of unlocked shares.
    function _withdraw(address by, address to, address _owner, uint256 assets, uint256 shares) internal override {
        _consumeUnlockedSharesOrRevert(_owner, shares);
        super._withdraw(by, to, _owner, assets, shares);
    }

{% endcode %}

{% code title="Staking.sol — _consumeUnlockedSharesOrRevert" %}

Solidity
    // ============================== Stake Bookkeeping ==============================

    /// @notice Consumes exactly `need` unlocked shares or reverts.
    /// @dev Single pass; swap-and-pop removal; partial consumption in-place.
    function _consumeUnlockedSharesOrRevert(address staker, uint256 need) internal {
        Stake[] storage userStakes = stakes[staker];
        uint256 _min = minStakePeriod;
        uint256 nowTs = block.timestamp;
        uint256 remaining = need;

        for (uint256 i; i < userStakes.length && remaining > 0;) {
            Stake memory s = userStakes[i];
            if (nowTs >= s.timestamp + _min) {
                uint256 take = s.shares <= remaining ? s.shares : remaining;
                if (take == s.shares) {
                    // full consume → swap and pop
                    remaining -= take;
                    userStakes[i] = userStakes[userStakes.length - 1];
                    userStakes.pop();
                    // don't ++i: a new element is now at index i
                } else {
                    // partial consume
                    userStakes[i].shares = s.shares - take;
                    remaining = 0;
                    unchecked {
                        ++i;
                    }
                }
            } else {
                unchecked {
                    ++i;
                }
            }
        }

        if (remaining != 0) revert MinStakePeriodNotMet();
    }

{% endcode %}

Because the contract uses a single global minStakePeriod for validation, changing minStakePeriod retroactively affects all existing stakes and can either shorten or extend their effective lock times.

Recommendation: store an explicit end timestamp (unlock time) for each stake at deposit time, and validate against that stored value when withdrawing. This prevents retroactive changes to lock lengths for already-created stakes.

Impact Details

If the minStakePeriod is increased after a user deposited, users who would otherwise be able to withdraw their shares can be prevented from withdrawing until the new (longer) period elapses — effectively extending the lock on already existing stakes.

Proof of Concept

<details> <summary>Test demonstrating that increasing minStakePeriod blocks withdrawal for existing stakes</summary>

Add the following test to staking.test.ts

TS
describe('Minimum Stake Period Changes Affect Existing Stakes', () => {
  it('should prevent withdrawal when minStakePeriod is increased after deposit', async () => {
    const { staking, long, admin, user1 } = await loadFixture(fixture);

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

    // User deposits with initial 1 day lock period
    await long.connect(admin).transfer(user1.address, amount);
    await long.connect(user1).approve(staking.address, amount);
    await staking.connect(user1).deposit(amount, user1.address);

    // Wait 12 hours (half the original lock period)
    await ethers.provider.send('evm_increaseTime', [23 * 60 * 60]);
    await ethers.provider.send('evm_mine', []);

    // Owner increases to minStakePeriod to 2 days
    await staking.connect(admin).setMinStakePeriod(30 * 24 * 60 * 60);

    // Try to withdraw - should fail even though original period was almost over
    await expect(staking.connect(user1).withdraw(amount, user1.address, user1.address))
      .to.be.revertedWithCustomError(staking, 'MinStakePeriodNotMet');

    // Wait another 6 hours (total 24 hours - original period would be complete)
    await ethers.provider.send('evm_increaseTime', [6 * 60 * 60]);
    await ethers.provider.send('evm_mine', []);

    // Still cannot withdraw because new 2-day period applies
    await expect(staking.connect(user1).withdraw(amount, user1.address, user1.address))
      .to.be.revertedWithCustomError(staking, 'MinStakePeriodNotMet');
  });
});
</details>

References

<details> <summary>Source lines referenced</summary> </details>

The original report as published on Immunefi, by Another. 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

Each stake records only a deposit timestamp, and withdrawal validation reads the current global minStakePeriod instead of a per-stake unlock time fixed at deposit.

Impact

Users who deposited under a shorter lock could be prevented from withdrawing until the newly increased period elapses, effectively extending the lock on existing stakes.

What the attacker needed

Owner changes minStakePeriod; user has an existing stake

The fix

The report recommends storing an explicit unlock timestamp per stake at deposit time and validating withdrawals against that stored value.

How it was found

  1. A user deposits tokens, creating a stake with the then-current minimum stake period.
  2. Time passes but less than the original lock period.
  3. The owner calls setMinStakePeriod with a longer period.
  4. The user tries to withdraw and the transaction reverts with MinStakePeriodNotMet.
  5. Even after the original period would have elapsed, withdrawal still reverts because the new longer period applies.

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.

A staking contract lets people lock tokens for a minimum time before withdrawing. The contract checks the lock time using one shared setting rather than remembering the rule each person agreed to when they deposited. If the owner later raises that setting, people who already deposited find their tokens locked for longer than they expected.

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 Another

View all

24 more disclosed reports, 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.