First Depositor can flash loan the protocol too artificially increase the token rewards without incurring any risk
The reward index update is skipped when the first user stakes because totalStakedAmount is zero, leaving the lastMinted timestamp unset. An attacker can flash loan tokens, stake them, trigger reward accrual to mint rewards for time before the stake, then unstake and repay the loan in one transaction.
0xBoraichoT Follow with 0xaxaxa, 0xleo and 47 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2025-09-super-dca-judging/issues/852
Found by
0xBoraichoT, 0xaxaxa, 0xleo, 0xpetern, 0xsolisec, 33audits, 4Nescient, 8olidity, Almanax, Bbash, Bobai23, BoyD, Chonkov, CodexBugmeNot, Divine_Dragon, DuoSec, EQUATION, HeckerTrieuTien, Hurricane, Immanux, Ironsidesec, JeRRy0422, JohnTPark24, MysteryAuditor, Opecon, Orhukl, OxSath404, R, Razkky, SOPROBRO, S_722, SuperDevFavour, TAdev0, TECHFUND-inc, TsvetanLobutov, WillyCode20, Y4nhu1, ZeroEx, Ziusz, aman, ami, axelot, bbl4de, dani3l526, denys_sosnovskyi, drdee, engineer, ezsia, frankauditcraft, fullstop, gneiss, grigorovv17, har0507, heavyw8t, itsRavin, jayjoshix, ke1caM, kimnoic, kimonic, lucky-gru, maigadoh, makeWeb3safe, merlin, namx05, nonso72, peazzycole, pollersan, proofvoid, r1ver, resosiloris, sakibcy, silver_eth, songyuqi, the_haritz, theweb3mechanic, tobi0x18, vinica_boy, vivekd, volleyking, whitehair0330, wickie, yeahChibyke, zcai
Summary
When a user stakes SuperDCATokens , the timestamp is updated to prevent a flashloan attack however when the first user stake the timestamp update is not updated due to the fact that the timestamp is skipped when totalStakedAmount is 0 (as seen in the code snippet below) and this is 0 during the time when the first depositor makes an initial deposit.
/**
* @notice Updates the global reward index based on elapsed time and total staked amount.
* @dev The 1e18 scaling factor provides mathematical precision for fractional rewards.
*/
function _updateRewardIndex() internal {
// Return early if no stakes exist or no time has passed
if (totalStakedAmount == 0) return;
uint256 elapsed = block.timestamp - lastMinted;
if (elapsed == 0) return;
// Calculate mint amount based on elapsed time and mint rate
uint256 mintAmount = elapsed * mintRate;
// Update global index: previous_index + (mint_amount * 1e18 / total_staked)
rewardIndex += Math.mulDiv(mintAmount, 1e18, totalStakedAmount);
lastMinted = block.timestamp;
emit RewardIndexUpdated(rewardIndex);
}
This allows a user to execute a flash loan to borrow DCATokens, stake them in the contract, claim rewards, and repay the flash loan—all within a single transaction.
Root Cause
The _updateRewardIndex() function is not fully executed when totalStakedAmount == 0. Let’s walk through what happens in the stake() function:
function stake(address token, uint256 amount) external override {
...
// Update global reward index to current time
_updateRewardIndex();
// Transfer SuperDCA tokens from user to contract
IERC20(DCA_TOKEN).transferFrom(msg.sender, address(this), amount);
// Update token bucket accounting and user stakes
TokenRewardInfo storage info = tokenRewardInfoOf[token];
info.stakedAmount += amount;
info.lastRewardIndex = rewardIndex;
totalStakedAmount += amount;
userStakes[msg.sender][token] += amount;
// Add token to user's active token set if new
userTokenSet[msg.sender].add(token);
emit Staked(token, msg.sender, amount);
}
Notice that _updateRewardIndex() is called before totalStakedAmount is updated. So, when the first user stakes, totalStakedAmount is still 0, causing _updateRewardIndex() to exit early without updating the lastMinted timestamp.
This means:
- The user's stake is registered.
- The reward index for the token is set to the current global
rewardIndex. - However,
lastMintedis still the contract deployment timestamp (or the last updated time, if any), and not the time of the stake.
⚠️ Vulnerability
A malicious user can exploit this as follows:
- Use a flash loan to borrow DCA tokens.
- Stake those tokens (triggering
_updateRewardIndex(), which exits early). - Trigger reward accrual via the
gaugecontract. - The
gaugecallsaccrueReward(), which in turn calls_updateRewardIndex()again:
function _updateRewardIndex() internal {
if (totalStakedAmount == 0) return; // Skipped during first stake
uint256 elapsed = block.timestamp - lastMinted;
if (elapsed == 0) return;
uint256 mintAmount = elapsed * mintRate;
rewardIndex += Math.mulDiv(mintAmount, 1e18, totalStakedAmount);
lastMinted = block.timestamp;
emit RewardIndexUpdated(rewardIndex);
}
At this point:
totalStakedAmountis non-zero, so the function proceeds.elapsedincludes the full time since contract deployment (or last mint), sincelastMintedwas never updated earlier.- As a result, the
rewardIndexincreases significantly.
Then, in accrueReward():
function accrueReward(address token) external override onlyGauge returns (uint256 rewardAmount) {
_updateRewardIndex();
TokenRewardInfo storage info = tokenRewardInfoOf[token];
if (info.stakedAmount == 0) return 0;
uint256 delta = rewardIndex - info.lastRewardIndex;
if (delta == 0) return 0;
rewardAmount = Math.mulDiv(info.stakedAmount, delta, 1e18);
info.lastRewardIndex = rewardIndex;
return rewardAmount;
}
- A non-zero delta is calculated.
- The user’s pool receives rewards for elapsed time they were not actually staked, since the stake timestamp was never correctly recorded.
Finally, the user repays the flash loan by unstaking— all within a single transaction — while extracting DCA token rewards they didn’t earn.
Internal Pre-conditions
totalStakedAmount should equal 0.
External Pre-conditions
A pool should be deployed with listed token and DCA token with pool hook set to Gauge contract.
Attack Path
- Michael has just deployed and initialised a USDc-DAC pool, with the hook contract being the guage contract.
- Michael has just listed USDc token via the SuperDCAListing.sol contract which passed succesfully, and add liquidity to the pool.
- Michael then takes a flashloan of 100e18 SuperDCAToken, which he stakes in the SuperDCAStaking contract by calling the stake function [
stake(address token, uint256 amount) external override] with the USDc token and amount of 100e18. - Michael has now staked he then performs a swap operation in the pool to trigger the accrueReward call via the SuperGauge contract.
- The stakingContract mints rewards to the pool.
- Michael unstakes his position and proceeds to pay the flashloan.
- Michael can claim SuperDCAToken by removing liquidity he added during step 2.
Impact
High, rewards are artificially minted.
PoC
No response
Mitigation
No response
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/Super-DCA-Tech/super-dca-gauge/pull/48
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
The _updateRewardIndex function returns early when totalStakedAmount is zero, so the lastMinted timestamp is not updated during the first stake.
Impact
Rewards are artificially minted, allowing the attacker to extract unearned tokens.
What the attacker needed
TotalStakedAmount is zero; pool deployed with gauge hook; attacker can flash loan DCA tokens
The fix
The protocol team fixed this issue in a pull request.
How it was found
- Deploy and initialise a pool with the gauge contract as hook and add liquidity.
- Take a flash loan of SuperDCA tokens.
- Stake the borrowed tokens in the staking contract.
- Perform a swap in the pool to trigger accrueReward via the gauge.
- Unstake the position and repay the flash loan.
- Claim the artificially minted rewards by removing liquidity.
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 tokens, the contract is supposed to record the time so it can calculate rewards fairly. But for the very first person to stake, that time is not recorded, so the contract later thinks a lot of time has passed and pays out extra rewards. An attacker can borrow tokens temporarily, stake them, collect the inflated rewards, and give the tokens back, all in one go.
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.