Code comment has been an important part of computer programs, greatly facilitating the understanding and maintenance of source code. However, high-quality code comments are often unavailable in smart contracts, the increasingly popular programs that run on the blockchain. In this paper, we propose a Multi-Modal Transformer-based (MMTrans) code summarization approach for smart contracts. Specifically, the MMTrans learns the representation of source code from the two heterogeneous modalities of the Abstract Syntax Tree (AST), i.e., Structure-based Traversal (SBT) sequences and graphs. The SBT sequence provides the global semantic information of AST, while the graph convolution focuses on the local details. The MMTrans uses two encoders to extract both global and local semantic information from the two modalities respectively, and then uses a joint decoder to generate code comments. Both the encoders and the decoder employ the multi-head attention structure of the Transformer to enhance the ability to capture the long-range dependencies between code tokens. We build a dataset with over 300K <method, comment> pairs of smart contracts, and evaluate the MMTrans on it. The experimental results demonstrate that the MMTrans outperforms the state-of-the-art baselines in terms of four evaluation metrics by a substantial margin, and can generate higher quality comments.
翻译:代码注释是计算机程序的一个重要部分,极大地便利了源代码的理解和维护。然而,智能合同中往往无法提供高质量的代码注释,因为智能合同中出现的程序越来越受欢迎。在本文中,我们建议对智能合同采用多式变换器(MMTrans)代码总和法。具体地说,MMTrans从简易语树(AST)的两种不同模式中学习源代码的表达方式,即基于结构的Traversal(SBT)序列和图形。SBT序列提供了AST的全球语义信息,而图形转换则侧重于本地细节。MMTrans使用两个编码器分别从两种模式中提取全球和地方语义信息,然后使用一个联合解码器生成代码评论。编码者和解码器都使用变换器的多重关注结构,即基于结构的Traversal(SBT)序列和图示。我们用300K以上<ethodriferal)的语义信息设置了一个数据集,而图表则侧重于4个标准基准(Transal-trainal),可以用来评估。