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

chore: use collect in invariant code #7259

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions crates/evm/evm/src/executors/invariant/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,14 @@ impl InvariantFuzzError {

let shrunk_call_indices = self.try_shrinking_recurse(calls, executor, 0, 0);

// we recreate the call sequence in the same order as they reproduce the failure
// otherwise we could end up with inverted sequence
// e.g. in a sequence of:
// We recreate the call sequence in the same order as they reproduce the failure,
// otherwise we could end up with inverted sequence.
// E.g. in a sequence of:
// 1. Alice calls acceptOwnership and reverts
// 2. Bob calls transferOwnership to Alice
// 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| {
new_calls_sequence.push(calls.get(*call_index).unwrap());
});
new_calls_sequence
// we shrink to indices of [2, 1] and we recreate call sequence in same order.
shrunk_call_indices.iter().map(|idx| &calls[*idx]).collect()
}

/// We try to construct a [powerset](https://en.wikipedia.org/wiki/Power_set) of the sequence if
Expand Down Expand Up @@ -341,14 +337,12 @@ impl InvariantFuzzError {
);
});

// SAFETY: there are no more live references to shrunk_call_indices as the parallel
// execution is finished, so it is fine to get the inner value via unwrap &
// into_inner
let shrunk_call_indices =
Arc::<RwLock<Vec<usize>>>::try_unwrap(shrunk_call_indices).unwrap().into_inner();
// There are no more live references to shrunk_call_indices as the parallel execution is
// finished, so it is fine to get the inner value via `Arc::unwrap`.
let shrunk_call_indices = Arc::try_unwrap(shrunk_call_indices).unwrap().into_inner();

if is_powerset {
// a powerset is guaranteed to be smallest local subset, so we return early
// A powerset is guaranteed to be smallest local subset, so we return early.
return shrunk_call_indices
}

Expand Down
Loading