[论文解读] Smart Contract Design Meets State Machine Synthesis: Case Studies
本文提出一种基于规格的自动方法,利用线性时序逻辑(LTL)合成与有限状态机(FSM)建模,自动生成正确性可保证的智能合约。通过将合约行为编码为LTL公式并整合测试场景,该方法合成出的FSM可编译为安全且可执行的Solidity代码,已在众筹、拍卖和许可等用例中得到验证,展示了端到端的验证与代码生成,并具备形式化正确性保证。
Modern blockchain systems support creation of smart contracts -- stateful programs hosted and executed on a blockchain. Smart contracts hold and transfer significant amounts of digital currency which makes them an attractive target for security attacks. It has been shown that many contracts deployed to public ledgers contain security vulnerabilities. Moreover, the design of blockchain systems does not allow the code of the smart contract to be changed after it has been deployed to the system. Therefore, it is important to guarantee the correctness of smart contracts prior to their deployment. Formal verification is widely used to check smart contracts for correctness with respect to given specification. In this work we consider program synthesis techniques in which the specification is used to generate correct-by-construction programs. We focus on one of the special cases of program synthesis where programs are modeled with finite state machines (FSMs). We show how FSM synthesis can be applied to the problem of automatic smart contract generation. Several case studies of smart contracts are outlined: crowdfunding platform, blinded auction and a license contract. For each case study we specify the corresponding smart contract with a set of formulas in linear temporal logic (LTL) and use this specification together with test scenarios to synthesize a FSM model for that contract. These models are later used to generate executable Solidity code which can be directly used in a blockchain system.
研究动机与目标
- 为解决智能合约安全性的关键挑战,实现在部署前自动生成正确性可保证的合约。
- 探究是否可将有限状态机(FSM)的程序合成技术有效应用于智能合约开发,鉴于其规模较小且具有状态特性。
- 通过从LTL规格和测试场景合成FSM,弥合形式化规格与可执行代码之间的鸿沟,确保满足时序逻辑约束。
- 通过涉及众筹、盲拍和许可合约的用例研究,证明该方法的可行性和实用性。
- 为未来将合成技术与源码级验证及Gas感知属性建模在智能合约中的集成奠定基础。
提出的方法
- 该方法将智能合约建模为扩展有限状态机(EFSM),其中输入事件对应合约方法,输出动作表示方法的实现。
- 形式化规格以线性时序逻辑(LTL)表达,捕捉期望的行为属性,如不变性、安全性和活锁条件。
- 结合LTL公式与测试场景,引导生成正确性可保证的FSM模型,确保行为一致性。
- 合成后的FSM通过自定义代码生成工具(fsmc)编译为可执行的Solidity代码,支持单个事件对应多个转移,优于现有工具(如VeriSolid)。
- 该方法利用EFSM-tools进行FSM合成,并集成时序逻辑验证,确保生成的合约满足指定的安全性和活锁属性。
- 该框架支持扩展至多合约系统,并可与源码级验证技术结合,以增强可信度。
实验结果
研究问题
- RQ1基于LTL的程序合成能否有效生成具备形式化行为保证的正确性可保证的智能合约?
- RQ2有限状态机合成在多大程度上能够建模现实世界智能合约(如众筹和拍卖系统)的控制流?
- RQ3如何将测试场景与LTL规格结合,以提升合成FSM模型的精度与实用性?
- RQ4LTL在表达复杂智能合约属性方面存在哪些局限性?在实践中如何缓解这些局限?
- RQ5该合成流程能否扩展以整合链上关注点(如Gas成本和代币转账)的形式化规格?
主要发现
- 所提出的方法成功为三种不同智能合约用例(众筹、盲拍和许可合约)生成了FSM模型,所有模型均通过形式化LTL规格验证。
- 每个用例的合成过程均在数秒内完成,尽管通用程序合成在理论上不可判定,但仍展现出实际效率。
- 生成的Solidity代码在给定LTL属性下具备正确性可保证,包括不变性如“noRemove”以及活锁条件如“donate”最终导致批准。
- 自定义工具fsmc支持单个事件对应多个转移,克服了现有工具(如VeriSolid)的关键限制,促进了可靠代码生成。
- 该方法证明了结合LTL的FSM合成在智能合约中的可行性,为自动化、形式化验证的合约部署提供了路径。
- 尽管LTL在表达某些属性(如“φ可无限次发生,而ψ尚未发生”)时表达能力有限,但通过使用足够长的测试场景覆盖所有FSM转移,该局限性在实践中得到缓解。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。