-
Notifications
You must be signed in to change notification settings - Fork 2
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
test: polish invariants #237
Conversation
8135889
to
2588c21
Compare
2588c21
to
bab585f
Compare
@andreivladbrg I've been trying to figure out an invariant that compares the total debt with the streamed amount. It goes like the following: For any non-voided stream, the total debt should be equal to the total streamed amount minus the total withdrawn amount. I chose non-voided stream because |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left some comments for now:
// Update the streamed amounts by adding up the difference between the ongoing debt before and after. | ||
for (uint256 i = 0; i < flowStore.lastStreamId(); ++i) { | ||
uint256 streamId = flowStore.streamIds(i); | ||
flowStore.updateStreamedAmount(streamId, flow.ongoingDebtOf(streamId) - initialOngoingDebts[i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This updates an incorrect streamed amount. Because it calls ongoingDebt
and add it to streamedAmount
very frequently, given that on every update, there will be some precision loss, then after a long time, when we compare the actual ongoing debt with the streamed amount, the different would be huge.
The actual ongoing debt = streamed amount + all those small amounts we missed in every update.
An alternate way is to store corrected time here and then use rps * (corrected time - previous stored time)
to calculate streamed amount in the invariant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed it from this PR.
24408e3
to
54e505b
Compare
54e505b
to
6fe5b3f
Compare
test: invariant to compare total debt, streamed amount and withdrawn amount test: calculate streamed amount from ongoing debt before and after Co-authored-by: Andrei Vlad Birgaoanu <99738872+andreivladbrg@users.noreply.github.com> test(invariant): update function calls made by stream ID test(invariant): move depositAmount to CreateParams struct to avoid stack too deep error Co-authored-by: Andrei Vlad Birgaoanu <99738872+andreivladbrg@users.noreply.github.com> test: remove incorrect invariant
6fe5b3f
to
1ac04d5
Compare
Merging this as well since the changes in this PR are minor and will be useful during testing. |
Changelog
Depends on
vm.assume
in handlers #245Note
The following implementation is incorrect. See #237 (comment) for more details.
Until now, there was no way to validate the accuracy of the streamed amount. The amount streamed is only changed whenever there is a passage of time. Therefore, the new variablestreamedAmount
in FlowStore tracks the streamed amount throughadjustTimestamp
modifier.The precision-related problems that we had been facing are mostly introduced only in the_withdraw
function. So, the new invariant aims to validate that the update in the total debt matches the difference between the streamed amount and the withdrawn amount all the time.