Case Studies/On-Chain Perpetuals & Derivatives
EVM

On-Chain Perpetuals & Derivatives

On-chain perpetuals compress the most dangerous DeFi attack surfaces into a single protocol — oracle manipulation, reentrancy, and accounting failures all in one system

Perpetuals protocols combine price oracles, liquidation engines, collateral accounting, and fee mechanisms in a tightly coupled architecture where errors in any single component can be used to drain the entire system. The liquidation path is particularly dangerous: it involves external calls, collateral transfers, and position state updates that must occur in a precise order and with no re-entrancy exposure. This analysis examines the historical exploits that have targeted on-chain derivatives protocols and the threat model that any perpetuals team must understand before deployment.

Overview

An on-chain perpetuals protocol allows users to hold leveraged long or short positions without an expiry date. The protocol's solvency depends on its ability to accurately track position values, calculate liquidation thresholds, and execute liquidations before a position's collateral is exhausted. Every one of these functions depends on oracle prices. If the oracle price can be manipulated, the protocol's accounting can be made to misrepresent the value of positions and collateral — allowing an attacker to borrow against inflated collateral values, avoid liquidation on underwater positions, or trigger profitable liquidations on positions that should not be liquidatable. The liquidation mechanism itself is a second major attack surface: any external call made during a liquidation before the position state is marked as closed creates a reentrancy opportunity, and any accounting asymmetry in the liquidation reward calculation can be exploited to extract value from the protocol's reserves.

Documented incidents

Historical exploits targeting this class of protocol, drawn from public post-mortems and on-chain data.

Mango Markets

2022$117M

The attacker used two accounts to execute a price manipulation attack against Mango's native token MNGO. Account A held a large short MNGO-PERP position. Account B then purchased MNGO aggressively on spot markets — Mango used an oracle that blended spot and TWAP prices from thin markets — inflating the MNGO price by approximately 10x. Account A's short position was deeply underwater, but Account B's MNGO collateral was now valued at 10x its real market price. The attacker used Account B's inflated collateral to borrow and drain nearly all of Mango's liquidity pools across multiple assets before the price normalised.

Euler Finance

2023$197M

Euler's liquidation mechanism contained a flaw in its collateral accounting that could be exploited via a donation attack. By donating assets directly to an Euler pool — a function intended for legitimate use — an attacker could create a position where the liquidation bonus paid to the liquidator exceeded the value of the donated assets. The attacker could then liquidate their own position, collecting a liquidation bonus larger than their cost. By repeating this across multiple transactions with flash-loaned capital, they extracted approximately $197M from the protocol.

Synthetix sKRW

2019$1B at risk (recovered)

A Synthetix price oracle providing the Korean Won exchange rate was misconfigured and reported the sKRW price at approximately 1000x the correct value. An automated arbitrage bot detected the discrepancy within minutes and began trading sETH for sKRW at the inflated rate, accumulating a position worth approximately $1B in real terms before Synthetix engineers paused trading. The trader agreed to return the funds in exchange for a bug bounty — the protocol avoided the loss through negotiation rather than technical prevention.

dYdX v3 Targeted Liquidations

2023$9M protocol insurance fund

An attacker built up large leveraged positions in thin markets on dYdX — specifically in SUSHI and YFI perpetuals — using borrowed capital. They then sold the underlying assets aggressively on spot markets to trigger liquidations of their own positions at prices where the insurance fund would absorb the losses. The attack exploited the combination of low liquidity in the targeted markets and dYdX's insurance fund backstop.

Threat vectors

The primary attack surfaces present in this class of protocol and their relative severity.

Critical

Oracle price manipulation

Any oracle that derives price from a single source, a thin market, or a mechanism susceptible to flash loan manipulation can be used to misrepresent the value of collateral or positions. A manipulated price allows an attacker to borrow against inflated collateral, avoid legitimate liquidation, or trigger profitable liquidations — any of which can drain the protocol's reserves. The Mango Markets attack demonstrated that even a brief price manipulation lasting only minutes is sufficient to borrow against inflated values before the price normalises.

Critical

Reentrancy in the liquidation path

