Skip to content

Commit 8a31ef3

Browse files
Merge pull request #634 from morpho-org/fix/issue-259
Add call to irm at market creation
2 parents 7fdf84a + 6f51034 commit 8a31ef3

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

certora/specs/Reverts.spec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ rule setFeeRecipientRevertCondition(env e, address newFeeRecipient) {
103103
assert lastReverted <=> e.msg.value != 0 || e.msg.sender != oldOwner || newFeeRecipient == oldFeeRecipient;
104104
}
105105

106-
// Check the revert condition for the createMarket function.
107-
rule createMarketRevertCondition(env e, MorphoHarness.MarketParams marketParams) {
106+
// Check that createMarket reverts when its input are not validated.
107+
rule createMarketInputValidation(env e, MorphoHarness.MarketParams marketParams) {
108108
MorphoHarness.Id id = libId(marketParams);
109109
bool irmEnabled = isIrmEnabled(marketParams.irm);
110110
bool lltvEnabled = isLltvEnabled(marketParams.lltv);
111111
bool wasCreated = isCreated(id);
112112
createMarket@withrevert(e, marketParams);
113-
assert lastReverted <=> e.msg.value != 0 || !irmEnabled || !lltvEnabled || wasCreated;
113+
assert e.msg.value != 0 || !irmEnabled || !lltvEnabled || wasCreated => lastReverted;
114114
}
115115

116116
// Check that supply reverts when its input are not validated.

src/Morpho.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ contract Morpho is IMorphoStaticTyping {
158158
idToMarketParams[id] = marketParams;
159159

160160
emit EventsLib.CreateMarket(id, marketParams);
161+
162+
// Call to initialize the IRM in case it is stateful.
163+
IIrm(marketParams.irm).borrowRate(marketParams, market[id]);
161164
}
162165

163166
/* SUPPLY MANAGEMENT */

test/forge/integration/CreateMarketIntegrationTest.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ contract CreateMarketIntegrationTest is BaseTest {
4747
if (marketParamsFuzz.irm != marketParams.irm) morpho.enableIrm(marketParamsFuzz.irm);
4848
if (marketParamsFuzz.lltv != marketParams.lltv) morpho.enableLltv(marketParamsFuzz.lltv);
4949

50+
vm.mockCall(marketParamsFuzz.irm, abi.encodeWithSelector(IIrm.borrowRate.selector), abi.encode(0));
51+
5052
vm.expectEmit(true, true, true, true, address(morpho));
5153
emit EventsLib.CreateMarket(marketParamsFuzz.id(), marketParamsFuzz);
5254
morpho.createMarket(marketParamsFuzz);
@@ -66,6 +68,9 @@ contract CreateMarketIntegrationTest is BaseTest {
6668
vm.startPrank(OWNER);
6769
if (marketParamsFuzz.irm != marketParams.irm) morpho.enableIrm(marketParamsFuzz.irm);
6870
if (marketParamsFuzz.lltv != marketParams.lltv) morpho.enableLltv(marketParamsFuzz.lltv);
71+
72+
vm.mockCall(marketParamsFuzz.irm, abi.encodeWithSelector(IIrm.borrowRate.selector), abi.encode(0));
73+
6974
morpho.createMarket(marketParamsFuzz);
7075

7176
vm.expectRevert(bytes(ErrorsLib.MARKET_ALREADY_CREATED));
@@ -81,6 +86,8 @@ contract CreateMarketIntegrationTest is BaseTest {
8186
if (marketParamsFuzz.irm != marketParams.irm) morpho.enableIrm(marketParamsFuzz.irm);
8287
if (marketParamsFuzz.lltv != marketParams.lltv) morpho.enableLltv(marketParamsFuzz.lltv);
8388

89+
vm.mockCall(marketParamsFuzz.irm, abi.encodeWithSelector(IIrm.borrowRate.selector), abi.encode(0));
90+
8491
morpho.createMarket(marketParamsFuzz);
8592
vm.stopPrank();
8693

0 commit comments

Comments
 (0)