From c2cabcae71cf01309f4a8a5542661f9052a49137 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Mon, 30 Sep 2024 18:27:27 -0400 Subject: [PATCH] fix(hooks): sort reverts in `BundleState` before comparison (#11358) --- .../engine/invalid-block-hooks/src/witness.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/engine/invalid-block-hooks/src/witness.rs b/crates/engine/invalid-block-hooks/src/witness.rs index 841427bc3f81..37d5bb08293d 100644 --- a/crates/engine/invalid-block-hooks/src/witness.rs +++ b/crates/engine/invalid-block-hooks/src/witness.rs @@ -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(); @@ -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()),