Rustyrabbit's comment on precision issue #297
Replies: 5 comments 7 replies
-
Would solution 1 also remove the condition that deposit amount is a multiple of RPS? Or does it just affect withdrawals? Regarding solution 2, are there any other advantages to storing snapshot in 18 decimals? Meaning consistency with other internal representations etc. aside from this "temporary" fix for high-worth tokens (as you said, after BTC gets a 10x, the problems comes back). |
Beta Was this translation helpful? Give feedback.
-
Thanks for the summary @smol-ninja.
I've started a discussion about this a long time ago: #152 Notes:
Yes.
Yes. We will simply add a warning about this in the docs and in the tooltips of the UI. This is Flow v1.0.0 — it doesn't have to be perfect. It just has to be launched ASAP so that we ship a new product this year. |
Beta Was this translation helpful? Give feedback.
-
Thank you for opening this. re solution 1, pasting my reply to Rusty on discord: was trying to think of a POC for implementing the amount + interval, but I’m not sure how this would fix the precision issue. Also, how would this be achievable in an “open-ended” environment (with no specific start or end time)? A solution I have in mind is: elt = (now - start);
intervals_passed = elt / interval_time;
td = interval_amount * intervals_passed; Assuming At some point, we would still need to perform a division (which is the apple of discord here). If this operation is done outside the contract, it would be better since Solidity is sensitive to this kind of mathematical operation. (a small point, but, how would the equivalent of to @smol-ninja
On the contrary, as mentioned above, I believe this would introduce a greater delay in certain scenarios
Yes, very well put Shub, I agree with you. to @razgraf
That condition was only for the
In terms of internal representations, this change would complicate things. In the current version (aside from the stored Line 474 in fbf6ff5 If we implement this change, we would need to maintain two versions of the total debt: one in token decimals to check the external amount parameter in withdraw/refund, and another to update the snapshot debt for the internal amount. I won’t list all the places where we would need to account for these two versions, but there are multiple locations throughout the code. |
Beta Was this translation helpful? Give feedback.
-
Great feedback from everyone.
PS: I am in favour of implementing snapshotDebt as 18 decimal format because it offers slightly better version of the current implementation in terms of precisions and the complexity is only extra lines of code as scaling and descaling are pretty straightforward. |
Beta Was this translation helpful? Give feedback.
-
Closing this as we all are in agreement. |
Beta Was this translation helpful? Give feedback.
-
From Rustyrabit:
So I see 3 separate issues:
As an example these are the values of 1 wei of each of these tokens vs their decimals:
As you can see it doesn’t hold up when you compare WBT against USDC. WBTC has more decimals but is worth more per wei.
FYI we also looked at the fact that the descaling is based on the decimals of the token as determined at the creation of the stream. If a token would change it’s decimals after creation of the stream it could cause problems. We didn’t find a way to exploit this though an any non-malicious token that alters their decimals is just a rebasing token and as such not supported.
Submission 1 Submission 2
My comments:
Note that they are assuming that $0.01 loss per ~20-30 withdrawals is not something we should dismiss, whereas we considered it to be extremely small variation and thus not realistic. Should we defend using this argument? cc @PaulRBerg @andreivladbrg
Two solutions being proposed:
I like the first solution as it can mitigate the precision loss entirely. Given that (cc @razgraf) users will be entering his interest in the form of “tokens streamed per interval” instead of exact rps , it makes sense to store it as it is to align with the users expectation. Thought it will be more effort and can affect our timeline for public audit and launch. We can also start a discussion out of it for for Flow’s future release.
Second solution, though, seems affordable given the timeline. But, $0.01 is too small, and I think that may still exist even after storing sd in 18 decimal format, it might end up being offering no solution. Given the fact that BTC is $60k now which can be $600k in a month and then it can end up being $0.01 loss to users even with sd as 18 decimals.
Thoughts?
tagging @sablier-labs/engineers as the decision may affect users' UX.
Beta Was this translation helpful? Give feedback.
All reactions