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

L-09 Rounding Error Might Prevent Borrowing at the Maximum Limit #489

Merged
merged 3 commits into from
Sep 22, 2023
Merged

Conversation

MerlinEgalite
Copy link
Contributor

Fixes #480

@MerlinEgalite MerlinEgalite requested review from a team September 15, 2023 08:13
@MerlinEgalite MerlinEgalite self-assigned this Sep 15, 2023
@MerlinEgalite MerlinEgalite requested review from Rubilmax, Jean-Grimal, QGarchery, peyha and MathisGD and removed request for a team September 15, 2023 08:13
@MerlinEgalite MerlinEgalite changed the title L-09 L-09 Rounding Error Might Prevent Borrowing at the Maximum Limit Sep 15, 2023
src/Morpho.sol Outdated Show resolved Hide resolved
Jean-Grimal
Jean-Grimal previously approved these changes Sep 15, 2023
Copy link
Contributor

@QGarchery QGarchery left a comment

Choose a reason for hiding this comment

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

I think I prefer just changing the inequality is _isHealthy into a strict inequality. Comments about 1 WEI of asset feel a bit too much in my opinion

@Rubilmax
Copy link
Contributor

I think I prefer just changing the inequality is _isHealthy into a strict inequality. Comments about 1 WEI of asset feel a bit too much in my opinion

I don't see how it solves the issue: it just shifts the issue by 1. See my reasoning considering a strict inequality:

When borrowing max (borrowed == maxBorrow - 1), your position would be considered healthy with maxBorrow - 1 while the protocol would round up twice and make your position unhealthy (maxBorrow == borrowed)

@MerlinEgalite
Copy link
Contributor Author

I've created a draft PR #490. Tbh I think it's more difficult to reason about especially in the tests you must tweaks some things to have the behavior you expect which I'm not confortable with...

@QGarchery
Copy link
Contributor

I don't see how it solves the issue: it just shifts the issue by 1

You are right, it doesn't change much. The intent is to signal that the user shouldn't expect to have precision down to the WEI. I still feel like it's not worth adding a big comment just for that: it is putting the focus on a small issue. For example a tiny change in price can change the behavior. If we were to add a comment, just making clear that precision is not down to the WEI should be enough (and it's more general and applies to other computations)

@Rubilmax
Copy link
Contributor

Rubilmax commented Sep 15, 2023

If we were to add a comment, just making clear that precision is not down to the WEI should be enough (and it's more general and applies to other computations)

I'm fine with that too
Where though?

@MerlinEgalite
Copy link
Contributor Author

You are right, it doesn't change much. The intent is to signal that the user shouldn't expect to have precision down to the WEI. I still feel like it's not worth adding a big comment just for that: it is putting the focus on a small issue. For example a tiny change in price can change the behavior. If we were to add a comment, just making clear that precision is not down to the WEI should be enough (and it's more general and applies to other computations)

Would the following works for you @QGarchery ?
/// @dev The precision of the inequality can vary up to 1 unit of the borrowable token.

@QGarchery
Copy link
Contributor

Would the following works for you @QGarchery ?

Perfect

Rubilmax
Rubilmax previously approved these changes Sep 18, 2023
Jean-Grimal
Jean-Grimal previously approved these changes Sep 18, 2023
QGarchery
QGarchery previously approved these changes Sep 18, 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.

This fix feels a little bit weird to me. We round in favor of the market every time right ? When you borrow and then repay you might need to repay one more asset. When you supply and withdraw you might be able to withdraw one less asset. It's not so surprising to see the "same" thing happening in _isHealthy. Anyway I'm not against the fix but I don't think that it was mandatory at all.

src/Morpho.sol Outdated Show resolved Hide resolved
Co-authored-by: MathisGD <[email protected]>
Signed-off-by: Merlin Egalite <[email protected]>
@MathisGD MathisGD merged commit 060f9f9 into main Sep 22, 2023
4 checks passed
@MathisGD MathisGD deleted the l-09 branch September 22, 2023 15:46
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.

L-09 Rounding Error Might Prevent Borrowing at the Maximum Limit
5 participants