Skip to content
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

fix: dont calculate initcode keccak on CREATE #969

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions crates/interpreter/src/inner_models.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub use crate::primitives::CreateScheme;
use crate::primitives::{Address, Bytes, B256, U256};
use crate::primitives::{Address, Bytes, U256};

/// Inputs for a call.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -45,16 +45,6 @@ impl CreateInputs {
.create2_from_code(salt.to_be_bytes(), &self.init_code),
}
}

/// Returns the address that this create call will create, without calculating the init code hash.
///
/// Note: `hash` must be `keccak256(&self.init_code)`.
pub fn created_address_with_hash(&self, nonce: u64, hash: &B256) -> Address {
match self.scheme {
CreateScheme::Create => self.caller.create(nonce),
CreateScheme::Create2 { salt } => self.caller.create2(salt.to_be_bytes(), hash),
}
}
}

/// Call schemes.
Expand Down
16 changes: 11 additions & 5 deletions crates/revm/src/evm_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::{
journaled_state::JournaledState,
precompile::{Precompile, Precompiles},
primitives::{
keccak256, Address, AnalysisKind, Bytecode, Bytes, EVMError, Env, Spec, SpecId::*, B256,
U256,
keccak256, Address, AnalysisKind, Bytecode, Bytes, CreateScheme, EVMError, Env, Spec,
SpecId::*, B256, U256,
},
CallStackFrame, CALL_STACK_LIMIT,
};
Expand Down Expand Up @@ -174,8 +174,14 @@ impl<'a, DB: Database> EvmContext<'a, DB> {
}

// Create address
let code_hash = keccak256(&inputs.init_code);
let created_address = inputs.created_address_with_hash(old_nonce, &code_hash);
let mut init_code_hash = B256::ZERO;
let created_address = match inputs.scheme {
CreateScheme::Create => inputs.caller.create(old_nonce),
CreateScheme::Create2 { salt } => {
init_code_hash = keccak256(&inputs.init_code);
inputs.caller.create2(salt.to_be_bytes(), init_code_hash)
}
};

// Load account so it needs to be marked as warm for access list.
if self
Expand Down Expand Up @@ -204,7 +210,7 @@ impl<'a, DB: Database> EvmContext<'a, DB> {
let contract = Box::new(Contract::new(
Bytes::new(),
bytecode,
code_hash,
init_code_hash,
created_address,
inputs.caller,
inputs.value,
Expand Down