-
Notifications
You must be signed in to change notification settings - Fork 21
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
Replace borrow index #1375
Replace borrow index #1375
Conversation
In the process of making this PR, I've discovered that replacing exchangeRateStored with a cached value is not guaranteed to be the same. The exchange rate can suffer minor rounding errors if any funds are supplied or borrowed in the same transaction as can be seen in this code, as the exchange rate is a function of the total supply and borrows in the cToken contract. And so only a select few instances of this are cached. Specifically, only the ones that are right after an index update, as this index should be correct since there has been no pool interaction to mess with the index at these points. Borrow index is replaceable with a cached value just fine though. |
Changing the base of the PR. |
That makes me think: should we update each time the indexes instead? or check that the |
If I'm not mistaken, the issue impacts the IRM as well: we took for granted that calling But here, we learn that the theorem holds only for the borrow index. So we should rework the IRM to use |
Yes we should definitely investigate this, here is a first step towards this: The issue is linked to #997, it seems like we missed this implication at the time. I'm not sure we should use |
If we don't use I think the |
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 approve the changes in this PR. Isn't it an optimization though? Is it the last optimization we're merging and deploying?
Because it's in contradiction with the measures we've taken recently, which goal is to decrease the nb of changes we apply to the deployed code (or I may have misunderstood)
This optimization is safe to me, but still: do we want to pursue such work in the future?
I didn't see exchangeRateStored
was replaced with lastSupplyPoolIndex
. I need to think about this
I disagree with this: with the changes of this PR, it seems Morpho could be overestimating the supplier's balance on the pool (because we are dividing the amount by the cached index) For this reason, I consider this change unsafe (I may be mistaken) We could in parallel think about what I highlight just above:
We may not want to pursue such optimizations anymore (because it's not necessary to Morpho for now) |
If my understanding is correct, the issue is that Then either we only use the cached |
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.
Not mergeable atm for the reasons mentioned above.
There are other things I want to clarify too:
|
I think that it is ok for P2P indexes computations. |
Because we are using |
Yes but within a block P2P indexes are fixed while |
Ok you are right, let's not make too quick assumptions, we need to make sure that it is not breaking anything. I'm notably thinking of 100% delta situations, were this could cause issues. |
So is it a R&D topic or should the solidity do the research? |
As you want, we have not started anything yet. |
Ok after some time on this, I don't think there's any issue with the |
Just to be sure then, this PR is good as is? |
No we must use the |
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.
LGTM !
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.
LGTM 🎉
|
Pull Request
Issue(s) fixed
This pull request fixes #1173