Skip to content
Business logic Audit finding Intermediate

Bucket rewards will be wiped by stake/unstake before accrueRewards, lastRewardIndex resets without settling rewards, accrueRewards delta becomes 0

The staking contract resets a token bucket's lastRewardIndex during stake or unstake without first settling pending rewards. An attacker can call stake or unstake just before accrueReward, making the reward delta zero and wiping out accrued rewards for all stakers.

0x00T1 Follow with 0xAadi, 0xAdwa and 47 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-09-super-dca-judging/issues/1065

Found by

0x00T1, 0xAadi, 0xAdwa, 0xB4nkz, 0xCrypt0nite, 0xCuru, 0xDemon, 0xDjango, 0xHexed, 0xImmortan, 0xaxaxa, 0xleo, 0xlookman, 0xpetern, 0xsolisec, 0xv1bh4, 0xzen, 33audits, 4Nescient, 8olidity, Aamirusmani1552, Al-Qa-qa, Almanax, Arav, Artur, BADROBINX, BengalCatBalu, Bobai23, Boy2000, BoyD, Chonkov, CodexBugmeNot, DemiGods, DuoSec, FonDevs, HeckerTrieuTien, Hunter, Hurricane, Icon_0x, Ironsidesec, IzuMan, JeRRy0422, JohnTPark24, JohnWeb3, Josh4324, JuggerNaut, KiroBrejka, LonWof-Demon, MysteryAuditor, NHristov, Orhukl, OxSath404, Phaethon, R, Ragnarok, Razkky, SMB62, SOPROBRO, S_722, Sa1ntRobi, ScarletFir, Siiiisivan, SuperDevFavour, Whiterabbit, WillyCode20, Y4nhu1, Yaneca_b, ZeroEx, Ziusz, alexbabits, algiz, aman, ami, axelot, bam0x7, bbl4de, cholakovvv, dani3l526, deadmanwalking, denys_sosnovskyi, derastephh, djshaneden, drdee, farman1094, fullstop, futureHack, gneiss, grigorovv17, harry, heavyw8t, hjo, illoy_sci, itsRavin, ivanalexandur, jah, jayjoshix, jo13, kangaroo, kazan, ke1caM, kimnoic, kimonic, maigadoh, makeWeb3safe, marcosecure0x, merlin, mingzoox, ni8mare, nonso72, oct0pwn, omeiza, oot2k, patitonar, peazzycole, pindarev, pollersan, prosper, proxima_centuri, pv, r1ver, rashmor, resosiloris, rsam_eth, sedare, shiazinho, shieldrey, silver_eth, slavina, softdev0323, soloking, sourav_DEV, surenyan-oks, taticuvostru, techOptimizor, theholymarvycodes, thekmj, theweb3mechanic, tinnohofficial, tobi0x18, typicalHuman, ubl4nk, udo, v10g1, v_2110, vinica_boy, vivekd, volleyking, whitehair0330, wickie, x0t0wt1w, xxiv, yeahChibyke, zcai

Summary

The contract resets a token bucket’s lastRewardIndex in stake / unstake without first settling pending rewards, this will cause a complete loss of accrued rewards for stakers as any user can call stake/unstake right before accrueReward and this will zero the bucket’s delta.

Root Cause

Inside SuperDCAStaking::accrueReward we subtract the info.lastRewardIndex from rewardIndex, however inside stake/unstake we set lastRewardIndex == rewardIndex:

