# Perpetual DEX audit: funding, margin and oracle latency

URL: https://shield.quillaudits.com/use-cases/perpetuals-dex/

A perpetual DEX audit checks how positions are priced and settled: funding and fee accrual, margin and liquidation thresholds, the delay between an oracle update and the order that uses it, and the accounting that tells liquidity providers what the pool is worth. QuillShield audits these contracts together, then checks each pull request against that audit.

Last updated 24 November 2026. 5 minute read. By the QuillShield team.

## What goes wrong in perpetual DEXs?

A perpetual DEX keeps several running totals at once, and each one has to stay right through every order type, keeper action and liquidation. These are the parts reviewers look at first.

- **Oracle latency.** Keepers often execute orders some time after the trader submits them. If a trader can see the next price before committing, or choose which price an order executes at, they can trade against the pool without risk. See [oracle price manipulation](https://shield.quillaudits.com/learn/vulnerabilities/oracle-price-manipulation/).
- **Funding and fees.** Cumulative funding and borrowing fees have to be updated before every position change, with the right sign and with rounding that favors the protocol. A rounding error of one unit per update grows with the number of updates, as the page on [rounding and precision errors](https://shield.quillaudits.com/learn/vulnerabilities/rounding-precision-errors/) shows.
- **Margin and liquidation.** Every path that changes size or collateral has to check margin afterwards, including partial closes and collateral withdrawals, and the protocol has to say what happens when a liquidation can't cover a position's losses.
- **Pool accounting.** When liquidity providers take the other side of trades, the pool's value includes traders' unrealized profit and loss. Any path that opens or closes positions without updating the totals behind that number moves the LP token price.
- **Keeper and payout paths.** Keeper-only functions need access control, and payouts or refunds to a receiver the trader chose can call back into the protocol. See [reentrancy](https://shield.quillaudits.com/learn/vulnerabilities/reentrancy/) and [access control](https://shield.quillaudits.com/learn/vulnerabilities/access-control/).

## What has gone wrong before?

On 9 July 2025 an attacker took nearly $42M from GMX V1 on Arbitrum. BlockSec's analysis traces it to a payout. When a keeper executed the attacker's decrease order, the OrderBook sent ETH to a receiver the attacker controlled, and that contract's fallback function called the Vault directly to open a WBTC short.

Opening the short that way skipped the routers that update the global short average price. GLP's price counts the unrealized profit and loss of shorts, so a skewed average inflated it. The attacker repeated the move, then minted GLP with flash-loaned USDC and redeemed it at the inflated price across the Vault's assets.

The OrderBook function had a `nonReentrant` modifier, but it only stopped calls back into the OrderBook, not into the Vault. Two days later the attacker accepted a 10% bounty and returned the rest, according to BlockSec.

## How do a full audit and pull request checks fit a perps team?

Put the whole trading path in scope: the order book, the position routers, the vault, the pricing and funding logic, the liquidity token and the contracts keepers call. GMX V1's bug shows up only when the OrderBook and the Vault are read together. A QuillShield full audit covers the codebase in scope as a whole and builds a security graph of it. Add your keeper design, oracle sources and privileged roles as context before the audit starts.

After launch, new markets, fee changes and new order types arrive as pull requests. With pull request checks on, each change is compared with that graph, and on GitHub a required check stops a pull request with a High or Critical finding from merging. A new order type that adds Solidity files gets a recommendation for a new full audit.

QuillShield covers Solidity in Foundry projects today. Off-chain keepers and price services are outside its scope and need their own review. For a launch, you can also request a manual audit from QuillAudits.

## What does a perps audit cost?

The price is set by the lines of Solidity in scope, without comments or blank lines. As of November 2026 the [pricing page](https://shield.quillaudits.com/pricing/) lists 10,000 lines at $1,899 and 40,000 lines at $5,429, with a quote by hand above that. Five pull request checks come with each full audit of a GitHub or GitLab.com repository. Start from the guide to [running your first audit](https://shield.quillaudits.com/guides/run-your-first-audit/), or [sign up free](https://shield.quillaudits.com/register) and see the quote before you pay.

## What should you check in a perpetual DEX?

- For each order type, which price does execution use, how old can it be, and can the trader know it before committing?
- Are funding and borrowing fees accrued before every position change, with the right sign and rounding in the protocol's favor?
- Does every path that changes size or collateral check margin afterwards, including partial closes?
- What happens to losses a liquidation can't cover, and who absorbs them?
- Which totals feed the LP token price, and can any path open or close positions without updating them?
- Can a payout or refund to a receiver the trader chose call back into any contract of the protocol?
- Which functions can only keepers call, and what goes wrong if a keeper acts late or out of order?

## Common questions

### Why does oracle latency matter for a perpetual DEX?

A trader who knows the price an order will execute at before the order is final can trade against the pool at no risk. Execution prices have to be ones the trader could not see or choose when they committed.

### Does a reentrancy guard protect a perpetual DEX?

Only the contract it sits on. GMX V1's OrderBook had a guard, and the attacker's callback went into the Vault instead. Guard every contract that shares the state, or update that state before any external call.

### How much does a perpetual DEX audit cost with QuillShield?

It follows the lines of Solidity in scope. The pricing page lists 10,000 lines at $1,899 and 40,000 lines at $5,429 as of November 2026, and larger codebases get a quote by hand.

### Can QuillShield audit keepers or off-chain order matching?

No. QuillShield supports Solidity in Foundry projects today. Keepers, matching engines and price services written in other languages need a separate review.

## Sources

- [GMX incident: cross-contract reentrancy bypasses a four-year-old guard, BlockSec](https://blocksec.com/blog/gmx-incident-cross-contract-reentrancy-bypasses-a-four-year-old-guard)
- [Hacker drains $42 million from decentralized perpetual exchange GMX, The Block](https://www.theblock.co/post/361806/hacker-drains-42-million-from-decentralized-perpetual-exchange-gmx)
