-
Notifications
You must be signed in to change notification settings - Fork 471
fix(serde): handle overflow in quantity deserialization for Arbitrum gas prices #2858
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
Conversation
crates/serde/src/quantity.rs
Outdated
#[inline] | ||
fn from_ruint(ruint: Self::Ruint) -> Self { | ||
ruint.try_into().ok().unwrap() | ||
ruint.try_into().unwrap_or_else(|_| Self::overflow_default()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current approach of returning 0
for all numeric types during overflow may not be semantically appropriate for all use cases. For gas prices specifically, defaulting to 0
could potentially allow transactions to be processed without fees, which might lead to economic issues or unexpected behavior.
Consider making the overflow handling more context-aware:
- Either return a
Result
type instead of usingunwrap_or_else
to propagate the error to the caller - Or make the default value configurable based on the specific field being deserialized (perhaps with a trait parameter)
- For gas prices specifically, a more appropriate default might be
u128::MAX
or another value that aligns with the expected behavior
This would ensure that overflow handling is semantically appropriate for each specific use case rather than using a one-size-fits-all approach.
ruint.try_into().unwrap_or_else(|_| Self::overflow_default()) | |
ruint.try_into().map_err(|_| serde::de::Error::custom("numeric overflow"))? |
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we cant really approach this like this, because we'd need to specialize the actual serde impl manually and cant change the regular quantity fn
if we're aiming for "I think we could make this u128::Max and maybe store it in an otherfield as u256 if it's for AnyBlock", how would you go about approaching it? |
the only way to do this really is manual serde impl on the block type |
@mattsse And updated the transaction types to use it and reverted the ConvertRuint changes. I hope this should fix the Arbitrum issue without breaking anything else. |
@mattsse Is there anything holding up this PR from being merged from your perspective? |
@mattsse we would also greatly benefit if this PR get's merged and new released pushed 🙏 |
Closed in favor of #3010. This requires too many changes to fix the AI slop and has unrelated changes. |
Fixes deserialization failures when processing Arbitrum Classic blocks with extremely high gas prices that overflow u128.
Problem:
0x30783134626639633464372e3333333333333333333333333333333333333333
cause u128 overflowSolution:
ConvertRuint::from_ruint()
to return 0 on overflow instead of panickingoverflow_default()
method to trait for configurable overflow handlingCloses #2842