K-Nearest neighbor smart contract classification with semantic feature enhancement

Gang Tian,Guangxin Zhao,Rui Wang,Jiachang Wang,Cheng He
DOI: https://doi.org/10.1093/comjnl/bxae070
2024-07-27
The Computer Journal
Abstract:Abstract How to quickly and accurately retrieve relevant smart contracts from a huge amount of smart contracts has become an urgent need for users. The classification of smart contracts offers a solution by narrowing down the search space. Existing smart contract classification methods suffer from incomplete semantic feature extraction and a lack of consideration of the existence of rich semantics in existing smart contracts of the same class. To address the above problems, we propose a contrast learning and semantic feature embedding approach to enhance K-Nearest Neighbor (CL-SFE-IKNN). Our method fuses local features, global features, and account transaction features of the smart contract source code to perfect the semantics of the contract. Our method adopts KNN to retrieve multiple instances of contracts in the same class and assigns weights to the model output based on their labels. Meanwhile, we introduce contrastive learning and semantic feature embedding to enhance KNN retrieval to high-quality nearest neighbors of the same class. Experimental results show that by combining a KNN classifier with a traditional linear classifier, our model achieves the best performance compared with other baseline models.
computer science, information systems, theory & methods, software engineering, hardware & architecture
What problem does this paper attempt to address?