|
|
@ -109,7 +109,7 @@ func testTwoOperandOp(t *testing.T, tests []TwoOperandTestcase, opFn executionFu |
|
|
|
expected := new(big.Int).SetBytes(common.Hex2Bytes(test.Expected)) |
|
|
|
expected := new(big.Int).SetBytes(common.Hex2Bytes(test.Expected)) |
|
|
|
stack.push(x) |
|
|
|
stack.push(x) |
|
|
|
stack.push(y) |
|
|
|
stack.push(y) |
|
|
|
opFn(&pc, evmInterpreter, nil, nil, stack) |
|
|
|
opFn(&pc, evmInterpreter, &callCtx{nil, stack, nil}) |
|
|
|
actual := stack.pop() |
|
|
|
actual := stack.pop() |
|
|
|
|
|
|
|
|
|
|
|
if actual.Cmp(expected) != 0 { |
|
|
|
if actual.Cmp(expected) != 0 { |
|
|
@ -223,7 +223,7 @@ func getResult(args []*twoOperandParams, opFn executionFunc) []TwoOperandTestcas |
|
|
|
y := new(big.Int).SetBytes(common.Hex2Bytes(param.y)) |
|
|
|
y := new(big.Int).SetBytes(common.Hex2Bytes(param.y)) |
|
|
|
stack.push(x) |
|
|
|
stack.push(x) |
|
|
|
stack.push(y) |
|
|
|
stack.push(y) |
|
|
|
opFn(&pc, interpreter, nil, nil, stack) |
|
|
|
opFn(&pc, interpreter, &callCtx{nil, stack, nil}) |
|
|
|
actual := stack.pop() |
|
|
|
actual := stack.pop() |
|
|
|
result[i] = TwoOperandTestcase{param.x, param.y, fmt.Sprintf("%064x", actual)} |
|
|
|
result[i] = TwoOperandTestcase{param.x, param.y, fmt.Sprintf("%064x", actual)} |
|
|
|
} |
|
|
|
} |
|
|
@ -260,7 +260,7 @@ func TestJsonTestcases(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func opBenchmark(bench *testing.B, op func(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error), args ...string) { |
|
|
|
func opBenchmark(bench *testing.B, op executionFunc, args ...string) { |
|
|
|
var ( |
|
|
|
var ( |
|
|
|
env = NewEVM(Context{}, nil, params.TestChainConfig, Config{}) |
|
|
|
env = NewEVM(Context{}, nil, params.TestChainConfig, Config{}) |
|
|
|
stack = newstack() |
|
|
|
stack = newstack() |
|
|
@ -281,7 +281,7 @@ func opBenchmark(bench *testing.B, op func(pc *uint64, interpreter *EVMInterpret |
|
|
|
a := new(big.Int).SetBytes(arg) |
|
|
|
a := new(big.Int).SetBytes(arg) |
|
|
|
stack.push(a) |
|
|
|
stack.push(a) |
|
|
|
} |
|
|
|
} |
|
|
|
op(&pc, evmInterpreter, nil, nil, stack) |
|
|
|
op(&pc, evmInterpreter, &callCtx{nil, stack, nil}) |
|
|
|
stack.pop() |
|
|
|
stack.pop() |
|
|
|
} |
|
|
|
} |
|
|
|
poolOfIntPools.put(evmInterpreter.intPool) |
|
|
|
poolOfIntPools.put(evmInterpreter.intPool) |
|
|
@ -509,12 +509,12 @@ func TestOpMstore(t *testing.T) { |
|
|
|
pc := uint64(0) |
|
|
|
pc := uint64(0) |
|
|
|
v := "abcdef00000000000000abba000000000deaf000000c0de00100000000133700" |
|
|
|
v := "abcdef00000000000000abba000000000deaf000000c0de00100000000133700" |
|
|
|
stack.pushN(new(big.Int).SetBytes(common.Hex2Bytes(v)), big.NewInt(0)) |
|
|
|
stack.pushN(new(big.Int).SetBytes(common.Hex2Bytes(v)), big.NewInt(0)) |
|
|
|
opMstore(&pc, evmInterpreter, nil, mem, stack) |
|
|
|
opMstore(&pc, evmInterpreter, &callCtx{mem, stack, nil}) |
|
|
|
if got := common.Bytes2Hex(mem.GetCopy(0, 32)); got != v { |
|
|
|
if got := common.Bytes2Hex(mem.GetCopy(0, 32)); got != v { |
|
|
|
t.Fatalf("Mstore fail, got %v, expected %v", got, v) |
|
|
|
t.Fatalf("Mstore fail, got %v, expected %v", got, v) |
|
|
|
} |
|
|
|
} |
|
|
|
stack.pushN(big.NewInt(0x1), big.NewInt(0)) |
|
|
|
stack.pushN(big.NewInt(0x1), big.NewInt(0)) |
|
|
|
opMstore(&pc, evmInterpreter, nil, mem, stack) |
|
|
|
opMstore(&pc, evmInterpreter, &callCtx{mem, stack, nil}) |
|
|
|
if common.Bytes2Hex(mem.GetCopy(0, 32)) != "0000000000000000000000000000000000000000000000000000000000000001" { |
|
|
|
if common.Bytes2Hex(mem.GetCopy(0, 32)) != "0000000000000000000000000000000000000000000000000000000000000001" { |
|
|
|
t.Fatalf("Mstore failed to overwrite previous value") |
|
|
|
t.Fatalf("Mstore failed to overwrite previous value") |
|
|
|
} |
|
|
|
} |
|
|
@ -539,7 +539,7 @@ func BenchmarkOpMstore(bench *testing.B) { |
|
|
|
bench.ResetTimer() |
|
|
|
bench.ResetTimer() |
|
|
|
for i := 0; i < bench.N; i++ { |
|
|
|
for i := 0; i < bench.N; i++ { |
|
|
|
stack.pushN(value, memStart) |
|
|
|
stack.pushN(value, memStart) |
|
|
|
opMstore(&pc, evmInterpreter, nil, mem, stack) |
|
|
|
opMstore(&pc, evmInterpreter, &callCtx{mem, stack, nil}) |
|
|
|
} |
|
|
|
} |
|
|
|
poolOfIntPools.put(evmInterpreter.intPool) |
|
|
|
poolOfIntPools.put(evmInterpreter.intPool) |
|
|
|
} |
|
|
|
} |
|
|
@ -560,7 +560,7 @@ func BenchmarkOpSHA3(bench *testing.B) { |
|
|
|
bench.ResetTimer() |
|
|
|
bench.ResetTimer() |
|
|
|
for i := 0; i < bench.N; i++ { |
|
|
|
for i := 0; i < bench.N; i++ { |
|
|
|
stack.pushN(big.NewInt(32), start) |
|
|
|
stack.pushN(big.NewInt(32), start) |
|
|
|
opSha3(&pc, evmInterpreter, nil, mem, stack) |
|
|
|
opSha3(&pc, evmInterpreter, &callCtx{mem, stack, nil}) |
|
|
|
} |
|
|
|
} |
|
|
|
poolOfIntPools.put(evmInterpreter.intPool) |
|
|
|
poolOfIntPools.put(evmInterpreter.intPool) |
|
|
|
} |
|
|
|
} |
|
|
|