Users can steal accumulated rewards when `totalCollateral` becomes zero due to incomplete state updates
When totalCollateral becomes zero, the reward update function skips updating userRewardPerTokenPaid for new depositors, leaving it at zero while rewardPerTokenStored retains accumulated values. An attacker could deposit minimal collateral, withdraw it, and later claim rewards that were already earned by previous users.
Source: https://github.com/sherlock-audit/2025-08-usg-tangent-judging/issues/348
Found by
0xHexed, 0xShoonya, BADROBINX, Bigsam, Brene, DharkArtz, HeckerTrieuTien, JeRRy0422, Mishkat6451, Sneks, Tigerfrake, Uddercover, Vesko210, almurhasan, auditorshambu, ck, ezsia, gh0xt, heavyw8t, illoy_sci, jayjoshix, kimnoic, maigadoh, maxim371, sl1, sourav_DEV, theholymarvycodes, udo, v1c7, vivekd
Summary
When totalCollateral becomes zero, the _updateReward() function skips updating userRewardPerTokenPaid for new depositors, leaving it at 0 while rewardPerTokenStored retains previously accumulated values. This allows attackers to claim rewards that were already earned by previous users.
Root Cause
In RewardAccumulator._updateReward(), the entire reward update logic is skipped when totalCollateral == 0:
function _updateReward(address market, address account, uint256 collateralBalance, uint256 totalCollateral) internal {
if (totalCollateral != 0) { // ❌ Skips when totalCollateral = 0
// ... reward calculations and userRewardPerTokenPaid updates
}
}
This leaves userRewardPerTokenPaid[market][account][token] at 0 instead of syncing it to the current rewardPerTokenStored value.
Internal Pre-conditions
totalCollateral = 0.rewardPerTokenStoredcontains accumulated reward data from previous periods.
External Pre-conditions
None
Attack Path
totalCollateralneeds to become zero.- Deposit minimal collateral (even 1 wei) to trigger
updateRewards(account). - Due to the bug,
userRewardPerTokenPaid[attacker][token]remains 0 instead of being updated to currentrewardPerTokenStored. - withdraw the deposited collateral.
- During withdrawal,
_earned()calculates:(balance * (rewardPerTokenStored - 0)) / 1e18= full accumulated rewards. - Wait for protocol to accumulate sufficient reward token balance through new reward periods
- Execute
claimSimple()to claim the phantom rewards once contract has enough balance.
Impact
- Fund Loss: Attacker claims rewards equivalent to previously accumulated
rewardPerTokenStoredvalues. - Reward Pool Depletion: Protocol reward balance gets drained by unearned claims.
- Legitimate other User Impact: Other users cannot claim their actual earned rewards due to insufficient contract balance caused by Attacker claims
PoC
none
Mitigation
Always update userRewardPerTokenPaid to sync with current rewardPerTokenStored, even when totalCollateral = 0:
function _updateReward(address market, address account, uint256 collateralBalance, uint256 totalCollateral) internal {
uint256 rewardLength = rewardTokens[market].length;
for (uint256 i; i < rewardLength;) {
IERC20 token = rewardTokens[market][i];
if (totalCollateral != 0) {
rewardData[market][token].rewardPerTokenStored = _rewardPerToken(market, token, totalCollateral);
rewardData[market][token].lastUpdateTime = _lastTimeRewardApplicable(rewardData[market][token].periodFinish);
}
if (account != address(0)) {
if (totalCollateral != 0) {
rewards[market][account][token] = _earned(market, account, token, collateralBalance, totalCollateral);
}
// FIX: Always sync userRewardPerTokenPaid
userRewardPerTokenPaid[market][account][token] = rewardData[market][token].rewardPerTokenStored;
}
unchecked { ++i; }
}
}
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/Tangent-labs/tangent-contracts/pull/120
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 reward update logic is entirely skipped when totalCollateral is zero, so userRewardPerTokenPaid is not synced to the current rewardPerTokenStored value.
Impact
An attacker could claim rewards equivalent to previously accumulated rewardPerTokenStored values, potentially draining the reward pool and preventing legitimate users from claiming their earned rewards.
What the attacker needed
TotalCollateral becomes zero; rewardPerTokenStored has accumulated value
The fix
The protocol team fixed this issue by always updating userRewardPerTokenPaid to sync with the current rewardPerTokenStored, even when totalCollateral is zero.
How it was found
- Make totalCollateral become zero.
- Deposit a minimal amount of collateral to trigger the reward update.
- The userRewardPerTokenPaid remains zero instead of being updated.
- Withdraw the deposited collateral.
- The earned calculation uses the full accumulated rewardPerTokenStored.
- Wait for the protocol to accumulate enough reward tokens, then claim the phantom rewards.
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.
This is a smart contract bug in a reward system. When the total amount of collateral in a market drops to zero, the code that normally records how many rewards a user has already been credited for is skipped. That means a new user's record stays at zero, so later the system thinks they are owed all the rewards that were accumulated before they arrived.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.