Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(eof): simplify magic checks #1633

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading