Skip to content

fix: decode the fork ID as a list #3492

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions crates/common/rlp/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ impl<'a> Decoder<'a> {
};
Ok((field, updated_self))
}

/// Returns the next field without decoding it, i.e. the payload bytes including its prefix.
pub fn get_encoded_item(self) -> Result<(Vec<u8>, Self), RLPDecodeError> {
match get_item_with_prefix(self.payload) {
Expand Down
8 changes: 6 additions & 2 deletions crates/networking/p2p/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,12 @@ impl NodeRecord {
decoded_pairs.secp256k1 = Some(H264::from_slice(&bytes))
}
"eth" => {
// the first byte is ignored as an array within an array is received
decoded_pairs.eth = ForkId::decode(&value[1..]).ok();
let Ok(decoder) = Decoder::new(&value) else {
continue;
};
let (fork_id, decoder) = decoder.decode_optional_field();
decoder.finish_unchecked();
decoded_pairs.eth = fork_id;
Comment on lines +274 to +275
Copy link
Preview

Copilot AI Jul 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using decoder.finish() (which returns a Result) instead of finish_unchecked() to catch any leftover bytes or malformed input.

Suggested change
decoder.finish_unchecked();
decoded_pairs.eth = fork_id;
match decoder.finish() {
Ok(_) => decoded_pairs.eth = fork_id,
Err(_) => continue,
}

Copilot uses AI. Check for mistakes.

}
_ => {}
}
Expand Down
Loading