FormalContract
Create a contract block.
Outside of verification uses, the arguments passed to the contract are simply returned as contract results. During formal verification, the contract may act as a cutpoint by returning symbolic values for its results and using the contract body as constraint.
Within the contract body, RequireProperty and EnsureProperty can be used to describe the pre and post-conditions of the contract. During formal verification, contracts can be used to divide large formal checks into smaller pieces by first asserting some local properties hold, and then assuming those properties hold in the context of the larger proof.
Attributes
- Example
-
The following is a contract with no arguments.
FormalContract { RequireProperty(a >= 1) EnsureProperty(a + a >= 2) }The following is a contract with a single argument. It expresses the fact that the hardware implementation
(a << 3) + ais equivalent toa * 9. During formal verification, this contract is interpreted as:assert((a << 3) + a === a * 9)as a proof that the contract holds.assume(b === a * 9)on a new symbolic valuebas a simplification of other proofs.
val b = FormalContract((a << 3) + a) { b => EnsureProperty(b === a * 9) }The following is a contract with multiple arguments. It expresses the fact that a carry-save adder with
p,q, andras inputs reduces the number of sum terms fromp + q + rtoc + sbut doesn't change the sum of the terms. During formal verification, this contract is interpreted as:assert(c + s === p + q + r)as a proof that the carry-save adder indeed compresses the three terms down to only two terms which have the same sum.assume(u + v === p + q + r)on new symbolic valuesuandvas a simplification of other proofs.
val s = p ^ q ^ r val c = (p & q | (p ^ q) & r) << 1 val (u, v) = FormalContract(c, s) { case (u, v) => EnsureProperty(u + v === p + q + r) } - Source
- FormalContract.scala
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
FormalContract.type