From d58d203c5855f5cbf27e89821a64d26c41856e3b Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Thu, 23 Nov 2023 02:58:29 +0100 Subject: [PATCH] Expose parent machine information in substate creation (#230) --- src/standard/invoker/mod.rs | 38 ++++++++++++++++++-------------- src/standard/invoker/routines.rs | 15 ++++++------- src/standard/mod.rs | 10 +++++---- 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/standard/invoker/mod.rs b/src/standard/invoker/mod.rs index 39b3fd7ef..b51772253 100644 --- a/src/standard/invoker/mod.rs +++ b/src/standard/invoker/mod.rs @@ -178,7 +178,7 @@ impl<'config, 'precompile, 'etable, S, G, H, Pre, Tr, F> impl<'config, 'precompile, 'etable, S, G, H, Pre, Tr, F> InvokerT for Invoker<'config, 'precompile, 'etable, S, G, H, Pre, Tr, F> where - S: MergeableRuntimeState, + S: MergeableRuntimeState>, G: GasometerT + TransactGasometer<'config, S>, H: RuntimeEnvironment + RuntimeBackend + TransactionalBackend, Pre: CodeResolver, @@ -506,12 +506,15 @@ where submeter.analyse_code(&code); } - let substate = machine.machine.state.substate(RuntimeState { - context: call_trap_data.context.clone(), - transaction_context, - retbuf: Vec::new(), - gas: U256::from(gas_limit), - }); + let substate = machine.machine.state.substate( + RuntimeState { + context: call_trap_data.context.clone(), + transaction_context, + retbuf: Vec::new(), + gas: U256::from(gas_limit), + }, + &machine, + ); Capture::Exit(routines::enter_call_substack( self.config, @@ -533,16 +536,19 @@ where let caller = create_trap_data.scheme.caller(); let address = create_trap_data.scheme.address(handler); - let substate = machine.machine.state.substate(RuntimeState { - context: Context { - address, - caller, - apparent_value: create_trap_data.value, + let substate = machine.machine.state.substate( + RuntimeState { + context: Context { + address, + caller, + apparent_value: create_trap_data.value, + }, + transaction_context, + retbuf: Vec::new(), + gas: U256::from(gas_limit), }, - transaction_context, - retbuf: Vec::new(), - gas: U256::from(gas_limit), - }); + &machine, + ); Capture::Exit( routines::enter_create_substack( diff --git a/src/standard/invoker/routines.rs b/src/standard/invoker/routines.rs index b64f6f37d..ae4ee6ff1 100644 --- a/src/standard/invoker/routines.rs +++ b/src/standard/invoker/routines.rs @@ -1,9 +1,9 @@ use super::{CallTrapData, CreateTrapData, Precompile, ResolvedCode, SubstackInvoke}; -use crate::standard::{Config, MergeableRuntimeState}; +use crate::standard::Config; use crate::{ ExitError, ExitException, ExitResult, GasedMachine, Gasometer as GasometerT, InvokerControl, - Machine, MergeStrategy, Opcode, RuntimeBackend, RuntimeEnvironment, StaticGasometer, - TransactionalBackend, Transfer, + Machine, MergeStrategy, Opcode, RuntimeBackend, RuntimeEnvironment, RuntimeState, + StaticGasometer, TransactionalBackend, Transfer, }; use alloc::rc::Rc; use primitive_types::{H160, U256}; @@ -19,7 +19,7 @@ pub fn make_enter_call_machine<'config, 'precompile, S, G, H, P>( handler: &mut H, ) -> Result, (ExitResult, (S, G, Vec))>, ExitError> where - S: MergeableRuntimeState, + S: AsRef, G: GasometerT, H: RuntimeEnvironment + RuntimeBackend + TransactionalBackend, P: Precompile, @@ -67,7 +67,7 @@ pub fn make_enter_create_machine<'config, S, G, H>( handler: &mut H, ) -> Result, ExitError> where - S: MergeableRuntimeState, + S: AsRef, G: GasometerT, H: RuntimeEnvironment + RuntimeBackend + TransactionalBackend, { @@ -125,7 +125,7 @@ pub fn enter_call_substack<'config, 'precompile, S, G, H, P>( ExitError, > where - S: MergeableRuntimeState, + S: AsRef, G: GasometerT, H: RuntimeEnvironment + RuntimeBackend + TransactionalBackend, P: Precompile, @@ -166,7 +166,7 @@ pub fn enter_create_substack<'config, S, G, H>( handler: &mut H, ) -> Result<(SubstackInvoke, GasedMachine), ExitError> where - S: MergeableRuntimeState, + S: AsRef, G: GasometerT, H: RuntimeEnvironment + RuntimeBackend + TransactionalBackend, { @@ -225,7 +225,6 @@ pub fn deploy_create_code<'config, S, G, H>( handler: &mut H, ) -> Result<(), ExitError> where - S: MergeableRuntimeState, G: GasometerT, H: RuntimeEnvironment + RuntimeBackend + TransactionalBackend, { diff --git a/src/standard/mod.rs b/src/standard/mod.rs index 7ce44ead7..3fecb7d72 100644 --- a/src/standard/mod.rs +++ b/src/standard/mod.rs @@ -11,15 +11,17 @@ pub type Efn = crate::Efn; pub type Etable> = crate::Etable; pub type GasedMachine = crate::GasedMachine; -pub trait MergeableRuntimeState: AsRef + AsMut { - fn substate(&self, runtime: crate::RuntimeState) -> Self; +pub trait MergeableRuntimeState: + AsRef + AsMut +{ + fn substate(&self, runtime: crate::RuntimeState, parent: &M) -> Self; fn merge(&mut self, substate: Self, strategy: crate::MergeStrategy); fn new_transact_call(runtime: crate::RuntimeState) -> Self; fn new_transact_create(runtime: crate::RuntimeState) -> Self; } -impl MergeableRuntimeState for crate::RuntimeState { - fn substate(&self, runtime: crate::RuntimeState) -> Self { +impl MergeableRuntimeState for crate::RuntimeState { + fn substate(&self, runtime: crate::RuntimeState, _parent: &M) -> Self { runtime } fn merge(&mut self, _substate: Self, _strategy: crate::MergeStrategy) {}