Skip to content

Commit

Permalink
feat: add Bytecode::original_bytecode_slice to match `BytecodeLocke…
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Apr 13, 2024
1 parent fa9e127 commit 7957c02
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
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

0 comments on commit 7957c02

Please sign in to comment.