Machine translation-based fine-grained comments generation for solidity smart contracts

Chaochen Shi, Yong Xiang, Jiangshan Yu, Keshav Sood, Longxiang Gao

Research output: Contribution to journalArticleResearchpeer-review

2 Citations (Scopus)

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 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.

Original languageEnglish
Article number107065
Number of pages15
JournalInformation and Software Technology
Volume153
DOIs
Publication statusPublished - Jan 2023

Keywords

  • Automatic comments generation
  • Machine translation
  • Reinforcement learning
  • Smart contract
  • Solidity

Cite this