A Vulnerability Detection Method for Smart Contract Using Opcode Sequences with Variable Length
摘要
Decentralized finance (DeFi) applications in the Ethereum ecosystem have flourished, attracting more and more users. Smart contracts as the logical backend involve transactions and money operations that cannot be changed once deployed. Therefore, detecting vulnerabilities in smart contracts before deployment is vital for securing Ethereum users’ funds and preventing hacker attacks. However, current vulnerability detection models only support fixed-length inputs, which breaks the integrity of the data. Therefore, based on deep learning, we propose a neural network model that can handle input sequences with variable length for detecting vulnerabilities in smart contracts. More specifically, we take the sequence of transaction opcodes obtained from replayed Ethereum transactions as our dataset. In order to retain the complete information of the sequence, we utilize a rotation layer without learnable parameters and Multilayer Perceptron to handle the input sequences with variable length, and capture the global features. We then introduce the retention mechanism in the neural network, employing multi-scale retention and feed-forward network to capture the key local characteristics. The experiments demonstrate that our model can efficiently detect vulnerabilities in smart contracts, achieving an accuracy of 93.5% and an F1-score of 90.6%.