arXiv:2608.25600cs.CRAug 2026

Manuscript Offprint

arXiv:2608.25600

Defending the Peg: Real-Time Dynamic Protection and Anomaly Detection in DeFi Stablecoins

Hengxing Zeng, Shipeng Ye, Xiaoqi Li

HENGXING ZENG ∗^{*}, Hainan University, China

SHIPENG YE ∗^{*}, Hainan University, China

XIAOQI LI, Hainan University, China

With the rapid evolution of the Decentralized Finance (DeFi) ecosystem, stablecoins have emerged as a critical infrastructure bridging the cryptocurrency market with traditional financial paradigms. However, stablecoin systems rely heavily on smart contracts to execute automated operations. The immutable nature of these systems post-deployment means that the exploitation of security vulnerabilities can lead to irreversible, massive economic losses and potentially trigger systemic financial risks. Current research on stablecoin smart contract security faces challenges such as a lack of domain-specific targeting and the obsolescence of static defense models. To address this, this paper systematically analyzes common attack vectors in stablecoin environments and proposes a practical, real-time dynamic defense architecture. By analyzing 12 real-world security incidents, we elucidate the underlying mechanisms of high-risk patterns such as reentrancy attacks, oracle manipulation, and composite flash loan attacks. Concurrently, we construct a real-time anomaly detection model utilizing multi-dimensional on-chain temporal features and the Bi-LSTM algorithm. Experimental results demonstrate that this model achieves a classification accuracy of 96.61%, with an average recall rate of 97.70% for malicious attack samples, and a single inference latency ranging from 1.5 to 2.8 milliseconds.

Additional Key Words and Phrases: Stablecoin, Smart Contract, Security Attacks, Dynamic Protection, Anomaly Detection

1 Introduction

With the continuous evolution of blockchain technology, the novel financial paradigm represented by Decentralized Finance has rapidly emerged, dismantling the geographical and institutional barriers of traditional finance and providing intermediary-free financial services globally [3,26,53][3, 26, 53]. As a core infrastructure of the DeFi ecosystem, stablecoins maintain value stability by pegging to fiat currencies or other assets. They effectively resolve the extreme volatility inherent in crypto assets, playing a crucial role as a medium of exchange, a store of value, and a form of collateral.

Recent market data indicates that by 2025, the total market capitalization of global stablecoins exceeded 260billion,accountingforover70260 billion, accounting for over 70% of the daily trading volume in the cryptocurrency market and serving as the primary source of liquidity [57]. Stablecoin systems rely heavily on smart contracts to automate operations such as token minting, burning, collateral management, and liquidation without manual intervention. However, the post-deployment immutability of smart contracts dictates that exploited vulnerabilities can cause irreversible and catastrophic economic losses [31]. Historically, smart contract vulnerabilities have constituted a primary risk factor in the DeFi ecosystem. For instance, the infamous 2016 DAO attack, caused by a reentrancy vulnerability, led to the Ethereum hard fork [27, 34, 40]. Subsequent incidents, including the 2017 Parity multisig wallet exploit [13], the 2018 Beauty Chain (BEC) overflow bug [46], and the50 million exploit on the Binance Smart Chain (BSC) during a contract migration in 2021 [8], profoundly underscore the critical urgency of stablecoin smart contract security[36].

Regarding specific vulnerability taxonomies, stablecoin smart contracts frequently encounter security flaws such as reentrancy attacks, integer overflows, access control defects, and oracle manipulation. Reentrancy attacks exploit external call mechanisms to repeatedly execute critical

∗^{*}These authors contributed equally to this work.

Authors' Contact Information: Hengxing Zeng, Hainan University, Haikou, China, 1434780680@qq.com; Shipeng Ye, Hainan University, Haikou, China, yeshipeng35@gmail.com; Xiaoqi Li, Hainan University, Haikou, China, csxqli@ieee.org.

, Vol. 1, No. 1, Article. Publication date: August 2026.

logic [25, 34, 35]. Integer overflows cause anomalous asset calculations and illegal token issuance [20]. Access control defects grant attackers unauthorized privileges to hijack core system functions [2]. Furthermore, oracle manipulation alters external price feeds to indirectly influence system behavior, serving as a primary risk for crypto-collateralized stablecoins. More alarmingly, these vulnerabilities are increasingly combined with novel financial instruments, such as flash loans, to orchestrate composite attacks [52]. In a single, atomic, and risk-free transaction, attackers can complete capital acquisition, market manipulation, arbitrage, and loan repayment [14]. This atomic execution significantly amplifies both the efficiency and stealth of the attacks, posing profound challenges to conventional security paradigms [11, 54].

Moreover, different categories of stablecoins exhibit distinct technical implementations and risk profiles. Fiat-collateralized stablecoins involve centralized operational management, presenting risks of administrative privilege abuse and access control deficiencies [58]. Crypto-collateralized stablecoins depend heavily on oracles and liquidation mechanisms, making oracle manipulation their primary attack vector [38]. Algorithmic stablecoins rely on supply-demand adjustments, facing severe risks of market manipulation and mechanism failures [61]. The catastrophic collapse of Terra Luna in 2022 demonstrated how algorithmic design flaws, exacerbated by market panic, could vaporize over $40 billion in market value and trigger industry-wide systemic contagion.

Under the current threat landscape, isolated vulnerability detection or static contract auditing is inadequate against complex attack scenarios [49]. As composite attacks leveraging flash loans and oracle manipulation grow increasingly sophisticated, integrating artificial intelligence for real-time anomaly detection and dynamic monitoring has become an imperative trajectory for enhancing system security [42, 47, 48]. Traditional pre-deployment static audits are fundamentally blind to novel, post-deployment composite attacks [30]. Conversely, a dynamic defense model can identify anomalous behaviors in real-time during an ongoing attack sequence and execute immediate interceptions, effectively bridging the inherent gaps of static auditing [65].

Therefore, a systematic investigation into the security vulnerabilities, attack patterns, and dynamic defense mechanisms of stablecoin smart contracts not only holds substantial theoretical value but also carries critical practical significance for safeguarding the stability of the DeFi ecosystem and mitigating systemic financial risks.

The main contributions of this paper are as follows:

• Systematic Threat Modeling for Stablecoin Ecosystems: We systematically dissect the distinct technical mechanisms and risk profiles of fiat-collateralized, crypto-collateralized, and algorithmic stablecoins.

• Full-Lifecycle Dynamic Defense Architecture: Moving beyond traditional static auditing, we propose a multi-layered, dynamic defense architecture that spans the pre-deployment, mid-execution, and post-incident phases.

• Real-Time Anomaly Detection via Mempool Monitoring: We introduce a novel node-level defense mechanism deploying a Bidirectional Long Short-Term Memory network directly at the mempool layer. Our model effectively extracts multi-dimensional on-chain temporal features to intercept malicious payloads before block inclusion.

References (67)