Benchmarking Flow implementations with Deviation and Delay #259
Closed
smol-ninja
started this conversation in
Show and tell
Replies: 3 comments 1 reply
-
|
Here is the supporting maths behind the calculation of snapshot time and snapshot debt in 7a80f4d. https://gist.github.com/smol-ninja/b26585e5514250f4b6099e8bd951112a Sumamry
cc @sablier-labs/solidity PS: sorry for long post. |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Wow, is Flow a monster or not. |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
Closing this as well. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have crunched some benchmarks for different solutions that we had come up for Flow. The findings can be found in this google sheet. The data was generated using this code. A similar fuzz test has also been added through this PR, which ensures that the maximum deviation and deviation are within accepted bounds which is 0.6% for deviation and 6 hours for delay (these bounds are based on the sheet data).
Definitions
B-1: Stream deviation
Stream deviation represents how much actual total amount withdrawn differ from the desired total amount withdrawn after multiple withdrawals. For example, if a stream is expected to stream 100 tokens in 1 hour, but due to precision error, a user can only withdraw 90 tokens in 1 hour, then deviation is 10%.
An important invariant is that$wa_{actual} <= wa_{desired}$ , otherwise the implementation may lead to over streaming.
Any better solution would yield into a lower deviation.
B-2: Stream Delay
Stream Delay represents the time by which a stream would incur delay in streamed tokens due to precision error introduced by the divisions. In the above example, if instead of 1 hour, it takes 1.5 hours before user can withdraw 100 tokens, the delay is 0.5 hours.
where
Any better solution would yield into a lower delay.
Data
The code is run on USDC with 100,000 fuzz runs in foundry. Data can be found in this google sheet.
Findings
On
mainbranch, I discovered that, for USDC, with certain RPS, over multiple withdrawals, the delay can go as high as 266 hours with an average of 4 hours. In terms of deviation, it can go as high as 50% with an avg of 0.6%. onfix-precision, the same numbers are very low bringing it closer to a real stream.Before 7a80f4d1, the test resulted into the failure of$wa_{actual} <= wa_{desired}$ invariant on $rps$ , the solution was leading to over streaming, which is bad.
fix/precision-issuewhich means that for some values ofExplanation below:
_streams[streamId].snapshotTime += uint40(scaledDifference / rps)ongoingDebt = (elapsedTime * rps) / scaleFactorThus it led to over streaming.
Conclusion
The difference that we thought can only be 1 or 2 can be much higher depending on the value of RPS. Thus, instead of asserting differences in the invariant, we should assert deviation and delay similar to #258.
Reference
Beta Was this translation helpful? Give feedback.
All reactions