Files
papers/lightspeed-dex/sections/05-uniswap-v4-native-precompile.tex

62 lines
2.5 KiB
TeX

\section{Uniswap V4 Native Precompile}
\subsection{Precompile vs On-Chain Execution}
Lux implements Uniswap V4 swap logic as a native EVM precompile at address
\texttt{0x9012}, eliminating smart contract overhead entirely. The precompile
executes the same AMM math (constant product formula with concentrated liquidity)
but bypasses EVM opcode dispatch, contract storage SLOAD/SSTORE, and ABI encoding.
\begin{table}[h]
\centering
\begin{tabular}{lrrl}
\toprule
\textbf{Method} & \textbf{Gas Cost} & \textbf{Overhead} & \textbf{Notes} \\
\midrule
V3 on-chain swap & 150{,}000--200{,}000 & Baseline & EVM bytecode, storage I/O \\
V4 precompile (0x9012) & $\sim$150{,}000 & Native & Hooks support, no EVM dispatch \\
\bottomrule
\end{tabular}
\caption{Uniswap V4 precompile vs V3 on-chain swap. Gas cost is similar, but the
precompile eliminates smart contract execution overhead entirely. V4 hooks are
supported natively, enabling custom logic without additional contract calls.}
\end{table}
The V4 precompile matches V3's gas profile while providing V4's hook architecture
natively. This means DEX-as-precompile eliminates smart contract overhead---the
precompile runs as compiled Go/C++ code inside the node, not as interpreted EVM
bytecode.
\subsection{GPU Matching Engine}
The GPU-accelerated order matching engine achieves throughput far beyond CPU
implementations:
\begin{table}[h]
\centering
\begin{tabular}{lrrl}
\toprule
\textbf{Implementation} & \textbf{Throughput} & \textbf{Latency} & \textbf{Platform} \\
\midrule
GPU (MLX Metal) & 434M orders/sec & 597\,ns/order & Apple M1 Max \\
C++ (CPU) & 444K--1.08M msg/s & --- & Apple M1 Max \\
Go (CPU) & 163--332K msg/s & --- & Apple M1 Max \\
\bottomrule
\end{tabular}
\caption{Order matching throughput comparison. GPU matching via MLX Metal is
200--1{,}000$\times$ faster than CPU implementations. Per-order latency of 597\,ns
enables sub-microsecond matching.}
\end{table}
The GPU is 200--1{,}000$\times$ faster than CPU for order matching. At 434M orders/sec
with 597\,ns per-order latency, the matching engine exceeds any centralized exchange.
\subsection{Cross-Chain Atomic Swaps}
Cross-chain swaps between Lux appchains use Warp messaging for atomic execution.
Warp messages carry BLS aggregate signatures from the source chain's validator set,
enabling the destination chain to verify message authenticity without a trusted relay.
Settlement completes in a single consensus round (10\,ms with GPU BLS).