Skip to content
Smart contracts Audit finding Intermediate

Harvest can be frontrun

The harvest function in a smart contract swaps tokens and adds liquidity without checking slippage, allowing an attacker to frontrun and cause the contract to receive fewer tokens than expected, reducing profits.

0xsanson Follow

Originally disclosed on Code4rena

Submitted by 0xsanson

Impact

In the NativeStrategyCurve3Crv._harvest there are two instances that a bad actor could use to frontrun the harvest.

First, when we are swapping WETH to a stablecoin by calling _swapTokens(weth, _stableCoin, _remainingWeth, 1) the function isn’t checking the slippage, leading to the risk to a frontun (by imbalancing the Uniswap pair) and losing part of the harvesting profits.

Second, during the _addLiquidity internal function: this calls stableSwap3Pool.add_liquidity(amounts, 1) not considering the slippage when minting the 3CRV tokens.

Proof of Concept

NativeStrategyCurve3Crv.sol L108

Tools Used

editor

Recommended Mitigation Steps

In the function _harvest(_estimatedWETH, _estimatedYAXIS) consider adding two additional estimated quantities: one for the swapped-out stablecoin and one for the minted 3CRV.

BobbyYaxis (yAxis) acknowledged

uN2RVw5q commented:

On second thought, I think this is a valid issue.

consider adding two additional estimated quantities: one for the swapped-out stablecoin and one for the minted 3CRV.

This suggestion should be considered.

GalloDaSballo (judge) commented:

Warden identified two paths for front-running

Since these are ways to extract value, severity is Medium

BobbyYaxis (yAxis) noted:

Mitigated in PR 114: https://github.com/yaxis-project/metavault/pull/114

The original report as published on Code4rena, by 0xsanson. 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 contract calls swap and add_liquidity functions with a minimum output amount of 1, effectively disabling slippage protection.

Impact

An attacker could frontrun the harvest to cause the contract to lose part of its harvesting profits.

What the attacker needed

Attacker can frontrun transactions

The fix

The harvest function should include estimated minimum amounts for the swapped stablecoin and minted 3CRV to enforce slippage protection; the project mitigated this in a pull request.

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 a smart contract trades tokens, it can set a minimum amount it will accept to protect against price changes. Here, the contract did not set such a minimum, so someone could manipulate the price just before the trade and make the contract get a worse deal, stealing some of the profit.

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 0xsanson

View all

8 more disclosed reports, best first.

More from yAxis contest

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.