一句话:提出 Solidity 语言扩展 ConSol,支持将行为契约附加到一等地址并在调用时监控违约,实现模块化的智能合约规约与验证。
智能合约在去中心化金融中广泛使用,其可靠性至关重要,但静态检查合约的丰富属性十分困难,动态验证因此更具实用前景。现有动态验证方法未能让程序员清晰表达组件之间的接口,尤其难以刻画代表不透明合约实例的地址行为。本文主张以“契约式设计”补充智能合约开发,并设计 Solidity 语言扩展 ConSol,提供模块化的规约与监控系统,同时覆盖功能性行为与潜在的地址行为。其核心能力是将规约附加到一等地址上,并在调用这些地址时监控违约。作者用 20 个真实案例评估 ConSol,展示其在表达关键条件与阻止攻击方面的有效性,并与手工插入断言修复的程序比较 gas 开销,表明仅引入边际开销。通过行为契约分离规约与实现,ConSol 帮助程序员编写更健壮、可读的智能合约。
Ensuring the reliability of smart contracts is of vital importance due to the wide adoption of smart contract programs in decentralized financial applications. However, statically checking many rich properties of smart contract programs can be challenging. On the other hand, dynamic validation approaches have shown promise for widespread adoption in practice. Nevertheless, as part of the programming environment for smart contracts, existing dynamic validation approaches have not provided programmers with a notion to clearly articulate the interface between components, especially for addresses representing opaque contract instances. We argue that the “design-by-contract” approach should complement the development of smart contract programs. Unfortunately, there is limited linguistic support for it in existing smart contract languages. In this paper, we design a Solidity language extension, ConSol, that supports behavioral contracts. ConSol provides programmers with a modular specification and monitoring system for both functional and latent address behaviors. The key capability of ConSol is to attach specifications to first-class addresses and monitor violations when invoking these addresses. We evaluate ConSol using 20 real-world cases, demonstrating its effectiveness in expressing critical conditions and preventing attacks. Additionally, we assess ConSol’s efficiency and compare gas consumption with programs fixed with manually inserted assertions, showing that our approach introduces only marginal gas overhead. By separating specifications and implementations using behavioral contracts, ConSol assists programmers in writing more robust and readable smart contracts.
@article{WeiXZYZ24,
title = {Consolidating Smart Contracts with Behavioral Contracts},
author = {Guannan Wei and Danning Xie and Wuqi Zhang and Yongwei Yuan and Zhuo Zhang},
journal = {Proceedings of the ACM on Programming Languages},
volume = {8},
number = {PLDI},
year = {2024},
doi = {10.1145/3656416}
}