ebtc-protocol / ebtc

GNU General Public License v3.0
56 stars 25 forks source link

fix bug in _calculateSurplusAndCap() for debt redistribution case #674

Closed rayeaster closed 1 year ago

rayeaster commented 1 year ago

The issue is found during Medusa invariant run and failure-analysis https://gist.github.com/GalloDaSballo/68046d8b089c4d29af40f31d197cc53a?permalink_comment_id=4714393#gistcomment-4714393

When a CDP is fully liquidated with some bad debt distributed (in recovery mode), there should be zero collateral as surplus for CDP owner to claim.

In previous implementation depending on Solidity multiplication and division, it might end with some rounding error that CDP ower got 1 wei collateral as surplus.

Now the issue is fixed by this PR

GalloDaSballo commented 1 year ago

Mostly trying to understand if:

It may be worth getting more eyes on this specific change and this flow

GalloDaSballo commented 1 year ago

This merge will prob have conflicts since this doesn't use shares everywhere

dapp-whisperer commented 1 year ago

great, will merge it down and track this as an issue