CDDSF: A Zero-Shot Domain Adaptation Framework for Secure Solidity Code Search
摘要
As blockchain technology continues to evolve, smart contracts have become fundamental components in decentralized applications, handling critical operations such as cryptocurrency transfers, digital asset management, and decentralized finance. While code search capabilities are essential for smart contract development to identify and reuse secure patterns, the effectiveness of existing code search models is limited by two major challenges in domain-specific languages like Solidity: the scarcity of labeled data and the critical requirement for code security. This paper introduces CDDSF, a zero-shot domain adaptation framework for secure Solidity code search that addresses these challenges through a three-stage approach. First, we construct a secure dataset by filtering smart contracts using vulnerability detection tools and generating natural language annotations via DeepSeek. Second, we develop a novel sampling strategy that considers semantic relevance between queries and negative samples to enhance the process of fine-tuning. Finally, we adapt the CodeBERT model to the Solidity domain through our proposed fine-tuning method. Experimental results demonstrate the effectiveness of our approach: the untuned CodeBERT achieves only 0.1% in SR@1, while CodeBERT with random sampling fine-tuning improves significantly to 27.3%. Our proposed sampling strategy further enhances the performance, achieving an MRR of 40.07% and an SR@1 of 28.4%, with relative improvements of 2.72% in MRR and 4.03% in SR@1 compared to random sampling baselines. Our framework significantly outperforms traditional methods and contributes a valuable secure Solidity code dataset to facilitate future research in smart contract development.