Skip to content
DoS Audit finding Intermediate

VE3DRewardPool and VE3DLocker adds to an unbounded array which may potentially lock all rewards in the contract

The reward pool and locker contracts allow the owner to add reward tokens to an unbounded list. If enough tokens are added, iterating over the list in the updateReward modifier could exceed the block gas limit, causing all functions that use it to revert and locking rewards.

kirk-baird Follow

Originally disclosed on Code4rena

Submitted by kirk-baird, also found by csanuragjain, Dravee, gzeon, IllIllI, Koustre, Ruhum, unforgiven, VAD37, and xiaoming90

https://github.com/code-423n4/2022-05-vetoken/blob/2d7cd1f6780a9bcc8387dea8fecfbd758462c152/contracts/VE3DRewardPool.sol#L102-L112

https://github.com/code-423n4/2022-05-vetoken/blob/2d7cd1f6780a9bcc8387dea8fecfbd758462c152/contracts/VE3DLocker.sol#L145-L172

Impact

The function addReward() allows the owner to add a new reward token to the list rewardTokens.

However, this is an unbounded list that when appended to cannot be shortened. The impact is it is possible to reach a state where the list is so long it cannot be iterated through due to the gas cost being larger than the block gas limit. This would cause a state where all transactions which iterate over this list will revert.

Since the modifier updateReward() iterates over this list it is possible that there will reach a state where the we are unable to call any functions with this modifier. The list includes

  • stake()
  • stakeAll()
  • stakeFor()
  • withdraw()
  • withdrawAll()
  • getReward()
  • notifyRewardAmount()

As a result it would therefore be impossible to withdraw any rewards from this contract.

The same issue exists in VE3DLocker. Where rewards can be added by either Booster or the owner.

Proof of Concept

    function addReward(
        address _rewardToken,
        address _veAssetDeposits,
        address _ve3TokenRewards,
        address _ve3Token
    ) external onlyOwner {
        rewardTokenInfo[_rewardToken].veAssetDeposits = _veAssetDeposits;
        rewardTokenInfo[_rewardToken].ve3TokenRewards = _ve3TokenRewards;
        rewardTokenInfo[_rewardToken].ve3Token = _ve3Token;
        rewardTokens.add(_rewardToken);
    }
    function addReward(
        address _rewardsToken,
        address _veAssetDeposits,
        address _ve3Token,
        address _ve3TokenStaking,
        address _distributor,
        bool _isVeAsset
    ) external {
        require(_msgSender() == owner() || operators.contains(_msgSender()), "!Auth");
        require(rewardData[_rewardsToken].lastUpdateTime == 0);
        require(_rewardsToken != address(stakingToken));
        rewardTokens.push(_rewardsToken);

        rewardData[_rewardsToken].lastUpdateTime = uint40(block.timestamp);
        rewardData[_rewardsToken].periodFinish = uint40(block.timestamp);
        rewardDistributors[_rewardsToken][_distributor] = true;

        rewardData[_rewardsToken].isVeAsset = _isVeAsset;
        // if reward is veAsset
        if (_isVeAsset) {
            require(_ve3Token != address(0));
            require(_ve3TokenStaking != address(0));
            require(_veAssetDeposits != address(0));
            rewardData[_rewardsToken].ve3Token = _ve3Token;
            rewardData[_rewardsToken].ve3TokenStaking = _ve3TokenStaking;
            rewardData[_rewardsToken].veAssetDeposits = _veAssetDeposits;
        }
    }

Recommended Mitigation Steps

Consider having some method for removing old reward tokens which are no longer in use.

Alternatively set a hard limit on the number of reward tokens that can be added.

A different option is to allow rewards to be iterated and distributed on a per token bases rather than all tokens at once.

jetbrain10 (veToken Finance) disagreed with severity and commented:

we’re going to add a bound, same as #222, #125.

Alex the Entreprenerd (judge) commented:

My guesstimate of the math is that each reward would add 100k gas to the updateReward modifier, meaning we’d need 120 reward tokens before any consideration about running out of gas would happen.

You also don’t seem to be able to add a second one (provided someone has used the contract at least once after an addition).

I’ll think about it but am thinking Medium is stretching it.

Alex the Entreprenerd (judge) commented:

Likelyhood is very low, however per the rules if enough rewards are added then claiming and withdrawing can be bricked permanently.

I’d recommend end users to ensure the unlikely number of 120 rewards is never reached.

Marking the finding as Valid and of Medium Severity.


The original report as published on Code4rena, by kirk-baird. 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

The reward token list is unbounded and cannot be shortened, so iterating over it in the updateReward modifier can exceed the block gas limit.

Impact

If enough reward tokens are added, functions like stake, withdraw, and getReward could become unusable, locking all rewards in the contract.

What the attacker needed

Owner adds many reward tokens

The fix

The team said they would add a bound to the number of reward tokens, and the report also suggests allowing removal of old tokens or distributing rewards per token.

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 can have a list of reward tokens. Each time someone stakes or withdraws, the contract loops over this list. If the list gets too long, the loop costs more gas than a block can hold, so every transaction fails. This means users cannot withdraw their rewards.

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 kirk-baird

View all

32 more disclosed reports, best first.

More from veToken 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.