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

fix(forge): Invariant Shrinking #6530

Merged
merged 10 commits into from
Dec 11, 2023
Merged

fix(forge): Invariant Shrinking #6530

merged 10 commits into from
Dec 11, 2023

Conversation

brockelmore
Copy link
Member

@brockelmore brockelmore commented Dec 6, 2023

Motivation

https://x.com/devdacian/status/1732065261195526515
https://x.com/devdacian/status/1731900735686685094

Our current shrinking algorithm for invariants doesn't work very well, leaving a ton of extra txs in the sequence. This improves it, making it easier for devs to understand the flow for the invariant to break.

Solution

Construct either a power set or random subsequence of function calls and run them all in parallel to see if the invariant still breaks. If the new shorter subsequence still breaks the invariant, update the global shortest sequence tracker. If we used a random subsequence (not power set), recurse and try to continue to reduce until we hit the shrink_run_limit. If we used a power set, we are guaranteed to have hit a local minimum in sequence length after it is completed.

Also adds a configuration option: shrink_run_limit - this is the number of sequences to try. A higher number of sequences allowed will result in more simplification (up until a local or global minimum is found).

Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

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

nits

crates/evm/evm/Cargo.toml Outdated Show resolved Hide resolved
crates/evm/evm/src/executors/invariant/error.rs Outdated Show resolved Hide resolved
Copy link
Member

@Evalir Evalir left a comment

Choose a reason for hiding this comment

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

this is sick! some nits

crates/evm/evm/src/executors/invariant/error.rs Outdated Show resolved Hide resolved
crates/evm/evm/src/executors/invariant/error.rs Outdated Show resolved Hide resolved
crates/evm/evm/src/executors/invariant/error.rs Outdated Show resolved Hide resolved
crates/evm/evm/src/executors/invariant/error.rs Outdated Show resolved Hide resolved
@brockelmore
Copy link
Member Author

TODO: Add documentation in book about shrink and shrink_run_limit
Screenshot 2023-12-06 at 9 50 16 AM

Copy link
Member

@Evalir Evalir left a comment

Choose a reason for hiding this comment

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

Love it, lgtm bar a few nits

crates/evm/evm/src/executors/invariant/error.rs Outdated Show resolved Hide resolved
crates/evm/evm/src/executors/invariant/error.rs Outdated Show resolved Hide resolved
Copy link
Member

@Evalir Evalir left a comment

Choose a reason for hiding this comment

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

lgtm — pinging @mattsse for any final nits before merge

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

not very familiar with the invariant impl,
but the comments make sense to me

Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

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

lgtm

@DaniPopes DaniPopes merged commit 6998c79 into master Dec 11, 2023
20 checks passed
@DaniPopes DaniPopes deleted the brock/invariant_shrinking branch December 11, 2023 00:51
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.

None yet

5 participants