Skip to content
Smart contracts Audit finding Intermediate

Functions in the VotiumStrategy contract are susceptible to sandwich attacks

The buyCvx() and sellCvx() functions in the VotiumStrategy contract call Curve's exchange_underlying() with a minimum output of zero, so users who interact directly with the VotiumStrategy contract lack slippage protection. An attacker could sandwich those users' transactions to profit at the users' expense.

MiloTruck Follow with MiloTruck, d3e4 and 2 others

Originally disclosed on Code4rena

Submitted by MiloTruck, also found by MiloTruck, d3e4, adriro (1, 2), m_Rassska, and rvierdiiev

In VotiumStrategyCore.sol, the buyCvx() and sellCvx() functions call exchange_underlying() of Curve’s ETH / CVX pool to buy and sell CVX respectively:

VotiumStrategyCore.sol#L233-L240

        ICrvEthPool(CVX_ETH_CRV_POOL_ADDRESS).exchange_underlying{
            value: _ethAmountIn
        }(
            0,
            1,
            _ethAmountIn,
            0 // this is handled at the afEth level
        );

VotiumStrategyCore.sol#L258-L263

        ICrvEthPool(CVX_ETH_CRV_POOL_ADDRESS).exchange_underlying(
            1,
            0,
            _cvxAmountIn,
            0 // this is handled at the afEth level
        );

As seen from above, exchange_underlying() is called with its _min_dy parameter as 0, which means the minimum amount of CVX or ETH to receive from the swap is effectively 0.

This isn’t an issue when users interact with the AfEth contract, as its deposit() and withdraw() functions include a _minOut parameter which protects against slippage.

However, users that interact with the VotiumStrategy contract directly will not be protected from slippage when they call any of the following functions:

Should users call any of the functions listed above directly, they will be susceptible to sandwich attacks by attackers, which would reduce the amount of CVX or ETH received from the swap with curve’s pool.

Impact

Due to a lack of slippage protection in buyCvx() and sellCvx(), users that interact with the VotiumStrategy contract will be susceptible to sandwich attacks. This results in a loss of funds for them as they will receive less CVX or ETH for the same amount of funds.

Proof of Concept

Consider the following scenario:

  • Bob calls the VotiumStrategy contract’s deposit() function directly to deposit ETH.

  • Alice sees his transaction in the mempool and front-runs his transaction. She swaps a large amount of ETH into the Curve pool and gets CVX in return.

  • Now, Bob’s transaction is executed:

    • buyCvx() attempts to swap Bob’s ETH deposit for CVX.
    • However, since the pool currently has a lot more ETH than CVX, Bob only gets a small amount of CVX in return.
  • Alice back-runs Bob’s transaction and swaps the CVX she gained for ETH in the pool, which would result in a profit for her.

In this scenario, Alice has sandwiched Bob’s deposit() transaction for a profit, causing Bob to receive less CVX for his deposited ETH.

Recommended Mitigation

Consider adding a _minOut parameter to either buyCvx() and sellCvx(), or the following functions:

This allows the caller to specify a minimum amount they expect from the swap, which would protect them from slippage.

elmutt (Asymmetry) confirmed and commented:

@toshiSat - I think we should just lock this down so afEth can only use votium strategy.

0xleastwood (Judge) commented:

Marking this as primary issue and best report because it addresses all edge cases where slippage should be checked.

elmutt (Asymmetry) commented:

In order fully solve it and issues marked as duplicates x(#24, #61, #15) we also need to pass _minout to afEth.applyRewards() :

0xleastwood (Judge) commented:

@elmutt - Agree with you on this.

Asymmetry mitigated:

For this one we locked down the depositRewards function and added a minout to the reward functions.

Status: Mitigation confirmed. Full details in reports from d3e4 and adriro.


The original report as published on Code4rena, by MiloTruck. 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 contract calls Curve's exchange_underlying() with the _min_dy parameter set to 0, so there is no minimum output amount and therefore no slippage protection.

Impact

Users who call the VotiumStrategy functions directly could lose funds to sandwich attacks, though users going through the AfEth contract are protected by its _minOut parameter.

What the attacker needed

User calls VotiumStrategy directly; attacker can see pending transactions

The fix

The project mitigated the issue by locking down the depositRewards function and adding a minimum output parameter to the reward functions.

How it was found

  1. Bob calls the VotiumStrategy contract's deposit() function directly to deposit ETH.
  2. Alice sees his transaction in the mempool and front-runs it by swapping a large amount of ETH into the Curve pool for CVX.
  3. Bob's transaction executes and buyCvx() swaps his ETH for CVX at the now-unfavourable pool ratio.
  4. Alice back-runs Bob's transaction, swapping her CVX back to ETH for a profit.

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.

When you swap one token for another on a decentralised exchange, you can set a minimum amount you are willing to receive. If you set that minimum to zero, someone who sees your transaction waiting to be processed can buy the token first, making the price worse for you, then sell afterwards for a profit. This report says two functions in a smart contract set that minimum to zero, so people calling those functions directly could lose money this way.

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 MiloTruck

View all

35 more disclosed reports, best first.

More from Asymmetry Finance afETH 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.