RDC-XLSTM: A Smart Contract Vulnerability Detection with Retrieval-Enhanced Generation and Contextual Long Memory
摘要
With the rapid advancement of blockchain technology, smart contract security has become a critical concern and the frequent occurrence of vulnerabilities has led to significant financial losses. Existing detection methods face limitations in handling cross-contract dependencies, unknown vulnerabilities, and semantic drift. We propose RDC-XLSTM, a framework that integrates Retrieval-Augmented Generation (RAG), domain-adapted CodeBERT, and an extended long short-term memory (XLSTM) network for enhanced vulnerability detection. First, an RAG-enhanced semantic distillation mechanism, combined with the DeepSeek model, dynamically aligns code logic with vulnerability patterns to generate high-purity input data. Second, a Solidity-optimized CodeBERT variant (Sol-CodeBERT) is introduced for domain-specific semantic feature extraction, improving code representation quality. Third, an optimized C-XLSTM network incorporates Multi-Head Attention (MHA) and cross-layer residual connections, augmented by Correlation Network (CorNet) modules for dual-mode vulnerability classification. Experiments demonstrate that RDC-XLSTM achieves superior performance, with average ACC and F1 scores of 97.45% and 93.36% in multi-label detection, respectively. Notably, recall rates for Reentrancy, Locked Ether, and tx.origin vulnerabilities reach 96.68%, 96.68%, and 97.42%. The framework effectively addresses semantic drift and long-sequence dependency challenges, offering a robust solution for smart contract security auditing.