-
Notifications
You must be signed in to change notification settings - Fork 34
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
Update last total assets in _setCap #338
Conversation
Co-authored-by: Merlin Egalite <44097430+MerlinEgalite@users.noreply.github.com> Signed-off-by: Jean-Grimal <83286814+Jean-Grimal@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the lastTotalAssets = lastTotalAssets + supply(vault)
update suspicious. It looks like the start of a loop that inflates lastTotalAssets
. There is also no update of lastTotalAssets
when supplyCap == 0
.
Suggestion: unconditionally call _updateLastTotalAssets(totalAssets())
at the end of every _setCap
. Unless _setCap
is called very often I think it's worth the gas cost.
In that case the assert in testEnableMarketWithLiquidity
should become:
uint depositedWithInterest = morpho.expectedSupplyAssets(allMarkets[0],address(vault));
assertEq(vault.lastTotalAssets(), depositedWithInterest + additionalSupply);
I first used
I think |
Was there a reason not to do that @morpho-org/onchain-reviewers? I can't remember |
Do you mean it could open up a vulnerability?
Because even if a cap is zero, the vault has access to this supply hence why the total assets are not decreased (and why |
The idea was that I couldn't see a way to make the loop work without timelocks during which |
…perf/market-params
perf(setCap): use market params
e06f7f0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super convinced about this issue. Why shouldn't a donation be taxed by the fee? And for me a removed market is lost funds, thus it's weird to modify the logic for this edge case.
I believe this comment also answers this question |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the end I'm fine taxing twice temporarily lost funds, and I'm also fine to prevent taxing it because the cost is not much
I still find it weird to merge this PR without having #337 |
89f0057
@@ -737,6 +744,8 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph | |||
|
|||
marketConfig.enabled = true; | |||
|
|||
_updateLastTotalAssets(lastTotalAssets + MORPHO.expectedSupplyAssets(marketParams, address(this))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider avoiding executing this function if MORPHO.expectedSupplyAssets(marketParams, address(this))
is equal to zero.
I would say that the normal scenario should be that you are enabling a market where no one has supplied on behalf of MM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but it would save only ~2k gas since we still need to call expectedSupplyAssets
. In the current configuration we're adding one cold SLOAD
and one warm SSTORE
that is not changing the value. So no sure it's worth considering this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it's worth it considering this case. The current implementation only adds one cold SLOAD
and one warm SSTORE
so around 2k gas.
@@ -737,6 +744,8 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph | |||
|
|||
marketConfig.enabled = true; | |||
|
|||
_updateLastTotalAssets(lastTotalAssets + MORPHO.expectedSupplyAssets(marketParams, address(this))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not documented yet, consider documenting the side effects of this operation. The share value (of MM) is increased.
@@ -737,6 +744,8 @@ contract MetaMorpho is ERC4626, ERC20Permit, Ownable2Step, Multicall, IMetaMorph | |||
|
|||
marketConfig.enabled = true; | |||
|
|||
_updateLastTotalAssets(lastTotalAssets + MORPHO.expectedSupplyAssets(marketParams, address(this))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a check that reverts if the market is broken?
MORPHO.expectedSupplyAssets
won't revert if elapsed == 0
(and the IRM is broken) and it does not use the oracle
(called once you need to withdraw)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's ok not to revert in this case. Vaults curators should not list broken markets in the first place.
Just to recap: this feature allows you to add the existing supply of a new ( The scenarios where this is needed are:
This does not handle the case that suppliers that were present at removal time could end up with less value in their shares if new suppliers have minted new shares in the meanwhile (before the market is re-added) |
Fixes https://cantina.xyz/ai/8409a0ce-6c21-4cc9-8ef2-bd77ce7425af/findings/8b4fe500-afc7-43a2-9c14-d2ca13c5ae0a