core/vm: fix modexp gas calculation

This commit is contained in:
MariusVanDerWijden 2025-09-10 10:24:28 +02:00
parent 24c9f08c28
commit 5052910fba

View file

@ -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)