Skip to content

Commit

Permalink
chore(eof): simplify magic checks (#1633)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Jul 17, 2024
1 parent 8700c8a commit 782c3dd
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/primitives/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl Bytecode {
/// Returns an error on incorrect EOF format.
#[inline]
pub fn new_raw_checked(bytecode: Bytes) -> Result<Self, EofDecodeError> {
if bytecode.get(..2) == Some(&[0xEF, 00]) {
if bytecode.starts_with(&EOF_MAGIC_BYTES) {
Ok(Self::Eof(Arc::new(Eof::decode(bytecode)?)))
} else {
Ok(Self::LegacyRaw(bytecode))
Expand Down
5 changes: 2 additions & 3 deletions crates/revm/src/context/evm_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl<DB: Database> EvmContext<DB> {

// ExtDelegateCall is not allowed to call non-EOF contracts.
if inputs.scheme.is_ext_delegate_call()
&& bytecode.bytes_slice().get(..2) != Some(&EOF_MAGIC_BYTES)
&& !bytecode.bytes_slice().starts_with(&EOF_MAGIC_BYTES)
{
return return_result(InstructionResult::InvalidExtDelegateCallTarget);
}
Expand Down Expand Up @@ -271,8 +271,7 @@ impl<DB: Database> EvmContext<DB> {
}

// Prague EOF
if spec_id.is_enabled_in(PRAGUE_EOF) && inputs.init_code.get(..2) == Some(&EOF_MAGIC_BYTES)
{
if spec_id.is_enabled_in(PRAGUE_EOF) && inputs.init_code.starts_with(&EOF_MAGIC_BYTES) {
return return_error(InstructionResult::CreateInitCodeStartingEF00);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ impl<EXT, DB: Database> Evm<'_, EXT, DB> {
TxKind::Create => {
// if first byte of data is magic 0xEF00, then it is EOFCreate.
if spec_id.is_enabled_in(SpecId::PRAGUE_EOF)
&& ctx.env().tx.data.get(0..2) == Some(&EOF_MAGIC_BYTES)
&& ctx.env().tx.data.starts_with(&EOF_MAGIC_BYTES)
{
exec.eofcreate(
ctx,
Expand Down

0 comments on commit 782c3dd

Please sign in to comment.