How to Audit an EVM Order-Book DEX: Lessons from a Private Review
The useful bugs were between the price, the fill, and the moment tokens moved.
Research at a glance
This anonymized private EVM audit field guide shows how to connect signed price data, order-book matching, toxicity adjustments, token transfers, callback settlement, and post-trade accounting. It discusses verified review lessons around intermediate price rounding and public route identity, plus a conditional reset and pending-transaction interaction. The guide emphasizes proof-of-concept limits, chain-specific clocks, and how to distinguish an observable behavior from an exploitable loss.
- Research type
- Private EVM audit field guide
- Scope
- Solidity · EVM · DEX · Oracle security · Order books
- Key lesson
- Trace each trade from its price inputs through matching and settlement; test router reachability, rounding, reset lifecycle, callbacks, and chain-specific timing, then report only the impact the evidence proves.
Evidence and context: Solidity and EVM security review experience
A swap can look like one operation: get a quote, send tokens, receive tokens. In an on-chain order-book DEX, that trade may depend on several separate pieces: signed price data, order-book depth, route-specific pricing, liquidity already consumed by recent trades, and chain-specific freshness rules.
This anonymized field guide draws on a private EVM review. It focuses on the audit methods and reusable bug patterns—not the client, deployment details, or private report. The biggest lesson was simple: trace the entire trade, not just the function named swap.
Model the trade before reading the code
I started by writing down what sets the price and where the assets move. The system combined per-token signed price data with published order-book levels. A matching engine used those inputs to calculate exact-input and exact-output quotes, then a swap contract moved tokens between the trader and a vault. Route and gas signals could also adjust the quoted output.
That map gave me a practical invariant: the quote, the amount transferred, and the liquidity recorded as consumed must describe the same trade. I then traced those values through views, matching, token transfers, callbacks, and settlement updates.
Trace values across the whole swap
For each exact-input and exact-output path, I followed the requested amount through normalization, order matching, fees, rounding, minimum-output checks, token transfers, and the final state update. I checked both sides of the trade: what the vault receives and what it sends.
This review exposed that exact pattern on an extreme low-price ratio: the intermediate exchange rate lost fractional precision before the final cost was rounded up, so the trader paid slightly less than the published prices implied. It was not a general free-profit strategy, and the size depended on the ratio. A later code change addressed the calculation. The lesson is not “always round up.” Compare the whole calculation against the intended price using full-precision math, and choose the rounding direction for each asset flow.
I also compared exact-input and exact-output behavior at order boundaries and across token decimals. A rounding difference that is one unit in an intermediate value can become meaningful when the ratio is extreme, the trade is large, or that value controls a cap.
Treat market data as a state machine
Signed oracle updates are not just data blobs. They have a lifecycle: a publisher creates an update, a transaction waits for inclusion, the contract checks ordering and freshness, an operator may reset the data, and the market resumes.
That lifecycle led to a useful recovery question: does reset invalidate updates that were signed before reset but have not landed yet? Clearing stored timestamps does not, by itself, revoke a pending signed transaction. A per-oracle generation or epoch can make the answer explicit: reset increments it, and every publication must match the current generation.
The full anonymized example is in this companion note on pending signed updates after an oracle reset. Its local proof of concept used a simulated price gap, so it demonstrates a possible path—not a live-market loss.
Test who the protocol sees
Protocols often classify a trade by the immediate caller. That makes routers and aggregators part of the pricing model. A route can have a “trusted” label, but the security question is whether an ordinary user can call that route directly and inherit its treatment.
I tested public executor paths rather than assuming an address was private because it belonged to an integrator. One trusted route could be called directly by users, allowing them to receive the route’s more favorable pricing. I separated reachability from impact: a route-tier mismatch matters only if a user can drive the contract into the protocol and receive a meaningful advantage.
Follow time through callbacks and chains
State does not always update at the moment an external contract can observe it. In callback swaps, output transfer, callback payment, and liquidity accounting can happen at different points in one transaction. A view called during that window may expose an intermediate state.
That observation alone is not an exploit. I looked for an on-chain consumer that could act on the temporary quote and a path to financial harm. Without those, it stays an integration caveat rather than a proven vulnerability. This is a useful discipline: report what the code does, then separately prove who can benefit.
Time settings also need chain context. “One block” is not one fixed duration across networks, and some EVM chains expose more than one useful block clock. I compared the code’s clocks and each deployment’s configuration instead of assuming a shared block interval.
Prove the path—and state the limits
I used source tracing to build hypotheses, then focused tests to answer narrow questions: can the caller reach the path, does the state change survive, and do token balances show the claimed effect? For low-level market-data updates written in assembly, I compared the optimized path with a Solidity reference and checked calldata and storage boundaries. For transaction-ordering questions, a local chain test is stronger than merely impersonating a signer.
A passing proof of concept is evidence for the assumptions in that test. If the price gap is simulated, say so. If no live market quote or external consumer was verified, do not imply one. That distinction makes a report more useful to protocol teams because it shows exactly what is proven and what remains conditional.
A practical EVM DEX audit checklist
- Map the money: identify the source of every price, depth limit, fee, and token transfer.
- Bind quote to execution: check that pair, amounts, caller, path, and block cannot drift between quote and settlement.
- Audit rounding end to end: compare exact-input and exact-output costs to a full-precision reference, including extreme ratios and caps.
- Probe trusted routes: determine whether public routers can inherit a route’s lower fee or preferred pricing.
- Model recovery: test whether resets invalidate pending updates, not only data already stored on-chain.
- Inspect callback windows: identify intermediate state, then look for a real consumer and a consequential action.
- Check every deployment clock: compare block semantics and live configuration on each target chain.
- Make PoCs prove impact: assert balances and state, include a control, and label simulated assumptions clearly.
Questions founders should ask
Does a passing test mean the protocol is secure?
No. A test supports the property and assumptions it covers. A strong audit also checks whether the model reflects the real user path, deployed configuration, and external interactions.
Is an unusual on-chain behavior automatically a vulnerability?
No. A finding needs a reachable attacker path and a meaningful impact. If the only effect is a temporary quote view with no consumer, describe it as an integration risk—not a proven loss.
Why review each chain separately?
Code may be shared while block timing, configuration, deployed bytecode, and integration routes differ. Verify the actual deployment rather than assuming source parity means identical behavior.
The main lesson
An EVM DEX audit is an exercise in connecting components: price to fill, fill to transfer, transfer to state, and state to the next trade. The most useful finding is not the strangest code line. It is a reproducible path from a real precondition to a clear consequence—and a fix that closes that path.