Skip to content
DoS Audit finding Intermediate

Reward may be locked forever if user doesn’t claim reward for a very long time such that too many epochs have been passed

The reward-claiming function loops over every epoch since the user's last claim, so if a user waits long enough the loop consumes more gas than a block allows and the claim transaction always fails. The report claims rewards could then be locked forever, though the team noted the weekly reward cadence makes this take years.

Chom Follow

Originally disclosed on Code4rena

Submitted by Chom

ExtraRewardsDistributor.sol#L233-L240 AuraLocker.sol#L334-L337

Reward may be locked forever if user doesn’t claim reward for a very long time such that too many epochs have been passed. The platform then forced to reimburse reward to the user that got their reward locked. Causing huge economics loss.

Proof of Concept

Can be done by reverse engineering from the affected code

        for (uint256 i = epochIndex; i < tokenEpochs; i++) {
            //only claimable after rewards are "locked in"
            if (rewardEpochs[_token][i] < latestEpoch) {
                claimableTokens += _claimableRewards(_account, _token, rewardEpochs[_token][i]);
                //return index user claims should be set to
                epochIndex = i + 1;
            }
        }

From this line you will see a loop from epochIndex to tokenEpochs which loop tokenEpochs - epochIndex times. If tokenEpochs - epochIndex value goes high, it will consume too much gas which go beyond the limit of the chain and cause the transaction to be always failed. As a result, reward may be locked forever.

        uint256 latestEpoch = auraLocker.epochCount() - 1;
        // e.g. tokenEpochs = 31, 21
        uint256 tokenEpochs = rewardEpochs[_token].length;

        // e.g. epochIndex = 0
        uint256 epochIndex = userClaims[_token][_account];
        // e.g. epochIndex = 27 > 0 ? 27 : 0 = 27
        epochIndex = _startIndex > epochIndex ? _startIndex : epochIndex;
  • epochIndex is the maximum of _startIndex and latest index of rewardEpochs that user has claim the reward
  • tokenEpochs is the number of epochs that has reward, can be added through addRewardToEpoch function up to latest epoch count of auraLocker
  • latestEpoch is epoch count of auraLocker

If you specified too high _startIndex, the reward may be skipped and these skipped reward are lost forever as the _getReward function set latest epoch that user has claim to the lastest index of rewardEpochs that can be claimed.

the aura locker epoch can be added by using checkpointEpoch function which will automatically add epochs up to current timestamp. Imagine today is 100 years from latest checkpoint and rewardsDuration is 1 day, the total of around 36500 epochs needed to be pushed into the array in single transaction which always failed due to gasLimit. The code that responsible for pushing new epochs below (in AuraLocker file)

            while (epochs[epochs.length - 1].date != currentEpoch) {
                uint256 nextEpochDate = uint256(epochs[epochs.length - 1].date).add(rewardsDuration);
                epochs.push(Epoch({ supply: 0, date: uint32(nextEpochDate) }));
            }

Even if these line are passed because the nature that checkpointEpoch is likely to be called daily and reward are added daily. if user doesn’t claim the reward for 100 years, rewardEpochs[_token].length = 36500 where epochIndex = 0. Which cause an impossible loop that run 36500 times. In this case this transaction will always be failed due to gas limit. In the worst case, If this problem cause staking fund to be frozen, the only way is to trash the reward and use emergencyWithdraw to withdraw staked fund.

From above statement, we can proof that there exists a case that user reward may be locked forever due to looping too many times causing gas to be used beyond the limit thus transaction always failed.

Tools Used

Reverse engineering using the help of IDE.

Recommended Mitigation Steps

User should be able to supply endEpochIndex to the claim reward functions. And only calculate reward from startIndex to min(auraLocker.epochCount() - 1, endEpochIndex). And also add support for partial reward claiming.

0xMaharishi (Aura Finance) acknowledged, but disagreed with severity and commented:

Valid report although given these are reward tokens and the max amount of entries is one per week, it would take some years for this to run over gas limit, during which time the contract could easily be changed.

LSDan (judge) decreased severity to Medium and commented:

I’m downgrading this to medium severity. It is unreasonable to expect contracts to be future proof to the tune of a hundred years or more, but if the frequency had been unreasonably fast this issue could have kicked in.

0xMaharishi (Aura Finance) resolved and commented:

code-423n4/2022-05-aura#6 code4rena aurafinance/aura-contracts#84


The original report as published on Code4rena, by Chom. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

Likely the claim function iterates over all unclaimed epochs in a single transaction without a way to cap the range, so the gas cost grows without bound as the number of epochs increases.

Impact

Rewards could be locked forever because the claim transaction always runs out of gas; the team noted the weekly reward cadence means this would take years, during which the contract could be changed.

What the attacker needed

User does not claim rewards for a very long time; many reward epochs accumulate

The fix

The claim functions should accept an end epoch index and only calculate rewards from the start index up to the minimum of the current epoch count and that end index, and should support partial reward claiming.

How it was found

  1. A user earns rewards but does not claim them for a very long time, so many epochs accumulate.
  2. The user later calls the reward-claiming function.
  3. The function loops from the user's last claimed epoch index up to the total number of reward epochs.
  4. The loop runs so many times that the transaction exceeds the chain's gas limit and always fails.

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.

A smart contract keeps a list of reward periods (epochs). When you claim, it walks through every period since your last claim. If that list is very long, the walk costs more computing power (gas) than a transaction is allowed to use, so the claim can never succeed. The report argues this could trap rewards, but the team says rewards are added only about once a week, so it would take many years.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by Chom

View all

13 more disclosed reports, best first.

More from Aura Finance contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.