Machine translation-based fine-grained comments generation for solidity smart contracts
【Author】 Shi, Chaochen; Xiang, Yong; Yu, Jiangshan; Sood, Keshav; Gao, Longxiang
【Source】INFORMATION AND SOFTWARE TECHNOLOGY
【影响因子】3.862
【Abstract】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 trans-lation 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.
【Keywords】Solidity; Smart contract; Reinforcement learning; Machine translation; Automatic comments generation
【发表时间】2023 JAN
【收录时间】2022-11-01
【文献类型】理论模型
【主题类别】
区块链技术-核心技术-智能合约
评论