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] Equivalent input of liquidate #659

Merged
merged 15 commits into from
Feb 20, 2024
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
4 changes: 2 additions & 2 deletions certora/confs/AccrueInterest.conf
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"files": [
"certora/harness/MorphoHarness.sol"
"certora/harness/MorphoHarness.sol",
],
"verify": "MorphoHarness:certora/specs/AccrueInterest.spec",
"prover_args": [
"-depth 3",
"-smt_hashingScheme plaininjectivity",
"-mediumTimeout 30"
"-mediumTimeout 30",
],
"rule_sanity": "basic",
"server": "production",
Expand Down
2 changes: 1 addition & 1 deletion certora/confs/AssetsAccounting.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"files": [
"certora/harness/MorphoHarness.sol"
"certora/harness/MorphoHarness.sol",
],
"verify": "MorphoHarness:certora/specs/AssetsAccounting.spec",
"rule_sanity": "basic",
Expand Down
2 changes: 1 addition & 1 deletion certora/confs/ConsistentState.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"files": [
"certora/harness/MorphoHarness.sol"
"certora/harness/MorphoHarness.sol",
],
"verify": "MorphoHarness:certora/specs/ConsistentState.spec",
"rule_sanity": "basic",
Expand Down
5 changes: 3 additions & 2 deletions certora/confs/ExactMath.conf
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"files": [
"certora/harness/MorphoHarness.sol"
"certora/harness/MorphoHarness.sol",
],
"verify": "MorphoHarness:certora/specs/ExactMath.spec",
"rule_sanity": "basic",
"prover_args": [
"-depth 3",
"-smt_hashingScheme plaininjectivity",
"-mediumTimeout 30"
"-mediumTimeout 30",
],
"server": "production",
"msg": "Morpho Blue Exact Math"
Expand Down
2 changes: 1 addition & 1 deletion certora/confs/Health.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"verify": "MorphoHarness:certora/specs/Health.spec",
"rule_sanity": "basic",
"prover_args": [
"-smt_hashingScheme plaininjectivity"
"-smt_hashingScheme plaininjectivity",
],
"server": "production",
"msg": "Morpho Blue Health"
Expand Down
2 changes: 1 addition & 1 deletion certora/confs/LibSummary.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"files": [
"certora/harness/MorphoHarness.sol"
"certora/harness/MorphoHarness.sol",
],
"verify": "MorphoHarness:certora/specs/LibSummary.spec",
"rule_sanity": "basic",
Expand Down
2 changes: 1 addition & 1 deletion certora/confs/Liveness.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"files": [
"certora/harness/MorphoInternalAccess.sol"
"certora/harness/MorphoInternalAccess.sol",
],
"verify": "MorphoInternalAccess:certora/specs/Liveness.spec",
"rule_sanity": "basic",
Expand Down
4 changes: 2 additions & 2 deletions certora/confs/RatioMath.conf
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"files": [
"certora/harness/MorphoHarness.sol"
"certora/harness/MorphoHarness.sol",
],
"verify": "MorphoHarness:certora/specs/RatioMath.spec",
"rule_sanity": "basic",
"prover_args": [
"-smt_hashingScheme plaininjectivity",
"-mediumTimeout 30",
"-timeout 3600"
"-timeout 3600",
],
"server": "production",
"msg": "Morpho Blue Ratio Math"
Expand Down
4 changes: 2 additions & 2 deletions certora/confs/Reentrancy.conf
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"files": [
"certora/harness/MorphoHarness.sol"
"certora/harness/MorphoHarness.sol",
],
"verify": "MorphoHarness:certora/specs/Reentrancy.spec",
"rule_sanity": "basic",
"prover_args": [
"-enableStorageSplitting false"
"-enableStorageSplitting false",
],
"server": "production",
"msg": "Morpho Blue Reentrancy"
Expand Down
2 changes: 1 addition & 1 deletion certora/confs/Reverts.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"files": [
"certora/harness/MorphoHarness.sol"
"certora/harness/MorphoHarness.sol",
],
"verify": "MorphoHarness:certora/specs/Reverts.spec",
"rule_sanity": "basic",
Expand Down
2 changes: 1 addition & 1 deletion certora/confs/Transfer.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"certora/harness/TransferHarness.sol",
"certora/dispatch/ERC20Standard.sol",
"certora/dispatch/ERC20USDT.sol",
"certora/dispatch/ERC20NoRevert.sol"
"certora/dispatch/ERC20NoRevert.sol",
],
"verify": "TransferHarness:certora/specs/Transfer.spec",
"rule_sanity": "basic",
Expand Down
34 changes: 30 additions & 4 deletions certora/specs/Health.spec
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ methods {
function borrowShares(MorphoHarness.Id, address) external returns uint256 envfree;
function collateral(MorphoHarness.Id, address) external returns uint256 envfree;
function isAuthorized(address, address user) external returns bool envfree;
function lastUpdate(MorphoHarness.Id) external returns uint256 envfree;

function libId(MorphoHarness.MarketParams) external returns MorphoHarness.Id envfree;
function isHealthy(MorphoHarness.MarketParams, address user) external returns bool envfree;
Expand All @@ -21,12 +22,12 @@ persistent ghost uint256 lastPrice;
persistent ghost bool priceChanged;

function mockPrice() returns uint256 {
uint256 somePrice;
if (somePrice != lastPrice) {
uint256 updatedPrice;
if (updatedPrice != lastPrice) {
priceChanged = true;
lastPrice = somePrice;
lastPrice = updatedPrice;
}
return somePrice;
return updatedPrice;
}

function summaryMulDivUp(uint256 x, uint256 y, uint256 d) returns uint256 {
Expand Down Expand Up @@ -106,3 +107,28 @@ filtered { f -> !f.isView }
// This invariant ensures that bad debt realization cannot be bypassed.
invariant alwaysCollateralized(MorphoHarness.Id id, address borrower)
borrowShares(id, borrower) != 0 => collateral(id, borrower) != 0;

// Checks that passing a seized amount input to liquidate leads to repaid shares S and repaid amount A such that liquidating instead with shares S also repays the amount A.
rule liquidateEquivalentInputDebtAndInputCollateral(env e, MorphoHarness.MarketParams marketParams, address borrower, uint256 seizedAssets, bytes data) {
MorphoHarness.Id id = libId(marketParams);

// Assume no interest accrual to ease the verification.
require lastUpdate(id) == e.block.timestamp;
QGarchery marked this conversation as resolved.
Show resolved Hide resolved

storage init = lastStorage;
uint256 sharesBefore = borrowShares(id, borrower);

uint256 repaidAssets1;
_, repaidAssets1 = liquidate(e, marketParams, borrower, seizedAssets, 0, data);
require !priceChanged;
QGarchery marked this conversation as resolved.
Show resolved Hide resolved
// Omit the bad debt realization case.
require collateral(id, borrower) != 0;
uint256 sharesAfter = borrowShares(id, borrower);
uint256 repaidShares1 = assert_uint256(sharesBefore - sharesAfter);

uint256 repaidAssets2;
_, repaidAssets2 = liquidate(e, marketParams, borrower, 0, repaidShares1, data) at init;
require !priceChanged;

assert repaidAssets1 == repaidAssets2;
}
Loading