Solidity
    function unstake(address token, uint256 amount) external override {
        // Validate amount is non-zero and available
        if (amount == 0) revert SuperDCAStaking__ZeroAmount();

        // Check both token bucket and user balances are sufficient
        TokenRewardInfo storage info = tokenRewardInfoOf[token];
        if (info.stakedAmount < amount) revert SuperDCAStaking__InsufficientBalance();
        if (userStakes[msg.sender][token] < amount) revert SuperDCAStaking__InsufficientBalance();

        // Update global reward index to current time
        _updateRewardIndex();

        // Update token bucket accounting and user stakes
        info.stakedAmount -= amount;
    @>    info.lastRewardIndex = rewardIndex;

        totalStakedAmount -= amount;
        userStakes[msg.sender][token] -= amount;

        // Remove token from user's set if balance reaches zero
        if (userStakes[msg.sender][token] == 0) {
            userTokenSet[msg.sender].remove(token);
        }

        // Transfer SuperDCA tokens back to user
        IERC20(DCA_TOKEN).transfer(msg.sender, amount);
        emit Unstaked(token, msg.sender, amount);
    }


If stake/unstake were to be called just before accrueRewards the system "forgets" about past rewards and can make the accrueRewards return zero leading to 100% lost rewards for users.

Internal Pre-conditions

Somebody called stake unstake before the hook _beforeAddLiquidity calls _handleDistributionAndSettlement

External Pre-conditions

Attack Path

  1. Lets say lastIndex is 50, Index now will be 100, user or attacker calls stake/unstake just before _beforeAddLiquidity is triggered.
  2. lastIndex becomes 100
  3. _beforeAddLiquidity calls into accrueReward, because delta is uint256 delta = rewardIndex - info.lastRewardIndex; and stake/unstake was called before than, delta results is a small number or even 0 so basically no rewards

Impact

High, the system forgets about past rewards, users will lose up to 100% of their rewards.

PoC

Inside SuperDCAStaking.t.sol::TokenRewardInfos, copy paste this test:

Solidity
    function test_PoC_UnstakeBeforeAccrue_WipesBucketDelta() public {
        // Set up a single bucket stake
        vm.prank(user);
        staking.stake(tokenA, 100e18);

        // Let rewards accrue
        uint256 start = staking.lastMinted();
        uint256 secs = 100;
        vm.warp(start + secs);

        //what should be paid 
        uint256 expectedMint = secs * rate;
        assertGt(expectedMint, 0, "sanity");

        // Unstake before accrue resets bucket lastRewardIndex and wipes  delta
        vm.prank(user);
        staking.unstake(tokenA, 1);

        // Accrue now => pays 0 due to wiped delta
        vm.prank(gauge);
        uint256 paid = staking.accrueReward(tokenA);
        assertEq(paid, 0, "pending bucket rewards wiped by unstake reset");
    }

Run with forge test --match-test test_PoC_UnstakeBeforeAccrue_WipesBucketDelta -vvvv

Console.logs:

Solidity
   └─ ← [Return] 0
    ├─ [0] VM::assertEq(0, 0, "pending bucket rewards wiped by unstake reset") [staticcall]
    │   └─ ← [Return]
    └─ ← [Stop]

Mitigation

Make the contract remember the passed rewards even after stake unstake has been called

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/Super-DCA-Tech/super-dca-gauge/pull/41

The original report as published on Sherlock, by 0x00T1. 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

Root cause

Likely the stake and unstake functions set info.lastRewardIndex to the current rewardIndex without first calling accrueReward to settle pending rewards, so the delta used in accrueReward becomes zero.

Impact

Users could lose up to 100% of their accrued rewards because the system forgets past rewards when stake or unstake is called before accrueReward.

What the attacker needed

A staked position in a token bucket; ability to call stake or unstake before accrueReward

The fix

The contract should settle pending rewards before updating lastRewardIndex in stake and unstake, or otherwise preserve the accrued rewards across these calls.

How it was found

  1. Set up a stake for a token.
  2. Let time pass so rewards accrue.
  3. Call unstake for a small amount before accrueReward is called.
  4. Call accrueReward and observe that it pays zero.

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 tracks rewards using an index. When someone stakes or unstakes, the contract updates a stored index to the current value without first paying out what was already earned. If this happens right before the reward payout function runs, the difference between the current index and the stored index becomes zero, so no rewards are paid. This means all pending rewards for that token are lost.

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 from Super DCA Liquidity Network

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.