-
Notifications
You must be signed in to change notification settings - Fork 322
Stake precision loss / truncation after many liquidations #310
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
Comments
Some more insights on this issue: The problemThe main problem seems to be in this line of dev/packages/contracts/contracts/TroveManager.sol Line 1207 in 555b641
when It has its origin in this line of function dev/packages/contracts/contracts/TroveManager.sol Line 1184 in 555b641
The main problem is that There is at least one trove from the beginning, that remains untouched forever.It’s not that relevant, but we can define “from the beginning” as “before the first liquidation happens”.
All the troves re-adjust frequently reacting to liquidationsTo understand how this happens, let’s build up a simple scenario (code for the test reproducing it below):
After 9 iterations the liquidation of the whale fails because Before failing, this is the state:
The way I see it, the main problem is that the system behaves as if there always was a trove from the very beginning with pending rewards, i.e., like if we were in the previous scenario. The code for that test is:
The solutionStill thinking about it, but somehow I think we should be able to reset
Then we could implement something similar to what we do with A simpler solution using scaling for the snapshot values is in the works by @RickGriff |
Could this be a realistic problem for Liquity?It seems not - for example, this test liquidates a constant fraction of total system collateral at each step: At 10% liquidated per step, it takes ~350 steps before fresh stakes get down to 1e-16: For a conservative (high) value of 10% total system collateral liquidated per month, it takes How much would realistically be liquidated? We've looked into some numbers for MakerDAO, and it seems very low: So we would expect a much lower liquidation fraction than 10% per month - even 1% per month seems high. Also a large proportion of liquidations will be absorbed by the Stability Pool - it is only redistributions that cause stake decline. So it seems very unlikely that Liquity could suffer from stake precision loss / truncation within the first 50 years of operation. |
Assessment from Trail of Bits (Gustavo, Slack message): "In summary, we believe that issue #310 is not an immediate concern during the lifetime of the Liquity contracts, unless there some "black swan event" (e.g. something causing ether to crash a very large number of times, forcing an abnormally high amounts of liquidations per year). So, instead of making modifications in the code, we recommend to monitor the precision loss and have a emergency migration procedure ready in the unlikely case of need it." So I'm closing this now. |
When a trove is created or updated, its stake is calculated by:
stake = _coll.mul(totalStakesSnapshot).div(totalCollateralSnapshot);
Its stake is what earns rewards it ETH and LUSD debt rewards in distributions from liquidations, i.e. in liquidations where the LUSD in the Stability Pool is less than the liquidated debt, and the liquidated collateral and debt is redistributed to all active troves.
Problem:
When a series of liquidations occur that trigger redistributions, the stakes of the liquidated troves are removed from the system, but the ETH collateral of the liquidated troves remains in the system - it just moves from
ActivePool
toDefaultPool
. ThustotalStakes
decreases buttotalCollateral
remains constant (ignoring gas compensation).Over time, as liquidations occur, due to equation 1), fresh stakes become smaller and smaller for a given trove collateral size. Eventually, stakes can get so small and close in magnitude to
1e-18
, such that they lose significant precision. Eventually new stakes may be truncated to 0, which breaks the proportional reward distribution mechanism.The rate of decline of new stakes depends on how much is liquidated at each step - liquidating 10% of the system's collateral causes new stakes to decrease more quickly than liquidating 1% of the system collateral.
This may or may not be a problem depending on what numbers are "realistic" - i.e. the real liquidation throughput relative to system size.
Initial simulations suggest that stakes become very small (~1e-16) after on the order of 1e4 or 1e5 liquidations, where 10-20% of system collateral is commonly liquidated. This seems like potential cause for concern.
Possible fix:
The text was updated successfully, but these errors were encountered: