Skip to content

Commit

Permalink
fix(hooks): sort reverts in BundleState before comparison (paradigm…
Browse files Browse the repository at this point in the history
  • Loading branch information
Rjected authored Sep 30, 2024
1 parent 68f0b0a commit c2cabca
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion crates/engine/invalid-block-hooks/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ where
db.merge_transitions(BundleRetention::Reverts);

// Take the bundle state
let bundle_state = db.take_bundle();
let mut bundle_state = db.take_bundle();

// Initialize a map of preimages.
let mut state_preimages = HashMap::default();
Expand Down Expand Up @@ -198,6 +198,21 @@ where
}

// The bundle state after re-execution should match the original one.
//
// NOTE: This should not be needed if `Reverts` had a comparison method that sorted first,
// or otherwise did not care about order.
//
// See: https://github.com/bluealloy/revm/issues/1813
let mut output = output.clone();
for reverts in output.state.reverts.iter_mut() {
reverts.sort_by(|left, right| left.0.cmp(&right.0));
}

// We also have to sort the `bundle_state` reverts
for reverts in bundle_state.reverts.iter_mut() {
reverts.sort_by(|left, right| left.0.cmp(&right.0));
}

if bundle_state != output.state {
let original_path = self.save_file(
format!("{}_{}.bundle_state.original.json", block.number, block.hash()),
Expand Down

0 comments on commit c2cabca

Please sign in to comment.