@@ -5,6 +5,7 @@ using Util as Util;
5
5
methods {
6
6
function extSloads (bytes32 [ ]) external returns (bytes32 [ ]) = > NONDET DELETE ;
7
7
8
+ function market_ (MorphoLiquidateHarness .Id ) external returns (MorphoLiquidateHarness .Market ) envfree ;
8
9
function virtualTotalBorrowAssets (MorphoLiquidateHarness .Id ) external returns uint256 envfree ;
9
10
function virtualTotalBorrowShares (MorphoLiquidateHarness .Id ) external returns uint256 envfree ;
10
11
function liquidateView (MorphoLiquidateHarness .MarketParams , uint256 , uint256 , uint256 ) external returns (uint256 , uint256 , uint256 , uint256 ) envfree ;
@@ -18,20 +19,25 @@ methods {
18
19
}
19
20
20
21
function summaryMulDivUp (uint256 x , uint256 y , uint256 d ) returns uint256 {
21
- // Safe require because the reference implementation would revert .
22
+ // Todo : why is this require ok ?
22
23
return require_uint256 ((x * y + (d - 1 )) / d );
23
24
}
24
25
25
26
function summaryMulDivDown (uint256 x , uint256 y , uint256 d ) returns uint256 {
26
- // Safe require because the reference implementation would revert .
27
+ // Todo : why is this require ok ?
27
28
return require_uint256 ((x * y ) / d );
28
29
}
29
30
31
+ function wDivDown (uint256 x , uint256 y ) returns uint256 {
32
+ return summaryMulDivDown (x , Util .wad (), y );
33
+ }
34
+
30
35
rule liquidateImprovePosition (MorphoLiquidateHarness .MarketParams marketParams , uint256 seizedAssetsInput , uint256 repaidSharesInput ) {
31
36
MorphoLiquidateHarness .Id id = Util .libId (marketParams );
32
37
33
38
// TODO : use a fixed price oracle instead of passing it to liquidateView .
34
39
uint256 collateralPrice ;
40
+ require collateralPrice > 0 ;
35
41
36
42
// TODO : take those directly from the borrower , and manage accrue interest .
37
43
uint256 borrowerShares ;
@@ -41,20 +47,22 @@ rule liquidateImprovePosition(MorphoLiquidateHarness.MarketParams marketParams,
41
47
uint256 borrowerAssets = summaryMulDivUp (borrowerShares , virtualTotalBorrowAssets (id ), virtualTotalBorrowShares (id ));
42
48
require borrowerAssets > 0 ;
43
49
44
- require seizedAssetsInput > 0 & & repaidSharesInput == 0 ;
50
+ require ( seizedAssetsInput > 0 & & repaidSharesInput == 0 ) | | ( seizedAssetsInput == 0 & & repaidSharesInput > 0 ) ;
45
51
46
52
uint256 seizedAssets ;
47
53
uint256 repaidShares ;
48
54
uint256 repaidAssets ;
49
- require repaidAssets > 0 ;
50
55
uint256 lif ;
51
56
(seizedAssets , repaidShares , repaidAssets , lif ) = liquidateView (marketParams , seizedAssetsInput , repaidSharesInput , collateralPrice );
57
+ require repaidAssets > 0 ;
52
58
53
- require summaryMulDivUp (borrowerCollateral , collateralPrice , Util .oraclePriceScale ()) >= summaryMulDivUp (lif , borrowerAssets , Util .wad ());
54
- assert summaryMulDivDown (summaryMulDivUp (borrowerCollateral , collateralPrice , Util .oraclePriceScale ()), Util .wad (), borrowerAssets ) >= lif ;
59
+ uint256 borrowerCollateralQuoted = summaryMulDivUp (borrowerCollateral , collateralPrice , Util .oraclePriceScale ());
60
+ require borrowerCollateralQuoted >= summaryMulDivUp (lif , borrowerAssets , Util .wad ());
61
+ assert wDivDown (borrowerCollateralQuoted , borrowerAssets ) >= lif ;
55
62
56
- assert summaryMulDivDown (lif , repaidAssets , Util .wad ()) >= summaryMulDivUp (seizedAssets , collateralPrice , Util .oraclePriceScale ());
57
- assert lif >= summaryMulDivDown (summaryMulDivUp (seizedAssets , collateralPrice , Util .oraclePriceScale ()), Util .wad (), repaidAssets );
63
+ uint256 seizedCollateralQuoted = summaryMulDivUp (seizedAssets , collateralPrice , Util .oraclePriceScale ());
64
+ assert summaryMulDivDown (lif , repaidAssets , Util .wad ()) >= seizedCollateralQuoted ;
65
+ assert lif >= wDivDown (seizedCollateralQuoted , repaidAssets );
58
66
59
67
// assert repaidShares * borrowerCollateral > seizedAssets * borrowerShares ;
60
68
}
0 commit comments