Skip to content

Conversation

@fedacking
Copy link
Contributor

Motivation

Fake Exponential defined in block.rs can overflow. As such, we need to use the U256 data type to avoid overflows

Description

  • Added intermediate conversions to U256 to avoid overflows
  • Added test for the overflow

@github-actions github-actions bot added the L1 Ethereum client label Oct 29, 2025
@github-actions
Copy link

github-actions bot commented Oct 29, 2025

Lines of code report

Total lines added: 8
Total lines removed: 0
Total lines changed: 8

Detailed view
+-------------------------------------+-------+------+
| File                                | Lines | Diff |
+-------------------------------------+-------+------+
| ethrex/crates/common/types/block.rs | 870   | +8   |
+-------------------------------------+-------+------+

Comment on lines +987 to +991
#[test]
fn test_fake_exponential_overflow() {
// With u64 this overflows
fake_exponential(57532635, 3145728, 3338477);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The 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);

Copy link
Collaborator

Choose a reason for hiding this comment

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

This test panics.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created issue to define a bound #5096

@fedacking fedacking marked this pull request as ready for review October 29, 2025 15:09
@fedacking fedacking requested a review from a team as a code owner October 29, 2025 15:09
@ethrex-project-sync ethrex-project-sync bot moved this to In Review in ethrex_l1 Oct 29, 2025
Copy link
Collaborator

@MegaRedHand MegaRedHand left a comment

Choose a reason for hiding this comment

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

I'm pretty sure the u64::MAX isn't reachable in practice, and can be bounded further down. We should check this, but I think it's safe to merge this PR as-is.

}
output / denominator
if (output / denominator) > U256::from(u64::MAX) {
u64::MAX
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should panic here, since I'm sure this is unreachable. In a later PR we can update this with an explanation.

Comment on lines +987 to +991
#[test]
fn test_fake_exponential_overflow() {
// With u64 this overflows
fake_exponential(57532635, 3145728, 3338477);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test panics.

@jrchatruc jrchatruc added this pull request to the merge queue Oct 29, 2025
@jrchatruc jrchatruc removed this pull request from the merge queue due to a manual request Oct 29, 2025
@jrchatruc jrchatruc added this pull request to the merge queue Oct 29, 2025
Merged via the queue into main with commit f335294 Oct 29, 2025
34 checks passed
@jrchatruc jrchatruc deleted the fix-exponential-overflow branch October 29, 2025 16:37
@github-project-automation github-project-automation bot moved this from In Review to Done in ethrex_l1 Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L1 Ethereum client

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants