mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
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.
50 lines
830 B
Go
50 lines
830 B
Go
package math
|
|
|
|
import (
|
|
gmath "math"
|
|
"testing"
|
|
)
|
|
|
|
type operation byte
|
|
|
|
const (
|
|
sub operation = iota
|
|
add
|
|
mul
|
|
)
|
|
|
|
func TestIsAddSafe(t *testing.T) {
|
|
for i, test := range []struct {
|
|
x uint64
|
|
y uint64
|
|
safe bool
|
|
op operation
|
|
}{
|
|
// add operations
|
|
{gmath.MaxUint64, 1, false, add},
|
|
{gmath.MaxUint64 - 1, 1, true, add},
|
|
|
|
// sub operations
|
|
{0, 1, false, sub},
|
|
{0, 0, true, sub},
|
|
|
|
// mul operations
|
|
{10, 10, true, mul},
|
|
{gmath.MaxUint64, 2, false, mul},
|
|
{gmath.MaxUint64, 1, true, mul},
|
|
} {
|
|
var isSafe bool
|
|
switch test.op {
|
|
case sub:
|
|
isSafe = IsSubSafe(test.x, test.y)
|
|
case add:
|
|
isSafe = IsAddSafe(test.x, test.y)
|
|
case mul:
|
|
isSafe = IsMulSafe(test.x, test.y)
|
|
}
|
|
|
|
if test.safe != isSafe {
|
|
t.Errorf("%d failed. Expected test to be %v, got %v", i, test.safe, isSafe)
|
|
}
|
|
}
|
|
}
|