-
Notifications
You must be signed in to change notification settings - Fork 95
[Certora] Liquidity #304
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
Merged
Merged
[Certora] Liquidity #304
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
789917f
Optimization for ratio computation
jhoenicke dc7f47b
Merge branch 'certora/dev' into certora/jochen
jhoenicke a0a1a2b
Fix merge
jhoenicke 97bd8e9
Merge remote-tracking branch 'origin/main' into certora/tmp
jhoenicke a486eaf
Proof for liquidity invariant
jhoenicke c845c36
Merge remote-tracking branch 'origin/certora/dev' into certora/liquid…
jhoenicke 294c1f5
Use invariant for idToBorrowable and Collateral
jhoenicke 6161ffd
Ignore certora prover directories
jhoenicke 41d57c5
Fix formatting
jhoenicke 7f41589
Clean-ups as suggested by QGarchery
jhoenicke 1a81dfd
Remove unused method declaration
jhoenicke c38a3c0
Update comment referencing new file
jhoenicke d3d8086
Update certora/specs/BlueRatioMathSummary.spec
jhoenicke 4c4e6cf
Update certora/specs/BlueRatioMathSummary.spec
jhoenicke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.