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

invariant (bug): inconsistent shrinked call sequence sometimes #7256

Merged
merged 2 commits into from
Feb 28, 2024

Conversation

grandizzy
Copy link
Collaborator

@grandizzy grandizzy commented Feb 28, 2024

Motivation

while testing fix for #5868 noticed that sometimes the shrinked sequence comes inverted, e.g.

        [Sequence]
                calldata=acceptOwnership(address) args=[0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f]
                calldata=transferOwnership(address,address) args=[0x7FA9385bE102ac3EAc297483Dd6233D62b3e1496, 0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f]

instead

        [Sequence]
                calldata=transferOwnership(address,address) args=[0x7FA9385bE102ac3EAc297483Dd6233D62b3e1496, 0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f]
                calldata=acceptOwnership(address) args=[0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f]

this happens when the same acceptOwnership call that breaks invariant is also performed before transferOwnership prereq, that is in a sequence of:

  1. Alice calls acceptOwnership and reverts
  2. Bob calls transferOwnership to Alice
  3. Alice calls acceptOwnership and breaks invariant
    in this case shrinked indices are [2, 1] but we recreate call sequence as 1 and 2

Solution

Recreate new shrinked call sequence by respecting the order from shrunk call indices

@grandizzy grandizzy marked this pull request as ready for review February 28, 2024 08:39
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.

lgtm, ty

@mattsse mattsse merged commit b279e55 into foundry-rs:master Feb 28, 2024
19 checks passed
// 3. Alice calls acceptOwnership and test fails
// we shrink to indices of [2, 1] and we recreate call sequence in same order
let mut new_calls_sequence = Vec::with_capacity(shrunk_call_indices.len());
shrunk_call_indices.iter().for_each(|call_index| {
Copy link
Member

Choose a reason for hiding this comment

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

this can just be map collect

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.

3 participants