-
Notifications
You must be signed in to change notification settings - Fork 2.3k
(#1) Alloy Migration: first batch (type conversions) #5768
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
Conversation
* 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
e9f5719 to
a602104
Compare
9110744 to
6efba29
Compare
mattsse
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more (temporary!!!) conversions
There was a problem hiding this 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:
- Keep pushing the conversions to the outer layers
- Use
alloy-dyn-abiinstead 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)
| [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" } |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
| /// `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, | ||
| ]); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
::ONE works i think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems ZERO's the only constant available: https://docs.rs/ruint/1.10.1/ruint/struct.Uint.html#associatedconstant.ZERO
| 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), |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
7730916 to
efd5751
Compare
|
CI failure unrelated, fixed in 2ffb568 |
Motivation
This migrates the main
ExecutorandBackendstructs 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
evmconstructs are used directly from the runners and anvil. From here, the entireexecutorfolder will be migrated, and from there the rest of theevmcrate.