-
Notifications
You must be signed in to change notification settings - Fork 207
fix(l1): use 0x80 sentinel for missing eth/71 BAL per EIP-8159 #6744
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
28dda08
fix(l1): use 0x80 sentinel for missing eth/71 BAL per EIP-8159
edg-l c2be1dd
test(l1): move BAL sentinel test to test crate, add invariant comment
edg-l 28f6b12
fix(l1): reword BAL invariant doc to avoid rustdoc blockquote lint
edg-l ecc73bb
test(l1): move BAL sentinel test to test crate
edg-l File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| pub(crate) mod block_access_lists; | ||
| pub mod block_access_lists; | ||
| pub mod blocks; | ||
| pub mod eth68; | ||
| mod eth69; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| use ethrex_common::types::block_access_list::BlockAccessList; | ||
| use ethrex_p2p::rlpx::{ | ||
| eth::block_access_lists::{BlockAccessLists, OptionalBal}, | ||
| message::RLPxMessage, | ||
| }; | ||
| use ethrex_rlp::encode::RLPEncode; | ||
|
|
||
| // ── BlockAccessLists (0x13, eth/71) ── | ||
| // | ||
| // EIP-8159 says a missing BAL is the RLP empty string (`0x80`), while a | ||
| // present-but-empty BAL (block with no state changes) is the RLP empty list | ||
| // (`0xc0`). The two must never alias, otherwise an upgraded node silently | ||
| // confuses "BAL unavailable" with "valid empty BAL" (interop break with geth). | ||
|
|
||
| #[test] | ||
| fn missing_bal_is_distinct_from_present_empty_bal() { | ||
| let missing = BlockAccessLists::new(1, vec![None]); | ||
| let empty = BlockAccessLists::new(1, vec![Some(BlockAccessList::from_accounts(vec![]))]); | ||
|
|
||
| let mut missing_buf = Vec::new(); | ||
| missing.encode(&mut missing_buf).unwrap(); | ||
| let mut empty_buf = Vec::new(); | ||
| empty.encode(&mut empty_buf).unwrap(); | ||
|
|
||
| // 0x80 sentinel must not collapse onto the 0xc0 empty-list encoding. | ||
| assert_ne!(missing_buf, empty_buf); | ||
| } | ||
|
|
||
| #[test] | ||
| fn missing_bal_roundtrips_as_none() { | ||
| let msg = BlockAccessLists::new(7, vec![None]); | ||
| let mut buf = Vec::new(); | ||
| msg.encode(&mut buf).unwrap(); | ||
|
|
||
| let decoded = BlockAccessLists::decode(&buf).unwrap(); | ||
| assert_eq!(decoded.id, 7); | ||
| assert_eq!(decoded.block_access_lists.len(), 1); | ||
| assert!(decoded.block_access_lists[0].is_none()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn present_empty_bal_roundtrips_as_some() { | ||
| let msg = BlockAccessLists::new(7, vec![Some(BlockAccessList::from_accounts(vec![]))]); | ||
| let mut buf = Vec::new(); | ||
| msg.encode(&mut buf).unwrap(); | ||
|
|
||
| let decoded = BlockAccessLists::decode(&buf).unwrap(); | ||
| assert_eq!(decoded.block_access_lists.len(), 1); | ||
| assert!(decoded.block_access_lists[0].is_some()); | ||
| } | ||
|
|
||
| /// Locks the EIP-8159 §"BlockAccessLists (0x13)" sentinel: a missing BAL | ||
| /// encodes as exactly the RLP empty string (`0x80`), never the empty list | ||
| /// (`0xc0`, a valid empty BAL). geth uses the same sentinel (`rlp.EmptyString` | ||
| /// in `eth/protocols/eth/handlers.go`); any drift here is silent interop | ||
| /// breakage. Asserts the raw byte directly on the `OptionalBal` wrapper, which | ||
| /// the message-level tests can't see (their bytes go through snappy). | ||
| #[test] | ||
| fn optional_bal_none_encodes_as_0x80_sentinel() { | ||
| let mut bytes = Vec::new(); | ||
| OptionalBal(None).encode(&mut bytes); | ||
| assert_eq!(bytes, vec![0x80]); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| mod block_access_lists_tests; | ||
| mod blocks_tests; | ||
| mod handshake_tests; | ||
| mod p2p_tests; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.