Skip to content
Smart contracts Audit finding Intermediate

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.

0xHexed Follow with 0xShoonya, BADROBINX and 27 others

Originally disclosed on Sherlock

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:

Solidity
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

  1. totalCollateral = 0.
  2. rewardPerTokenStored contains accumulated reward data from previous periods.

External Pre-conditions

None

Attack Path

  1. totalCollateral needs to become zero.
  2. Deposit minimal collateral (even 1 wei) to trigger updateRewards(account).
  3. Due to the bug, userRewardPerTokenPaid[attacker][token] remains 0 instead of being updated to current rewardPerTokenStored.
  4. withdraw the deposited collateral.
  5. During withdrawal, _earned() calculates: (balance * (rewardPerTokenStored - 0)) / 1e18 = full accumulated rewards.
  6. Wait for protocol to accumulate sufficient reward token balance through new reward periods
  7. Execute claimSimple() to claim the phantom rewards once contract has enough balance.

Impact

  1. Fund Loss: Attacker claims rewards equivalent to previously accumulated rewardPerTokenStored values.
  2. Reward Pool Depletion: Protocol reward balance gets drained by unearned claims.
  3. 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:

Solidity
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

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

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

  1. Make totalCollateral become zero.
  2. Deposit a minimal amount of collateral to trigger the reward update.
  3. The userRewardPerTokenPaid remains zero instead of being updated.
  4. Withdraw the deposited collateral.
  5. The earned calculation uses the full accumulated rewardPerTokenStored.
  6. 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.

More by 0xHexed

View all

1 more disclosed report, best first.

More from USG - Tangent

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.