Class invariants -- consistency constraints preserved by every operation on objects of a given type -- are fundamental to building and understanding object-oriented programs. They should also be a key help in verifying them, but turn out instead to raise major verification challenges which have prompted a significant literature with, until now, no widely accepted solution. The present work introduces a general proof rule meant to address invariant-related issues and allow verification tools benefit from invariants. It first clarifies the notion of invariant and identify the three 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 "Simple Model" and an associated proof rule, demonstrating its soundness. It then removes one by one the three assumptions of the Simple Model, each removal bringing up one of the three issues, and introduces the corresponding adaptation to the proof rule. The final version of the rule can tackle tricky examples, including "challenge problems" listed in the literature.
翻译:类别变异性 -- -- 每种操作对特定类型物体所保持的一致性限制 -- -- 对建立和理解面向目标的程序至关重要。它们也应该成为验证它们的关键帮助,但结果却提出了重大的核查挑战,这促使人们用大量文献来进行大量研究,但至今为止还没有得到广泛接受的解决办法。目前的工作引入了一个一般性的证明规则,旨在处理与异变有关的问题,使核查工具能够从异变性中受益。它首先澄清了异变性概念,并确定了三个问题:回调、偷盗访问和参考泄漏。例如,2016年Etheem DAO错误案,其中5 000万美元被盗,是因回调而导致的反弹使反向无效。讨论从“简单模型”和相关的证据规则开始,显示了其正确性。然后,它逐个删除了简单模型的三种假设,每次删除都引出三个问题中的一个,并介绍了对证据规则的相应调整。规则的最后版本可以解决棘手的例子,包括文献中列出的“挑战问题”。