Skip to content
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: add invariant_DebtGt0_RpsGt0_DebtIncrease #129

Merged
merged 6 commits into from
May 28, 2024
Merged

Conversation

smol-ninja
Copy link
Member

@smol-ninja smol-ninja commented May 26, 2024

Changelog

One New Invariant

  1. If rps > 0 and no additional deposits are made, then debt should never decrease. This invariant failing led me to feat: persist amount owed beyond depletion timestamp #126 PR.

Other changes

  1. In README.md, I have used LaTeX to re-write invariant formulas. The order of invariants match the same order in which they are written in Flow.t.sol.
  2. Adds NatSpec over all invariant functions. It match the formulas mentioned in README file.
  3. Makes some changes to invariant_DepositAmountsSumGeExtractedAmountsSum and also renamed them.
  4. Adds new variables in FlowHandler to track key data. These new variables are required by the above 2 new invariants.
  5. updateFlowStates modifier it added to handler to update states prior to the function call.
  6. I have removed restartAndDeposit from handler as its just a proxy for restart and deposit.
  7. Replaced extractedAmounts with refundedAmounts and withdrawnAmounts
  8. Added "only to recipient" note for withdraw made by sender

PR dependencies

Note

The CI test would fail. It demonstrates the bug in the current implementation.

@smol-ninja smol-ninja requested a review from andreivladbrg May 26, 2024 12:47
README.md Outdated Show resolved Hide resolved
Copy link
Member

@andreivladbrg andreivladbrg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If rps > 0 and no additional deposits are made, then debt should never decrease. This invariant failing led me to #126 PR.
If rps > 0 and no withdraws are made, remaining amount + streamed amount should never decrease

aren't these pretty much the same?

let's keep only one - invariant_RpsGt0_RemainingPlusStreamedIncrease

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
test/invariant/handlers/FlowHandler.sol Show resolved Hide resolved
@smol-ninja
Copy link
Member Author

aren't these pretty much the same?

I think no, they are not the same.

  • The first invariant focusses on the debt while the second focusses on the amount owed to the recipient.
  • When debt = 0 and rps > 0, the amount owed should keep increasing.
  • When debt > 0 and rps > 0, the debt should keep increasing.

The test thats failing is invariant_DebtGt0_RpsGt0_DebtIncrease and not invariant_RpsGt0_RemainingPlusStreamedIncrease. So we should keep invariant_DebtGt0_RpsGt0_DebtIncrease but invariant_RpsGt0_RemainingPlusStreamedIncrease is important too for recipient.

@andreivladbrg
Copy link
Member

  • The first invariant focusses on the debt while the second focusses on the amount owed to the recipient

amount owed to the recipient and the stream debt are correlated

it is the same argument you said here

you can't have one(invariant) without the other

but invariant_RpsGt0_RemainingPlusStreamedIncrease is important too for recipient

same thing you can say for $bal \ge rfa$ it is useful for recipient but it is not needed since we have $bal = rfa + wa$

wdyt?

@smol-ninja
Copy link
Member Author

smol-ninja commented May 28, 2024

May be, invariant_RpsGt0_RemainingPlusStreamedIncrease is not a key invariant and the same invariant may already be achieved by other invariants. (I am still thinking if its true). But its not same as the invariant_DebtGt0_RpsGt0_DebtIncrease otherwise both should fail at the same time.

I can remove it for now since I don't have any good argument in its support.

@smol-ninja
Copy link
Member Author

@andreivladbrg I have removed invariant_RpsGt0_RemainingPlusStreamedIncrease invariant. lmk if all looks good now.

@smol-ninja smol-ninja changed the title Add two new invariant tests Tes: add a new invariant test invariant_DebtGt0_RpsGt0_DebtIncrease May 28, 2024
@smol-ninja smol-ninja changed the title Tes: add a new invariant test invariant_DebtGt0_RpsGt0_DebtIncrease test: add a new invariant test invariant_DebtGt0_RpsGt0_DebtIncrease May 28, 2024
@smol-ninja smol-ninja changed the title test: add a new invariant test invariant_DebtGt0_RpsGt0_DebtIncrease test: add a new invariant invariant_DebtGt0_RpsGt0_DebtIncrease May 28, 2024
@smol-ninja smol-ninja changed the title test: add a new invariant invariant_DebtGt0_RpsGt0_DebtIncrease test: add a new invariant_DebtGt0_RpsGt0_DebtIncrease May 28, 2024
@smol-ninja smol-ninja changed the title test: add a new invariant_DebtGt0_RpsGt0_DebtIncrease test: add invariant_DebtGt0_RpsGt0_DebtIncrease May 28, 2024
smol-ninja and others added 6 commits May 28, 2024 14:56
docs: update invariants in readme
test(invariant): replace extractedAmounts with refundedAmounts and withdrawnAmounts
test(invariant): add updateFlowStates modifier
test(invariant): remove restartAndDeposit
test(invariant): add natspecs over invariant tests
test: correct grammar in dev natspec
test: order invariants alphabetically
@smol-ninja smol-ninja force-pushed the test/new-invariants branch from c20a47f to 72de62b Compare May 28, 2024 13:56
README.md Show resolved Hide resolved
Copy link
Member

@andreivladbrg andreivladbrg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good now

@smol-ninja smol-ninja merged commit c45a6d4 into main May 28, 2024
6 checks passed
@smol-ninja smol-ninja deleted the test/new-invariants branch May 28, 2024 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants