test: add stateful invariant suite for Vault#7
Merged
Conversation
Mirrors the Staking invariant pattern: handler exposes deposit/withdraw, foundry picks random sequences across three actors, and three invariants are checked after every call: - contract ETH balance == sum of user balances - contract balance == ghostDeposits - ghostWithdrawals (independent accounting catches state corruption that affects both sides equally) - totalAssets() never disagrees with balance
Owner
Author
|
Reviewed - the ghost-accounting invariant is the one I want long-term; it's the cheapest way to catch class-of-bug where two paths drift in the same direction. 0 reverts across 3840 calls per run. Merging. |
oliv3rdrt
added a commit
that referenced
this pull request
Jun 27, 2026
Mirrors the Staking invariant pattern: handler exposes deposit/withdraw, foundry picks random sequences across three actors, and three invariants are checked after every call: - contract ETH balance == sum of user balances - contract balance == ghostDeposits - ghostWithdrawals (independent accounting catches state corruption that affects both sides equally) - totalAssets() never disagrees with balance Co-authored-by: Oliver Anyanwu <oliver.anyanwu@aol.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
test/VaultInvariant.t.solwith three invariants run across 256 sequences × 15 calls each.ghostTotalDeposits - ghostTotalWithdrawals == balance) on top of the obvious 'sum of balances' invariant - independent accounting catches state corruption that would otherwise fool a balance-vs-balance comparison.StakingInvariantHandlerso the patterns stay readable side by side.Test plan
forge test --match-contract VaultInvariantTest- 3/3 (256 runs each, 3840 calls each, 0 reverts)forge test- 51/51, no regressions