Price Manipulation
Attacks that artificially move asset prices to exploit protocols relying on those prices for critical operations.
Price manipulation attacks artificially move asset prices to exploit DeFi protocols that rely on those prices for critical operations like liquidations, collateral valuation, or trade execution. These attacks have caused hundreds of millions in losses across lending protocols, derivatives platforms, and other DeFi applications. Understanding price manipulation vectors is essential for building secure protocols and conducting thorough security audits.
How Price Manipulation Works
Most DeFi protocols need external price data for operations:
- Lending: Collateral valuation, liquidation triggers
- Derivatives: Settlement prices, margin calculations
- AMMs: Arbitrage reference, concentrated liquidity ranges
If an attacker can manipulate the price source, they can:
- Borrow against inflated collateral
- Trigger unfair liquidations
- Extract value through arbitrage
Common Attack Vectors
Flash Loan + DEX Manipulation
The most common pattern:
11. Borrow large amount via flash loan (no collateral needed)22. Swap on DEX to move the price dramatically33. Exploit protocol using the manipulated price44. Reverse the swap55. Repay flash loan with profit
All within a single atomic transaction.
Oracle Manipulation
Targeting the price feed directly:
1// Vulnerable: Using spot price from DEX2function getCollateralValue(uint256 amount) public view returns (uint256) {3 uint256 price = uniswapPool.getSpotPrice(); // Manipulable!4 return amount * price;5}
Sandwich Attacks
Front-running and back-running victim transactions:
11. Detect victim's large swap in mempool22. Front-run: Buy before victim (raises price)33. Victim's swap executes at worse price44. Back-run: Sell at the elevated price55. Profit from the price difference
Real-World Examples
Cream Finance ($130M, 2021)
Attacker manipulated the price of yUSD:
- Flash borrowed massive amounts
- Manipulated yUSD price via Yearn vault
- Used inflated yUSD as collateral
- Borrowed real assets against fake collateral value
Harvest Finance ($34M, 2020)
USDC/USDT price manipulation:
- Flash loan to acquire large USDC position
- Swapped to move Curve pool price
- Deposited at manipulated price
- Withdrew at normal price
- Repeated multiple times
Mango Markets ($114M, 2022)
Perpetual futures price manipulation:
- Attacker took large perpetual position
- Spot market manipulation inflated mark price
- Used unrealized PnL as collateral
- Borrowed protocol's entire treasury
Defense Mechanisms
Time-Weighted Average Prices (TWAP)
Average prices over time to resist short-term manipulation:
1// Requires manipulating price for entire period2uint256 price = twapOracle.consult(token, 30 minutes);
Multiple Oracle Sources
Cross-reference different price sources:
1function getSecurePrice() external view returns (uint256) {2 uint256 chainlinkPrice = chainlinkOracle.latestAnswer();3 uint256 twapPrice = uniswapTwap.consult(30 minutes);45 // Require agreement within 5%6 require(deviation(chainlinkPrice, twapPrice) < 500, "Price mismatch");78 return (chainlinkPrice + twapPrice) / 2;9}
Liquidity Requirements
Ensure price sources have sufficient depth:
1function validatePool(address pool) internal view {2 require(IPool(pool).liquidity() > MIN_LIQUIDITY, "Low liquidity");3}
Circuit Breakers
Pause operations on suspicious price movements:
1uint256 public lastPrice;2uint256 public constant MAX_CHANGE = 1000; // 10%34function updatePrice(uint256 newPrice) internal {5 if (lastPrice > 0) {6 uint256 change = diff(newPrice, lastPrice) * 10000 / lastPrice;7 require(change < MAX_CHANGE, "Circuit breaker");8 }9 lastPrice = newPrice;10}
Delayed Operations
Add time delays to critical actions:
1mapping(address => uint256) public withdrawalTime;23function requestWithdrawal() external {4 withdrawalTime[msg.sender] = block.timestamp + 1 hours;5}67function executeWithdrawal() external {8 require(block.timestamp >= withdrawalTime[msg.sender], "Too early");9 // Process withdrawal at current (non-manipulated) price10}
Audit Checklist
When auditing for price manipulation vulnerabilities:
- Identify all external price dependencies
- Check if spot prices are used (vulnerable)
- Verify TWAP periods are sufficient
- Assess oracle decentralization
- Look for flash loan + price manipulation paths
- Check for circuit breakers on price changes
- Evaluate liquidity of price source pools
- Test with extreme price scenarios
Economic Analysis
For manipulation to be profitable:
1Profit = Value extracted - Cost of manipulation - Gas fees23Cost of manipulation includes:4- Capital required (can be flash loaned)5- Slippage from moving price6- Time cost (for TWAP manipulation)
Good defenses make manipulation unprofitable by increasing costs or reducing extractable value.
Price manipulation remains one of the most common and damaging attack vectors in DeFi. Robust oracle design, multiple price sources, and conservative parameters are essential for protecting user funds.
Related Terms
Oracle
A service that provides external data (prices, events, random numbers) to smart contracts that cannot access off-chain information directly.
Flash Loan
Uncollateralized loan borrowed and repaid within a single transaction, often used for arbitrage or attacks.
TWAP (Time-Weighted Average Price)
A price calculation method that averages asset prices over a time period to resist short-term manipulation.
Sandwich Attack
An MEV attack where an attacker front-runs and back-runs a victim's trade to extract profit from the induced price movement.
Need expert guidance on Price Manipulation?
Our team at Zealynx has deep expertise in blockchain security and DeFi protocols. Whether you need an audit or consultation, we're here to help.
Get a Quote
