-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTBPoolNoRevert.sol
102 lines (83 loc) · 4.2 KB
/
TBPoolNoRevert.sol
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import "../crytic-export/flattening/BPool.sol";
import "./MyToken.sol";
import "./CryticInterface.sol";
contract TBPoolNoRevert is CryticInterface, BPool {
constructor() public { // out-of-gas?
// Create a new token with initial_token_balance as total supply.
// After the token is created, each user defined in CryticInterface
// (crytic_owner, crytic_user and crytic_attacker) receives 1/3 of
// the initial balance
MyToken t;
t = new MyToken(initial_token_balance, address(this));
bind(address(t), MIN_BALANCE, MIN_WEIGHT);
}
// initial token balances is the max amount for uint256
uint internal initial_token_balance = uint(-1);
// this function allows to create as many tokens as needed
function create_and_bind(uint balance, uint denorm) public returns (address) {
// Create a new token with initial_token_balance as total supply.
// After the token is created, each user defined in CryticInterface
// (crytic_owner, crytic_user and crytic_attacker) receives 1/3 of
// the initial balance
MyToken bt = new MyToken(initial_token_balance, address(this));
bt.approve(address(this), initial_token_balance);
// Bind the token with the provided parameters
bind(address(bt), balance, denorm);
// Save the balance and denorm values used. These are used in the rebind checks
return address(bt);
}
function echidna_getSpotPrice_no_revert() public returns (bool) {
address[] memory current_tokens = this.getCurrentTokens();
for (uint i = 0; i < current_tokens.length; i++) {
for (uint j = 0; j < current_tokens.length; j++) {
// getSpotPrice should not revert for any pair of tokens
this.getSpotPrice(address(current_tokens[i]), address(current_tokens[j]));
}
}
return true;
}
function echidna_getSpotPriceSansFee_no_revert() public returns (bool) {
address[] memory current_tokens = this.getCurrentTokens();
for (uint i = 0; i < current_tokens.length; i++) {
for (uint j = 0; j < current_tokens.length; j++) {
// getSpotPriceSansFee should not revert for any pair of tokens
this.getSpotPriceSansFee(address(current_tokens[i]), address(current_tokens[j]));
}
}
return true;
}
function echidna_swapExactAmountIn_no_revert() public returns (bool) {
// if the controller was changed, return true
if (this.getController() != crytic_owner)
return true;
// if the pool was not finalized, enable the public swap
if (!this.isFinalized())
setPublicSwap(true);
address[] memory current_tokens = this.getCurrentTokens();
for (uint i = 0; i < current_tokens.length; i++) {
// a small balance is 1% of the total balance available
uint small_balance = this.getBalance(current_tokens[i])/100;
// if the user has a small balance, it should be able to swap it
if (IERC20(current_tokens[i]).balanceOf(crytic_owner) > small_balance)
swapExactAmountIn(address(current_tokens[i]), small_balance, address(current_tokens[i]), 0, uint(-1));
}
return true;
}
function echidna_swapExactAmountOut_no_revert() public returns (bool) {
// if the controller was changed, return true
if (this.getController() != crytic_owner)
return true;
// if the pool was not finalized, enable the public swap
if (!this.isFinalized())
setPublicSwap(true);
address[] memory current_tokens = this.getCurrentTokens();
for (uint i = 0; i < current_tokens.length; i++) {
// a small balance is 1% of the total balance available
uint small_balance = this.getBalance(current_tokens[i])/100;
// if the user has a small balance, it should be able to swap it
if (IERC20(current_tokens[i]).balanceOf(crytic_owner) > small_balance)
swapExactAmountOut(address(current_tokens[i]), uint(-1), address(current_tokens[i]), small_balance, uint(-1));
}
return true;
}
}