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

arXiv: https://arxiv.org/abs/2510.16024 · HTML: https://mlsanity.com/paper/2510.16024/

## Key facts

- No citing papers in the map yet (data through 14 Oct 2026).
- Builds on 33 of its 79 references that are in the map.
- First posted on arXiv 15 Oct 2025.

## Builds on (most cited first, 30 of 33)

- [SoK: Decentralized Finance (DeFi) Attacks](https://mlsanity.com/paper/2208.13035/) (2022)
- [A Survey on Ethereum Systems Security: Vulnerabilities, Attacks and Defenses](https://mlsanity.com/paper/1908.04507/) (2019)
- [A Survey of Zero-Knowledge Proof Based Verifiable Machine Learning](https://mlsanity.com/paper/2502.18535/) (2025)
- [opML: Optimistic Machine Learning on Blockchain](https://mlsanity.com/paper/2401.17555/) (2024)
- [A scalable verification solution for blockchains](https://mlsanity.com/paper/1908.04756/) (2019)
- [DAppSCAN: Building Large-Scale Datasets for Smart Contract Weaknesses in DApp Projects](https://mlsanity.com/paper/2305.08456/) (2023)
- [Smart Contract and DeFi Security Tools: Do They Meet the Needs of Practitioners?](https://mlsanity.com/paper/2304.02981/) (2023)
- [Blockchain for Large Language Model Security and Safety: A Holistic Survey](https://mlsanity.com/paper/2407.20181/) (2024)
- [Characterizing Code Clones in the Ethereum Smart Contract Ecosystem](https://mlsanity.com/paper/1905.00272/) (2019)
- [DeFiTail: DeFi Protocol Inspection through Cross-Contract Execution Analysis](https://mlsanity.com/paper/2405.11035/) (2024)
- [Agatha: Smart Contract for DNN Computation](https://mlsanity.com/paper/2105.04919/) (2021)
- [Empirical Analysis of EIP-1559: Transaction Fees, Waiting Time, and Consensus Security](https://mlsanity.com/paper/2201.05574/) (2022)
- [Trust the Process: Zero-Knowledge Machine Learning to Enhance Trust in Generative AI Interactions](https://mlsanity.com/paper/2402.06414/) (2024)
- [Why and How zk-SNARK Works](https://mlsanity.com/paper/1906.07221/) (2019)
- [Layer 2 Blockchain Scaling: a Survey](https://mlsanity.com/paper/2107.10881/) (2021)
- [ScrawlD: A Dataset of Real World Ethereum Smart Contracts Labelled with Vulnerabilities](https://mlsanity.com/paper/2202.11409/) (2022)
- [YODA: Enabling computationally intensive contracts on blockchains with Byzantine and Selfish nodes](https://mlsanity.com/paper/1811.03265/) (2018)
- [Eliminating Sandwich Attacks with the Help of Game Theory](https://mlsanity.com/paper/2202.03762/) (2022)
- [Reap the Harvest on Blockchain: A Survey of Yield Farming Protocols](https://mlsanity.com/paper/2210.04194/) (2022)
- [LookAhead: Preventing DeFi Attacks via Unveiling Adversarial Contracts](https://mlsanity.com/paper/2401.07261/) (2024)
- [A Framework and DataSet for Bugs in Ethereum Smart Contracts](https://mlsanity.com/paper/2009.02066/) (2020)
- [ML2SC: Deploying Machine Learning Models as Smart Contracts on the Blockchain](https://mlsanity.com/paper/2404.16967/) (2024)
- [SoK: Attacks on DAOs](https://mlsanity.com/paper/2406.15071/) (2024)
- [AI-Based Crypto Tokens: The Illusion of Decentralized AI?](https://mlsanity.com/paper/2505.07828/) (2025)
- [Dissecting Bitcoin and Ethereum Transactions: On the Lack of Transaction Contention and Prioritization Transparency in Blockchains](https://mlsanity.com/paper/2302.06962/) (2023)
- [A Survey on Off-chain Networks: Frameworks, Technologies, Solutions and Challenges](https://mlsanity.com/paper/2311.10298/) (2023)
- [Characterizing Ethereum Upgradable Smart Contracts and Their Security Implications](https://mlsanity.com/paper/2403.01290/) (2024)
- [Vulnerabilities of smart contracts and mitigation schemes: A Comprehensive Survey](https://mlsanity.com/paper/2403.19805/) (2024)
- [A Novel Classification of Attacks on Blockchain Layers: Vulnerabilities, Attacks, Mitigations, and Research Directions](https://mlsanity.com/paper/2404.18090/) (2024)
- [Yoimiya: A Scalable Framework for Optimal Resource Utilization in ZK-SNARK Systems](https://mlsanity.com/paper/2502.18288/) (2025)

## Abstract (arXiv)

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 textitPoIm 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.
