# Attacker will prevent distribution of USDC to stakers through frequent reward updates

USDC's 6-decimal precision makes rewardPerToken round to zero on frequent updates, letting an attacker grief all 10K weekly USDC staker rewards.

- Payout: Audit contest
- Severity: medium
- Program: Kwenta Staking Contracts
- Found by: aslanbek
- Disclosed: 2024-07-24
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-07-kwenta-staking-contracts-judging/issues/22
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-07-kwenta-staking-contracts%3AM-1
- Tags: area:web3 domain:web3 impact:dos impact:funds-loss kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:source-review vuln:dos vuln:precision-loss

**Target:** StakingRewardsV2 reward accounting (Solidity, Optimism)
**Root cause:** rewardPerTokenUSDC uses the same 1e18-scaled formula as KWENTA but USDC has 6 decimals; with rewardRateUSDC=16534 and 100k KWENTA staked, elapsed*rate*1e18/totalStaked truncates to 0 for short intervals.
**Steps:**
1. Stake 100_000e18 KWENTA into StakingRewardsV2.
2. Notifier calls `notifyRewardAmount(0, 10_000e6)` setting rewardRateUSDC=16534 over 1 week.
3. Attacker calls `stake`/`unstake` (or `getReward`) every 1-3 blocks (~2-6s on Optimism).
4. Each update computes `(6 * 16534 * 1e18) / 100_000e18` which truncates to 0, so rewardPerTokenUSDC never advances.
5. Repeat for the week; stakers earn 0 of the 10_000e6 USDC.
**How found:** Noticed USDC's 6 decimals vs KWENTA's 18 were fed through the identical reward-per-token formula; computed that small elapsed-time deltas truncate the division to zero and confirmed with a modified Foundry test.
**Exploitation:** Griefing: attacker repeatedly triggers reward updates with cheap Optimism txs (~$0.01 each, ~$134/week) to keep elapsed time per update small enough that the USDC reward-per-token division truncates to zero, denying all stakers their weekly USDC.
**Insight:** When a staking contract supports reward tokens of differing decimals, check whether reward-per-token math is scaled to the reward token's precision; low-decimal tokens (USDC/USDT) truncate to zero under frequent small updates, enabling cheap griefing.

## Proof of concept (copied exactly from the original report)

**PoC test showing USDC rewardPerToken rounds to zero**

```
function test_rewardPerTokenUSDC() public {
        // fund so that staking can succeed
        uint256 stakedAmount = 100_000e18; // @audit 100_000 staked KWENTA
        fundAndApproveAccountV2(address(this), stakedAmount);

        // check reward per token starts as 0
        assertEq(stakingRewardsV2.rewardPerTokenUSDC(), 0);

        // stake
        stakingRewardsV2.stake(stakedAmount);
        assertEq(stakingRewardsV2.totalSupply(), stakedAmount);

        // set rewards
        uint256 reward = 10_000e6; // @audit 10,000 USDC will be distributed every week
        vm.prank(address(rewardsNotifier));
        stakingRewardsV2.notifyRewardAmount(0, reward);

        // ff to end of period
        vm.warp(block.timestamp + 2);

        // check reward per token updated
        assertEq(stakingRewardsV2.rewardPerTokenUSDC(), 1 ether); // @audit this will return 0
```

