TY - JOUR
T1 - Machine translation-based fine-grained comments generation for solidity smart contracts
AU - Shi, Chaochen
AU - Xiang, Yong
AU - Yu, Jiangshan
AU - Sood, Keshav
AU - Gao, Longxiang
N1 - Funding Information:
This work was supported in part by the Australian Research Council (Grant No. DP220100983 ).
Publisher Copyright:
© 2022 Elsevier B.V.
PY - 2023/1
Y1 - 2023/1
N2 - Context.: As self-executing programs on blockchain platforms, smart contracts can build a trusted environment between multi-parties. However, participants who lack programming knowledge usually have difficulties understanding smart contracts by reading the source code. It brings them difficulties and risks when interacting with decentralized applications. Objective.: We aim to translate the smart contract source code into natural language descriptions as fine-grained in-line comments to help people better understand, learn and operate smart contracts. Method.: We propose an automated translation approach for smart contracts written in Solidity, termed SolcTrans, based on an Syntax Tree (AST) and formal grammar. We have investigated representative Solidity smart contracts, identified the AST parsing paths and core attributes used for translation, and proposed corresponding translation templates for special statements. Then, we leveraged reinforcement learning to train a Probabilistic Context-Free Grammar-based syntax synthesizer used to generate comprehensible English sentences as comments. Result.: The experimental results show that SolcTrans outperforms four state-of-the-art neural machine translation models under currently available training data and is less affected by lengths of code snippets and translation outputs. We also conducted a human evaluation among 20 volunteers and asked them to score the generated comments. The results demonstrate that SolcTrans performs well on three metrics: Accuracy, Readability, and Instructiveness. Conclusion.: Our approach produces high-quality fine-grained comments for smart contract source code under the small training dataset, which creates a paradigm for future studies.
AB - Context.: As self-executing programs on blockchain platforms, smart contracts can build a trusted environment between multi-parties. However, participants who lack programming knowledge usually have difficulties understanding smart contracts by reading the source code. It brings them difficulties and risks when interacting with decentralized applications. Objective.: We aim to translate the smart contract source code into natural language descriptions as fine-grained in-line comments to help people better understand, learn and operate smart contracts. Method.: We propose an automated translation approach for smart contracts written in Solidity, termed SolcTrans, based on an Syntax Tree (AST) and formal grammar. We have investigated representative Solidity smart contracts, identified the AST parsing paths and core attributes used for translation, and proposed corresponding translation templates for special statements. Then, we leveraged reinforcement learning to train a Probabilistic Context-Free Grammar-based syntax synthesizer used to generate comprehensible English sentences as comments. Result.: The experimental results show that SolcTrans outperforms four state-of-the-art neural machine translation models under currently available training data and is less affected by lengths of code snippets and translation outputs. We also conducted a human evaluation among 20 volunteers and asked them to score the generated comments. The results demonstrate that SolcTrans performs well on three metrics: Accuracy, Readability, and Instructiveness. Conclusion.: Our approach produces high-quality fine-grained comments for smart contract source code under the small training dataset, which creates a paradigm for future studies.
KW - Automatic comments generation
KW - Machine translation
KW - Reinforcement learning
KW - Smart contract
KW - Solidity
UR - https://www.scopus.com/pages/publications/85138475019
U2 - 10.1016/j.infsof.2022.107065
DO - 10.1016/j.infsof.2022.107065
M3 - Article
AN - SCOPUS:85138475019
SN - 0950-5849
VL - 153
JO - Information and Software Technology
JF - Information and Software Technology
M1 - 107065
ER -