Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Certora] Added borrow less supply invariant #294

Merged
merged 1 commit into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions certora/harness/MorphoHarness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import "../../src/Morpho.sol";
import "../../src/libraries/SharesMathLib.sol";

contract MorphoHarness is Morpho {
using MarketLib for Market;

constructor(address newOwner) Morpho(newOwner) {}

function getVirtualTotalSupply(Id id) external view returns (uint256) {
Expand All @@ -14,15 +16,7 @@ contract MorphoHarness is Morpho {
return totalSupplyShares[id] + SharesMathLib.VIRTUAL_SHARES;
}

function getTotalSupply(Id id) external view returns (uint256) {
return totalSupply[id];
}

function getTotalSupplyShares(Id id) external view returns (uint256) {
return totalSupplyShares[id];
}

function getTotalBorrowShares(Id id) external view returns (uint256) {
return totalBorrowShares[id];
function getMarketId(Market memory market) external pure returns (Id) {
return market.id();
}
}
34 changes: 12 additions & 22 deletions certora/specs/Blue.spec
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ methods {
function supply(MorphoHarness.Market, uint256, uint256, address, bytes) external;
function getVirtualTotalSupply(MorphoHarness.Id) external returns uint256 envfree;
function getVirtualTotalSupplyShares(MorphoHarness.Id) external returns uint256 envfree;
function getTotalSupply(MorphoHarness.Id) external returns uint256 envfree;
function getTotalSupplyShares(MorphoHarness.Id) external returns uint256 envfree;
function getTotalBorrowShares(MorphoHarness.Id) external returns uint256 envfree;
function totalSupply(MorphoHarness.Id) external returns uint256 envfree;
function totalBorrow(MorphoHarness.Id) external returns uint256 envfree;
function totalSupplyShares(MorphoHarness.Id) external returns uint256 envfree;
function totalBorrowShares(MorphoHarness.Id) external returns uint256 envfree;

function _.borrowRate(MorphoHarness.Market) external => DISPATCHER(true);

// function _.safeTransfer(address, uint256) internal => DISPATCHER(true);
// function _.safeTransferFrom(address, address, uint256) internal => DISPATCHER(true);

}

ghost mapping(MorphoHarness.Id => mathint) sumSupplyShares
Expand Down Expand Up @@ -37,28 +39,16 @@ hook Sstore collateral[KEY MorphoHarness.Id id][KEY address owner] uint256 newAm
sumCollateral[id] = sumCollateral[id] - oldAmount + newAmount;
}

definition VIRTUAL_ASSETS() returns mathint = 1;
definition VIRTUAL_SHARES() returns mathint = 1000000000000000000;

invariant sumSupplySharesCorrect(MorphoHarness.Id id)
to_mathint(getTotalSupplyShares(id)) == sumSupplyShares[id];
to_mathint(totalSupplyShares(id)) == sumSupplyShares[id];
invariant sumBorrowSharesCorrect(MorphoHarness.Id id)
to_mathint(getTotalBorrowShares(id)) == sumBorrowShares[id];

rule whatDoesNotIncreaseRatio(MorphoHarness.Id id) {
mathint assetsBefore = getVirtualTotalSupply(id);
mathint sharesBefore = getVirtualTotalSupplyShares(id);

method f;
env e;
calldataarg args;

f(e,args);

mathint assetsAfter = getVirtualTotalSupply(id);
mathint sharesAfter = getVirtualTotalSupplyShares(id);

// check if assetsBefore/shareBefore <= assetsAfter / sharesAfter;
assert assetsBefore * sharesAfter <= assetsAfter * sharesBefore;
}
to_mathint(totalBorrowShares(id)) == sumBorrowShares[id];

invariant borrowLessSupply(MorphoHarness.Id id)
totalBorrow(id) <= totalSupply(id);

rule supplyRevertZero(MorphoHarness.Market market) {
env e;
Expand Down