Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fcfbac4

Browse files
committedDec 17, 2024·
state: Avoid overflows in blob gas price
1 parent bd2052b commit fcfbac4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed
 

‎test/state/block.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,16 @@ intx::uint256 compute_blob_gas_price(uint64_t excess_blob_gas) noexcept
1818
intx::uint256 i = 1;
1919
intx::uint256 output = 0;
2020
intx::uint256 numerator_accum = factor * denominator;
21+
const intx::uint256 numerator256 = numerator;
2122
while (numerator_accum > 0)
2223
{
2324
output += numerator_accum;
24-
numerator_accum = (numerator_accum * numerator) / (denominator * i);
25+
// Ensure the multiplication won't overflow 256 bits.
26+
if (const auto p = intx::umul(numerator_accum, numerator256);
27+
p <= std::numeric_limits<intx::uint256>::max())
28+
numerator_accum = intx::uint256(p) / (denominator * i);
29+
else
30+
return std::numeric_limits<intx::uint256>::max();
2531
i += 1;
2632
}
2733
return output / denominator;

0 commit comments

Comments
 (0)
Please sign in to comment.