一句话:提出抽象类型传播与检查系统,将智能合约业务逻辑建模为银行式原语,以自动发现记账错误。
智能合约中的记账错误常位于核心业务逻辑,具有合约特定性,现有自动化工具难以发现,人工审计也因需理解业务模型而困难。本文观察到大量业务逻辑可由存款、取款、贷款、还款等银行式原语或其组合建模,这些操作的性质可被抽象类型系统刻画。为此,作者提出一种新的类型传播与检查系统,用抽象类型建模代币单位、缩放因子和金融类型等高层信息,以识别记账错误。在29个真实项目的57个已知记账错误上评估,58%的错误是类型错误,系统捕获其中87.9%;在近期审计竞赛项目中还发现6个零日记账错误,其中4个导致直接资金损失。
Bugs in smart contracts may have devastating effects as they tend to cause financial loss. According to a recent study, accounting bugs are the most common kind of bugs in smart contracts that are beyond automated tools during pre-deployment auditing. The reason lies in that these bugs are usually in the core business logic and hence contract-specific. They are analogous to functional bugs in traditional software, which are largely beyond automated bug finding tools whose effectiveness hinges on uniform and machine checkable characteristics of bugs. It was also reported that accounting bugs are the second-most difficult to find through manual auditing, due to the need of understanding underlying business models. We observe that a large part of business logic in smart contracts can be modeled by a few primitive operations like those in a bank, such as deposit, withdraw, loan, and pay-off, or by their combinations. The properties of these operations can be clearly defined and checked by an abstract type system that models high-order information such as token units, scaling factors, and financial types. We hence develop a novel type propagation and checking system with the aim of identifying accounting bugs. Our evaluation on a large set of 57 existing accounting bugs in 29 real-world projects shows that 58% of the accounting bugs are type errors. Our system catches 87.9% of these type errors. In addition, applying our technique to auditing a large project in a very recent auditing contest has yielded the identification of 6 zero-day accounting bugs with 4 leading to direct fund loss.