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

Function to cover lost assets #6

Closed
wants to merge 5 commits into from

Conversation

MathisGD
Copy link
Contributor

@MathisGD MathisGD commented Aug 9, 2024

Nb: not super convinced about this against supplying on behalf of address zero

@MathisGD MathisGD self-assigned this Aug 9, 2024
src/MetaMorpho.sol Outdated Show resolved Hide resolved
src/MetaMorpho.sol Outdated Show resolved Hide resolved
src/interfaces/IMetaMorpho.sol Outdated Show resolved Hide resolved
src/interfaces/IMetaMorpho.sol Outdated Show resolved Hide resolved
Co-authored-by: Merlin Egalite <44097430+MerlinEgalite@users.noreply.github.com>
Signed-off-by: MathisGD <74971347+MathisGD@users.noreply.github.com>
lostAssets -= assets;
emit EventsLib.UpdateLostAssets(lostAssets);

SafeERC20.safeTransferFrom(IERC20(asset()), msg.sender, address(this), assets);
Copy link
Contributor

Choose a reason for hiding this comment

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

If the token is an ERC777, one can reenter to decrease the lostAssets value further while transferring only once assets

Copy link
Contributor

Choose a reason for hiding this comment

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

Since the function is public this can be very problematic since we can't rely on the fact that the owner is trusted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the token is an ERC777, one can reenter to decrease the lostAssets value further while transferring only once assets

how can they skip the second token transfer?


SafeERC20.safeTransferFrom(IERC20(asset()), msg.sender, address(this), assets);

_supplyMorpho(assets);
Copy link
Contributor

@MerlinEgalite MerlinEgalite Aug 9, 2024

Choose a reason for hiding this comment

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

Doesn't it double count the deposited assets into newLostAssets?

Since lostAssets is reduced by assets and realTotalAssets is increased by assets at the next interaction using _accrueInterest

Copy link
Contributor Author

Choose a reason for hiding this comment

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

newTotalAssets = realTotalAsset + lostAssets
               = prevRealTotalAssets + assets + prevLostAssets - assets
               = prevRealTotalAssets - prevLostAssets

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added an assertion in a test for this

Copy link
Contributor

@Jean-Grimal Jean-Grimal left a comment

Choose a reason for hiding this comment

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

Looks good tbh.

I don't have anything to see at first sight. It doesn't affect the share/asset conversion price or totalAssets, just reduces lostAssets. It looks safe.

But I agree with you that it could have implications that we don't see now, so it doesn't feel safe to add this feature. Reminds me a lot of the unfamous Euler donate function that ruined their protocol.

Although it's cool to have it, I don't think having a function to cleat bad debt is a priority. I think we shouldn't take this risk

@Rubilmax
Copy link
Contributor

Rubilmax commented Aug 9, 2024

Nb: not super convinced about this against supplying on behalf of address zero

Yeah it seems deposit(assets, address(0)) does the job if we document clearly that lost assets on a vault is actually lostAssets() - convertToAssets(balanceOf(address(0)) instead of simply lostAssets(0). It doesn't look like a burden to me

Maybe we could even rename lostAssets to shortfall or whatever and have a lostAssets getter that calculates this (renaming is useful, the getter is overkill to me)?

@adhusson
Copy link
Contributor

adhusson commented Aug 15, 2024

revisiting this, lost assets must take address(0)'s phantom assets into account so lost assets are: nevermind, when giving to address(1) their assets:share ratio is correct.

// the following is wrong
uint donatedAssets = _convertToAssetsWithTotals({
  shares: balanceOf(address(0)), 
  newTotalSupply: totalSupply(), 
  newTotalAssets: totalAssets() - lostAssets()
});

uint actualLostAssets = lostAssets() - donatedAssets

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.

5 participants