RiskProtocol / core-protocol

2 stars 0 forks source link

Check 1 wei rounding #142

Open mz7mz7mz7 opened 1 year ago

mz7mz7mz7 commented 1 year ago

Check if, in the scenario, someone has one wei worth of RiskOn or RiskOff, when the rebase happens if that user can be rebased to have 0 (aka less than one wei) worth of respective RiskOn / Off tokens.

The context of this question is from the AMM pools' perspective; we want to make sure that if, before the rebase, the pool was non-empty, it would stay non-empty after the rebase, at all times.

haidarally commented 11 months ago

@mz7mz7mz7 Mathematically Ding said that he would look into his calculations. like using integers rather than decimals and he also mentioned that he might not be able to come up with a solution for the rounding given the complexity.

We also reviewed how other projects are doing it. 0x was supposedly reverting if the loss value is more than 0.1%( dead code though). I think reverting wont solve our issue.

Our current solution involves using a big multiplier(10E18). Generally the larger the multiplier the smaller the precision loss.

An alternative is to use Fixed-Point Arithmetic. But they'd still have certain rounding off and we need to trust them https://forum.openzeppelin.com/t/list-of-solidity-libraries-in-the-wild/2250#fixed-point-arithmetic-4

haidarally commented 11 months ago
haidarally commented 11 months ago

The behaviour noticed is that, the totalsupply of SmartTokenX/Y when there is no holders, that is everyone redeemed, == the residual underlying token amount. We dont have a simple way of neither updating the tokenSupply accurately nor simply retriving the residual underlying token amount. One work around is that we keep count of the number of token holders and if token holders ==0, then we retrieve the remaining underlying token. However this approach is not gas efficient and seems to not be worth it. Therefore, we stop the implementation