arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2109.06557cs.PLcs.SE
收藏

面向对象编程中类不变式的概念

The concept of class invariant in object-oriented programming

Bertrand Meyer, Alisa Arkadova, Alexander Kogtenkov

AI总结:

本文提出一种面向对象程序验证的类不变式证明规则,系统解决回调、隐秘访问和引用泄漏三大难题,并能处理文献中的挑战性示例。

摘要:

类不变式——即对给定类型的对象进行每一次操作时所保持的一致性约束——是构建、理解和验证面向对象程序的基础。然而,在验证方面,它们带来了困难,至今尚未得到普遍接受的解决方案。本文引入了一条证明规则,旨在解决这些问题,并使验证工具能够从不变式中受益。该规则澄清了不变式的概念,并识别出三个相关问题:回调、隐秘访问和引用泄漏。例如,2016年以太坊DAO漏洞导致5000万美元被盗,就是由于回调使某个不变式失效所致。讨论从一个简化的计算模型和相应的证明规则开始,并证明了其可靠性。随后逐一移除三个简化假设,每移除一个假设就引出三个问题之一,并导致对证明规则进行相应的调整。最终版本的规则能够处理棘手的示例,包括文献中列出的“挑战性问题”。

英文摘要:

Class invariants -- consistency constraints preserved by every operation on objects of a given type -- are fundamental to building, understanding and verifying object-oriented programs. For verification, however, they raise difficulties, which have not yet received a generally accepted solution. The present work introduces a proof rule meant to address these issues and allow verification tools to benefit from invariants. It clarifies the notion of invariant and identifies the three associated problems: callbacks, furtive access and reference leak. As an example, the 2016 Ethereum DAO bug, in which $50 million were stolen, resulted from a callback invalidating an invariant. The discussion starts with a simplified model of computation and an associated proof rule, demonstrating its soundness. It then removes one by one the three simplifying assumptions, each removal raising one of the three issues, and leading to a corresponding adaptation to the proof rule. The final version of the rule can tackle tricky examples, including "challenge problems" listed in the literature.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