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

2023 
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.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.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.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.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.
    • Correction
    • Source
    • Cite
    • Save
    • Machine Reading By IdeaReader
    0
    References
    0
    Citations
    NaN
    KQI
    []