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.
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
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
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.