From 5052910fba8c7b53169cf4e5b1c57fc9f105734f Mon Sep 17 00:00:00 2001 From: MariusVanDerWijden Date: Wed, 10 Sep 2025 10:24:28 +0200 Subject: [PATCH] core/vm: fix modexp gas calculation --- core/vm/contracts.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/vm/contracts.go b/core/vm/contracts.go index 5d72fe4ac1..77fac2f907 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -469,9 +469,12 @@ func modexpIterationCount(expLen uint64, expHead uint256.Int, multiplier uint64) // For large exponents (expLen > 32), add (expLen - 32) * multiplier if expLen > 32 { - iterationCount = (expLen - 32) * multiplier + carry, count := bits.Mul64(expLen-32, multiplier) + if carry > 0 { + return math.MaxUint64 + } + iterationCount = count } - // Add the MSB position - 1 if expHead is non-zero if bitLen := expHead.BitLen(); bitLen > 0 { count, carry := bits.Add64(iterationCount, uint64(bitLen-1), 0)