Skip to content
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
12 changes: 11 additions & 1 deletion crates/primitives/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Bytecode {
if self.is_empty() {
KECCAK_EMPTY
} else {
keccak256(&self.original_bytes())
keccak256(self.original_byte_slice())
}
}

Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion crates/primitives/src/bytecode/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down