11methods {
2- function doTransfer (address , address , address , uint256 ) external envfree ;
2+ function doTransfer (address , address , uint256 ) external envfree ;
3+ function doTransferFrom (address , address , address , uint256 ) external envfree ;
34 function getBalance (address , address ) external returns (uint256 ) envfree ;
5+ function getAllowance (address , address , address ) external returns (uint256 ) envfree ;
46 function getTotalSupply (address ) external returns (uint256 ) envfree ;
57
8+ function _ .transfer (address , uint256 ) external = > DISPATCHER (true );
69 function _ .transferFrom (address , address , uint256 ) external = > DISPATCHER (true );
710 function _ .balanceOf (address ) external = > DISPATCHER (true );
11+ function _ .allowance (address , address ) external = > DISPATCHER (true );
812 function _ .totalSupply () external = > DISPATCHER (true );
913}
1014
@@ -22,16 +26,49 @@ function summarySafeTransferFrom(address token, address from, address to, uint25
2226 }
2327}
2428
25- rule checkTransfer (address token , address from , address to , uint256 amount ) {
26- require from == currentContract | | to == currentContract ;
29+ rule checkTransferFromSummary (address token , address from , uint256 amount ) {
30+ mathint initialBalance = getBalance (token , currentContract );
31+ require from != currentContract = > initialBalance + getBalance (token , from ) <= to_mathint (getTotalSupply (token ));
32+
33+ doTransferFrom (token , from , currentContract , amount );
34+ mathint finalBalance = getBalance (token , currentContract );
2735
28- require from != to = > getBalance (token , from ) + getBalance (token , to ) <= to_mathint (getTotalSupply (token ));
36+ require myBalances [token ] == initialBalance ;
37+ summarySafeTransferFrom (token , from , currentContract , amount );
38+ assert myBalances [token ] == finalBalance ;
39+ }
2940
41+ rule checkTransferSummary (address token , address to , uint256 amount ) {
3042 mathint initialBalance = getBalance (token , currentContract );
31- doTransfer (token , from , to , amount );
43+ require to != currentContract = > initialBalance + getBalance (token , to ) <= to_mathint (getTotalSupply (token ));
44+
45+ doTransfer (token , to , amount );
3246 mathint finalBalance = getBalance (token , currentContract );
3347
3448 require myBalances [token ] == initialBalance ;
35- summarySafeTransferFrom (token , from , to , amount );
49+ summarySafeTransferFrom (token , currentContract , to , amount );
3650 assert myBalances [token ] == finalBalance ;
3751}
52+
53+ rule transferRevertCondition (address token , address to , uint256 amount ) {
54+ uint256 initialBalance = getBalance (token , currentContract );
55+ uint256 toInitialBalance = getBalance (token , to );
56+ require to != currentContract = > initialBalance + toInitialBalance <= to_mathint (getTotalSupply (token ));
57+ require currentContract != 0 & & to != 0 ;
58+
59+ doTransfer @withrevert (token , to , amount );
60+
61+ assert lastReverted == (initialBalance < amount );
62+ }
63+
64+ rule transferFromRevertCondition (address token , address from , address to , uint256 amount ) {
65+ uint256 initialBalance = getBalance (token , from );
66+ uint256 toInitialBalance = getBalance (token , to );
67+ uint256 allowance = getAllowance (token , from , currentContract );
68+ require to != from = > initialBalance + toInitialBalance <= to_mathint (getTotalSupply (token ));
69+ require from != 0 & & to != 0 ;
70+
71+ doTransferFrom @withrevert (token , from , to , amount );
72+
73+ assert lastReverted == (initialBalance < amount ) | | allowance < amount ;
74+ }
0 commit comments