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

remove proptest-specific encoding logic from Header #6329

Closed
Rjected opened this issue Feb 1, 2024 · 2 comments · Fixed by #6503
Closed

remove proptest-specific encoding logic from Header #6329

Rjected opened this issue Feb 1, 2024 · 2 comments · Fixed by #6503
Assignees
Labels
C-enhancement New feature or request C-test A change that impacts how or what we test D-good-first-issue Nice and easy! A great choice to get started

Comments

@Rjected
Copy link
Member

Rjected commented Feb 1, 2024

Describe the feature

This code needs to be removed, along with the similar looking code in that file:

if started_len - buf.len() < rlp_head.payload_length {
if buf.first().map(|b| *b == EMPTY_LIST_CODE).unwrap_or_default() {
buf.advance(1)
} else {
this.base_fee_per_gas = Some(u64::decode(buf)?);
}
}
// Withdrawals root for post-shanghai headers
if started_len - buf.len() < rlp_head.payload_length {
if buf.first().map(|b| *b == EMPTY_STRING_CODE).unwrap_or_default() {
buf.advance(1)
} else {
this.withdrawals_root = Some(Decodable::decode(buf)?);
}
}
// Blob gas used and excess blob gas for post-cancun headers
if started_len - buf.len() < rlp_head.payload_length {
if buf.first().map(|b| *b == EMPTY_LIST_CODE).unwrap_or_default() {
buf.advance(1)
} else {
this.blob_gas_used = Some(u64::decode(buf)?);
}
}
if started_len - buf.len() < rlp_head.payload_length {
if buf.first().map(|b| *b == EMPTY_LIST_CODE).unwrap_or_default() {
buf.advance(1)
} else {
this.excess_blob_gas = Some(u64::decode(buf)?);
}
}
// Decode parent beacon block root. If new fields are added, the above pattern will need to
// be repeated and placeholders decoded. Otherwise, it's impossible to tell _which_
// fields are missing. This is mainly relevant for contrived cases where a header is
// created at random, for example:
// * A header is created with a withdrawals root, but no base fee. Shanghai blocks are
// post-London, so this is technically not valid. However, a tool like proptest would
// generate a block like this.
if started_len - buf.len() < rlp_head.payload_length {
this.parent_beacon_block_root = Some(B256::decode(buf)?);
}
let consumed = started_len - buf.len();
if consumed != rlp_head.payload_length {
return Err(alloy_rlp::Error::ListLengthMismatch {
expected: rlp_head.payload_length,
got: consumed,
})
}

We need to fix the proptest::arbitrary::Arbitrary implementation to only include i.e. excess_blob_gas if all previous fork specific fields exist.

#[cfg(any(test, feature = "arbitrary"))]
impl proptest::arbitrary::Arbitrary for SealedHeader {
type Parameters = ();
fn arbitrary_with(_: Self::Parameters) -> Self::Strategy {
use proptest::prelude::{any, Strategy};
any::<(Header, BlockHash)>().prop_map(move |(header, _)| header.seal_slow()).boxed()
}
type Strategy = proptest::strategy::BoxedStrategy<SealedHeader>;
}
#[cfg(any(test, feature = "arbitrary"))]
impl<'a> arbitrary::Arbitrary<'a> for SealedHeader {
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
Ok(Header::arbitrary(u)?.seal_slow())
}
}

Additional context

No response

@Rjected Rjected added C-enhancement New feature or request D-good-first-issue Nice and easy! A great choice to get started C-test A change that impacts how or what we test labels Feb 1, 2024
@supernovahs
Copy link
Contributor

Let me take this

@Rjected
Copy link
Member Author

Rjected commented Feb 5, 2024

Let me take this

hey! feel free to submit a PR and I'll review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement New feature or request C-test A change that impacts how or what we test D-good-first-issue Nice and easy! A great choice to get started
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants