@@ -5,6 +5,8 @@ methods {
5
5
function supplyShares (MorphoHarness .Id , address ) external returns uint256 envfree ;
6
6
function borrowShares (MorphoHarness .Id , address ) external returns uint256 envfree ;
7
7
function collateral (MorphoHarness .Id , address ) external returns uint256 envfree ;
8
+ function totalSupplyShares (MorphoHarness .Id ) external returns uint256 envfree ;
9
+ function totalBorrowShares (MorphoHarness .Id ) external returns uint256 envfree ;
8
10
function virtualTotalSupplyAssets (MorphoHarness .Id ) external returns uint256 envfree ;
9
11
function virtualTotalSupplyShares (MorphoHarness .Id ) external returns uint256 envfree ;
10
12
function virtualTotalBorrowAssets (MorphoHarness .Id ) external returns uint256 envfree ;
@@ -32,21 +34,23 @@ function expectedBorrowAssets(MorphoHarness.Id id, address user) returns uint256
32
34
return libMulDivUp (userShares , totalBorrowAssets , totalBorrowShares );
33
35
}
34
36
35
- // Check that the assets supplied are greater than the assets owned in the end .
37
+ // Check that the assets supplied are greater than the increase in owned assets .
36
38
rule supplyAssetsAccounting (env e , MorphoHarness .MarketParams marketParams , uint256 assets , uint256 shares , address onBehalf , bytes data ) {
37
39
MorphoHarness .Id id = libId (marketParams );
38
40
39
41
// Assume no interest as it would increase the total supply assets .
40
42
require lastUpdate (id ) == e .block .timestamp ;
41
- // Assume no supply position to begin with .
42
- require supplyShares ( id , onBehalf ) == 0 ;
43
+ // Safe require because of the sumSupplySharesCorrect invariant .
44
+ require supplyShares (id , onBehalf ) <= totalSupplyShares (id );
45
+
46
+ uint256 ownedAssetsBefore = expectedSupplyAssets (id , onBehalf );
43
47
44
48
uint256 suppliedAssets ;
45
49
suppliedAssets , _ = supply (e , marketParams , assets , shares , onBehalf , data );
46
50
47
51
uint256 ownedAssets = expectedSupplyAssets (id , onBehalf );
48
52
49
- assert suppliedAssets >= ownedAssets ;
53
+ assert ownedAssetsBefore + suppliedAssets >= to_mathint ( ownedAssets ) ;
50
54
}
51
55
52
56
// Check that the assets withdrawn are less than the assets owned initially .
@@ -64,22 +68,24 @@ rule withdrawAssetsAccounting(env e, MorphoHarness.MarketParams marketParams, ui
64
68
assert withdrawnAssets <= ownedAssets ;
65
69
}
66
70
67
- // Check that the assets borrowed are less than the assets owed in the end .
71
+ // Check that the increase of owed assets are greater than the borrowed assets .
68
72
rule borrowAssetsAccounting (env e , MorphoHarness .MarketParams marketParams , uint256 shares , address onBehalf , address receiver ) {
69
73
MorphoHarness .Id id = libId (marketParams );
70
74
71
75
// Assume no interest as it would increase the total borrowed assets .
72
76
require lastUpdate (id ) == e .block .timestamp ;
73
- // Assume no outstanding debt to begin with .
74
- require borrowShares ( id , onBehalf ) == 0 ;
77
+ // Safe require because of the sumBorrowSharesCorrect invariant .
78
+ require borrowShares (id , onBehalf ) <= totalBorrowShares (id );
79
+
80
+ uint256 owedAssetsBefore = expectedBorrowAssets (id , onBehalf );
75
81
76
82
// The borrow call is restricted to shares as input to make it easier on the prover .
77
83
uint256 borrowedAssets ;
78
84
borrowedAssets , _ = borrow (e , marketParams , 0 , shares , onBehalf , receiver );
79
85
80
86
uint256 owedAssets = expectedBorrowAssets (id , onBehalf );
81
87
82
- assert borrowedAssets <= owedAssets ;
88
+ assert owedAssetsBefore + borrowedAssets <= to_mathint ( owedAssets ) ;
83
89
}
84
90
85
91
// Check that the assets repaid are greater than the assets owed initially .
@@ -100,18 +106,17 @@ rule repayAssetsAccounting(env e, MorphoHarness.MarketParams marketParams, uint2
100
106
assert repaidAssets >= owedAssets ;
101
107
}
102
108
103
- // Check that the collateral assets supplied are greater than the assets owned in the end .
109
+ // Check that the collateral assets supplied are equal to the increase of owned assets .
104
110
rule supplyCollateralAssetsAccounting (env e , MorphoHarness .MarketParams marketParams , uint256 suppliedAssets , address onBehalf , bytes data ) {
105
111
MorphoHarness .Id id = libId (marketParams );
106
112
107
- // Assume no collateral to begin with .
108
- require collateral ( id , onBehalf ) == 0 ;
113
+ uint256 ownedAssetsBefore = collateral (id , onBehalf );
109
114
110
115
supplyCollateral (e , marketParams , suppliedAssets , onBehalf , data );
111
116
112
117
uint256 ownedAssets = collateral (id , onBehalf );
113
118
114
- assert suppliedAssets == ownedAssets ;
119
+ assert ownedAssetsBefore + suppliedAssets == to_mathint ( ownedAssets ) ;
115
120
}
116
121
117
122
// Check that the collateral assets withdrawn are less than the assets owned initially .
0 commit comments