github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/core/vm/instructions_test.go (about)

     1  
     2  //此源码被清华学神尹成大魔王专业翻译分析并修改
     3  //尹成QQ77025077
     4  //尹成微信18510341407
     5  //尹成所在QQ群721929980
     6  //尹成邮箱 yinc13@mails.tsinghua.edu.cn
     7  //尹成毕业于清华大学,微软区块链领域全球最有价值专家
     8  //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620
     9  //版权所有2017 Go Ethereum作者
    10  //此文件是Go以太坊库的一部分。
    11  //
    12  //Go-Ethereum库是免费软件:您可以重新分发它和/或修改
    13  //根据GNU发布的较低通用公共许可证的条款
    14  //自由软件基金会,或者许可证的第3版,或者
    15  //(由您选择)任何更高版本。
    16  //
    17  //Go以太坊图书馆的发行目的是希望它会有用,
    18  //但没有任何保证;甚至没有
    19  //适销性或特定用途的适用性。见
    20  //GNU较低的通用公共许可证,了解更多详细信息。
    21  //
    22  //你应该收到一份GNU较低级别的公共许可证副本
    23  //以及Go以太坊图书馆。如果没有,请参见<http://www.gnu.org/licenses/>。
    24  
    25  package vm
    26  
    27  import (
    28  	"math/big"
    29  	"testing"
    30  
    31  	"github.com/ethereum/go-ethereum/common"
    32  	"github.com/ethereum/go-ethereum/params"
    33  )
    34  
    35  type twoOperandTest struct {
    36  	x        string
    37  	y        string
    38  	expected string
    39  }
    40  
    41  func testTwoOperandOp(t *testing.T, tests []twoOperandTest, opFn func(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error)) {
    42  	var (
    43  		env            = NewEVM(Context{}, nil, params.TestChainConfig, Config{})
    44  		stack          = newstack()
    45  		pc             = uint64(0)
    46  		evmInterpreter = NewEVMInterpreter(env, env.vmConfig)
    47  	)
    48  
    49  	env.interpreter = evmInterpreter
    50  	evmInterpreter.intPool = poolOfIntPools.get()
    51  	for i, test := range tests {
    52  		x := new(big.Int).SetBytes(common.Hex2Bytes(test.x))
    53  		shift := new(big.Int).SetBytes(common.Hex2Bytes(test.y))
    54  		expected := new(big.Int).SetBytes(common.Hex2Bytes(test.expected))
    55  		stack.push(x)
    56  		stack.push(shift)
    57  		opFn(&pc, evmInterpreter, nil, nil, stack)
    58  		actual := stack.pop()
    59  		if actual.Cmp(expected) != 0 {
    60  			t.Errorf("Testcase %d, expected  %v, got %v", i, expected, actual)
    61  		}
    62  //检查池使用情况
    63  //1.池不允许包含堆栈上的任何内容
    64  //2.池不允许包含同一指针两次
    65  		if evmInterpreter.intPool.pool.len() > 0 {
    66  
    67  			poolvals := make(map[*big.Int]struct{})
    68  			poolvals[actual] = struct{}{}
    69  
    70  			for evmInterpreter.intPool.pool.len() > 0 {
    71  				key := evmInterpreter.intPool.get()
    72  				if _, exist := poolvals[key]; exist {
    73  					t.Errorf("Testcase %d, pool contains double-entry", i)
    74  				}
    75  				poolvals[key] = struct{}{}
    76  			}
    77  		}
    78  	}
    79  	poolOfIntPools.put(evmInterpreter.intPool)
    80  }
    81  
    82  func TestByteOp(t *testing.T) {
    83  	var (
    84  		env            = NewEVM(Context{}, nil, params.TestChainConfig, Config{})
    85  		stack          = newstack()
    86  		evmInterpreter = NewEVMInterpreter(env, env.vmConfig)
    87  	)
    88  
    89  	env.interpreter = evmInterpreter
    90  	evmInterpreter.intPool = poolOfIntPools.get()
    91  	tests := []struct {
    92  		v        string
    93  		th       uint64
    94  		expected *big.Int
    95  	}{
    96  		{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 0, big.NewInt(0xAB)},
    97  		{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 1, big.NewInt(0xCD)},
    98  		{"00CDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff", 0, big.NewInt(0x00)},
    99  		{"00CDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff", 1, big.NewInt(0xCD)},
   100  		{"0000000000000000000000000000000000000000000000000000000000102030", 31, big.NewInt(0x30)},
   101  		{"0000000000000000000000000000000000000000000000000000000000102030", 30, big.NewInt(0x20)},
   102  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 32, big.NewInt(0x0)},
   103  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 0xFFFFFFFFFFFFFFFF, big.NewInt(0x0)},
   104  	}
   105  	pc := uint64(0)
   106  	for _, test := range tests {
   107  		val := new(big.Int).SetBytes(common.Hex2Bytes(test.v))
   108  		th := new(big.Int).SetUint64(test.th)
   109  		stack.push(val)
   110  		stack.push(th)
   111  		opByte(&pc, evmInterpreter, nil, nil, stack)
   112  		actual := stack.pop()
   113  		if actual.Cmp(test.expected) != 0 {
   114  			t.Fatalf("Expected  [%v] %v:th byte to be %v, was %v.", test.v, test.th, test.expected, actual)
   115  		}
   116  	}
   117  	poolOfIntPools.put(evmInterpreter.intPool)
   118  }
   119  
   120  func TestSHL(t *testing.T) {
   121  //测试案例来自https://github.com/ethereum/eips/blob/master/eips/eip-145.md shl shift-left
   122  	tests := []twoOperandTest{
   123  		{"0000000000000000000000000000000000000000000000000000000000000001", "00", "0000000000000000000000000000000000000000000000000000000000000001"},
   124  		{"0000000000000000000000000000000000000000000000000000000000000001", "01", "0000000000000000000000000000000000000000000000000000000000000002"},
   125  		{"0000000000000000000000000000000000000000000000000000000000000001", "ff", "8000000000000000000000000000000000000000000000000000000000000000"},
   126  		{"0000000000000000000000000000000000000000000000000000000000000001", "0100", "0000000000000000000000000000000000000000000000000000000000000000"},
   127  		{"0000000000000000000000000000000000000000000000000000000000000001", "0101", "0000000000000000000000000000000000000000000000000000000000000000"},
   128  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "00", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   129  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "01", "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"},
   130  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "ff", "8000000000000000000000000000000000000000000000000000000000000000"},
   131  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0100", "0000000000000000000000000000000000000000000000000000000000000000"},
   132  		{"0000000000000000000000000000000000000000000000000000000000000000", "01", "0000000000000000000000000000000000000000000000000000000000000000"},
   133  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "01", "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"},
   134  	}
   135  	testTwoOperandOp(t, tests, opSHL)
   136  }
   137  
   138  func TestSHR(t *testing.T) {
   139  //测试案例来自https://github.com/ethereum/eips/blob/master/eips/eip-145.md shr logical shift right
   140  	tests := []twoOperandTest{
   141  		{"0000000000000000000000000000000000000000000000000000000000000001", "00", "0000000000000000000000000000000000000000000000000000000000000001"},
   142  		{"0000000000000000000000000000000000000000000000000000000000000001", "01", "0000000000000000000000000000000000000000000000000000000000000000"},
   143  		{"8000000000000000000000000000000000000000000000000000000000000000", "01", "4000000000000000000000000000000000000000000000000000000000000000"},
   144  		{"8000000000000000000000000000000000000000000000000000000000000000", "ff", "0000000000000000000000000000000000000000000000000000000000000001"},
   145  		{"8000000000000000000000000000000000000000000000000000000000000000", "0100", "0000000000000000000000000000000000000000000000000000000000000000"},
   146  		{"8000000000000000000000000000000000000000000000000000000000000000", "0101", "0000000000000000000000000000000000000000000000000000000000000000"},
   147  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "00", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   148  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "01", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   149  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "ff", "0000000000000000000000000000000000000000000000000000000000000001"},
   150  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0100", "0000000000000000000000000000000000000000000000000000000000000000"},
   151  		{"0000000000000000000000000000000000000000000000000000000000000000", "01", "0000000000000000000000000000000000000000000000000000000000000000"},
   152  	}
   153  	testTwoOperandOp(t, tests, opSHR)
   154  }
   155  
   156  func TestSAR(t *testing.T) {
   157  //测试案例来自https://github.com/ethereum/eips/blob/master/eips/eip-145.md sar算术右移
   158  	tests := []twoOperandTest{
   159  		{"0000000000000000000000000000000000000000000000000000000000000001", "00", "0000000000000000000000000000000000000000000000000000000000000001"},
   160  		{"0000000000000000000000000000000000000000000000000000000000000001", "01", "0000000000000000000000000000000000000000000000000000000000000000"},
   161  		{"8000000000000000000000000000000000000000000000000000000000000000", "01", "c000000000000000000000000000000000000000000000000000000000000000"},
   162  		{"8000000000000000000000000000000000000000000000000000000000000000", "ff", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   163  		{"8000000000000000000000000000000000000000000000000000000000000000", "0100", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   164  		{"8000000000000000000000000000000000000000000000000000000000000000", "0101", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   165  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "00", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   166  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "01", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   167  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "ff", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   168  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0100", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   169  		{"0000000000000000000000000000000000000000000000000000000000000000", "01", "0000000000000000000000000000000000000000000000000000000000000000"},
   170  		{"4000000000000000000000000000000000000000000000000000000000000000", "fe", "0000000000000000000000000000000000000000000000000000000000000001"},
   171  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "f8", "000000000000000000000000000000000000000000000000000000000000007f"},
   172  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "fe", "0000000000000000000000000000000000000000000000000000000000000001"},
   173  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "ff", "0000000000000000000000000000000000000000000000000000000000000000"},
   174  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0100", "0000000000000000000000000000000000000000000000000000000000000000"},
   175  	}
   176  
   177  	testTwoOperandOp(t, tests, opSAR)
   178  }
   179  
   180  func TestSGT(t *testing.T) {
   181  	tests := []twoOperandTest{
   182  
   183  		{"0000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000000"},
   184  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000000"},
   185  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000000"},
   186  		{"0000000000000000000000000000000000000000000000000000000000000001", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000001"},
   187  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000000"},
   188  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000001"},
   189  		{"0000000000000000000000000000000000000000000000000000000000000001", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000000"},
   190  		{"8000000000000000000000000000000000000000000000000000000000000001", "8000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000000"},
   191  		{"8000000000000000000000000000000000000000000000000000000000000001", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000001"},
   192  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "8000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000000"},
   193  		{"fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb", "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd", "0000000000000000000000000000000000000000000000000000000000000001"},
   194  		{"fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd", "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb", "0000000000000000000000000000000000000000000000000000000000000000"},
   195  	}
   196  	testTwoOperandOp(t, tests, opSgt)
   197  }
   198  
   199  func TestSLT(t *testing.T) {
   200  	tests := []twoOperandTest{
   201  		{"0000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000000"},
   202  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000000"},
   203  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000000"},
   204  		{"0000000000000000000000000000000000000000000000000000000000000001", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000000"},
   205  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000001"},
   206  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000000"},
   207  		{"0000000000000000000000000000000000000000000000000000000000000001", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000001"},
   208  		{"8000000000000000000000000000000000000000000000000000000000000001", "8000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000000"},
   209  		{"8000000000000000000000000000000000000000000000000000000000000001", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000000"},
   210  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "8000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000001"},
   211  		{"fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb", "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd", "0000000000000000000000000000000000000000000000000000000000000000"},
   212  		{"fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd", "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb", "0000000000000000000000000000000000000000000000000000000000000001"},
   213  	}
   214  	testTwoOperandOp(t, tests, opSlt)
   215  }
   216  
   217  func opBenchmark(bench *testing.B, op func(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error), args ...string) {
   218  	var (
   219  		env            = NewEVM(Context{}, nil, params.TestChainConfig, Config{})
   220  		stack          = newstack()
   221  		evmInterpreter = NewEVMInterpreter(env, env.vmConfig)
   222  	)
   223  
   224  	env.interpreter = evmInterpreter
   225  	evmInterpreter.intPool = poolOfIntPools.get()
   226  //转换ARGS
   227  	byteArgs := make([][]byte, len(args))
   228  	for i, arg := range args {
   229  		byteArgs[i] = common.Hex2Bytes(arg)
   230  	}
   231  	pc := uint64(0)
   232  	bench.ResetTimer()
   233  	for i := 0; i < bench.N; i++ {
   234  		for _, arg := range byteArgs {
   235  			a := new(big.Int).SetBytes(arg)
   236  			stack.push(a)
   237  		}
   238  		op(&pc, evmInterpreter, nil, nil, stack)
   239  		stack.pop()
   240  	}
   241  	poolOfIntPools.put(evmInterpreter.intPool)
   242  }
   243  
   244  func BenchmarkOpAdd64(b *testing.B) {
   245  	x := "ffffffff"
   246  	y := "fd37f3e2bba2c4f"
   247  
   248  	opBenchmark(b, opAdd, x, y)
   249  }
   250  
   251  func BenchmarkOpAdd128(b *testing.B) {
   252  	x := "ffffffffffffffff"
   253  	y := "f5470b43c6549b016288e9a65629687"
   254  
   255  	opBenchmark(b, opAdd, x, y)
   256  }
   257  
   258  func BenchmarkOpAdd256(b *testing.B) {
   259  	x := "0802431afcbce1fc194c9eaa417b2fb67dc75a95db0bc7ec6b1c8af11df6a1da9"
   260  	y := "a1f5aac137876480252e5dcac62c354ec0d42b76b0642b6181ed099849ea1d57"
   261  
   262  	opBenchmark(b, opAdd, x, y)
   263  }
   264  
   265  func BenchmarkOpSub64(b *testing.B) {
   266  	x := "51022b6317003a9d"
   267  	y := "a20456c62e00753a"
   268  
   269  	opBenchmark(b, opSub, x, y)
   270  }
   271  
   272  func BenchmarkOpSub128(b *testing.B) {
   273  	x := "4dde30faaacdc14d00327aac314e915d"
   274  	y := "9bbc61f5559b829a0064f558629d22ba"
   275  
   276  	opBenchmark(b, opSub, x, y)
   277  }
   278  
   279  func BenchmarkOpSub256(b *testing.B) {
   280  	x := "4bfcd8bb2ac462735b48a17580690283980aa2d679f091c64364594df113ea37"
   281  	y := "97f9b1765588c4e6b69142eb00d20507301545acf3e1238c86c8b29be227d46e"
   282  
   283  	opBenchmark(b, opSub, x, y)
   284  }
   285  
   286  func BenchmarkOpMul(b *testing.B) {
   287  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   288  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   289  
   290  	opBenchmark(b, opMul, x, y)
   291  }
   292  
   293  func BenchmarkOpDiv256(b *testing.B) {
   294  	x := "ff3f9014f20db29ae04af2c2d265de17"
   295  	y := "fe7fb0d1f59dfe9492ffbf73683fd1e870eec79504c60144cc7f5fc2bad1e611"
   296  	opBenchmark(b, opDiv, x, y)
   297  }
   298  
   299  func BenchmarkOpDiv128(b *testing.B) {
   300  	x := "fdedc7f10142ff97"
   301  	y := "fbdfda0e2ce356173d1993d5f70a2b11"
   302  	opBenchmark(b, opDiv, x, y)
   303  }
   304  
   305  func BenchmarkOpDiv64(b *testing.B) {
   306  	x := "fcb34eb3"
   307  	y := "f97180878e839129"
   308  	opBenchmark(b, opDiv, x, y)
   309  }
   310  
   311  func BenchmarkOpSdiv(b *testing.B) {
   312  	x := "ff3f9014f20db29ae04af2c2d265de17"
   313  	y := "fe7fb0d1f59dfe9492ffbf73683fd1e870eec79504c60144cc7f5fc2bad1e611"
   314  
   315  	opBenchmark(b, opSdiv, x, y)
   316  }
   317  
   318  func BenchmarkOpMod(b *testing.B) {
   319  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   320  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   321  
   322  	opBenchmark(b, opMod, x, y)
   323  }
   324  
   325  func BenchmarkOpSmod(b *testing.B) {
   326  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   327  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   328  
   329  	opBenchmark(b, opSmod, x, y)
   330  }
   331  
   332  func BenchmarkOpExp(b *testing.B) {
   333  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   334  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   335  
   336  	opBenchmark(b, opExp, x, y)
   337  }
   338  
   339  func BenchmarkOpSignExtend(b *testing.B) {
   340  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   341  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   342  
   343  	opBenchmark(b, opSignExtend, x, y)
   344  }
   345  
   346  func BenchmarkOpLt(b *testing.B) {
   347  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   348  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   349  
   350  	opBenchmark(b, opLt, x, y)
   351  }
   352  
   353  func BenchmarkOpGt(b *testing.B) {
   354  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   355  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   356  
   357  	opBenchmark(b, opGt, x, y)
   358  }
   359  
   360  func BenchmarkOpSlt(b *testing.B) {
   361  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   362  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   363  
   364  	opBenchmark(b, opSlt, x, y)
   365  }
   366  
   367  func BenchmarkOpSgt(b *testing.B) {
   368  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   369  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   370  
   371  	opBenchmark(b, opSgt, x, y)
   372  }
   373  
   374  func BenchmarkOpEq(b *testing.B) {
   375  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   376  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   377  
   378  	opBenchmark(b, opEq, x, y)
   379  }
   380  func BenchmarkOpEq2(b *testing.B) {
   381  	x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff"
   382  	y := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201fffffffe"
   383  	opBenchmark(b, opEq, x, y)
   384  }
   385  func BenchmarkOpAnd(b *testing.B) {
   386  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   387  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   388  
   389  	opBenchmark(b, opAnd, x, y)
   390  }
   391  
   392  func BenchmarkOpOr(b *testing.B) {
   393  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   394  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   395  
   396  	opBenchmark(b, opOr, x, y)
   397  }
   398  
   399  func BenchmarkOpXor(b *testing.B) {
   400  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   401  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   402  
   403  	opBenchmark(b, opXor, x, y)
   404  }
   405  
   406  func BenchmarkOpByte(b *testing.B) {
   407  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   408  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   409  
   410  	opBenchmark(b, opByte, x, y)
   411  }
   412  
   413  func BenchmarkOpAddmod(b *testing.B) {
   414  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   415  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   416  	z := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   417  
   418  	opBenchmark(b, opAddmod, x, y, z)
   419  }
   420  
   421  func BenchmarkOpMulmod(b *testing.B) {
   422  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   423  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   424  	z := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   425  
   426  	opBenchmark(b, opMulmod, x, y, z)
   427  }
   428  
   429  func BenchmarkOpSHL(b *testing.B) {
   430  	x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff"
   431  	y := "ff"
   432  
   433  	opBenchmark(b, opSHL, x, y)
   434  }
   435  func BenchmarkOpSHR(b *testing.B) {
   436  	x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff"
   437  	y := "ff"
   438  
   439  	opBenchmark(b, opSHR, x, y)
   440  }
   441  func BenchmarkOpSAR(b *testing.B) {
   442  	x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff"
   443  	y := "ff"
   444  
   445  	opBenchmark(b, opSAR, x, y)
   446  }
   447  func BenchmarkOpIsZero(b *testing.B) {
   448  	x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff"
   449  	opBenchmark(b, opIszero, x)
   450  }
   451  
   452  func TestOpMstore(t *testing.T) {
   453  	var (
   454  		env            = NewEVM(Context{}, nil, params.TestChainConfig, Config{})
   455  		stack          = newstack()
   456  		mem            = NewMemory()
   457  		evmInterpreter = NewEVMInterpreter(env, env.vmConfig)
   458  	)
   459  
   460  	env.interpreter = evmInterpreter
   461  	evmInterpreter.intPool = poolOfIntPools.get()
   462  	mem.Resize(64)
   463  	pc := uint64(0)
   464  	v := "abcdef00000000000000abba000000000deaf000000c0de00100000000133700"
   465  	stack.pushN(new(big.Int).SetBytes(common.Hex2Bytes(v)), big.NewInt(0))
   466  	opMstore(&pc, evmInterpreter, nil, mem, stack)
   467  	if got := common.Bytes2Hex(mem.Get(0, 32)); got != v {
   468  		t.Fatalf("Mstore fail, got %v, expected %v", got, v)
   469  	}
   470  	stack.pushN(big.NewInt(0x1), big.NewInt(0))
   471  	opMstore(&pc, evmInterpreter, nil, mem, stack)
   472  	if common.Bytes2Hex(mem.Get(0, 32)) != "0000000000000000000000000000000000000000000000000000000000000001" {
   473  		t.Fatalf("Mstore failed to overwrite previous value")
   474  	}
   475  	poolOfIntPools.put(evmInterpreter.intPool)
   476  }
   477  
   478  func BenchmarkOpMstore(bench *testing.B) {
   479  	var (
   480  		env            = NewEVM(Context{}, nil, params.TestChainConfig, Config{})
   481  		stack          = newstack()
   482  		mem            = NewMemory()
   483  		evmInterpreter = NewEVMInterpreter(env, env.vmConfig)
   484  	)
   485  
   486  	env.interpreter = evmInterpreter
   487  	evmInterpreter.intPool = poolOfIntPools.get()
   488  	mem.Resize(64)
   489  	pc := uint64(0)
   490  	memStart := big.NewInt(0)
   491  	value := big.NewInt(0x1337)
   492  
   493  	bench.ResetTimer()
   494  	for i := 0; i < bench.N; i++ {
   495  		stack.pushN(value, memStart)
   496  		opMstore(&pc, evmInterpreter, nil, mem, stack)
   497  	}
   498  	poolOfIntPools.put(evmInterpreter.intPool)
   499  }