-
Notifications
You must be signed in to change notification settings - Fork 966
fix(primitives) : Check first byte for EOF #1479
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,18 @@ | ||
| pub mod eof; | ||
| pub mod legacy; | ||
|
|
||
| pub use eof::Eof; | ||
| pub use eof::{Eof, EofDecodeError}; | ||
| pub use legacy::{JumpTable, LegacyAnalyzedBytecode}; | ||
|
|
||
| use crate::{keccak256, Bytes, B256, KECCAK_EMPTY}; | ||
|
|
||
| /// EOF prefix as per EIP-3540. | ||
| const EOF_PREFIX: u8 = 0xEF; | ||
|
|
||
| /// Version byte that immediately follows the EOF prefix in EIP-3540. | ||
| // See https://github.com/bluealloy/revm/issues/1464 | ||
| const EOF_VERSION: u8 = 0x01; | ||
|
|
||
| /// State of the [`Bytecode`] analysis. | ||
| #[derive(Clone, Debug, PartialEq, Eq, Hash)] | ||
| #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
|
|
@@ -66,10 +73,23 @@ impl Bytecode { | |
| matches!(self, Self::Eof(_)) | ||
| } | ||
|
|
||
| /// 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 | ||
| } | ||
|
|
||
| /// Creates a new raw [`Bytecode`]. | ||
| #[inline] | ||
| pub fn new_raw(bytecode: Bytes) -> Self { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Would additionally add
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would return error here |
||
| Self::LegacyRaw(bytecode) | ||
| if Self::is_eof_format(&bytecode) { | ||
| Eof::decode(bytecode.clone()) | ||
| .map(Self::Eof) | ||
| .unwrap_or_else(|_| Self::LegacyRaw(bytecode)) | ||
| } else { | ||
| // If not EOF format, use as legacy raw bytecode | ||
| Self::LegacyRaw(bytecode) | ||
| } | ||
| } | ||
|
|
||
| /// Create new checked bytecode. | ||
|
|
||
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_MAGICis 0xEF00 whileEOF_VERSION(At least version one) is 0x01. Would be good to move those in revm-primitives crateprefix is
0xEF0001