Skip to content
Smart contracts Audit finding Intermediate

AaveStrategy.sol : Changing swapper breaks the contract

The AaveStrategy contract grants the swapper contract an unlimited token allowance only in its constructor, and the setMultiSwapper function replaces the swapper without updating that approval. After the owner changes the swapper, the new swapper cannot pull reward tokens, so compounding fails and withdrawals that call compound are blocked.

carrotsmuggler Follow with 0xfuje, Vagner and 3 others

Originally disclosed on Code4rena

Submitted by carrotsmuggler, also found by 0xfuje, Vagner, kaden, rvierdiiev, and ladboy233

The contract AaveStrategy.sol manages wETH tokens and deposits them to the aave lending pool, and collects rewards. These rewards are then swapped into WETH again to compound on the WETH being managed by the contract. this is done in the compound function.

uint256 calcAmount = swapper.getOutputAmount(swapData, "");
uint256 minAmount = calcAmount - (calcAmount * 50) / 10_000; //0.5%
swapper.swap(swapData, minAmount, address(this), "");

To carry out these operations, the swapper contract needs to be given approval to use the tokens being stored in the strategy contract. This is required since the swapper contract calls transferFrom on the tokens to pull it out of the strategy contract. This allowance is set in the constructor.

rewardToken.approve(_multiSwapper, type(uint256).max);

The issue arises when the swapper contract is changed. The change is done via the setMultiSwapper function. This function however does not give approval to the new swapper contract. Thus if the swapper is upgraded/changed, the approval is not transferred to the new swapper contract, which makes the swappers dysfunctional.

Since the swapper is critical to the system, and compound is called before withdrawals, a broken swapper will break the withdraw functionality of the contract. Thus this is classified as a high severity issue.

Proof of Concept

The bug is due to the absence of approve calls in the setMultiSwapper function. This can be seen from the implementation of the function.

function setMultiSwapper(address _swapper) external onlyOwner {
        emit MultiSwapper(address(swapper), _swapper);
        swapper = ISwapper(_swapper);
    }

Recommended Mitigation Steps

In the setMultiSwapper function, remove approval from the old swapper and add approval to the new swapper. The same function has the proper implementation in the ConvexTricryptoStrategy.sol contract which can be used here as well.

function setMultiSwapper(address _swapper) external onlyOwner {
    emit MultiSwapper(address(swapper), _swapper);
    rewardToken.approve(address(swapper), 0);
    swapper = ISwapper(_swapper);
    rewardToken.approve(_swapper, type(uint256).max);
}

0xRektora (Tapioca) confirmed via duplicate issue 222


The original report as published on Code4rena, by carrotsmuggler. 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 setMultiSwapper function replaces the swapper address without revoking the old allowance or granting a new one, so the approval set in the constructor no longer matches the active swapper.

Impact

After the swapper is changed, compounding and withdrawals that depend on it will fail, locking user funds in the strategy until the approval is corrected.

What the attacker needed

Owner changes the swapper via setMultiSwapper

The fix

The setMultiSwapper function should revoke the old swapper's allowance and grant an unlimited allowance to the new swapper, as done in ConvexTricryptoStrategy.

How it was found

  1. The strategy contract is deployed and its constructor approves the initial swapper for the reward token.
  2. The owner calls setMultiSwapper to point the strategy at a different swapper contract.
  3. The new swapper has no allowance, so its transferFrom call fails when compound tries to swap rewards.
  4. Because compound runs before withdrawals, the withdraw path also 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 can let another contract spend its tokens by recording an allowance, similar to a standing permission. Here the permission was recorded once when the contract was created, but a later function that swaps in a new helper contract never records a permission for it. As a result the new helper cannot move the tokens, and any action that depends on it stops working.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by carrotsmuggler

View all

42 more disclosed reports, best first.

More from Tapioca Invitational

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.