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
26 changes: 13 additions & 13 deletions crates/handler/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl EthFrame<EthInterpreter> {
Ok(ItemOrResult::Result(FrameResult::Create(CreateOutcome {
result: InterpreterResult {
result: e,
gas: Gas::new(inputs.gas_limit),
gas: Gas::new(inputs.gas_limit()),
output: Bytes::new(),
},
address: None,
Expand All @@ -284,11 +284,11 @@ impl EthFrame<EthInterpreter> {

// Fetch balance of caller.
let journal = context.journal_mut();
let mut caller_info = journal.load_account_mut(inputs.caller)?;
let mut caller_info = journal.load_account_mut(inputs.caller())?;

// Check if caller has enough balance to send to the created contract.
// decrement of balance is done in the create_account_checkpoint.
if *caller_info.balance() < inputs.value {
if *caller_info.balance() < inputs.value() {
return return_error(InstructionResult::OutOfFunds);
}

Expand All @@ -300,11 +300,11 @@ impl EthFrame<EthInterpreter> {

// Create address
let mut init_code_hash = None;
let created_address = match inputs.scheme {
CreateScheme::Create => inputs.caller.create(old_nonce),
let created_address = match inputs.scheme() {
CreateScheme::Create => inputs.caller().create(old_nonce),
CreateScheme::Create2 { salt } => {
let init_code_hash = *init_code_hash.insert(keccak256(&inputs.init_code));
inputs.caller.create2(salt.to_be_bytes(), init_code_hash)
let init_code_hash = *init_code_hash.insert(keccak256(inputs.init_code()));
inputs.caller().create2(salt.to_be_bytes(), init_code_hash)
}
CreateScheme::Custom { address } => address,
};
Expand All @@ -316,28 +316,28 @@ impl EthFrame<EthInterpreter> {

// Create account, transfer funds and make the journal checkpoint.
let checkpoint = match context.journal_mut().create_account_checkpoint(
inputs.caller,
inputs.caller(),
created_address,
inputs.value,
inputs.value(),
spec,
) {
Ok(checkpoint) => checkpoint,
Err(e) => return return_error(e.into()),
};

let bytecode = ExtBytecode::new_with_optional_hash(
Bytecode::new_legacy(inputs.init_code.clone()),
Bytecode::new_legacy(inputs.init_code().clone()),
init_code_hash,
);

let interpreter_input = InputsImpl {
target_address: created_address,
caller_address: inputs.caller,
caller_address: inputs.caller(),
bytecode_address: None,
input: CallInput::Bytes(Bytes::new()),
call_value: inputs.value,
call_value: inputs.value(),
};
let gas_limit = inputs.gas_limit;
let gas_limit = inputs.gas_limit();

this.get(EthFrame::invalid).clear(
FrameData::Create(CreateFrame { created_address }),
Expand Down
63 changes: 58 additions & 5 deletions crates/interpreter/src/interpreter_action/create_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use primitives::{Address, Bytes, U256};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CreateInputs {
/// Caller address of the EVM
pub caller: Address,
caller: Address,
/// The create scheme
pub scheme: CreateScheme,
scheme: CreateScheme,
/// The value to transfer
pub value: U256,
value: U256,
/// The init code of the contract
pub init_code: Bytes,
init_code: Bytes,
/// The gas limit of the call
pub gas_limit: u64,
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))]
Expand Down Expand Up @@ -53,4 +53,57 @@ impl CreateInputs {
CreateScheme::Custom { address } => address,
})
}

/// Returns the caller address of the EVM.
pub fn caller(&self) -> Address {
self.caller
}

/// Returns the create scheme of the EVM.
pub fn scheme(&self) -> CreateScheme {
self.scheme
}

/// Returns the value to transfer.
pub fn value(&self) -> U256 {
self.value
}

/// Returns the init code of the contract.
pub fn init_code(&self) -> &Bytes {
&self.init_code
}

/// Returns the gas limit of the call.
pub fn gas_limit(&self) -> u64 {
self.gas_limit
}

/// Set call
pub fn set_call(&mut self, caller: Address) {
self.caller = caller;
self.cached_address = OnceCell::new();
}

/// Set scheme
pub fn set_scheme(&mut self, scheme: CreateScheme) {
self.scheme = scheme;
self.cached_address = OnceCell::new();
}

/// Set value
pub fn set_value(&mut self, value: U256) {
self.value = value;
}

/// Set init code
pub fn set_init_code(&mut self, init_code: Bytes) {
self.init_code = init_code;
self.cached_address = OnceCell::new();
}

/// Set gas limit
pub fn set_gas_limit(&mut self, gas_limit: u64) {
self.gas_limit = gas_limit;
}
}
Loading