Skip to content

Commit

Permalink
Fix: Refactore EOFMAGIC check creation (#59)
Browse files Browse the repository at this point in the history
* Refactore EOFMAGIC code creation, issue #58

* Change index CreateContractStartingWithEF to 16
  • Loading branch information
mrLSD committed Aug 27, 2024
1 parent 53f3ce2 commit 1d9d1dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExitError> for ExitReason {
Expand Down
10 changes: 5 additions & 5 deletions src/executor/stack/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1085,10 +1085,10 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
reason: ExitReason,
return_data: Vec<u8>,
) -> (ExitReason, Option<H160>, Vec<u8>) {
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(())
}
Expand All @@ -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());
Expand Down

0 comments on commit 1d9d1dc

Please sign in to comment.