Skip to content
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: store eof bytecode with header in compact #10375

Closed
wants to merge 2 commits into from
Closed
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
30 changes: 28 additions & 2 deletions crates/primitives-traits/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ impl Compact for Bytecode {
where
B: bytes::BufMut + AsMut<[u8]>,
{
let bytecode = &self.0.bytecode()[..];
// TODO: this is a hack, ideally we should store the bytecode type first
let bytecode =
if self.0.is_eof() { self.0.original_byte_slice() } else { &self.0.bytecode()[..] };
buf.put_u32(bytecode.len() as u32);
buf.put_slice(bytecode);
let len = match &self.0 {
Expand Down Expand Up @@ -154,7 +156,7 @@ impl From<Account> for AccountInfo {
#[cfg(test)]
mod tests {
use super::*;
use alloy_primitives::{hex_literal::hex, B256, U256};
use alloy_primitives::{hex_literal::hex, Address, B256, U256};
use revm_primitives::LegacyAnalyzedBytecode;

#[test]
Expand Down Expand Up @@ -222,5 +224,29 @@ mod tests {
let (decoded, remainder) = Bytecode::from_compact(&buf, len);
assert_eq!(decoded, bytecode);
assert!(remainder.is_empty());

let mut buf = vec![];
let bytecode = Bytecode(
RevmBytecode::new_raw(
Bytes::from(
&hex!("ef0001010004020001007c04006800008000056080806040526004361015e100035f80fd5f3560e01c8063964efccb14e1002e63f6b4dfb41415e1ffe434e1001d5f600319360112e1001060209060018060a01b035f54168152f35f80fd5f80fd34e100275f600319360112e1001a306bffffffffffffffffffffffff60a01b5f5416175f555f80f35f80fd5f80fda3646970667358221220d3bad1e010bf2bc1b82399d0fc56a03009ef435628e0d1ef547138fcfcb470d86c6578706572696d656e74616cf564736f6c637827302e382e32372d646576656c6f702e323032342e382e352b636f6d6d69742e38386366363036300066")
)
)
);
let len = bytecode.to_compact(&mut buf);
assert_eq!(len, 499);

let (decoded, remainder) = Bytecode::from_compact(&buf, len);
assert_eq!(decoded, bytecode);
assert!(remainder.is_empty());

let mut buf = vec![];
let bytecode = Bytecode(RevmBytecode::new_eip7702(Address::with_last_byte(42)));
let len = bytecode.to_compact(&mut buf);
assert_eq!(len, 51);

let (decoded, remainder) = Bytecode::from_compact(&buf, len);
assert_eq!(decoded, bytecode);
assert!(remainder.is_empty());
}
}
Loading