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

fix(reallocate): prevent withdrawing from market not enabled #358

Merged
merged 4 commits into from
Dec 27, 2023

Conversation

Rubilmax
Copy link
Contributor

@Rubilmax Rubilmax commented Dec 22, 2023

Fixes https://cantina.xyz/code/8409a0ce-6c21-4cc9-8ef2-bd77ce7425af/findings/131b79f3-83fc-4674-a222-c5c4dc7d0539

This PR makes reverting when withdrawing from a market that is not enabled. This prevents users to benefit from a donation but it's considered quite unlikely. It also prevents the vault managers to tax the principal of funds deposited on a removed market.

We also acknowledge that the fee recipient will lose entitled fees in case of bad debt events. This is considered fairer since the loss result from the bad management from vault curators.

@Rubilmax Rubilmax marked this pull request as ready for review December 22, 2023 08:32
@Rubilmax
Copy link
Contributor Author

2 is what worries me the most: at worst, a vault manager cannot reallocate liquidity during the duration of their timelock
But it may be fine

@MerlinEgalite
Copy link
Contributor

MerlinEgalite commented Dec 22, 2023

I don't think taxing donations is a big deal. It's bonus for everyone anyway.

But it may be fine

I don't think it's fine. Like if one market is frozen it could be for any reason including reason that could affect similar assets. The allocator would not be able to rebalance the portfolio to reduce risk exposure.

The increase of the gas cost is worrying. IMO reallocation should be as cheap as possible.

@Rubilmax
Copy link
Contributor Author

It's bonus for everyone anyway.

Not in all cases, see point 1 + in case of a forced market removal that no longer reverts for some reason

@MerlinEgalite
Copy link
Contributor

Not in all cases, see point 1 + in case of a forced market removal that no longer reverts for some reason

But this is fixed by #338 right?

@Jean-Grimal
Copy link
Contributor

Jean-Grimal commented Dec 22, 2023

fixes the fact that a withdrawn donation gets taxed from the vault manager

Romain is right. #338 allows to recover (without being "taxed" by the feeRecipient) previously lost supply on reverting markets only when these markets are enabled again. But without enabling these markets it's possible (if they stop reverting) to withdraw from these market (to recover the supply) with reallocate. And in this case, if we don't accrue interest at the start of the function, fee will accrue from this supply.

@MerlinEgalite
Copy link
Contributor

Ok right I get it now, sorry

@MerlinEgalite
Copy link
Contributor

what's the cost of reallocate @Rubilmax ?

@Rubilmax
Copy link
Contributor Author

what's the cost of reallocate @Rubilmax ?

according to hardhat tests, 360k gas before this change, 560k gas now (on avg)

Copy link
Contributor

@MerlinEgalite MerlinEgalite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be tested I think

Copy link
Contributor

@MerlinEgalite MerlinEgalite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a (simpler?) solution would be to prevent withdrawing from a market that is not listed? It removes the possibility to withdraw donations but maybe the spec is clearer?

@Rubilmax Rubilmax changed the title fix(metamorpho): accrue fee on reallocate fix(reallocate): prevent withdrawing from market not enabled Dec 22, 2023
Jean-Grimal
Jean-Grimal previously approved these changes Dec 22, 2023
MerlinEgalite
MerlinEgalite previously approved these changes Dec 22, 2023
Copy link
Contributor

@MathisGD MathisGD left a 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 to agree with this fix.

  • if the manager enables the market, the donation/previously loosed funds will be slashed right ?
  • why shouldn't a donation profit to the fee too ?

@QGarchery
Copy link
Contributor

QGarchery commented Dec 27, 2023

if the manager enables the market, the donation/previously loosed funds will be slashed right ?

(in english loosed -> lost, and also loose -> lose)

If by "slashed" you mean that it will be subject to the MM fee, then yes.

why shouldn't a donation profit to the fee too ?

I don't think it's a problem that a donation can be subject to the MM fee. In effect, donations to enabled markets are subject to the fee, even with the changes of this PR. We can imagine vaults making profit in other ways, and this can be cleanly accounted for with a donation.
What's more problematic is if funds of forced-removed markets are subject to the fee. This is because in this case the fee is taken on the principal, and not on the interest.
Moreover, this change is a safety measure that was already requested in #219, and marked as not planned because not doing it allowed to recover funds more cleanly from previously forced-removed markets. Indeed, enabling such markets again previously added them in the supply queue, so there would be some weird time where users would be able to supply on broken markets. Markets are not automatically added to the supply queue anymore (since #351), so it enables doing this change without problems

QGarchery
QGarchery previously approved these changes Dec 27, 2023
src/libraries/ErrorsLib.sol Show resolved Hide resolved
adhusson
adhusson previously approved these changes Dec 27, 2023
@MerlinEgalite MerlinEgalite dismissed stale reviews from adhusson, QGarchery, Jean-Grimal, and themself via 44fe10d December 27, 2023 12:49
Copy link
Contributor Author

@Rubilmax Rubilmax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@MathisGD MathisGD merged commit a3307b0 into post-cantina Dec 27, 2023
6 checks passed
@MathisGD MathisGD deleted the fix/reallocate-donation branch December 27, 2023 21:24
@Jean-Grimal Jean-Grimal mentioned this pull request Dec 28, 2023
@StErMi
Copy link

StErMi commented Dec 30, 2023

The entrypoint reallocate now reverts as soon as at least 1 market of the withdraw queue is broken. The curator no longer can reallocate liquidity across working markets as soon as 1 market is broken: they are forced to submitMarketRemoval and cannot reallocate for the duration of the timelock

@Rubilmax would you mind explaining this? I don't see how the PR has changed this behavior, compared to before

@MerlinEgalite
Copy link
Contributor

MerlinEgalite commented Dec 30, 2023

The entrypoint reallocate now reverts as soon as at least 1 market of the withdraw queue is broken. The curator no longer can reallocate liquidity across working markets as soon as 1 market is broken: they are forced to submitMarketRemoval and cannot reallocate for the duration of the timelock

@Rubilmax would you mind explaining this? I don't see how the PR has changed this behavior, compared to before

This is indeed no longer true (it has been removed in the second commit of this PR).

The point 3 is no longer true as well I think.

@StErMi
Copy link

StErMi commented Dec 31, 2023

If you can update the description of the PR with the logic that you want to achieve with the changes, it would allow me to verify that the code is correct and has no side effects.

In general:

  1. what it should do
  2. what it should not change

@MerlinEgalite
Copy link
Contributor

If you can update the description of the PR with the logic that you want to achieve with the changes, it would allow me to verify that the code is correct and has no side effects.

In general:

  1. what it should do
  2. what it should not change

I updated the description

@QGarchery QGarchery mentioned this pull request May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants