diff --git a/crates/primitives/src/bytecode.rs b/crates/primitives/src/bytecode.rs index 538a57af44..e36afa48ba 100644 --- a/crates/primitives/src/bytecode.rs +++ b/crates/primitives/src/bytecode.rs @@ -47,7 +47,7 @@ impl Bytecode { if self.is_empty() { KECCAK_EMPTY } else { - keccak256(&self.original_bytes()) + keccak256(self.original_byte_slice()) } } @@ -118,6 +118,16 @@ impl Bytecode { } } + /// Returns the original bytecode as a byte slice. + #[inline] + pub fn original_byte_slice(&self) -> &[u8] { + match self { + Self::LegacyRaw(bytes) => bytes, + Self::LegacyAnalyzed(analyzed) => analyzed.original_byte_slice(), + Self::Eof(eof) => eof.raw(), + } + } + /// Returns the length of the raw bytes. #[inline] pub fn len(&self) -> usize { diff --git a/crates/primitives/src/bytecode/legacy.rs b/crates/primitives/src/bytecode/legacy.rs index 18949f0aa6..3e6f2d2b90 100644 --- a/crates/primitives/src/bytecode/legacy.rs +++ b/crates/primitives/src/bytecode/legacy.rs @@ -53,7 +53,12 @@ impl LegacyAnalyzedBytecode { /// Original bytes without padding. pub fn original_bytes(&self) -> Bytes { - self.bytecode.slice(0..self.original_len) + self.bytecode.slice(..self.original_len) + } + + /// Original bytes without padding. + pub fn original_byte_slice(&self) -> &[u8] { + &self.bytecode[..self.original_len] } /// Jumptable of analyzed bytes.