From 4ac87781e2a29c54fdcaca5b3ef03fb14c5668ff Mon Sep 17 00:00:00 2001 From: Jean-Grimal Date: Wed, 6 Dec 2023 16:45:09 +0100 Subject: [PATCH 1/5] fix: add call to irm at market creation --- src/Morpho.sol | 3 +++ test/forge/integration/CreateMarketIntegrationTest.sol | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/src/Morpho.sol b/src/Morpho.sol index f755904b6..103c5239a 100644 --- a/src/Morpho.sol +++ b/src/Morpho.sol @@ -158,6 +158,9 @@ contract Morpho is IMorphoStaticTyping { idToMarketParams[id] = marketParams; emit EventsLib.CreateMarket(id, marketParams); + + // Call Irm in case it is statefull. + IIrm(marketParams.irm).borrowRate(marketParams, market[id]); } /* SUPPLY MANAGEMENT */ diff --git a/test/forge/integration/CreateMarketIntegrationTest.sol b/test/forge/integration/CreateMarketIntegrationTest.sol index 1fd2eb083..50bfdc38a 100644 --- a/test/forge/integration/CreateMarketIntegrationTest.sol +++ b/test/forge/integration/CreateMarketIntegrationTest.sol @@ -47,6 +47,8 @@ contract CreateMarketIntegrationTest is BaseTest { if (marketParamsFuzz.irm != marketParams.irm) morpho.enableIrm(marketParamsFuzz.irm); if (marketParamsFuzz.lltv != marketParams.lltv) morpho.enableLltv(marketParamsFuzz.lltv); + vm.mockCall(marketParamsFuzz.irm, abi.encodeWithSelector(IIrm.borrowRate.selector), abi.encode(0)); + vm.expectEmit(true, true, true, true, address(morpho)); emit EventsLib.CreateMarket(marketParamsFuzz.id(), marketParamsFuzz); morpho.createMarket(marketParamsFuzz); @@ -66,6 +68,9 @@ contract CreateMarketIntegrationTest is BaseTest { vm.startPrank(OWNER); if (marketParamsFuzz.irm != marketParams.irm) morpho.enableIrm(marketParamsFuzz.irm); if (marketParamsFuzz.lltv != marketParams.lltv) morpho.enableLltv(marketParamsFuzz.lltv); + + vm.mockCall(marketParamsFuzz.irm, abi.encodeWithSelector(IIrm.borrowRate.selector), abi.encode(0)); + morpho.createMarket(marketParamsFuzz); vm.expectRevert(bytes(ErrorsLib.MARKET_ALREADY_CREATED)); @@ -81,6 +86,8 @@ contract CreateMarketIntegrationTest is BaseTest { if (marketParamsFuzz.irm != marketParams.irm) morpho.enableIrm(marketParamsFuzz.irm); if (marketParamsFuzz.lltv != marketParams.lltv) morpho.enableLltv(marketParamsFuzz.lltv); + vm.mockCall(marketParamsFuzz.irm, abi.encodeWithSelector(IIrm.borrowRate.selector), abi.encode(0)); + morpho.createMarket(marketParamsFuzz); vm.stopPrank(); From 01f9e2ba95fa6156c7df6563f07cb436e2a261a5 Mon Sep 17 00:00:00 2001 From: Quentin Garchery Date: Thu, 7 Dec 2023 10:16:53 +0100 Subject: [PATCH 2/5] refactor: create market input validation rule --- certora/specs/Reverts.spec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/certora/specs/Reverts.spec b/certora/specs/Reverts.spec index 9ae422c51..059011fde 100644 --- a/certora/specs/Reverts.spec +++ b/certora/specs/Reverts.spec @@ -103,14 +103,14 @@ rule setFeeRecipientRevertCondition(env e, address newFeeRecipient) { assert lastReverted <=> e.msg.value != 0 || e.msg.sender != oldOwner || newFeeRecipient == oldFeeRecipient; } -// Check the revert condition for the createMarket function. -rule createMarketRevertCondition(env e, MorphoHarness.MarketParams marketParams) { +// Check that createMarket reverts when its input are not validated. +rule createMarketInputValidation(env e, MorphoHarness.MarketParams marketParams) { MorphoHarness.Id id = libId(marketParams); bool irmEnabled = isIrmEnabled(marketParams.irm); bool lltvEnabled = isLltvEnabled(marketParams.lltv); bool wasCreated = isCreated(id); createMarket@withrevert(e, marketParams); - assert lastReverted <=> e.msg.value != 0 || !irmEnabled || !lltvEnabled || wasCreated; + assert e.msg.value != 0 || !irmEnabled || !lltvEnabled || wasCreated => lastReverted; } // Check that supply reverts when its input are not validated. From c02daf829149990a542bd09d6272aa418a427919 Mon Sep 17 00:00:00 2001 From: Jean-Grimal <83286814+Jean-Grimal@users.noreply.github.com> Date: Thu, 7 Dec 2023 13:43:00 +0100 Subject: [PATCH 3/5] Update src/Morpho.sol Co-authored-by: Romain Milon Signed-off-by: Jean-Grimal <83286814+Jean-Grimal@users.noreply.github.com> --- src/Morpho.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Morpho.sol b/src/Morpho.sol index 103c5239a..9b03acdd8 100644 --- a/src/Morpho.sol +++ b/src/Morpho.sol @@ -159,7 +159,7 @@ contract Morpho is IMorphoStaticTyping { emit EventsLib.CreateMarket(id, marketParams); - // Call Irm in case it is statefull. + // Call IRM in case it is stateful. IIrm(marketParams.irm).borrowRate(marketParams, market[id]); } From faef77c2905a28f4b641a6d26a1f04ed7491e44a Mon Sep 17 00:00:00 2001 From: Jean-Grimal <83286814+Jean-Grimal@users.noreply.github.com> Date: Thu, 7 Dec 2023 14:12:31 +0100 Subject: [PATCH 4/5] Update src/Morpho.sol Co-authored-by: Romain Milon Signed-off-by: Jean-Grimal <83286814+Jean-Grimal@users.noreply.github.com> --- src/Morpho.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Morpho.sol b/src/Morpho.sol index 9b03acdd8..96ffb67f2 100644 --- a/src/Morpho.sol +++ b/src/Morpho.sol @@ -159,7 +159,7 @@ contract Morpho is IMorphoStaticTyping { emit EventsLib.CreateMarket(id, marketParams); - // Call IRM in case it is stateful. + // Call to initialize IRM in case it is stateful. IIrm(marketParams.irm).borrowRate(marketParams, market[id]); } From 4d68d40cc25930fa8d07cbee883974b949434589 Mon Sep 17 00:00:00 2001 From: Jean-Grimal <83286814+Jean-Grimal@users.noreply.github.com> Date: Thu, 7 Dec 2023 14:18:04 +0100 Subject: [PATCH 5/5] Update src/Morpho.sol Co-authored-by: Merlin Egalite <44097430+MerlinEgalite@users.noreply.github.com> Signed-off-by: Jean-Grimal <83286814+Jean-Grimal@users.noreply.github.com> --- src/Morpho.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Morpho.sol b/src/Morpho.sol index 96ffb67f2..16fd75c80 100644 --- a/src/Morpho.sol +++ b/src/Morpho.sol @@ -159,7 +159,7 @@ contract Morpho is IMorphoStaticTyping { emit EventsLib.CreateMarket(id, marketParams); - // Call to initialize IRM in case it is stateful. + // Call to initialize the IRM in case it is stateful. IIrm(marketParams.irm).borrowRate(marketParams, market[id]); }