From 8358262126b0a8b19a8aee1d292fa166f3a234fc Mon Sep 17 00:00:00 2001 From: mandreyel Date: Tue, 28 Mar 2023 14:29:07 +0400 Subject: [PATCH 1/2] fix: double substate discard in eip-3860 --- src/executor/stack/executor.rs | 1 - src/executor/stack/memory.rs | 4 ++-- src/executor/stack/precompile.rs | 3 ++- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/executor/stack/executor.rs b/src/executor/stack/executor.rs index 05d41c3ee..f3355465b 100644 --- a/src/executor/stack/executor.rs +++ b/src/executor/stack/executor.rs @@ -404,7 +404,6 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> // EIP-3860 if init_code.len() > limit { self.state.metadata_mut().gasometer.fail(); - let _ = self.exit_substate(StackExitKind::Failed); return Err(ExitError::OutOfGas); } return self diff --git a/src/executor/stack/memory.rs b/src/executor/stack/memory.rs index 0ec07eabf..1aa7711ba 100644 --- a/src/executor/stack/memory.rs +++ b/src/executor/stack/memory.rs @@ -54,8 +54,8 @@ impl<'config> MemoryStackSubstate<'config> { &mut self.metadata } - /// Deconstruct the executor, return state to be applied. Panic if the - /// executor is not in the top-level substate. + /// Deconstruct the memory stack substate, return state to be applied. Panic if the + /// substate is not in the top-level substate. #[must_use] pub fn deconstruct( mut self, diff --git a/src/executor/stack/precompile.rs b/src/executor/stack/precompile.rs index 25fbee35a..bd9dead42 100644 --- a/src/executor/stack/precompile.rs +++ b/src/executor/stack/precompile.rs @@ -73,7 +73,8 @@ pub trait PrecompileHandle { } /// A set of precompiles. -/// Checks of the provided address being in the precompile set should be +/// +/// Checks if the provided address is in the precompile set. This should be /// as cheap as possible since it may be called often. pub trait PrecompileSet { /// Tries to execute a precompile in the precompile set. From 94f42b69c435b78a39d8644cc6f5e14976205f0f Mon Sep 17 00:00:00 2001 From: mandreyel Date: Tue, 28 Mar 2023 15:52:21 +0400 Subject: [PATCH 2/2] fix: use CreateContractLimit error for initcode limit violation --- core/src/error.rs | 4 ---- src/executor/stack/executor.rs | 6 +++--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/core/src/error.rs b/core/src/error.rs index 0cd0daf72..510d6df4a 100644 --- a/core/src/error.rs +++ b/core/src/error.rs @@ -154,10 +154,6 @@ pub enum ExitError { /// Other normal errors. #[cfg_attr(feature = "with-codec", codec(index = 13))] Other(Cow<'static, str>), - - /// Init code exceeds limit (runtime). - #[cfg_attr(feature = "with-codec", codec(index = 7))] - InitCodeLimit, } impl From for ExitReason { diff --git a/src/executor/stack/executor.rs b/src/executor/stack/executor.rs index f3355465b..2a3de3d7a 100644 --- a/src/executor/stack/executor.rs +++ b/src/executor/stack/executor.rs @@ -404,7 +404,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> // EIP-3860 if init_code.len() > limit { self.state.metadata_mut().gasometer.fail(); - return Err(ExitError::OutOfGas); + return Err(ExitError::CreateContractLimit); } return self .state @@ -436,7 +436,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> if init_code.len() > limit { self.state.metadata_mut().gasometer.fail(); let _ = self.exit_substate(StackExitKind::Failed); - return emit_exit!(ExitError::InitCodeLimit.into(), Vec::new()); + return emit_exit!(ExitError::CreateContractLimit.into(), Vec::new()); } } @@ -477,7 +477,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> if init_code.len() > limit { self.state.metadata_mut().gasometer.fail(); let _ = self.exit_substate(StackExitKind::Failed); - return emit_exit!(ExitError::InitCodeLimit.into(), Vec::new()); + return emit_exit!(ExitError::CreateContractLimit.into(), Vec::new()); } }