Skip to content
Crypto.world

Research

Werracle: Sub-Cent Intra-Block AI Reflex Oracles and Flash-Loan Circuit Breakers for EVM Smart Contracts

Storing neural network weights directly on-chain is prohibitively expensive, and offloading inference to Zero-Knowledge Machine Learning (ZK-ML) provers introduces 10 to 300 seconds of proving…

Werracle: Sub-Cent Intra-Block AI Reflex Oracles and Flash-Loan Circuit Breakers for EVM Smart Contracts
arXiv
2609.30719
Published
2026-09-25
Authors
Volkan Dağlı, Zerrin Dağlı, Dağhan Dağlı

AI summary

Overview

Research area: Computer security (cs.CR), specifically on-chain artificial intelligence, DeFi exploit mitigation, and EVM smart-contract engineering.

Technical level: Advanced. The paper assumes familiarity with EVM gas mechanics and storage layout, fixed-point arithmetic, Uniswap v4 hooks, AMM/LVR economics, and ZK-ML proving pipelines.

Scope: The paper describes Werracle, a zero-storage AI decision oracle that encodes its entire model in one 32-byte EVM storage slot using Mandelbrot escape dynamics, and demonstrates it as a Uniswap v4 dynamic swap-fee governor and intra-block flash-loan circuit breaker.

What This Paper Is About

Storing neural network weights directly on-chain is prohibitively expensive, and offloading inference to Zero-Knowledge Machine Learning (ZK-ML) provers introduces 10 to 300 seconds of proving latency plus 250,000 to 500,000 gas per on-chain verification — far too slow to stop exploits that complete atomically inside a single block. The authors propose replacing weight matrices entirely with procedural fractal geometry: a 24-byte coordinate triplet drives Mandelbrot escape calculations that produce a non-linear decision boundary with no stored parameters. The goal is an oracle that reacts within the same block, at sub-cent cost, with no off-chain dependency.

Key Contributions

  1. A zero-storage oracle architecture. The full model is packed into a single bytes32 word: 64-bit signed Q16.16 cx, 64-bit signed Q16.16 cy, 64-bit Q16.16 zoom, a 16-bit threshold, a 16-bit nonce, and 32 bits of security/domain flags. After the initial warm access, subsequent reads cost exactly 100 gas, and no dynamic memory arrays are allocated, avoiding quadratic memory-expansion penalties.

  2. WerrMath.sol, a pure-Solidity fixed-point engine. The library represents 1.0 as 65,536 (2^16), performs multiplication via a 128-bit intermediate widening followed by an arithmetic right shift, and tests the escape condition (|z|² > 4.0) against the integer constant 262,144. Decisions come from a 16-point (4×4) Pareto micro-grid centered on the perturbed coordinate, where the proportion of non-escaping points determines permit-versus-revert.

  3. WerracleFeeHook.sol, a Uniswap v4 dynamic fee governor. The hook intercepts swaps through the beforeSwap callback, measures instantaneous pool turbulence from volume and tick-velocity deltas, and atomically adjusts LP fees between 0.05% and 0.50% within the swap transaction.

  4. A sealed 1,000-test verification battery. 250 fixed-point invariance tests, 250 flash-loan exploit reverts, 250 AML/OFAC sanction traps, and 250 Uniswap v4 dynamic fee regimes, all passing at 100.0% deterministic parity, with results sealed under a SHA-256 digest in SEAL_MANIFEST.json.

Main Findings

  • Total inference cost of 21,438 gas: slot SLOAD and bit unpacking 2,342 gas; 16-point Q16.16 iteration 14,810 gas; Pareto density aggregation 2,416 gas; event log and ABI return 1,870 gas. The paper reports this as under $0.00042 on Base L2 (the abstract states "under $0.0005" on Layer-2 rollups such as Base and Arbitrum).

  • Sub-millisecond latency: execution is atomic within the block, reported as under 1 ms, versus 10 to 300 seconds for ZK-ML proving and 12 to 36 seconds for Web2 oracles.

  • 18× gas reduction and over 1,000× latency reduction relative to state-of-the-art ZK-ML provers. The comparison table lists ~60,000 gas for Web2 oracles (12–36 s latency) and ~380,000 gas for ZK-ML (EZKL) verification, against Werracle's 21,438 gas.

  • Storage footprint of 0 bytes for model weights (32 bytes total, one slot), compared with gigabytes for Web2 oracle models and off-chain provers for ZK-ML.

  • No liveness risk from external infrastructure: no server node, no dedicated GPU cluster, and no off-chain signer, eliminating centralized signer failure and prover outage failure modes.

  • Contrast with naive on-chain weights: a 100,000-weight FP32 multilayer perceptron needs 400 KB, which would cost over 2.5 billion gas (over $100,000 on Ethereum Mainnet) via SSTORE.

  • Deployment status: the protocol is reported as operating live on a dedicated EVM devnet sandbox with Chain ID 4242, with telemetry permanently disabled (TELEMETRY_ENABLED = False). No mainnet deployment or production value-locked results are reported.

