Enhance rounding for scaled tokens to mitigate minor insolvency #852
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Vulnerable Functions
The following three AToken functions all round the result to the nearest integer, which may bring minor insolvency to the protocol.
Mitigation
Enhance rounding for scaled tokens (including AToken and VariableDebtToken) so that rounding always act in the direction that protects the protocol (instead of having some cases benefiting the user).
Rounding used
AToken.mint: ROUNDING.DOWN
AToken.burn: ROUNDING.UP
AToken.balanceOf: ROUNDING.DOWN
VariableDebtToken.mint: ROUNDING.UP
VariableDebtToken.burn: ROUNDING.DOWN
VariableDebtToken.balanceOf: ROUNDING.UP
New Dependency
RayMathExplicitRounding.sol, which is also used in StaticAToken's implementation.