refactor: inject call to CREATE2 factory through custom revm handler#7653
Merged
Conversation
DaniPopes
requested changes
Apr 13, 2024
mattsse
requested changes
Apr 15, 2024
mattsse
left a comment
Member
There was a problem hiding this comment.
this is great,
only have pedantic doc nits for the register function
DaniPopes
approved these changes
Apr 15, 2024
| foundry-common.workspace = true | ||
| foundry-config.workspace = true | ||
| foundry-evm.workspace = true | ||
| foundry-evm-core.workspace = true |
| call.caller = broadcast.new_origin; | ||
| let is_fixed_gas_limit = check_if_fixed_gas_limit(ecx, call.gas_limit); | ||
|
|
||
| let account = ecx.journaled_state.state().get(&broadcast.new_origin).unwrap(); |
Member
There was a problem hiding this comment.
Suggested change
| let account = ecx.journaled_state.state().get(&broadcast.new_origin).unwrap(); | |
| let account = ecx.journaled_state.state()[&broadcast.new_origin]; |
| @@ -1,17 +1,26 @@ | |||
| use std::{cell::RefCell, rc::Rc, sync::Arc}; | |||
|
|
|||
| pub use revm::primitives::State as StateChangeset; | ||
|
|
||
| pub use crate::ic::*; | ||
| use crate::{constants::DEFAULT_CREATE2_DEPLOYER, InspectorExt}; |
| spent - (refunded).min(spent / refund_quotient) | ||
| } | ||
|
|
||
| pub fn get_create2_factory_call_inputs(salt: U256, inputs: CreateInputs) -> CallInputs { |
cabfe24 to
2713557
Compare
2713557 to
c1547da
Compare
2 tasks
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
ref #7632 (comment)
This changes flow for CREATE2 deployments routed through CREATE2 factory. Earlier we would just patch the sender of CREATE2 frame which resulted in data appearing in traces and state diff being different from the actual transaction data.
The way this PR addresses this is by implementing a revm handler register which replaces CREATE2 frame with CALL frame to factory when needed.
Thus, trace of a simple counter CREATE2 deployment changes from:
to:
Solution
Implement
InspectorExttrait withshould_use_create2_factorymethod returning false by default which allows our inspectors to decide if the CREATE frame should be routed through create2 factory.Implement handler register overriding
createandinsert_call_outcomehooks:createhook returnsCALLframe instead ofCREATEframe whenshould_use_create2_factoryfn returns true for the current frame.insert_call_outcomehook decodes result of the create2 factory invocation and inserts it directly into interpreter.Solution is not really clean because I had to duplicate parts of
callandinsert_call_outcomehooks from revm inspector hander register instead of just invoking them in register. The motivation behind this is following:insert_call_outcomehook because it would invokeinspector.insert_call_outcome().insert_call_outcome,callcannot be reused as well because we'd mess up internal stack of inspector handler register (https://github.com/bluealloy/revm/blob/f4f4745e00b1c2907b6a3527eee3765bc1603b58/crates/revm/src/inspector/handler_register.rs#L167)This impl lets us keep cheatcodes inspector and overall flow simpler however it introduces additional complexity in EVM construction step and might result in issues if revm implementation of inspector handler register changes, so not sure if we should include that