Table of Contents
Fetching ...

On-Chain Decentralized Learning and Cost-Effective Inference for DeFi Attack Mitigation

Abdulrahman Alhaidari, Balaji Palanisamy, Prashant Krishnamurthy

TL;DR

This work tackles the challenge of mitigating DeFi exploits in real time by embedding a decentralized, fully on-chain learning framework within the Ethereum ecosystem. Training and governance occur on Layer-2, while inference runs on Layer-1 under strict gas constraints, enabled by a commit-verify propagation and PoIm protocol that ensures only improvements propagate. The approach demonstrates bit-exact, verifiable on-chain inferences across multiple neural architectures, supported by a curated dataset of 298 real-world exploits across eight chains, achieving high recall and competitive F1 scores with low per-inference gas. The framework promises scalable, decentralized threat intelligence that evolves with emerging exploits, reducing both latency and reliance on centralized monitors. It also provides a practical baseline for comparing on-chain ML architectures, balancing zero-cost off-chain inference with fully on-chain verifiable decisions for high-security DeFi functions.

Abstract

Billions of dollars are lost every year in DeFi platforms by transactions exploiting business logic or accounting vulnerabilities. Existing defenses focus on static code analysis, public mempool screening, attacker contract detection, or trusted off-chain monitors, none of which prevents exploits submitted through private relays or malicious contracts that execute within the same block. We present the first decentralized, fully on-chain learning framework that: (i) performs gas-prohibitive computation on Layer-2 to reduce cost, (ii) propagates verified model updates to Layer-1, and (iii) enables gas-bounded, low-latency inference inside smart contracts. A novel Proof-of-Improvement (PoIm) protocol governs the training process and verifies each decentralized micro update as a self-verifying training transaction. Updates are accepted by \textit{PoIm} only if they demonstrably improve at least one core metric (e.g., accuracy, F1-score, precision, or recall) on a public benchmark without degrading any of the other core metrics, while adversarial proposals get financially penalized through an adaptable test set for evolving threats. We develop quantization and loop-unrolling techniques that enable inference for logistic regression, SVM, MLPs, CNNs, and gated RNNs (with support for formally verified decision tree inference) within the Ethereum block gas limit, while remaining bit-exact to their off-chain counterparts, formally proven in Z3. We curate 298 unique real-world exploits (2020 - 2025) with 402 exploit transactions across eight EVM chains, collectively responsible for \$3.74 B in losses.

On-Chain Decentralized Learning and Cost-Effective Inference for DeFi Attack Mitigation

TL;DR

This work tackles the challenge of mitigating DeFi exploits in real time by embedding a decentralized, fully on-chain learning framework within the Ethereum ecosystem. Training and governance occur on Layer-2, while inference runs on Layer-1 under strict gas constraints, enabled by a commit-verify propagation and PoIm protocol that ensures only improvements propagate. The approach demonstrates bit-exact, verifiable on-chain inferences across multiple neural architectures, supported by a curated dataset of 298 real-world exploits across eight chains, achieving high recall and competitive F1 scores with low per-inference gas. The framework promises scalable, decentralized threat intelligence that evolves with emerging exploits, reducing both latency and reliance on centralized monitors. It also provides a practical baseline for comparing on-chain ML architectures, balancing zero-cost off-chain inference with fully on-chain verifiable decisions for high-security DeFi functions.

Abstract

Billions of dollars are lost every year in DeFi platforms by transactions exploiting business logic or accounting vulnerabilities. Existing defenses focus on static code analysis, public mempool screening, attacker contract detection, or trusted off-chain monitors, none of which prevents exploits submitted through private relays or malicious contracts that execute within the same block. We present the first decentralized, fully on-chain learning framework that: (i) performs gas-prohibitive computation on Layer-2 to reduce cost, (ii) propagates verified model updates to Layer-1, and (iii) enables gas-bounded, low-latency inference inside smart contracts. A novel Proof-of-Improvement (PoIm) protocol governs the training process and verifies each decentralized micro update as a self-verifying training transaction. Updates are accepted by \textit{PoIm} only if they demonstrably improve at least one core metric (e.g., accuracy, F1-score, precision, or recall) on a public benchmark without degrading any of the other core metrics, while adversarial proposals get financially penalized through an adaptable test set for evolving threats. We develop quantization and loop-unrolling techniques that enable inference for logistic regression, SVM, MLPs, CNNs, and gated RNNs (with support for formally verified decision tree inference) within the Ethereum block gas limit, while remaining bit-exact to their off-chain counterparts, formally proven in Z3. We curate 298 unique real-world exploits (2020 - 2025) with 402 exploit transactions across eight EVM chains, collectively responsible for \$3.74 B in losses.
Paper Structure (27 sections, 9 figures, 12 tables, 4 algorithms)

This paper contains 27 sections, 9 figures, 12 tables, 4 algorithms.

Figures (9)

  • Figure 1: PCA reduces 7D attack transaction features from the original feature space ${\cal X} \subset \mathbb{R}^7$ to a 2D latent space ${\cal F} \subset \mathbb{R}^2$ for pattern clustering.
  • Figure 2: Left: PCA projection of DeFi attack transactions using two principal components with KMeans clustering ($k=3$). Right: The scree plot shows the explained variance ratio per principal component. Even though PC1 and PC2 capture less than 50% of the total variance, the projection shows distinct DeFi attack transaction patterns.
  • Figure 3: Framework overview.
  • Figure 4: Serialization example of quantized model parameters.
  • Figure 5: PoIm protocol update flow. Each proposed model is evaluated on $\mathcal{D}_{\text{test}}$ and accepted only if it improves performance.
  • ...and 4 more figures