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

3.0.1. Inconsistency between calculation of borrow index on _updateIndexes() and on getNormalizedDebt() #754

Closed
eboadom opened this issue Dec 6, 2022 · 1 comment
Assignees

Comments

@eboadom
Copy link
Collaborator

eboadom commented Dec 6, 2022

_updateIndexes() only updates the reserve.variableBorrowIndex whenever reserveCache.currScaledVariableDebt != 0. Even if this is expected behavior, it creates an inconsistency with the calculation on getNormalizedDebt(), specifically in the case when the scaled variable borrow supply is 0, but the variable borrow rate is > 0, caused by a base variable borrow rate > 0

@eboadom eboadom self-assigned this Dec 6, 2022
@eboadom
Copy link
Collaborator Author

eboadom commented Dec 7, 2022

Some extra context and potential solution:

_updateIndexes() will not update the variable borrow index whenever there is no variable borrow debt. For this to happen, and taking into account the protocol's flow of update state (indexes) -> change state -> update rates (flash loan is not really relevant in this case), at the beginning of the action, there can't be outstanding variable borrow debt.
So, as expected: indexes will not change, but getNormalizedDebt() will be continuously increased based on time, as a function of the last stored variable borrow index, time and base borrow variable rate.
But this actually doesn't seem correct, because, in practice, that base variable borrow rate (standalone, nothing "on top" based on 0 variable debt) will never be applied that way. Whenever somebody borrows at variable, when the code reaches the point of updating interest rates, utilization will already be > 0, and so, the base borrow variable rate will get added the extra component based on such positive borrow utilization (variable side).

But still, the code of the interest rate strategy returns as currentVariableBorrowRate the _baseVariableBorrowRate https://github.com/aave/aave-v3-core/blob/feat/3.0.1/contracts/protocol/pool/DefaultReserveInterestRateStrategy.sol#L209
It seems that given that that rate will factually never be applied when scaled borrow debt is 0, better to just return 0 as currentVariableBorrowRate on the rate strategy.

Other alternative changes seem not so correct, considering:

  • Changing _updateIndexes() to still do the update when the rate is > 0 seems just incorrect. It would mean that for example, for assets not enabled to borrow the variable borrow index will get overridden again and again.
  • Changing getNormalizedDebt() to return the current variable borrow index (not changed) whenever the scaled variable debt is 0 seems counternatural: the function deals with the "growth" of debt, not with the debt itself.

Important to highlight that this problem is pretty minor in practice. The protocol itself doesn't get affected anyhow by this inconsistency, because wherever getNormalizedDebt() is used, there is a component 0 used in the calculation in advance (e.g. variable debt user balance, variable debt supply).
For off-chain and on-chain integration, I also have important doubts if there is any case where they don't use the result of getNormalizedDebt() in combination with a debt value zeroed.

miguelmtzinf pushed a commit that referenced this issue Dec 19, 2022
…d `_updateIndexes` (#754) (#768)

* Added clarification on getReserveNormalizedVariableDebt() in IPool
* Updated docs on getReserveNormalizedVariableDebt IPool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants