diff --git a/core/src/error.rs b/core/src/error.rs index 9a8be94c..5aa73bee 100644 --- a/core/src/error.rs +++ b/core/src/error.rs @@ -168,6 +168,8 @@ pub enum ExitError { /// `usize` casting overflow #[cfg_attr(feature = "with-codec", codec(index = 15))] UsizeOverflow, + #[cfg_attr(feature = "with-codec", codec(index = 16))] + CreateContractStartingWithEF, } impl From for ExitReason { diff --git a/src/executor/stack/executor.rs b/src/executor/stack/executor.rs index 58c22e62..a1106d1e 100644 --- a/src/executor/stack/executor.rs +++ b/src/executor/stack/executor.rs @@ -1085,10 +1085,10 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> reason: ExitReason, return_data: Vec, ) -> (ExitReason, Option, Vec) { - fn check_first_byte(config: &Config, code: &[u8]) -> Result<(), ExitError> { - if config.disallow_executable_format && Some(&Opcode::EOFMAGIC.as_u8()) == code.first() - { - return Err(ExitError::InvalidCode(Opcode::EOFMAGIC)); + // EIP-3541: Reject new contract code starting with the 0xEF byte (EOF Magic) + fn check_first_byte_eof_magic(config: &Config, code: &[u8]) -> Result<(), ExitError> { + if config.disallow_executable_format && Some(&0xEF) == code.first() { + return Err(ExitError::CreateContractStartingWithEF); } Ok(()) } @@ -1100,7 +1100,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> let out = return_data; let address = created_address; // As of EIP-3541 code starting with 0xef cannot be deployed - if let Err(e) = check_first_byte(self.config, &out) { + if let Err(e) = check_first_byte_eof_magic(self.config, &out) { self.state.metadata_mut().gasometer.fail(); let _ = self.exit_substate(&StackExitKind::Failed); return (e.into(), None, Vec::new());