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

Add call to irm at market creation #634

Merged
merged 6 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions certora/specs/Reverts.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions src/Morpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ contract Morpho is IMorphoStaticTyping {
idToMarketParams[id] = marketParams;

emit EventsLib.CreateMarket(id, marketParams);

// Call IRM in case it is stateful.
Jean-Grimal marked this conversation as resolved.
Show resolved Hide resolved
IIrm(marketParams.irm).borrowRate(marketParams, market[id]);
Rubilmax marked this conversation as resolved.
Show resolved Hide resolved
}

/* SUPPLY MANAGEMENT */
Expand Down
7 changes: 7 additions & 0 deletions test/forge/integration/CreateMarketIntegrationTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
Expand All @@ -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();

Expand Down
Loading