|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | + |
| 3 | +using Util as Util; |
| 4 | + |
| 5 | +methods { |
| 6 | + function extSloads(bytes32[]) external returns (bytes32[]) => NONDET DELETE; |
| 7 | + |
| 8 | + function lastUpdate(MorphoHarness.Id) external returns (uint256) envfree; |
| 9 | + function borrowShares(MorphoHarness.Id, address) external returns (uint256) envfree; |
| 10 | + function collateral(MorphoHarness.Id, address) external returns (uint256) envfree; |
| 11 | + function totalBorrowShares(MorphoHarness.Id) external returns (uint256) envfree; |
| 12 | + function totalBorrowAssets(MorphoHarness.Id) external returns (uint256) envfree; |
| 13 | + function virtualTotalBorrowAssets(MorphoHarness.Id) external returns uint256 envfree; |
| 14 | + function virtualTotalBorrowShares(MorphoHarness.Id) external returns uint256 envfree; |
| 15 | + |
| 16 | + function Util.libId(MorphoHarness.MarketParams) external returns (MorphoHarness.Id) envfree; |
| 17 | + function Util.lif(uint256) external returns (uint256) envfree; |
| 18 | + function Util.oraclePriceScale() external returns (uint256) envfree; |
| 19 | + function Util.wad() external returns (uint256) envfree; |
| 20 | + |
| 21 | + function Morpho._isHealthy(MorphoHarness.MarketParams memory, MorphoHarness.Id,address) internal returns (bool) => NONDET; |
| 22 | + function Morpho._accrueInterest(MorphoHarness.MarketParams memory, MorphoHarness.Id) internal => NONDET; |
| 23 | + |
| 24 | + function _.price() external => constantPrice expect uint256; |
| 25 | +} |
| 26 | + |
| 27 | +persistent ghost uint256 constantPrice; |
| 28 | + |
| 29 | +// Check that for a position with LTV < 1 / LIF, its health improves after a liquidation. |
| 30 | +rule liquidateImprovePosition(env e, MorphoHarness.MarketParams marketParams, address borrower, uint256 seizedAssetsInput, uint256 repaidSharesInput, bytes data) { |
| 31 | + // Assume no callback. |
| 32 | + require data.length == 0; |
| 33 | + |
| 34 | + MorphoHarness.Id id = Util.libId(marketParams); |
| 35 | + |
| 36 | + // We place ourselves at the last block for getting the following variables. |
| 37 | + require lastUpdate(id) == e.block.timestamp; |
| 38 | + |
| 39 | + uint256 borrowerShares = borrowShares(id, borrower); |
| 40 | + // Safe require because of the sumBorrowSharesCorrect invariant. |
| 41 | + require borrowerShares <= totalBorrowShares(id); |
| 42 | + |
| 43 | + uint256 borrowerCollateral = collateral(id, borrower); |
| 44 | + uint256 lif = Util.lif(marketParams.lltv); |
| 45 | + uint256 virtualTotalAssets = virtualTotalBorrowAssets(id); |
| 46 | + uint256 virtualTotalShares = virtualTotalBorrowShares(id); |
| 47 | + |
| 48 | + // Let borrowerAssets = borrowerShares * virtualTotalAssets / virtualTotalShares |
| 49 | + // and borrowerCollateralQuoted = borrowerCollateral * constantPrice / Util.oraclePriceScale() |
| 50 | + // then the following line is the assumption borrowerAssets / borrowerCollateralQuoted < 1 / LIF. |
| 51 | + require borrowerCollateral * constantPrice * virtualTotalShares * Util.wad() > borrowerShares * Util.oraclePriceScale() * virtualTotalAssets * lif; |
| 52 | + |
| 53 | + uint256 seizedAssets; |
| 54 | + (seizedAssets, _) = liquidate(e, marketParams, borrower, seizedAssetsInput, repaidSharesInput, data); |
| 55 | + |
| 56 | + uint256 newBorrowerShares = borrowShares(id, borrower); |
| 57 | + uint256 newBorrowerCollateral = collateral(id, borrower); |
| 58 | + uint256 repaidShares = assert_uint256(borrowerShares - newBorrowerShares); |
| 59 | + uint256 newVirtualTotalAssets = virtualTotalBorrowAssets(id); |
| 60 | + uint256 newVirtualTotalShares = virtualTotalBorrowShares(id); |
| 61 | + |
| 62 | + // Hint for the prover to show that there is no bad debt realization. |
| 63 | + assert newBorrowerCollateral != 0; |
| 64 | + // Hint for the prover about the ratio used to close the position. |
| 65 | + assert repaidShares * borrowerCollateral >= seizedAssets * borrowerShares; |
| 66 | + // Prove that the ratio of shares of debt over collateral is smaller after the liquidation. |
| 67 | + assert borrowerShares * newBorrowerCollateral >= newBorrowerShares * borrowerCollateral; |
| 68 | + // Prove that the value of borrow shares is smaller after the liquidation. |
| 69 | + // Note that this is only shown for the case where there are still borrow positions on the markets. |
| 70 | + assert totalBorrowAssets(id) > 0 => newVirtualTotalShares * virtualTotalAssets >= newVirtualTotalAssets * virtualTotalShares; |
| 71 | +} |
0 commit comments