diff --git a/crates/handler/src/frame.rs b/crates/handler/src/frame.rs index 6338ea44af..479e4093c1 100644 --- a/crates/handler/src/frame.rs +++ b/crates/handler/src/frame.rs @@ -270,7 +270,7 @@ impl EthFrame { 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, @@ -284,11 +284,11 @@ impl EthFrame { // 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); } @@ -300,11 +300,11 @@ impl EthFrame { // 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, }; @@ -316,9 +316,9 @@ impl EthFrame { // 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, @@ -326,18 +326,18 @@ impl EthFrame { }; 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 }), diff --git a/crates/interpreter/src/interpreter_action/create_inputs.rs b/crates/interpreter/src/interpreter_action/create_inputs.rs index fe88771072..1085c3dab8 100644 --- a/crates/interpreter/src/interpreter_action/create_inputs.rs +++ b/crates/interpreter/src/interpreter_action/create_inputs.rs @@ -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))] @@ -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; + } }