-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #304 from morpho-labs/certora/liquiditywip
[Certora] Liquidity
- Loading branch information
Showing
8 changed files
with
216 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ docs/ | |
|
||
# Certora | ||
.certora** | ||
emv-*-certora* | ||
|
||
# Hardhat | ||
/types | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/sh | ||
|
||
certoraRun \ | ||
certora/harness/MorphoHarness.sol \ | ||
--verify MorphoHarness:certora/specs/BlueRatioMath.spec \ | ||
--solc_allow_path src \ | ||
--msg "Morpho Ratio Math" \ | ||
--send_only \ | ||
"$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/sh | ||
|
||
certoraRun \ | ||
certora/harness/MorphoHarness.sol \ | ||
--verify MorphoHarness:certora/specs/BlueRatioMathSummary.spec \ | ||
--msg "Morpho Ratio Math Summary" \ | ||
"$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
methods { | ||
function totalSupply(MorphoHarness.Id) external returns uint256 envfree; | ||
function totalSupplyShares(MorphoHarness.Id) external returns uint256 envfree; | ||
function fee(MorphoHarness.Id) external returns uint256 envfree; | ||
|
||
function MathLib.mulDivDown(uint256 a, uint256 b, uint256 c) internal returns uint256 => summaryMulDivDown(a,b,c); | ||
function MathLib.mulDivUp(uint256 a, uint256 b, uint256 c) internal returns uint256 => summaryMulDivUp(a,b,c); | ||
function MathLib.wTaylorCompounded(uint256, uint256) internal returns uint256 => NONDET; | ||
|
||
function _.borrowRate(MorphoHarness.Market) external => HAVOC_ECF; | ||
} | ||
|
||
definition VIRTUAL_ASSETS() returns mathint = 1; | ||
definition VIRTUAL_SHARES() returns mathint = 10^18; | ||
definition MAX_FEE() returns mathint = 10^18 * 25/100; | ||
|
||
invariant feeInRange(MorphoHarness.Id id) | ||
to_mathint(fee(id)) <= MAX_FEE(); | ||
|
||
/* This is a simple overapproximative summary, stating that it rounds in the right direction. | ||
* The summary is checked by the specification in BlueRatioMathSummary.spec. | ||
*/ | ||
function summaryMulDivUp(uint256 x, uint256 y, uint256 d) returns uint256 { | ||
uint256 result; | ||
require result * d >= x * y; | ||
return result; | ||
} | ||
|
||
/* This is a simple overapproximative summary, stating that it rounds in the right direction. | ||
* The summary is checked by the specification in BlueRatioMathSummary.spec. | ||
*/ | ||
function summaryMulDivDown(uint256 x, uint256 y, uint256 d) returns uint256 { | ||
uint256 result; | ||
require result * d <= x * y; | ||
return result; | ||
} | ||
|
||
rule onlyLiquidateCanDecreasesRatio(method f) | ||
filtered { | ||
f -> f.selector != sig:liquidate(MorphoHarness.Market, address, uint256, bytes).selector | ||
} | ||
{ | ||
MorphoHarness.Id id; | ||
requireInvariant feeInRange(id); | ||
|
||
mathint assetsBefore = totalSupply(id) + VIRTUAL_ASSETS(); | ||
mathint sharesBefore = totalSupplyShares(id) + VIRTUAL_SHARES(); | ||
|
||
env e; | ||
calldataarg args; | ||
f(e,args); | ||
|
||
mathint assetsAfter = totalSupply(id) + VIRTUAL_ASSETS(); | ||
mathint sharesAfter = totalSupplyShares(id) + VIRTUAL_SHARES(); | ||
|
||
// check if ratio increases: assetsBefore/sharesBefore <= assetsAfter / sharesAfter; | ||
assert assetsBefore * sharesAfter <= assetsAfter * sharesBefore; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
methods { | ||
function mathLibMulDivUp(uint256, uint256, uint256) external returns uint256 envfree; | ||
function mathLibMulDivDown(uint256, uint256, uint256) external returns uint256 envfree; | ||
} | ||
|
||
/* Check the summaries required by BlueRatioMath.spec */ | ||
rule checkSummaryMulDivUp(uint256 x, uint256 y, uint256 d) { | ||
uint256 result = mathLibMulDivUp(x, y, d); | ||
assert result * d >= x * y; | ||
} | ||
|
||
rule checkSummaryMulDivDown(uint256 x, uint256 y, uint256 d) { | ||
uint256 result = mathLibMulDivDown(x, y, d); | ||
assert result * d <= x * y; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters