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

Improve precision for the PositiveTokenRebaseLimiter library #835

Open
TheDZhon opened this issue May 4, 2024 · 0 comments
Open

Improve precision for the PositiveTokenRebaseLimiter library #835

TheDZhon opened this issue May 4, 2024 · 0 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@TheDZhon
Copy link
Contributor

TheDZhon commented May 4, 2024

tl;dr

Change internal math reference precision from 1e9 to 1e27 to make the PositiveTokenRebaseLimiter library more robust against unusual input data

Context:

As a part of the Repovation initiative the PositiveTokenRebase library (contracts/0.8.9/lib/PositiveTokenRebaseLimiter.sol) has been covered with an extensive fuzzing test suite.

What:

Turns out the internal math precision with a reference 1 == 1e9 is insufficient to maintain wide (or even unconstrainted) data boundaries, see the relevant code in lidofinance/core#88, the method is testFuzz_getSharesToBurnLimit. When the values are out of range, the allowed theoretical positive rebase start diverging from the calculated one due to the weak precision math.

It should be possible to maintain the accuracy for the following assumptions:

  • allow near zero protocol TVL not sacrificing on the estimation precision (the current model uses 1 ether, better to allow 1 gwei at least)
  • require more accuracy for max rebase calculation (the current model requires 0.1 basis point, wish it was 0.001 basis point)
  • allow more outrageous share rates for the model (0.001 ≤ shareRate ≤ 10001e-6 ≤ shareRate ≤ 1e6)
  • allow more drastically changes for decreaseEther to be passed

Possible fix:

Implement getSharesToBurnLimit with the internal 1e27 precision model.

@TheDZhon TheDZhon added bug Something isn't working enhancement New feature or request labels May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant