From 3bc2f3ac2118bf1ea3ee8bfce8c170bd1abbe7b4 Mon Sep 17 00:00:00 2001 From: Marcelo Date: Fri, 21 May 2021 20:41:36 +0200 Subject: [PATCH 1/4] Precompile support state --- src/executor/stack/mod.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/executor/stack/mod.rs b/src/executor/stack/mod.rs index 3f824215f..2e0aadd2d 100644 --- a/src/executor/stack/mod.rs +++ b/src/executor/stack/mod.rs @@ -90,15 +90,16 @@ pub struct PrecompileOutput { /// Stack-based executor. pub struct StackExecutor<'config, S> { config: &'config Config, - precompile: fn(H160, &[u8], Option, &Context) -> Option>, + precompile: fn(H160, &[u8], Option, &Context, &mut S) -> Option>, state: S, } -fn no_precompile( +fn no_precompile( _address: H160, _input: &[u8], _target_gas: Option, _context: &Context, + _state: &mut S ) -> Option> { None } @@ -123,7 +124,7 @@ impl<'config, S: StackState<'config>> StackExecutor<'config, S> { pub fn new_with_precompile( state: S, config: &'config Config, - precompile: fn(H160, &[u8], Option, &Context) -> Option>, + precompile: fn(H160, &[u8], Option, &Context, &mut S) -> Option>, ) -> Self { Self { config, @@ -531,7 +532,7 @@ impl<'config, S: StackState<'config>> StackExecutor<'config, S> { } } - if let Some(ret) = (self.precompile)(code_address, &input, Some(gas_limit), &context) { + if let Some(ret) = (self.precompile)(code_address, &input, Some(gas_limit), &context, &mut self.state) { match ret { Ok(PrecompileOutput { exit_status , output, cost, logs }) => { for Log { address, topics, data} in logs { From 47e23f525a7b7f685f842c22c377e68704b3f9e6 Mon Sep 17 00:00:00 2001 From: Marcelo Date: Sun, 30 May 2021 23:06:47 +0200 Subject: [PATCH 2/4] Pass is_static to precompiles --- src/executor/stack/mod.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/executor/stack/mod.rs b/src/executor/stack/mod.rs index 2e0aadd2d..b7552b5f0 100644 --- a/src/executor/stack/mod.rs +++ b/src/executor/stack/mod.rs @@ -87,10 +87,18 @@ pub struct PrecompileOutput { pub logs: Vec, } +/// Precompiles function signature. Expected input arguments are: +/// * Address +/// * Input +/// * Context +/// * State +/// * Is static +type PrecompileFn = fn(H160, &[u8], Option, &Context, &mut S, bool) -> Option>; + /// Stack-based executor. pub struct StackExecutor<'config, S> { config: &'config Config, - precompile: fn(H160, &[u8], Option, &Context, &mut S) -> Option>, + precompile: PrecompileFn, state: S, } @@ -99,7 +107,8 @@ fn no_precompile( _input: &[u8], _target_gas: Option, _context: &Context, - _state: &mut S + _state: &mut S, + _is_static: bool, ) -> Option> { None } @@ -124,7 +133,7 @@ impl<'config, S: StackState<'config>> StackExecutor<'config, S> { pub fn new_with_precompile( state: S, config: &'config Config, - precompile: fn(H160, &[u8], Option, &Context, &mut S) -> Option>, + precompile: PrecompileFn, ) -> Self { Self { config, @@ -532,7 +541,7 @@ impl<'config, S: StackState<'config>> StackExecutor<'config, S> { } } - if let Some(ret) = (self.precompile)(code_address, &input, Some(gas_limit), &context, &mut self.state) { + if let Some(ret) = (self.precompile)(code_address, &input, Some(gas_limit), &context, &mut self.state, is_static) { match ret { Ok(PrecompileOutput { exit_status , output, cost, logs }) => { for Log { address, topics, data} in logs { From b2aea1ad111b803bfa50cd26ed8aec6b63c1c55c Mon Sep 17 00:00:00 2001 From: Marcelo Date: Sun, 30 May 2021 23:08:30 +0200 Subject: [PATCH 3/4] Nit --- src/executor/stack/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/executor/stack/mod.rs b/src/executor/stack/mod.rs index b7552b5f0..7dd4740c1 100644 --- a/src/executor/stack/mod.rs +++ b/src/executor/stack/mod.rs @@ -91,7 +91,7 @@ pub struct PrecompileOutput { /// * Address /// * Input /// * Context -/// * State +/// * State /// * Is static type PrecompileFn = fn(H160, &[u8], Option, &Context, &mut S, bool) -> Option>; From 866657dc4132daecc03bd67731a42f110c85cf76 Mon Sep 17 00:00:00 2001 From: Marcelo Date: Thu, 10 Jun 2021 21:10:55 +0200 Subject: [PATCH 4/4] Use tab instead of space --- src/executor/stack/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/executor/stack/mod.rs b/src/executor/stack/mod.rs index 7dd4740c1..2ede0a629 100644 --- a/src/executor/stack/mod.rs +++ b/src/executor/stack/mod.rs @@ -107,7 +107,7 @@ fn no_precompile( _input: &[u8], _target_gas: Option, _context: &Context, - _state: &mut S, + _state: &mut S, _is_static: bool, ) -> Option> { None