Skip to content

Commit 2a0028f

Browse files
authored
Merge pull request #609 from morpho-org/certora/mutant-10
[Certora] mutant 10
2 parents 4b5116a + 35eb09a commit 2a0028f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

certora/specs/Liveness.spec

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,41 @@ rule withdrawCollateralChangesTokensAndBalance(env e, MorphoInternalAccess.Marke
219219
assert balanceAfter == balanceBefore - assets;
220220
}
221221

222+
// Check that tokens are properly accounted following a liquidate.
223+
rule liquidateChangesTokens(env e, MorphoInternalAccess.MarketParams marketParams, address borrower, uint256 seized, uint256 repaidShares, bytes data) {
224+
MorphoInternalAccess.Id id = libId(marketParams);
225+
226+
// Safe require because Morpho cannot call such functions by itself.
227+
require currentContract != e.msg.sender;
228+
// Assumption to simplify the balance specification in the rest of this rule.
229+
require marketParams.loanToken != marketParams.collateralToken;
230+
// Assumption to ensure that no interest is accumulated.
231+
require lastUpdate(id) == e.block.timestamp;
232+
233+
mathint collateralBefore = collateral(id, borrower);
234+
mathint balanceLoanBefore = myBalances[marketParams.loanToken];
235+
mathint balanceCollateralBefore = myBalances[marketParams.collateralToken];
236+
mathint liquidityBefore = totalSupplyAssets(id) - totalBorrowAssets(id);
237+
238+
mathint borrowLoanAssetsBefore = totalBorrowAssets(id);
239+
240+
uint256 seizedAssets;
241+
uint256 repaidAssets;
242+
seizedAssets, repaidAssets = liquidate(e, marketParams, borrower, seized, repaidShares, data);
243+
244+
mathint collateralAfter = collateral(id, borrower);
245+
mathint balanceLoanAfter = myBalances[marketParams.loanToken];
246+
mathint balanceCollateralAfter = myBalances[marketParams.collateralToken];
247+
mathint liquidityAfter = totalSupplyAssets(id) - totalBorrowAssets(id);
248+
249+
assert seized != 0 => seizedAssets == seized;
250+
assert collateralBefore > to_mathint(seizedAssets) => collateralAfter == collateralBefore - seizedAssets;
251+
assert balanceLoanAfter == balanceLoanBefore + repaidAssets;
252+
assert balanceCollateralAfter == balanceCollateralBefore - seizedAssets;
253+
// Taking the min to handle the zeroFloorSub in the code.
254+
assert liquidityAfter == liquidityBefore + min(repaidAssets, borrowLoanAssetsBefore);
255+
}
256+
222257
// Check that one can always repay the debt in full.
223258
rule canRepayAll(env e, MorphoInternalAccess.MarketParams marketParams, uint256 shares, bytes data) {
224259
MorphoInternalAccess.Id id = libId(marketParams);

0 commit comments

Comments
 (0)