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

Error Redistribution - Manual Review #647

Open
dapp-whisperer opened this issue Sep 20, 2023 · 1 comment
Open

Error Redistribution - Manual Review #647

dapp-whisperer opened this issue Sep 20, 2023 · 1 comment

Comments

@dapp-whisperer
Copy link
Contributor

dapp-whisperer commented Sep 20, 2023

See testBrokenInvariantFive in EchidnaToFoundry.t.sol

There is a big lastEBTCDebtErrorRedistribution in this example, > 1e18
(lastEBTCDebtErrorRedistribution is used to calculate the remainder error in rounding and store it for the calc)

I would assume it would never go above 1 since it's a value that once it goes above 1e18 it would be added as 1 unit of debt

This test is going to require some manual review to see if the lastEBTCDebtErrorRedistribution is correct and a reasonable finding to have occur.

@rayeaster
Copy link
Contributor

rayeaster commented Sep 20, 2023

@dapp-whisperer the lastEBTCDebtErrorRedistribution in this test is correct as expected. Please note that lastEBTCDebtErrorRedistribution is capped by totalStake instead of 1e18 as it is the residue from redistributed debt divided by totalStake(see _redistributeDebt() in LiquidationLibrary.sol):

        uint256 EBTCDebtNumerator = (_debt * DECIMAL_PRECISION) + lastEBTCDebtErrorRedistribution;
        ......
        uint256 EBTCDebtRewardPerUnitStaked = EBTCDebtNumerator / _totalStakes;

        lastEBTCDebtErrorRedistribution =
            EBTCDebtNumerator -
            (EBTCDebtRewardPerUnitStaked * _totalStakes);

In this particular test case, the debt to be redistributed is 73080202887917575 and totalStake is 2837658138915260125 thus the calculated error is

     EBTCDebtNumerator = 73080202887917575 * 1e18 = 73080202887917575000000000000000000
     EBTCDebtRewardPerUnitStaked = 73080202887917575000000000000000000 / 2837658138915260125 = 25753702282070398
     lastEBTCDebtErrorRedistribution  = 73080202887917575000000000000000000 - 25753702282070398 * 2837658138915260125 = 1856500538267720250 < totalStake

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

No branches or pull requests

2 participants