From bc0a9f94c87abc64708b52d7d1f67bf99e43fca8 Mon Sep 17 00:00:00 2001 From: Agusrodri Date: Tue, 25 Jun 2024 06:16:43 -0700 Subject: [PATCH] add SetCodeOrigin enum --- interpreter/src/runtime.rs | 9 ++++++++- interpreter/tests/usability.rs | 4 ++-- src/backend/overlayed.rs | 4 ++-- src/standard/invoker/mod.rs | 8 ++++---- src/standard/invoker/routines.rs | 6 +++--- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/interpreter/src/runtime.rs b/interpreter/src/runtime.rs index 91908600..63d85dd6 100644 --- a/interpreter/src/runtime.rs +++ b/interpreter/src/runtime.rs @@ -77,6 +77,13 @@ pub struct Log { pub data: Vec, } +// Identify if the origin of set_code() comes from a transact or subcall. +#[derive(Clone, Debug)] +pub enum SetCodeOrigin { + Transaction, + Subcall(H160), +} + #[auto_impl::auto_impl(&, Box)] pub trait RuntimeEnvironment { /// Get environmental block hash. @@ -160,7 +167,7 @@ pub trait RuntimeBackend: RuntimeBaseBackend { &mut self, address: H160, code: Vec, - caller: Option, + origin: SetCodeOrigin, ) -> Result<(), ExitError>; /// Reset balance of an account. fn reset_balance(&mut self, address: H160); diff --git a/interpreter/tests/usability.rs b/interpreter/tests/usability.rs index d25230a1..a5b8cecd 100644 --- a/interpreter/tests/usability.rs +++ b/interpreter/tests/usability.rs @@ -7,7 +7,7 @@ use evm_interpreter::{ opcode::Opcode, runtime::{ Context, Log, RuntimeBackend, RuntimeBaseBackend, RuntimeEnvironment, RuntimeState, - TransactionContext, + SetCodeOrigin, TransactionContext, }, EtableInterpreter, RunInterpreter, }; @@ -169,7 +169,7 @@ impl RuntimeBackend for UnimplementedHandler { &mut self, _address: H160, _code: Vec, - _caller: Option, + _origin: SetCodeOrigin, ) -> Result<(), ExitError> { unimplemented!() } diff --git a/src/backend/overlayed.rs b/src/backend/overlayed.rs index 4f302c23..638fbc85 100644 --- a/src/backend/overlayed.rs +++ b/src/backend/overlayed.rs @@ -7,7 +7,7 @@ use core::mem; use evm_interpreter::{ error::{ExitError, ExitException}, - runtime::{Log, RuntimeBackend, RuntimeBaseBackend, RuntimeEnvironment}, + runtime::{Log, RuntimeBackend, RuntimeBaseBackend, RuntimeEnvironment, SetCodeOrigin}, }; use primitive_types::{H160, H256, U256}; @@ -196,7 +196,7 @@ impl RuntimeBackend for OverlayedBackend { &mut self, address: H160, code: Vec, - _caller: Option, + _origin: SetCodeOrigin, ) -> Result<(), ExitError> { self.substate.codes.insert(address, code); Ok(()) diff --git a/src/standard/invoker/mod.rs b/src/standard/invoker/mod.rs index 7797dc04..b1735eed 100644 --- a/src/standard/invoker/mod.rs +++ b/src/standard/invoker/mod.rs @@ -12,8 +12,8 @@ use evm_interpreter::{ }, opcode::Opcode, runtime::{ - Context, GasState, RuntimeBackend, RuntimeEnvironment, RuntimeState, TransactionContext, - Transfer, + Context, GasState, RuntimeBackend, RuntimeEnvironment, RuntimeState, SetCodeOrigin, + TransactionContext, Transfer, }, Interpreter, }; @@ -375,7 +375,7 @@ where retbuf, &mut substate, handler, - None, + SetCodeOrigin::Transaction, )?; Ok(TransactValue::Create { @@ -574,7 +574,7 @@ where retbuf.clone(), &mut substate, handler, - Some(caller), + SetCodeOrigin::Subcall(caller), )?; Ok(address) diff --git a/src/standard/invoker/routines.rs b/src/standard/invoker/routines.rs index 26c63d03..cdd3909c 100644 --- a/src/standard/invoker/routines.rs +++ b/src/standard/invoker/routines.rs @@ -3,7 +3,7 @@ use alloc::vec::Vec; use evm_interpreter::{ error::{CallTrapData, CreateTrapData, ExitError, ExitException, ExitResult}, opcode::Opcode, - runtime::{RuntimeBackend, RuntimeEnvironment, RuntimeState, Transfer}, + runtime::{RuntimeBackend, RuntimeEnvironment, RuntimeState, SetCodeOrigin, Transfer}, }; use primitive_types::{H160, U256}; @@ -197,7 +197,7 @@ pub fn deploy_create_code<'config, S, H>( retbuf: Vec, state: &mut S, handler: &mut H, - caller: Option, + origin: SetCodeOrigin, ) -> Result<(), ExitError> where S: InvokerState<'config>, @@ -213,7 +213,7 @@ where state.record_codedeposit(retbuf.len())?; - handler.set_code(address, retbuf, caller)?; + handler.set_code(address, retbuf, origin)?; Ok(()) }