Methodology in Plain English

Instead of teaching a contract a neural network, the authors make the contract compute a fractal. The Mandelbrot set is generated by repeatedly squaring a complex number and adding a constant; points that stay bounded belong to the set, points that fly off past a radius of 2 do not. Right at the boundary between those two behaviors, tiny changes in the input flip the outcome — that sensitivity is what the authors use as a classifier.

Each incoming transaction's features (volume, tick velocity, address attributes) are normalized and turned into a small shift in the fractal coordinate. The contract then samples a 4×4 grid of 16 nearby points, counts how many stay bounded, and compares that density against a threshold packed into the same storage slot. If the density clears the threshold, the transaction is permitted; otherwise it reverts or the fee is raised.

Because the EVM only does integer math, all of this is done in Q16.16 fixed-point arithmetic, and correctness is checked by running a large deterministic test suite comparing Solidity bytecode, a Python simulator, and client runtimes against Float64 ground truth.

Why This Matters

Impact on research: The paper challenges the assumption that on-chain machine intelligence requires either enormous storage or off-chain proving. It offers a third design point — procedural, parameter-free model synthesis — and supplies a concrete gas and latency profile that other researchers can benchmark against. It also reframes oracle design around intra-block reflex speed rather than predictive accuracy.

Real-world applications:

  • Flash-loan defense: an atomic circuit breaker that reverts an attack inside the same transaction, before reserves are drained.
  • Dynamic AMM fees: a Uniswap v4 hook that drops fees to 0.05% during calm orderflow to attract retail routing and scales them to 0.50% under volatile or attack conditions to neutralize predatory margins.
  • LVR mitigation for liquidity providers: fee escalation against informed orderflow that front-runs price changes.
  • Compliance screening: address classification through the 250 AML/OFAC sanction trap tests described in the verification battery.

Industry relevance: The cost profile (21,438 gas, under $0.00042 on Base L2) makes continuous per-swap invocation economically plausible for everyday decentralized exchanges, which the paper argues is not true for 250,000 to 500,000 gas ZK verification. The zero-telemetry design and single-slot footprint also target institutional adopters concerned with computational sovereignty and state bloat. A Turkish patent application (TR 2026/016285) is cited for the underlying zero-storage procedural fractal synthesis.

Future Directions

  • Mainnet and adversarial validation. Results are reported from a dedicated devnet sandbox (Chain ID 4242) and a deterministic test battery; the paper does not report deployment on a production network, real value at risk, or testing against adaptive adversaries who know the decision rule.

  • Classification quality beyond determinism. The 1,000-test battery measures deterministic parity and boundary behavior, not predictive accuracy on labeled DeFi attack data; whether fractal escape density separates benign from malicious flow as well as a trained model is not reported.

  • Generalization beyond the Uniswap v4 fee hook. The paper demonstrates one integration; extending the same 32-byte slot to lending-market collateral factors, liquidation thresholds, or other oracle consumers is left open.

  • Formal security analysis of the threshold and packing scheme. The 16-bit threshold, 16-bit nonce, and 32-bit flags field are specified at the bit level, but the paper does not report formal verification of the bytecode or an analysis of how coordinate perturbation choices affect decision stability.

Target Audience

Smart-contract engineers and protocol security researchers working on DeFi exploit mitigation; AMM and Uniswap v4 hook developers interested in dynamic fee mechanisms; and researchers in on-chain AI or ZK-ML who want a low-gas, low-latency alternative design point. Economists and risk analysts studying LVR and MEV will find the fee-governor demonstration relevant. Readers without EVM gas and fixed-point arithmetic background will need to consult the companion theoretical work (arXiv:2609.25498) first.

Authors’ abstract

Contemporary on-chain artificial intelligence (AI) encounters an intractable Von Neumann memory and latency wall. Storing static floating-point neural weight matrices inside Ethereum Virtual Machine (EVM) storage costs millions of gas, rendering direct on-chain inference impossible. While Zero-Knowledge Machine Learning (ZK-ML) offloads matrix tensor multiplications to off-chain provers, it introduces fatal constraints: 10 to 300 seconds of SNARK proving latency and 250,000…

The full abstract on arXiv
Read the original paper