github.com/luckypickle/go-ethereum-vet@v1.14.2/core/vm/instructions_test.go (about)

     1  // Copyright 2017 The go-ethereum Authors
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The go-ethereum library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package vm
    18  
    19  import (
    20  	"math/big"
    21  	"testing"
    22  
    23  	"github.com/luckypickle/go-ethereum-vet/common"
    24  	"github.com/luckypickle/go-ethereum-vet/params"
    25  )
    26  
    27  type twoOperandTest struct {
    28  	x        string
    29  	y        string
    30  	expected string
    31  }
    32  
    33  func testTwoOperandOp(t *testing.T, tests []twoOperandTest, opFn func(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error)) {
    34  	var (
    35  		env            = NewEVM(Context{}, nil, params.TestChainConfig, Config{})
    36  		stack          = newstack()
    37  		pc             = uint64(0)
    38  		evmInterpreter = NewEVMInterpreter(env, env.vmConfig)
    39  	)
    40  
    41  	env.interpreter = evmInterpreter
    42  	evmInterpreter.intPool = poolOfIntPools.get()
    43  	for i, test := range tests {
    44  		x := new(big.Int).SetBytes(common.Hex2Bytes(test.x))
    45  		shift := new(big.Int).SetBytes(common.Hex2Bytes(test.y))
    46  		expected := new(big.Int).SetBytes(common.Hex2Bytes(test.expected))
    47  		stack.push(x)
    48  		stack.push(shift)
    49  		opFn(&pc, evmInterpreter, nil, nil, stack)
    50  		actual := stack.pop()
    51  		if actual.Cmp(expected) != 0 {
    52  			t.Errorf("Testcase %d, expected  %v, got %v", i, expected, actual)
    53  		}
    54  		// Check pool usage
    55  		// 1.pool is not allowed to contain anything on the stack
    56  		// 2.pool is not allowed to contain the same pointers twice
    57  		if evmInterpreter.intPool.pool.len() > 0 {
    58  
    59  			poolvals := make(map[*big.Int]struct{})
    60  			poolvals[actual] = struct{}{}
    61  
    62  			for evmInterpreter.intPool.pool.len() > 0 {
    63  				key := evmInterpreter.intPool.get()
    64  				if _, exist := poolvals[key]; exist {
    65  					t.Errorf("Testcase %d, pool contains double-entry", i)
    66  				}
    67  				poolvals[key] = struct{}{}
    68  			}
    69  		}
    70  	}
    71  	poolOfIntPools.put(evmInterpreter.intPool)
    72  }
    73  
    74  func TestByteOp(t *testing.T) {
    75  	var (
    76  		env            = NewEVM(Context{}, nil, params.TestChainConfig, Config{})
    77  		stack          = newstack()
    78  		evmInterpreter = NewEVMInterpreter(env, env.vmConfig)
    79  	)
    80  
    81  	env.interpreter = evmInterpreter
    82  	evmInterpreter.intPool = poolOfIntPools.get()
    83  	tests := []struct {
    84  		v        string
    85  		th       uint64
    86  		expected *big.Int
    87  	}{
    88  		{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 0, big.NewInt(0xAB)},
    89  		{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 1, big.NewInt(0xCD)},
    90  		{"00CDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff", 0, big.NewInt(0x00)},
    91  		{"00CDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff", 1, big.NewInt(0xCD)},
    92  		{"0000000000000000000000000000000000000000000000000000000000102030", 31, big.NewInt(0x30)},
    93  		{"0000000000000000000000000000000000000000000000000000000000102030", 30, big.NewInt(0x20)},
    94  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 32, big.NewInt(0x0)},
    95  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 0xFFFFFFFFFFFFFFFF, big.NewInt(0x0)},
    96  	}
    97  	pc := uint64(0)
    98  	for _, test := range tests {
    99  		val := new(big.Int).SetBytes(common.Hex2Bytes(test.v))
   100  		th := new(big.Int).SetUint64(test.th)
   101  		stack.push(val)
   102  		stack.push(th)
   103  		opByte(&pc, evmInterpreter, nil, nil, stack)
   104  		actual := stack.pop()
   105  		if actual.Cmp(test.expected) != 0 {
   106  			t.Fatalf("Expected  [%v] %v:th byte to be %v, was %v.", test.v, test.th, test.expected, actual)
   107  		}
   108  	}
   109  	poolOfIntPools.put(evmInterpreter.intPool)
   110  }
   111  
   112  func TestSHL(t *testing.T) {
   113  	// Testcases from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-145.md#shl-shift-left
   114  	tests := []twoOperandTest{
   115  		{"0000000000000000000000000000000000000000000000000000000000000001", "00", "0000000000000000000000000000000000000000000000000000000000000001"},
   116  		{"0000000000000000000000000000000000000000000000000000000000000001", "01", "0000000000000000000000000000000000000000000000000000000000000002"},
   117  		{"0000000000000000000000000000000000000000000000000000000000000001", "ff", "8000000000000000000000000000000000000000000000000000000000000000"},
   118  		{"0000000000000000000000000000000000000000000000000000000000000001", "0100", "0000000000000000000000000000000000000000000000000000000000000000"},
   119  		{"0000000000000000000000000000000000000000000000000000000000000001", "0101", "0000000000000000000000000000000000000000000000000000000000000000"},
   120  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "00", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   121  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "01", "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"},
   122  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "ff", "8000000000000000000000000000000000000000000000000000000000000000"},
   123  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0100", "0000000000000000000000000000000000000000000000000000000000000000"},
   124  		{"0000000000000000000000000000000000000000000000000000000000000000", "01", "0000000000000000000000000000000000000000000000000000000000000000"},
   125  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "01", "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"},
   126  	}
   127  	testTwoOperandOp(t, tests, opSHL)
   128  }
   129  
   130  func TestSHR(t *testing.T) {
   131  	// Testcases from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-145.md#shr-logical-shift-right
   132  	tests := []twoOperandTest{
   133  		{"0000000000000000000000000000000000000000000000000000000000000001", "00", "0000000000000000000000000000000000000000000000000000000000000001"},
   134  		{"0000000000000000000000000000000000000000000000000000000000000001", "01", "0000000000000000000000000000000000000000000000000000000000000000"},
   135  		{"8000000000000000000000000000000000000000000000000000000000000000", "01", "4000000000000000000000000000000000000000000000000000000000000000"},
   136  		{"8000000000000000000000000000000000000000000000000000000000000000", "ff", "0000000000000000000000000000000000000000000000000000000000000001"},
   137  		{"8000000000000000000000000000000000000000000000000000000000000000", "0100", "0000000000000000000000000000000000000000000000000000000000000000"},
   138  		{"8000000000000000000000000000000000000000000000000000000000000000", "0101", "0000000000000000000000000000000000000000000000000000000000000000"},
   139  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "00", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   140  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "01", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   141  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "ff", "0000000000000000000000000000000000000000000000000000000000000001"},
   142  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0100", "0000000000000000000000000000000000000000000000000000000000000000"},
   143  		{"0000000000000000000000000000000000000000000000000000000000000000", "01", "0000000000000000000000000000000000000000000000000000000000000000"},
   144  	}
   145  	testTwoOperandOp(t, tests, opSHR)
   146  }
   147  
   148  func TestSAR(t *testing.T) {
   149  	// Testcases from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-145.md#sar-arithmetic-shift-right
   150  	tests := []twoOperandTest{
   151  		{"0000000000000000000000000000000000000000000000000000000000000001", "00", "0000000000000000000000000000000000000000000000000000000000000001"},
   152  		{"0000000000000000000000000000000000000000000000000000000000000001", "01", "0000000000000000000000000000000000000000000000000000000000000000"},
   153  		{"8000000000000000000000000000000000000000000000000000000000000000", "01", "c000000000000000000000000000000000000000000000000000000000000000"},
   154  		{"8000000000000000000000000000000000000000000000000000000000000000", "ff", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   155  		{"8000000000000000000000000000000000000000000000000000000000000000", "0100", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   156  		{"8000000000000000000000000000000000000000000000000000000000000000", "0101", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   157  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "00", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   158  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "01", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   159  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "ff", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   160  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0100", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   161  		{"0000000000000000000000000000000000000000000000000000000000000000", "01", "0000000000000000000000000000000000000000000000000000000000000000"},
   162  		{"4000000000000000000000000000000000000000000000000000000000000000", "fe", "0000000000000000000000000000000000000000000000000000000000000001"},
   163  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "f8", "000000000000000000000000000000000000000000000000000000000000007f"},
   164  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "fe", "0000000000000000000000000000000000000000000000000000000000000001"},
   165  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "ff", "0000000000000000000000000000000000000000000000000000000000000000"},
   166  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0100", "0000000000000000000000000000000000000000000000000000000000000000"},
   167  	}
   168  
   169  	testTwoOperandOp(t, tests, opSAR)
   170  }
   171  
   172  func TestSGT(t *testing.T) {
   173  	tests := []twoOperandTest{
   174  
   175  		{"0000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000000"},
   176  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000000"},
   177  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000000"},
   178  		{"0000000000000000000000000000000000000000000000000000000000000001", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000001"},
   179  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000000"},
   180  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000001"},
   181  		{"0000000000000000000000000000000000000000000000000000000000000001", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000000"},
   182  		{"8000000000000000000000000000000000000000000000000000000000000001", "8000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000000"},
   183  		{"8000000000000000000000000000000000000000000000000000000000000001", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000001"},
   184  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "8000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000000"},
   185  		{"fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb", "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd", "0000000000000000000000000000000000000000000000000000000000000001"},
   186  		{"fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd", "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb", "0000000000000000000000000000000000000000000000000000000000000000"},
   187  	}
   188  	testTwoOperandOp(t, tests, opSgt)
   189  }
   190  
   191  func TestSLT(t *testing.T) {
   192  	tests := []twoOperandTest{
   193  		{"0000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000000"},
   194  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000000"},
   195  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000000"},
   196  		{"0000000000000000000000000000000000000000000000000000000000000001", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000000"},
   197  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000001"},
   198  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000000"},
   199  		{"0000000000000000000000000000000000000000000000000000000000000001", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000001"},
   200  		{"8000000000000000000000000000000000000000000000000000000000000001", "8000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000000"},
   201  		{"8000000000000000000000000000000000000000000000000000000000000001", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000000"},
   202  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "8000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000001"},
   203  		{"fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb", "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd", "0000000000000000000000000000000000000000000000000000000000000000"},
   204  		{"fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd", "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb", "0000000000000000000000000000000000000000000000000000000000000001"},
   205  	}
   206  	testTwoOperandOp(t, tests, opSlt)
   207  }
   208  
   209  func opBenchmark(bench *testing.B, op func(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error), args ...string) {
   210  	var (
   211  		env            = NewEVM(Context{}, nil, params.TestChainConfig, Config{})
   212  		stack          = newstack()
   213  		evmInterpreter = NewEVMInterpreter(env, env.vmConfig)
   214  	)
   215  
   216  	env.interpreter = evmInterpreter
   217  	evmInterpreter.intPool = poolOfIntPools.get()
   218  	// convert args
   219  	byteArgs := make([][]byte, len(args))
   220  	for i, arg := range args {
   221  		byteArgs[i] = common.Hex2Bytes(arg)
   222  	}
   223  	pc := uint64(0)
   224  	bench.ResetTimer()
   225  	for i := 0; i < bench.N; i++ {
   226  		for _, arg := range byteArgs {
   227  			a := new(big.Int).SetBytes(arg)
   228  			stack.push(a)
   229  		}
   230  		op(&pc, evmInterpreter, nil, nil, stack)
   231  		stack.pop()
   232  	}
   233  	poolOfIntPools.put(evmInterpreter.intPool)
   234  }
   235  
   236  func BenchmarkOpAdd64(b *testing.B) {
   237  	x := "ffffffff"
   238  	y := "fd37f3e2bba2c4f"
   239  
   240  	opBenchmark(b, opAdd, x, y)
   241  }
   242  
   243  func BenchmarkOpAdd128(b *testing.B) {
   244  	x := "ffffffffffffffff"
   245  	y := "f5470b43c6549b016288e9a65629687"
   246  
   247  	opBenchmark(b, opAdd, x, y)
   248  }
   249  
   250  func BenchmarkOpAdd256(b *testing.B) {
   251  	x := "0802431afcbce1fc194c9eaa417b2fb67dc75a95db0bc7ec6b1c8af11df6a1da9"
   252  	y := "a1f5aac137876480252e5dcac62c354ec0d42b76b0642b6181ed099849ea1d57"
   253  
   254  	opBenchmark(b, opAdd, x, y)
   255  }
   256  
   257  func BenchmarkOpSub64(b *testing.B) {
   258  	x := "51022b6317003a9d"
   259  	y := "a20456c62e00753a"
   260  
   261  	opBenchmark(b, opSub, x, y)
   262  }
   263  
   264  func BenchmarkOpSub128(b *testing.B) {
   265  	x := "4dde30faaacdc14d00327aac314e915d"
   266  	y := "9bbc61f5559b829a0064f558629d22ba"
   267  
   268  	opBenchmark(b, opSub, x, y)
   269  }
   270  
   271  func BenchmarkOpSub256(b *testing.B) {
   272  	x := "4bfcd8bb2ac462735b48a17580690283980aa2d679f091c64364594df113ea37"
   273  	y := "97f9b1765588c4e6b69142eb00d20507301545acf3e1238c86c8b29be227d46e"
   274  
   275  	opBenchmark(b, opSub, x, y)
   276  }
   277  
   278  func BenchmarkOpMul(b *testing.B) {
   279  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   280  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   281  
   282  	opBenchmark(b, opMul, x, y)
   283  }
   284  
   285  func BenchmarkOpDiv256(b *testing.B) {
   286  	x := "ff3f9014f20db29ae04af2c2d265de17"
   287  	y := "fe7fb0d1f59dfe9492ffbf73683fd1e870eec79504c60144cc7f5fc2bad1e611"
   288  	opBenchmark(b, opDiv, x, y)
   289  }
   290  
   291  func BenchmarkOpDiv128(b *testing.B) {
   292  	x := "fdedc7f10142ff97"
   293  	y := "fbdfda0e2ce356173d1993d5f70a2b11"
   294  	opBenchmark(b, opDiv, x, y)
   295  }
   296  
   297  func BenchmarkOpDiv64(b *testing.B) {
   298  	x := "fcb34eb3"
   299  	y := "f97180878e839129"
   300  	opBenchmark(b, opDiv, x, y)
   301  }
   302  
   303  func BenchmarkOpSdiv(b *testing.B) {
   304  	x := "ff3f9014f20db29ae04af2c2d265de17"
   305  	y := "fe7fb0d1f59dfe9492ffbf73683fd1e870eec79504c60144cc7f5fc2bad1e611"
   306  
   307  	opBenchmark(b, opSdiv, x, y)
   308  }
   309  
   310  func BenchmarkOpMod(b *testing.B) {
   311  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   312  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   313  
   314  	opBenchmark(b, opMod, x, y)
   315  }
   316  
   317  func BenchmarkOpSmod(b *testing.B) {
   318  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   319  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   320  
   321  	opBenchmark(b, opSmod, x, y)
   322  }
   323  
   324  func BenchmarkOpExp(b *testing.B) {
   325  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   326  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   327  
   328  	opBenchmark(b, opExp, x, y)
   329  }
   330  
   331  func BenchmarkOpSignExtend(b *testing.B) {
   332  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   333  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   334  
   335  	opBenchmark(b, opSignExtend, x, y)
   336  }
   337  
   338  func BenchmarkOpLt(b *testing.B) {
   339  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   340  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   341  
   342  	opBenchmark(b, opLt, x, y)
   343  }
   344  
   345  func BenchmarkOpGt(b *testing.B) {
   346  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   347  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   348  
   349  	opBenchmark(b, opGt, x, y)
   350  }
   351  
   352  func BenchmarkOpSlt(b *testing.B) {
   353  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   354  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   355  
   356  	opBenchmark(b, opSlt, x, y)
   357  }
   358  
   359  func BenchmarkOpSgt(b *testing.B) {
   360  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   361  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   362  
   363  	opBenchmark(b, opSgt, x, y)
   364  }
   365  
   366  func BenchmarkOpEq(b *testing.B) {
   367  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   368  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   369  
   370  	opBenchmark(b, opEq, x, y)
   371  }
   372  func BenchmarkOpEq2(b *testing.B) {
   373  	x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff"
   374  	y := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201fffffffe"
   375  	opBenchmark(b, opEq, x, y)
   376  }
   377  func BenchmarkOpAnd(b *testing.B) {
   378  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   379  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   380  
   381  	opBenchmark(b, opAnd, x, y)
   382  }
   383  
   384  func BenchmarkOpOr(b *testing.B) {
   385  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   386  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   387  
   388  	opBenchmark(b, opOr, x, y)
   389  }
   390  
   391  func BenchmarkOpXor(b *testing.B) {
   392  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   393  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   394  
   395  	opBenchmark(b, opXor, x, y)
   396  }
   397  
   398  func BenchmarkOpByte(b *testing.B) {
   399  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   400  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   401  
   402  	opBenchmark(b, opByte, x, y)
   403  }
   404  
   405  func BenchmarkOpAddmod(b *testing.B) {
   406  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   407  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   408  	z := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   409  
   410  	opBenchmark(b, opAddmod, x, y, z)
   411  }
   412  
   413  func BenchmarkOpMulmod(b *testing.B) {
   414  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   415  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   416  	z := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   417  
   418  	opBenchmark(b, opMulmod, x, y, z)
   419  }
   420  
   421  func BenchmarkOpSHL(b *testing.B) {
   422  	x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff"
   423  	y := "ff"
   424  
   425  	opBenchmark(b, opSHL, x, y)
   426  }
   427  func BenchmarkOpSHR(b *testing.B) {
   428  	x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff"
   429  	y := "ff"
   430  
   431  	opBenchmark(b, opSHR, x, y)
   432  }
   433  func BenchmarkOpSAR(b *testing.B) {
   434  	x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff"
   435  	y := "ff"
   436  
   437  	opBenchmark(b, opSAR, x, y)
   438  }
   439  func BenchmarkOpIsZero(b *testing.B) {
   440  	x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff"
   441  	opBenchmark(b, opIszero, x)
   442  }
   443  
   444  func TestOpMstore(t *testing.T) {
   445  	var (
   446  		env            = NewEVM(Context{}, nil, params.TestChainConfig, Config{})
   447  		stack          = newstack()
   448  		mem            = NewMemory()
   449  		evmInterpreter = NewEVMInterpreter(env, env.vmConfig)
   450  	)
   451  
   452  	env.interpreter = evmInterpreter
   453  	evmInterpreter.intPool = poolOfIntPools.get()
   454  	mem.Resize(64)
   455  	pc := uint64(0)
   456  	v := "abcdef00000000000000abba000000000deaf000000c0de00100000000133700"
   457  	stack.pushN(new(big.Int).SetBytes(common.Hex2Bytes(v)), big.NewInt(0))
   458  	opMstore(&pc, evmInterpreter, nil, mem, stack)
   459  	if got := common.Bytes2Hex(mem.Get(0, 32)); got != v {
   460  		t.Fatalf("Mstore fail, got %v, expected %v", got, v)
   461  	}
   462  	stack.pushN(big.NewInt(0x1), big.NewInt(0))
   463  	opMstore(&pc, evmInterpreter, nil, mem, stack)
   464  	if common.Bytes2Hex(mem.Get(0, 32)) != "0000000000000000000000000000000000000000000000000000000000000001" {
   465  		t.Fatalf("Mstore failed to overwrite previous value")
   466  	}
   467  	poolOfIntPools.put(evmInterpreter.intPool)
   468  }
   469  
   470  func BenchmarkOpMstore(bench *testing.B) {
   471  	var (
   472  		env            = NewEVM(Context{}, nil, params.TestChainConfig, Config{})
   473  		stack          = newstack()
   474  		mem            = NewMemory()
   475  		evmInterpreter = NewEVMInterpreter(env, env.vmConfig)
   476  	)
   477  
   478  	env.interpreter = evmInterpreter
   479  	evmInterpreter.intPool = poolOfIntPools.get()
   480  	mem.Resize(64)
   481  	pc := uint64(0)
   482  	memStart := big.NewInt(0)
   483  	value := big.NewInt(0x1337)
   484  
   485  	bench.ResetTimer()
   486  	for i := 0; i < bench.N; i++ {
   487  		stack.pushN(value, memStart)
   488  		opMstore(&pc, evmInterpreter, nil, mem, stack)
   489  	}
   490  	poolOfIntPools.put(evmInterpreter.intPool)
   491  }