-
Notifications
You must be signed in to change notification settings - Fork 0
/
lottery.dfy
41 lines (32 loc) · 1.01 KB
/
lottery.dfy
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
include "contract.dfy"
class Lottery extends address {
var manager: address
var players: seq<address>
constructor()
ensures manager == this.address
predicate isManager(caller: address)
ensures isManager() ==> msg.sender == manager
{
manager == msg.sender == manager
}
method enterPlayerToLottery(player: address)
requires player.msg.value > 1
modifies this
ensures exists i :: 0 <= i < |players| && players[i] == player
ensures players == old(players[players:player])
{
players := players + [player];
}
function random(): int
ensures 0 <= random() < |players|
method pickWinner()
requires |players| > 1
requires isManager()
modifies this
ensures |players| == 0
ensures this.balance == 0
{
var index := random();
players[index].transfer(this.balance);
}
}