-
Notifications
You must be signed in to change notification settings - Fork 642
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
fix(primitives) : Check first byte for EOF #1479
Conversation
crates/primitives/src/bytecode.rs
Outdated
/// 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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would return error here
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 { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
Superseded by #1607 |
Closes #1464