From b436a7f4b34a1bc63857938f09a32ecd397537c9 Mon Sep 17 00:00:00 2001 From: mandreyel Date: Tue, 18 Apr 2023 11:45:05 +0400 Subject: [PATCH] fix: double substate discard in eip-3860 (#160) * fix: double substate discard in eip-3860 * fix: use CreateContractLimit error for initcode limit violation --- core/src/error.rs | 4 ---- src/executor/stack/executor.rs | 7 +++---- src/executor/stack/memory.rs | 4 ++-- src/executor/stack/precompile.rs | 3 ++- 4 files changed, 7 insertions(+), 11 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 05d41c3ee..2a3de3d7a 100644 --- a/src/executor/stack/executor.rs +++ b/src/executor/stack/executor.rs @@ -404,8 +404,7 @@ 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 Err(ExitError::CreateContractLimit); } return self .state @@ -437,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()); } } @@ -478,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()); } } 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 bca915f12..716eed631 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.