-
Notifications
You must be signed in to change notification settings - Fork 20
/
Voting.spec
43 lines (34 loc) · 1.21 KB
/
Voting.spec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* # Simple voting invariant example
*
* A simple invariant example. Additionally there are two rules, one is a correct
* translation of the invariant to a rule, and the other is a wrong translation.
*/
methods
{
function votesInFavor() external returns (uint256) envfree;
function votesAgainst() external returns (uint256) envfree;
function totalVotes() external returns (uint256) envfree;
}
/// @title Sum of voter in favor and against equals total number of voted
invariant sumResultsEqualsTotalVotes()
votesInFavor() + votesAgainst() == to_mathint(totalVotes());
/// @title This rule is a correct translation of the invariant
rule sumResultsEqualsTotalVotesAsRule(method f) {
// Precondition
require votesInFavor() + votesAgainst() == to_mathint(totalVotes());
env e;
calldataarg args;
f(e, args);
assert (
votesInFavor() + votesAgainst() == to_mathint(totalVotes()),
"Sum of votes should equal total votes"
);
}
/// @title This rule is a wrong translation of the invariant
rule sumResultsEqualsTotalVotesWrong() {
assert (
votesInFavor() + votesAgainst() == to_mathint(totalVotes()),
"Sum of votes should equal total votes"
);
}