Pre-FRP: Topological MEV Detection During Block Construction

Pre-FRP: Topological MEV Detection During Block Construction

I’ve been investigating whether Topological Data Analysis (TDA) can detect MEV on Ethereum, using the EigenPhi DeFi-Behavior 0728 labeled dataset, Ethereum block data, and a ~25-hour public mempool capture from Xatu.

The project started with a simple question: can the structure of the public mempool reveal that a sandwich attack is about to occur?

Across persistent homology, transaction graphs, and conventional transaction features, public-mempool prediction converged at approximately 0.55 ROC-AUC.

Investigating why suggested a major limitation: approximately 82% of labeled sandwich blocks contained no trace of the attack transaction in the public mempool capture. Restricting evaluation to attacks that were actually mempool-visible increased performance to 0.70 ROC-AUC, suggesting that the weak overall result is primarily a visibility problem.

The TDA representation

The main approach represents transactions as points in a custom metric space:

\begin{aligned} D(i,j) = \; & w_{\mathrm{sender}} \cdot \mathbf{1}(\text{sender}_i \neq \text{sender}_j) + w_{\mathrm{order}} \cdot |\text{order}_i - \text{order}_j| \\ & + w_{\mathrm{nonce}} \cdot \operatorname{nonce\_gap}(i,j) + w_{\mathrm{gas}} \cdot |\text{gas_rank}_i - \text{gas_rank}_j| \end{aligned}

Here, order refers to the transaction’s execution position within the canonical block, and gas_rank represents its percentile rank relative to that full block.

The strongest configuration used gas-heavy weights:

w_{\mathrm{sender}}=3, \quad w_{\mathrm{order}}=1, \quad w_{\mathrm{nonce}}=2, \quad w_{\mathrm{gas}}=4

Persistent homology is then computed on the resulting transaction point cloud.

Using this representation, TDA alone reached 0.943 ROC-AUC for sandwich detection. Combining TDA with structural and tabular features reached 0.962 ROC-AUC, with out-of-time validation in the 0.95–0.97 range.

I also tested the other MEV categories available in the EigenPhi dataset. The strongest additional result was JIT liquidity at 0.805 ROC-AUC.

Incremental block detection

The result I find most interesting comes from looking at partial blocks.

Across 2,905 labeled sandwich events, the characteristic sandwich structure was complete at a median position of just 3.2% into the block, with 76.6% complete within the first 10% of transactions.

Evaluating on prefixes of unseen blocks:

Information available ROC-AUC
Public mempool 0.552
Visible attacks only 0.700
First 10% of block 0.884
First 50% of block 0.939
Full block, TDA 0.943
Full block, combined 0.962

The important caveat is that this is not yet a realistic real-time builder-side experiment. The prefix evaluation uses the eventual transaction execution order and full-block gas percentile ranks. It should therefore be viewed as a proxy experiment: the strong signal is present in early portions of the final block, but the next question is whether it remains when every feature is computed strictly from information available at that point during block construction.

This leads to the question I’d like to explore:

Can this topological signal be reproduced using information actually available to builders during block construction, early enough to provide useful MEV intelligence?

A major limitation of the current work is data coverage: the experiments cover only ~25 hours and a single observation period. Establishing whether these results generalize requires substantially more data.

I’d therefore be particularly interested in:

  • comparable labeled MEV data across additional days and market regimes;
  • additional labeled MEV categories;
  • builder/relay or block-construction data that would allow the prefix result to be tested against a realistic temporal information set.

Potential follow-up work would also include:

  • testing how early the signal appears under a realistic builder-side information model, including replacing full-block gas percentile ranks with dynamic or rolling ranks computed strictly from the transactions visible at each partial block state;
  • measuring the latency of the current Ripser-based pipeline;
  • investigating lightweight or approximate topological representations that could preserve useful signal while reducing computational cost;
  • determining whether the resulting features can be computed quickly enough to be useful during block construction.

The full code, data artifacts, notebooks, and methodology are available here:

Simplex-TDA MEV Detection Repository

I’m considering developing this into a formal research proposal and would welcome feedback on the builder-side direction, relevant prior work, and possible datasets or infrastructure for testing it more realistically.