The Yield Sandwich: Why Trusting Spot Prices in DeFi Vaults is a Costly Mistake
The vault's reinvest function used the pool's instantaneous spot price to calculate token ratios, so an attacker could skew the price with a flash swap before the keeper's transaction and profit from the bad ratio. The protocol argued that Sui's lack of a public mempool and the keeper's retry mechanism made the attack impractical, reducing it to a transient revert.
In Decentralized Finance (DeFi), Yield Aggregators (Vaults) are the ultimate honeypots. They pool user funds, harvest farming rewards, and auto-compound them back into liquidity pools to maximize APY.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The contract used the pool's instantaneous spot price for a critical state-changing calculation instead of a time-weighted average or external oracle.
Impact
The vault could suffer a large loss from depositing at a bad ratio, but the protocol argued that Sui's lack of a public mempool and the keeper's retry mechanism made the attack impractical, reducing it to a transient revert.
What the attacker needed
Ability to submit flash swaps on Sui; keeper transaction in flight; no public mempool (per protocol)
The fix
The contract should use a time-weighted average price or an external oracle instead of the instantaneous spot price for ratio calculations.
How it was found
- Monitor the network for the keeper's incoming reinvest transaction.
- Before it executes, push a large flash swap to skew the pool's spot price.
- Let the keeper's transaction land, so the vault deposits harvested yield at the skewed ratio.
- Reverse the flash swap to restore the price and extract the vault's loss as 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 write-up has not been written yet. The Original tab links to the source.
A vault is a smart contract that pools users' funds and automatically reinvests rewards. It used the pool's current price, which anyone can temporarily push around with a large flash loan, to decide how much of each token to deposit. An attacker could move the price just before the vault reinvested, making the vault trade at a bad rate, then undo the move and keep the difference.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.