Skip to content
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: 6 additions & 6 deletions crates/handler/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ pub fn create_init_frame(
return_memory_offset: 0..0,
}))
}
TxKind::Create => FrameInput::Create(Box::new(CreateInputs {
caller: tx.caller(),
scheme: CreateScheme::Create,
value: tx.value(),
init_code: input,
TxKind::Create => FrameInput::Create(Box::new(CreateInputs::new(
tx.caller(),
CreateScheme::Create,
tx.value(),
input,
gas_limit,
})),
))),
}
}
8 changes: 4 additions & 4 deletions crates/interpreter/src/instructions/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ pub fn create<WIRE: InterpreterTypes, const IS_CREATE2: bool, H: Host + ?Sized>(
.interpreter
.bytecode
.set_action(InterpreterAction::NewFrame(FrameInput::Create(Box::new(
CreateInputs {
caller: context.interpreter.input.target_address(),
CreateInputs::new(
context.interpreter.input.target_address(),
scheme,
value,
init_code: code,
code,
gas_limit,
},
),
))));
}

Expand Down
31 changes: 28 additions & 3 deletions crates/interpreter/src/interpreter_action/create_inputs.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use context_interface::CreateScheme;
use core::cell::OnceCell;
use primitives::{Address, Bytes, U256};

/// Inputs for a create call
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CreateInputs {
/// Caller address of the EVM
Expand All @@ -15,17 +16,41 @@ pub struct CreateInputs {
pub init_code: Bytes,
/// The gas limit of the call
pub gas_limit: u64,
/// Cached created address. This is computed lazily and cached to avoid
/// redundant keccak computations when inspectors call `created_address`.
#[cfg_attr(feature = "serde", serde(skip))]
cached_address: OnceCell<Address>,
}

impl CreateInputs {
/// Creates a new `CreateInputs` instance.
pub fn new(
caller: Address,
scheme: CreateScheme,
value: U256,
init_code: Bytes,
gas_limit: u64,
) -> Self {
Self {
caller,
scheme,
value,
init_code,
gas_limit,
cached_address: OnceCell::new(),
}
}

/// Returns the address that this create call will create.
///
/// The result is cached to avoid redundant keccak computations.
pub fn created_address(&self, nonce: u64) -> Address {
match self.scheme {
*self.cached_address.get_or_init(|| match self.scheme {
CreateScheme::Create => self.caller.create(nonce),
CreateScheme::Create2 { salt } => self
.caller
.create2_from_code(salt.to_be_bytes(), &self.init_code),
CreateScheme::Custom { address } => address,
}
})
}
}
Loading