/
WithEnv.spec
48 lines (41 loc) · 1.4 KB
/
WithEnv.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
44
45
46
47
/**
Example for ghost summary using `with env`.
*/
methods {
// Summarization by a ghost.
// This summarization makes the result of balanceOf deterministic. For the same user and timestamp
// balanceOf is the same.
function balanceOf(address user) internal returns (uint256) with (env e) =>
discount_ghost[user][e.block.timestamp];
}
ghost mapping(address => mapping (uint256 => uint256)) discount_ghost;
ghost mapping(uint256 => uint256) index_ghost;
/**
* Query index_ghost for the index value at the input timestamp
**/
function indexAtTimestamp(uint256 timestamp) returns uint256 {
return index_ghost[timestamp];
}
/**
* Query discount_ghost for the [user]'s balance of discount token at [timestamp]
**/
function balanceOfDiscountTokenAtTimestamp(address user, uint256 timestamp) returns uint256 {
return discount_ghost[user][timestamp];
}
/**
* @title proves that the user's balance of debt token (as reported by GhoVariableDebtToken::balanceOf) can't increase by calling any external non-mint function.
**/
rule nonMintFunctionCantIncreaseBalance(method f) {
address user;
uint256 ts1;
uint256 ts2;
env e;
require(e.block.timestamp == ts2);
require(ts2 >= ts1);
uint256 balanceBeforeOp = callBalanceOf(e, user);
calldataarg args;
f(e,args);
mathint balanceAfterOp = balanceOf(e, user);
mathint allowedDiff = indexAtTimestamp(ts2) / 5;
assert(balanceAfterOp <= balanceBeforeOp + allowedDiff);
}