Skip to content
Business logic Audit finding Intermediate

Attackers will reset `avgStart` of any user making rewards stuck for longer and get lost to savings

The StakedExa contract resets a user's average start time when a deposit is made after a reference time, allowing an attacker to deposit 1 wei to a victim and reset their avgStart, which delays or reduces their rewards. The victim cannot claim rewards until minTime passes and may lose rewards to savings upon withdrawal.

0x73696d616f Follow with HackTrace

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-07-exactly-stacking-contracts-judging/issues/22

Found by

0x73696d616f, HackTrace

Summary

StakedExa::_update() resets avgStart[to] whenever the time passed is bigger than the reference time. An attacker can deposit 1 wei to some user and reset the avgStart, which will make claiming for the to address return 0 rewards until at least minTime and/or the to address loses the rewards to savings when withdrawing.

Root Cause

In StakedExa.sol::151, if (time > memRefTime) avgStart[to] = block.timestamp * 1e18; resets the average start time to the current block timestamp, which may be performed by an attacker donating just 1 wei to the to address.

Internal pre-conditions

  1. User must stake for at least refTime, which is expected as this the moment the user can claim the maximum rewards.

External pre-conditions

None.

Attack Path

  1. User stakes until reaching at least the reference time + 1.
  2. Attacker deposits 1 wei to the user forcing avgStart to reset and discount all rewards to 0 until minTime passes.

Impact

User will not receive any rewards until minTime and will lose to savings when withdrawing as no rewards would have vested due to avgStart[to] having been reset.

PoC

Add the following test to StakedEXA.t.sol.

Solidity
function test_POC_anyone_can_reset_stakedTime() external {
  bool attack = true;
  uint256 assets = 1e18;
  uint256 time = refTime;

  exa.mint(address(this), assets);
  stEXA.deposit(assets, address(this));

  uint256 initTime = block.timestamp * 1e18;
  skip(time + 1);
  uint256 finalTime = block.timestamp * 1e18;

  stEXA.claim(rA);
  assertEq(stEXA.avgStart(address(this)), initTime);

  // Add some more rewards
  rA.mint(address(stEXA), initialAmount);
  stEXA.notifyRewardAmount(rA, initialAmount);

  // Attacker deposits 1 to reset start time and get rewards stuck
  if (attack) {
    address attacker = makeAddr("attacker");
    exa.mint(attacker, 1);
    vm.startPrank(attacker);
    exa.approve(address(stEXA), 1);
    stEXA.deposit(1, address(this));
    vm.stopPrank();
    assets += 1;
  }

  skip(minTime);

  assertEq(stEXA.avgStart(address(this)), attack ? finalTime : initTime, "avgStart");
  assertEq(stEXA.claimable(rA, address(this), assets), attack ? 0 : 20833334711198888308, "claimable");
}

Mitigation

Remove the avgStart[to] reset mechanism in _update(), as users can decrease their staked time by withdrawing and depositing again, it should not be able to reset like this because they might want to just keep claiming or withdraw in the near future while paying only some excessFactor rewards. With the code as is, attackers can manipulate other users rewards and make them lose funds.

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/exactly/protocol/pull/750

sherlock-admin2

The Lead Senior Watson signed off on the fix.

The original report as published on Sherlock, by 0x73696d616f. 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 _update function resets avgStart[to] to the current block timestamp whenever the time since last update exceeds a reference time, without checking if the deposit is significant or if the user intended to reset.

Impact

The user will not receive any rewards until minTime and will lose rewards to savings when withdrawing because no rewards would have vested due to the reset.

What the attacker needed

Victim has staked for at least refTime; attacker can deposit 1 wei to victim's address

The fix

The protocol team fixed this issue by removing the avgStart reset mechanism in _update().

How it was found

  1. User stakes until reaching at least the reference time + 1.
  2. Attacker deposits 1 wei to the user forcing avgStart to reset and discount all rewards to 0 until minTime passes.

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.

In a staking contract, rewards are calculated based on how long you've staked. The contract tracks a start time for each user. If someone else sends you a tiny deposit, the contract mistakenly resets your start time to now, so it looks like you just started staking. This means you lose credit for the time you already staked and get fewer or no rewards.

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 by 0x73696d616f

View all

172 more disclosed reports, best first.

More from Exactly Protocol Update - Staking Contract

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.