作者投稿和查稿 主编审稿 专家审稿 编委审稿 远程编辑

计算机工程 ›› 2023, Vol. 49 ›› Issue (9): 137-143, 157. doi: 10.19678/j.issn.1000-3428.0066982

• 网络空间安全 • 上一篇    下一篇

一种基于时间自动机的安全智能合约生成方法

刘阳, 张圣杰   

  1. 上海海事大学 物流科学与工程研究院, 上海 201306
  • 收稿日期:2023-02-20 出版日期:2023-09-15 发布日期:2023-04-04
  • 作者简介:

    刘阳(1980-), 男, 教授、博士, CCF高级会员, 主研方向为软件工程、区块链智能合约安全、形式化验证

    张圣杰, 硕士研究生

  • 基金资助:
    新加坡-英国联合网络安全专项(EP/N020170/1); 国家自然科学基金(61303022)

A Secure Smart Contract Generation Method Based on Timed Automata

Yang LIU, Shengjie ZHANG   

  1. Institute of Logistics Science and Engineering, Shanghai Maritime University, Shanghai 201306, China
  • Received:2023-02-20 Online:2023-09-15 Published:2023-04-04

摘要:

区块链是一种去中心化的计算范式,在诸多领域具有良好的应用前景。智能合约是区块链应用的关键,然而,智能合约的安全问题时有发生,有些甚至造成重大的经济损失。为了避免智能合约在设计开发阶段出现由逻辑不严谨或错误逻辑所造成的安全漏洞,提出一种基于时间自动机模型的安全智能合约生成方法。相较于直接编写合约代码,该方法通过将证明为正确的模型转换为可执行的智能合约代码,有效解决在智能合约开发设计阶段所存在的安全性问题。利用UPPAAL工具将人类可理解的文本合约建模为时间自动机并通过模型验证来确保模型的安全性和可靠性。通过对智能合约的正式定义建立时间自动机与智能合约的映射规则,根据相应的映射规则,时间自动机被转换为模块化的Solidity智能合约代码。设计一个具体的商品预售活动案例进行分析,结果表明,通过所提方法生成的商品预售合约的Solidity代码可成功编译并部署在以太坊测试网络中。

关键词: 区块链, 智能合约, 时间自动机, UPPAAL工具, 模型验证, 映射规则

Abstract:

Blockchain is a decentralized computing paradigm with promising application prospects in many fields. Smart contracts are the key to blockchain applications; however, security issues with smart contracts often occur, occasionally leading to significant economic losses. In this study, a secure smart contract generation method based on timed automata model is proposed to prevent security vulnerabilities caused by imprecise or erroneous logic at the design and development stage of smart contracts. Compared to directly writing a contract code, this method effectively resolves the security issues that occur during the development and design phase of smart contracts by converting the proven correct model into executable smart contract code. The UPPAAL tool is used to model human-understandable text contracts as timed automata, thereby ensuring the security and reliability of the model through model validation.By formally defining smart contracts, mapping rules between timed automata and smart contracts are established; based on the corresponding mapping rules, timed automata are converted into modular Solidity smart contract codes. A specific case of the product pre-sale activity is designed and analyzed, and the results show that the Solidity code of the product pre-sale contract generated by the proposed method can be successfully compiled and deployed in the Ethereum testing network.

Key words: blockchain, smart contract, Timed Automata(TA), UPPAAL tool, model verification, mapping rule