The liquidation function of a perpetuals protocol is one of the highest-risk code paths in DeFi: it transfers collateral to an external address (the liquidator), closes the position, and updates the global accounting state. Any external call made before the position state is marked as closed creates a reentrancy window. A malicious liquidator contract can re-enter the liquidation function during the collateral transfer, repeatedly claiming liquidation rewards against the same position until the settlement pool is drained.

High

Donation and accounting asymmetry attacks

Protocols that allow direct asset donations to pool contracts — or that have asymmetries between the accounting of deposit and withdrawal operations — can be exploited to create positions where the liquidation incentives produce a net extraction from protocol reserves. The Euler attack demonstrated that what appears to be a normal protocol function can become a critical vulnerability when combined with the liquidation mechanism's incentive structure.

High

Insurance fund depletion via targeted thin-market liquidations

Protocols that backstop losses from bad debt with an insurance fund are vulnerable to attacks that deliberately trigger bad debt. By building large leveraged positions in illiquid markets and then crashing those markets, an attacker can force liquidations that the insurance fund must absorb — depleting the fund and potentially destabilising the protocol's ability to cover future bad debt.

Medium

Front-running oracle updates

Protocols that use delayed or predictable oracle updates create a window in which an informed trader can submit transactions knowing the next price update before it is reflected on-chain. By trading in the direction of the incoming update, the trader extracts value from the protocol's other users. This is a lower-severity but persistent extraction mechanism that compounds over time.

Analysis

The Mango Markets attack is the most instructive example of oracle manipulation in perpetuals because it was not a bug in the conventional sense — it was a logical consequence of the oracle design operating exactly as specified. The oracle blended prices from thin markets and was therefore susceptible to manipulation. The attacker did not need to find a contract vulnerability; they needed only to understand how the oracle worked and have sufficient capital to move the market. This is an important distinction: the vulnerability was not in the code but in the economic assumptions the code was built on. The Euler attack represents a different class of failure — one where a legitimate protocol function (asset donation) interacted with the liquidation mechanism in a way that was never intended and was not detectable without cross-function analysis. The attack required understanding both the donation mechanics and the liquidation incentive structure in combination, not either in isolation. This is why perpetuals protocols cannot be audited by reviewing individual functions: the attack surface is in the interactions between components. The dYdX insurance fund attack points to a fundamental tension in perpetuals design: protocols need an insurance fund to remain solvent through normal market volatility, but that insurance fund itself creates an attack vector. Any protocol whose insurance fund can be depleted faster than it is replenished has a survival risk that is independent of any code vulnerability. The common thread is that perpetuals protocols are economically adversarial environments — every incentive, every parameter, and every external data dependency is a potential attack surface for a sufficiently motivated and capitalised attacker.

Deep Guard's approach

How Deep Guard reviews and secures protocols of this type.

01

Oracle design and manipulation resistance analysis

Deep Guard reviews the full oracle stack: data sources, aggregation mechanism, TWAP parameters, circuit breakers, and deviation bounds. The economic cost of manipulating the oracle to a degree that enables profitable extraction is modelled against the protocol's TVL.

02

Liquidation path reentrancy analysis

Every state transition and external call in the liquidation flow is traced to identify paths where a reentrancy condition can arise. Deep Guard verifies that the checks-effects-interactions pattern is applied and that reentrancy guards cover all relevant liquidation entry points.

03

Cross-function accounting analysis

The interaction between all functions that affect pool accounting — including deposits, withdrawals, donations, fee collection, and liquidations — is analysed for asymmetries that could be exploited to extract value through their combination rather than individually.

04

Market depth and insurance fund stress testing

For each supported market, Deep Guard models the cost of an intentional liquidation attack: the capital required to build a sufficiently large position and then crash the market to trigger bad debt that depletes the insurance fund.

05

On-chain monitoring and oracle anomaly detection

Deep Guard designs monitoring rules that flag anomalous oracle deviations, unusual position sizing relative to market depth, and rapid position changes consistent with manipulation. For perpetuals protocols, the window between an attack beginning and funds being extractable is often measured in minutes.

Building a on-chain perpetuals & derivatives?

Talk to a Deep Guard engineer about your specific architecture and get a scoped threat model or audit quote within 24 hours.

Talk to us
Back to case studies