Skip to content
DoS Audit finding Advanced

Incorrect handling of Stash Tokens within the `ConvexRewardsAdapter._claimRewards()`

The reward-claiming function identifies stash tokens by checking whether their total supply is zero, but stash tokens can have a non-zero total supply. When such a token is encountered, the code calls balanceOf on a contract that does not implement it, which can make the claim revert and block the vault from claiming Aura rewards.

duc Follow with nobody2018

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-06-tokemak-judging/issues/632

Found by

duc, nobody2018 The ConvexRewardsAdapter._claimRewards() function incorrectly handles Stash tokens, leading to potential vulnerabilities.

Vulnerability Detail

The primary task of the ConvexRewardAdapter._claimRewards() function revolves around claiming rewards for Convex/Aura staked LP tokens.

function _claimRewards(
    address gauge,
    address defaultToken,
    address sendTo
) internal returns (uint256[] memory amounts, address[] memory tokens) {
    ... 

    // Record balances before claiming
    for (uint256 i = 0; i < totalLength; ++i) {
        // The totalSupply check is used to identify stash tokens, which can
        // substitute as rewardToken but lack a "balanceOf()"
        if (IERC20(rewardTokens[i]).totalSupply() > 0) {
            balancesBefore[i] = IERC20(rewardTokens[i]).balanceOf(account);
        }
    }

    // Claim rewards
    bool result = rewardPool.getReward(account, /*_claimExtras*/ true);
    if (!result) {
        revert RewardAdapter.ClaimRewardsFailed();
    }

    // Record balances after claiming and calculate amounts claimed
    for (uint256 i = 0; i < totalLength; ++i) {
        uint256 balance = 0;
        // Same check for "stash tokens"
        if (IERC20(rewardTokens[i]).totalSupply() > 0) {
            balance = IERC20(rewardTokens[i]).balanceOf(account);
        }

        amountsClaimed[i] = balance - balancesBefore[i];

        if (sendTo != address(this) && amountsClaimed[i] > 0) {
            IERC20(rewardTokens[i]).safeTransfer(sendTo, amountsClaimed[i]);
        }
    }

    RewardAdapter.emitRewardsClaimed(rewardTokens, amountsClaimed);

    return (amountsClaimed, rewardTokens);
}

An intriguing aspect of this function's logic lies in its management of "stash tokens" from AURA staking. The check to identify whether rewardToken[i] is a stash token involves attempting to invoke IERC20(rewardTokens[i]).totalSupply(). If the returned total supply value is 0, the implementation assumes the token is a stash token and bypasses it. However, this check is flawed since the total supply of stash tokens can indeed be non-zero. For instance, at this address, the stash token has totalSupply = 150467818494283559126567, which is definitely not zero.

This misstep in checking can potentially lead to a Denial-of-Service (DOS) situation when calling the claimRewards() function. This stems from the erroneous attempt to call the balanceOf function on stash tokens, which lack the balanceOf() method. Consequently, such incorrect calls might incapacitate the destination vault from claiming rewards from AURA, resulting in protocol losses.

Impact

  • The AuraRewardsAdapter.claimRewards() function could suffer from a Denial-of-Service (DOS) scenario.
  • The destination vault's ability to claim rewards from AURA staking might be hampered, leading to protocol losses.

Code Snippet

https://github.com/sherlock-audit/2023-06-tokemak/blob/main/v2-core-audit-2023-07-14/src/destinations/adapters/rewards/ConvexRewardsAdapter.sol#L80-L86

Tool used

Manual Review

Recommendation

To accurately determine whether a token is a stash token, it is advised to perform a low-level balanceOf() call to the token and subsequently validate the call's success.

Discussion

sherlock-admin2

Escalate

#649 is a duplicate of this issue.

You've deleted an escalation for this issue.

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

Likely the code uses a token's total supply being zero as a proxy for 'this is a stash token without balanceOf', which is an unreliable assumption because stash tokens can report a non-zero supply.

Impact

The claim function could revert, causing a denial of service and preventing the destination vault from claiming rewards from Aura, which may lead to protocol losses.

What the attacker needed

Rewards include a stash token with non-zero supply

The fix

The check should instead make a low-level balanceOf call and treat a failed call as the signal that the token is a stash 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 here tries to tell two kinds of tokens apart by asking each one for its total supply and assuming a zero answer means it is a special 'stash' token. Some of those special tokens actually report a non-zero total supply, so the contract then asks them for a balance in a way they do not support. That call fails, the whole reward claim stops, and the vault cannot collect its 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 duc

View all

5 more disclosed reports, best first.

More from Tokemak

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.