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)