-
Notifications
You must be signed in to change notification settings - Fork 144
fix(l1): fix exponential overflow in fake exponential #5093
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -398,14 +398,14 @@ pub fn calculate_base_fee_per_blob_gas(parent_excess_blob_gas: u64, update_fract | |
| // Defined in [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844) | ||
| pub fn fake_exponential(factor: u64, numerator: u64, denominator: u64) -> u64 { | ||
| let mut i = 1; | ||
| let mut output = 0; | ||
| let mut numerator_accum = factor * denominator; | ||
| while numerator_accum > 0 { | ||
| let mut output = U256::zero(); | ||
| let mut numerator_accum = (U256::zero() + factor) * denominator; | ||
| while numerator_accum > U256::zero() { | ||
MegaRedHand marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| output += numerator_accum; | ||
| numerator_accum = numerator_accum * numerator / (denominator * i); | ||
| i += 1; | ||
| } | ||
| output / denominator | ||
| (output / denominator).as_u64() | ||
MegaRedHand marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| #[derive(Debug, thiserror::Error)] | ||
|
|
@@ -983,4 +983,10 @@ mod test { | |
| let res = calc_excess_blob_gas(&parent, schedule, fork); | ||
| assert_eq!(res, 3538944) | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_fake_exponential_overflow() { | ||
| // With u64 this overflows | ||
| fake_exponential(57532635, 3145728, 3338477); | ||
| } | ||
|
Comment on lines
+991
to
+995
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a test with the maximum expected inputs here, for good measure: fake_exponential(MIN_BASE_FEE_PER_BLOB_GAS, u64::MAX, BLOB_BASE_FEE_UPDATE_FRACTION);
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test panics.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created issue to define a bound #5096 |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.