# Smart Contract Vulnerability Detection Based on Hybrid Attention Mechanism Model
## 6 Discussions and Conclusions  
The security of smart contracts is of great significance to the sustainable development of blockchain. To enhance the performance of traditional approaches, we propose a deep learning-based hybrid attention mechanism model for smart contract vulnerability detection. This model makes full use of the advantage that hybrid attention can extract more semantic information, which is composed of a single-head attention encoder and a multi-head attention encoder. It operates on four phases, namely, code fragment reaction, word embedding, feature learning, and vulnerability detection. We adopted the Word2 Vec technology to complete the word embedding of smart contracts. Then the feature vectors of smart contracts are learned and extracted using two branches of HAM. Finally, the obtained features are concatenated and input to the fully connected layer and softmax activation for classification. We have proven the performance of HAM with a wide range of experiments. First, we compared the HAM on code fragments with unsliced smart contracts. The improvement for each metric is obvious with an accuracy of 88.96%, precision of 89.8%, recall of 91.64%, and F1 of 90.51%, improved by 4.39%, 3.2%, 7.08% and 5.05%, respectively. Then, we chose six deep learning-based models, such as RNN, GRU, and LSTM, and three popular vulnerability detection tools, such as Smartcheck, Oyente, and Security, for comparison with our proposed HAM. The results show that HAM model achieved better prediction accuracy of 93.36%, 80.85%, 82.56%, 85.62%, and 82.19% in reentrancy vulnerability, arithmetic vulnerability, unchecked return value, timestamp dependency, and tx.origin, respectively. In addition, the results also indicates that HAM is capable of detecting multiple smart contract vulnerabilities. We experimentally demonstrate that the HAM model significantly outperforms other nine advanced vulnerability detection methods with higher accuracy again a large number of smart contract vulnerabilities. However, it needs to be noted that existing deep learning-based smart contract vulnerability detection methods are mostly black box detection processes, which only present final vulnerability detection results by training models. Due to the inherent \"black box\" nature of deep learning model, the specific internal working state and processing process are not transparent, so there is no reasonable interpretation \begin{table}
\begin{tabular}{c c c c c c} \hline \hline \multirow{2}{*}{**Vulnerability**} & \multirow{2}{*}{**Performance Metrics**} & \multicolumn{4}{c}{**Method**} \\ \cline{3-6}  & & **Smartheck** & **Oyente** & **Securify** & **HAM** \\ \hline \multirow{4}{*}{Reentrancy} & Accuracy & 64.89\% & 72.39\% & 75.23\% & 93.36\% \\  & Precision & 32.16\% & 53.47\% & 54.79\% & 91.58\% \\  & Recall & 24.79\% & 47.78\% & 48.54\% & 96.64\% \\  & F1 & 28.00\% & 50.47\% & 51.48\% & 94.04\% \\ \hline \multirow{4}{*}{Arithmetic Vulnerability} & Accuracy & 42.19\% & 67.36\% & N/A & 80.85\% \\  & Precision & 38.24\% & 37.13\% & N/A & 79.65\% \\  & Recall & 36.50\% & 27.39\% & N/A & 71.89\% \\  & F1 & 37.35\% & 31.52\% & N/A & 75.57\% \\ \hline \multirow{4}{*}{Unchecked Return Value} & Accuracy & 38.66\% & N/A & 37.36\% & 82.56\% \\  & Precision & 32.50\% & N/A & 34.13\% & 81.24\% \\  & Recall & 87.54\% & N/A & 92.48\% & 73.46\% \\  & F1 & 47.40\% & N/A & 47.16\% & 77.15\% \\ \hline \multirow{4}{*}{Timestamp Dependency} & Accuracy & 58.34\% & 60.32\% & N/A & 85.62\% \\  & Precision & 48.12\% & 46.68\% & N/A & 87.03\% \\ \cline{1-1}  & Recall & 27.36\% & 30.48\% & N/A & 88.69\% \\ \cline{1-1}  & F1 & 34.89\% & 36.88\% & N/A & 87.85\% \\ \hline \multirow{4}{*}{Tx.origin} & Accuracy & 70.86\% & N/A & 35.57\% & 82.19\% \\ \cline{1-1}  & Precision & 49.85\% & N/A & 31.28\% & 81.45\% \\ \cline{1-1}  & Recall & 54.86\% & N/A & 86.19\% & 80.32\% \\ \cline{1-1}  & F1 & 52.24\% & N/A & 45.90\% & 80.88\% \\ \hline \hline \end{tabular}
\end{table} 
Table 6: Performance comparison with three existing state-of-the-art methods.