erigon-pulse/common/math/integer.go
hexoscott 8969b9c58f
txpool changes for eip-3860 (#820)
shanghai changes to txpool.

intrinsic gas updated to match the new version in Erigon.

unsure if the `isShanghai` check is robust enough or there would be a
better way to approach this.
2023-01-16 22:15:42 +00:00

18 lines
339 B
Go

package math
import (
"math/bits"
)
// SafeMul returns x*y and checks for overflow.
func SafeMul(x, y uint64) (uint64, bool) {
hi, lo := bits.Mul64(x, y)
return lo, hi != 0
}
// SafeAdd returns x+y and checks for overflow.
func SafeAdd(x, y uint64) (uint64, bool) {
sum, carryOut := bits.Add64(x, y, 0)
return sum, carryOut != 0
}