Skip to content

Commit

Permalink
add SetCodeOrigin enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Agusrodri committed Jun 25, 2024
1 parent 8bf3859 commit bc0a9f9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
9 changes: 8 additions & 1 deletion interpreter/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ pub struct Log {
pub data: Vec<u8>,
}

// 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.
Expand Down Expand Up @@ -160,7 +167,7 @@ pub trait RuntimeBackend: RuntimeBaseBackend {
&mut self,
address: H160,
code: Vec<u8>,
caller: Option<H160>,
origin: SetCodeOrigin,
) -> Result<(), ExitError>;
/// Reset balance of an account.
fn reset_balance(&mut self, address: H160);
Expand Down
4 changes: 2 additions & 2 deletions interpreter/tests/usability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use evm_interpreter::{
opcode::Opcode,
runtime::{
Context, Log, RuntimeBackend, RuntimeBaseBackend, RuntimeEnvironment, RuntimeState,
TransactionContext,
SetCodeOrigin, TransactionContext,
},
EtableInterpreter, RunInterpreter,
};
Expand Down Expand Up @@ -169,7 +169,7 @@ impl RuntimeBackend for UnimplementedHandler {
&mut self,
_address: H160,
_code: Vec<u8>,
_caller: Option<H160>,
_origin: SetCodeOrigin,
) -> Result<(), ExitError> {
unimplemented!()
}
Expand Down
4 changes: 2 additions & 2 deletions src/backend/overlayed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -196,7 +196,7 @@ impl<B: RuntimeBaseBackend> RuntimeBackend for OverlayedBackend<B> {
&mut self,
address: H160,
code: Vec<u8>,
_caller: Option<H160>,
_origin: SetCodeOrigin,
) -> Result<(), ExitError> {
self.substate.codes.insert(address, code);
Ok(())
Expand Down
8 changes: 4 additions & 4 deletions src/standard/invoker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -375,7 +375,7 @@ where
retbuf,
&mut substate,
handler,
None,
SetCodeOrigin::Transaction,
)?;

Ok(TransactValue::Create {
Expand Down Expand Up @@ -574,7 +574,7 @@ where
retbuf.clone(),
&mut substate,
handler,
Some(caller),
SetCodeOrigin::Subcall(caller),
)?;

Ok(address)
Expand Down
6 changes: 3 additions & 3 deletions src/standard/invoker/routines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -197,7 +197,7 @@ pub fn deploy_create_code<'config, S, H>(
retbuf: Vec<u8>,
state: &mut S,
handler: &mut H,
caller: Option<H160>,
origin: SetCodeOrigin,
) -> Result<(), ExitError>
where
S: InvokerState<'config>,
Expand All @@ -213,7 +213,7 @@ where

state.record_codedeposit(retbuf.len())?;

handler.set_code(address, retbuf, caller)?;
handler.set_code(address, retbuf, origin)?;

Ok(())
}

0 comments on commit bc0a9f9

Please sign in to comment.