go-ethereum/common/math/integer.go
Jeffrey Wilcke 4c0e2f32f9 common/math, core/vm, core/state: EVM gas calculations to 64bit
This changes the internals of the EVM-JIT by dropping support for
blocks (and therefor also transactions) that can exceed a 64^2-1
gas-limit. This means that the EVM-JIT can drop support for abritrary
precision (*big.Int) and move to 64bit based gas calculations.

For obvious reasons integer overflows have added to make sure that
gas calculations such as gas for memory doesn't overflow 64bit. If the
overflow check fails it throws an out-of-gas error and will halt the
execution of the code.
2016-10-10 21:48:20 +02:00

22 lines
566 B
Go

package math
import gmath "math"
/*
* NOTE: The following methods need to be optimised using either bit checking or asm
*/
// IsMinSafe returns whether the subtraction is safe and does not overflow.
func IsSubSafe(x, y uint64) bool {
return x >= y
}
// IsAddSafe returns whether the addition is safe and does not overflow.
func IsAddSafe(x, y uint64) bool {
return y <= gmath.MaxUint64-x
}
// IsAddSafe returns whether the multiplication is safe and does not overflow.
func IsMulSafe(x, y uint64) bool {
return x == 0 || y == 0 || y <= gmath.MaxUint64/x
}