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

fix(primitives) : Check first byte for EOF #1479

Closed

Conversation

DoTheBestToGetTheBest
Copy link
Contributor

Closes #1464

/// Checks if the bytecode starts with the EOF prefix followed by the correct version.
#[inline]
pub fn is_eof_format(bytes: &Bytes) -> bool {
bytes.len() >= 2 && bytes[0] == EOF_PREFIX && bytes[1] == EOF_VERSION
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct. EOF_MAGIC is 0xEF00 while EOF_VERSION (At least version one) is 0x01. Would be good to move those in revm-primitives crate

prefix is 0xEF0001

pub fn is_eof_format(bytes: &Bytes) -> bool {
bytes.len() >= 2 && bytes[0] == EOF_PREFIX && bytes[1] == EOF_VERSION
}

/// Creates a new raw [`Bytecode`].
#[inline]
pub fn new_raw(bytecode: Bytes) -> Self {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would return Error here as Legacy bytecode with 0xEF is considered invalid. And only valid EOF can have 0xEF prefix.

Would additionally add new_legacy function for legacy codes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would return error here

Comment on lines +77 to +82
if bytes.len() >= 3 {
let prefix = u16::from_be_bytes([bytes[0], bytes[1]]);
let version = bytes[2];

prefix == EOF_PREFIX && version == EOF_VERSION
} else {
Copy link
Member

@rakita rakita Jun 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be missleading in tx create case. For EOF only first two bytes should be checked.

You can do this as:
inputs.init_code.get(..2) == Some(&EOF_MAGIC_BYTES)


/// Version byte that immediately follows the EOF prefix in EIP-3540.
// See https://github.com/bluealloy/revm/issues/1464
pub const EOF_VERSION: u8 = 0x01;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EOF_MAGIC_BYTES const were added to src/bytecode/eof.rs

@rakita
Copy link
Member

rakita commented Jul 12, 2024

Superseded by #1607

@rakita rakita closed this Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bytecode::new_raw should check first byte for EOF
2 participants