Skip to content

Conversation

@Evalir
Copy link
Member

@Evalir Evalir commented Aug 31, 2023

Motivation

This migrates the main Executor and Backend structs to use alloy types. None of the wrappers around the executor/backend or related builders were migrated, and instead, glue was added between them for this PR to serve as a checkpoint in the migration.

Beyond this point, preventing more type-spill is probably not possible as many evm constructs are used directly from the runners and anvil. From here, the entire executor folder will be migrated, and from there the rest of the evm crate.

@Evalir Evalir marked this pull request as draft September 1, 2023 00:09
@Evalir Evalir changed the base branch from alloy-migration to master September 13, 2023 13:22
* feat: migrate non-cheatcode inspectors

* fix: properly create both create and create2 addresses

* chore: clippy

* (#3) Alloy Migration: migrate fork-adjacent files to alloy primitives (#5771)

* chore: use create2_from_code

* borrow it brah

* chore: use from word

* chore: drop to_be_bytes

* fmt

* chore: use from_word on both palces
@Evalir Evalir force-pushed the evalir/make-executor-alloy branch from e9f5719 to a602104 Compare September 15, 2023 16:26
@Evalir Evalir force-pushed the evalir/make-executor-alloy branch from 9110744 to 6efba29 Compare September 15, 2023 17:08
@Evalir Evalir requested a review from DaniPopes September 15, 2023 17:52
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.

more (temporary!!!) conversions

Copy link
Member

@gakonst gakonst left a comment

Choose a reason for hiding this comment

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

Supportive - needless to say calling this project "complete" implies we have no more x_to_y & vice versa conversion code so we still have a lot of work to do...

Next steps IMO:

  1. Keep pushing the conversions to the outer layers
  2. Use alloy-dyn-abi instead of ethabi

In my ideal world, if you switch the ABI types and the CLI result types to Alloy, the only place where I'd expect to see any type conversion code is Anvil's RPC code (which is blocked on alloy-rpc) and the Forking code (which is blocked on alloy-rpc & alloy-providers integrating with Ethereum Mainnet)

Comment on lines 172 to +176
[patch.crates-io]
revm = { git = "https://github.com/bluealloy/revm/", rev = "429da731cd8efdc0939ed912240b2667b9155834" }
revm-interpreter = { git = "https://github.com/bluealloy/revm/", rev = "429da731cd8efdc0939ed912240b2667b9155834" }
revm-precompile = { git = "https://github.com/bluealloy/revm/", rev = "429da731cd8efdc0939ed912240b2667b9155834" }
revm-primitives = { git = "https://github.com/bluealloy/revm/", rev = "429da731cd8efdc0939ed912240b2667b9155834" }
revm = { git = "https://github.com/Evalir/revm/", branch = "reintroduce-alloy-rebased" }
revm-interpreter = { git = "https://github.com/Evalir/revm/", branch = "reintroduce-alloy-rebased" }
revm-precompile = { git = "https://github.com/Evalir/revm/", branch = "reintroduce-alloy-rebased" }
revm-primitives = { git = "https://github.com/Evalir/revm/", branch = "reintroduce-alloy-rebased" }
Copy link
Member

Choose a reason for hiding this comment

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

mental note that once we merge that PR we're able to finally get rid of all patches

types::{H256, U256},
utils::rlp,
};
use foundry_evm::utils::b256_to_h256;
Copy link
Member

Choose a reason for hiding this comment

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

Is the plan still to transition the Anvil types to Alloy U256? And we just are going to do for this file and other untouched ones in follow-up?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep eventually we'll get to them—just letting it happen somewhat naturally by pushing the migration out of the evm crate first.

Comment on lines -14 to 19
/// `address(bytes20(uint160(uint256(keccak256('hevm cheat code')))))`
pub const CHEATCODE_ADDRESS: Address = H160([
pub const CHEATCODE_ADDRESS: Address = Address::new([
0x71, 0x09, 0x70, 0x9E, 0xcf, 0xa9, 0x1a, 0x80, 0x62, 0x6f, 0xf3, 0x98, 0x9d, 0x68, 0xf6, 0x7f,
0x5b, 0x1d, 0xd1, 0x2d,
]);
Copy link
Member

Choose a reason for hiding this comment

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

nit we can prob use const-keccak here and instead of hardcoding the hash have the pre-image in it, but no need

fn next_id(&mut self) -> U256 {
let id = self.next_fork_id;
self.next_fork_id += U256::one();
self.next_fork_id += U256::from(1);
Copy link
Member

Choose a reason for hiding this comment

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

::ONE works i think

Copy link
Member Author

Choose a reason for hiding this comment

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

data.journaled_state
.set_code(h160_to_b160(inner.0), Bytecode::new_raw(code.0).to_checked());
data.journaled_state.set_code(
h160_to_b160(inner.0),
Copy link
Member

Choose a reason for hiding this comment

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

I am realizing some of this code snafu could've been avoided if we had added a From<ethers::U256> for alloy::U256 etc. compatibility layer in Alloy, to make the migration easier - as an optional feature, and then remove it

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep. We'll introduce a conversion trait on foundry to aid with this after we merge this PR!

@Evalir Evalir force-pushed the evalir/make-executor-alloy branch from 7730916 to efd5751 Compare September 16, 2023 04:42
@Evalir Evalir changed the title (#1) Alloy Migration: Migrate executor / backend structs (#1) Alloy Migration: first update batch. Sep 18, 2023
@Evalir Evalir changed the title (#1) Alloy Migration: first update batch. (#1) Alloy Migration: first batch (type conversions) Sep 18, 2023
@Evalir
Copy link
Member Author

Evalir commented Sep 18, 2023

CI failure unrelated, fixed in 2ffb568

@Evalir Evalir merged commit 49f4530 into master Sep 18, 2023
@Evalir Evalir deleted the evalir/make-executor-alloy branch September 18, 2023 14:31
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.

5 participants