github.com/klaytn/klaytn@v1.10.2/blockchain/vm/instructions_test.go (about)

     1  // Modifications Copyright 2018 The klaytn Authors
     2  // Copyright 2017 The go-ethereum Authors
     3  // This file is part of the go-ethereum library.
     4  //
     5  // The go-ethereum library is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU Lesser General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // The go-ethereum library is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    13  // GNU Lesser General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU Lesser General Public License
    16  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    17  //
    18  // This file is derived from core/vm/instructions_test.go (2018/06/04).
    19  // Modified and improved for the klaytn development.
    20  
    21  package vm
    22  
    23  import (
    24  	"bytes"
    25  	"encoding/json"
    26  	"fmt"
    27  	"io/ioutil"
    28  	"math/big"
    29  	"testing"
    30  
    31  	"github.com/klaytn/klaytn/blockchain/state"
    32  	"github.com/klaytn/klaytn/blockchain/types"
    33  	"github.com/klaytn/klaytn/common"
    34  	"github.com/klaytn/klaytn/crypto"
    35  	"github.com/klaytn/klaytn/params"
    36  	"github.com/klaytn/klaytn/storage/database"
    37  )
    38  
    39  type TwoOperandTestcase struct {
    40  	X        string
    41  	Y        string
    42  	Expected string
    43  }
    44  
    45  type twoOperandParams struct {
    46  	x string
    47  	y string
    48  }
    49  
    50  var (
    51  	commonParams []*twoOperandParams
    52  	twoOpMethods map[string]executionFunc
    53  )
    54  
    55  func init() {
    56  	// Params is a list of common edgecases that should be used for some common tests
    57  	params := []string{
    58  		"0000000000000000000000000000000000000000000000000000000000000000", // 0
    59  		"0000000000000000000000000000000000000000000000000000000000000001", // +1
    60  		"0000000000000000000000000000000000000000000000000000000000000005", // +5
    61  		"7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe", // + max -1
    62  		"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", // + max
    63  		"8000000000000000000000000000000000000000000000000000000000000000", // - max
    64  		"8000000000000000000000000000000000000000000000000000000000000001", // - max+1
    65  		"fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb", // - 5
    66  		"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", // - 1
    67  	}
    68  	// Params are combined so each param is used on each 'side'
    69  	commonParams = make([]*twoOperandParams, len(params)*len(params))
    70  	for i, x := range params {
    71  		for j, y := range params {
    72  			commonParams[i*len(params)+j] = &twoOperandParams{x, y}
    73  		}
    74  	}
    75  	twoOpMethods = map[string]executionFunc{
    76  		"add":     opAdd,
    77  		"sub":     opSub,
    78  		"mul":     opMul,
    79  		"div":     opDiv,
    80  		"sdiv":    opSdiv,
    81  		"mod":     opMod,
    82  		"smod":    opSmod,
    83  		"exp":     opExp,
    84  		"signext": opSignExtend,
    85  		"lt":      opLt,
    86  		"gt":      opGt,
    87  		"slt":     opSlt,
    88  		"sgt":     opSgt,
    89  		"eq":      opEq,
    90  		"and":     opAnd,
    91  		"or":      opOr,
    92  		"xor":     opXor,
    93  		"byte":    opByte,
    94  		"shl":     opSHL,
    95  		"shr":     opSHR,
    96  		"sar":     opSAR,
    97  	}
    98  }
    99  
   100  func testTwoOperandOp(t *testing.T, tests []TwoOperandTestcase, opFn executionFunc, name string) {
   101  	var (
   102  		env            = NewEVM(Context{}, nil, params.TestChainConfig, &Config{})
   103  		stack          = newstack()
   104  		pc             = uint64(0)
   105  		evmInterpreter = env.interpreter
   106  	)
   107  	// Stuff a couple of nonzero bigints into pool, to ensure that ops do not rely on pooled integers to be zero
   108  	evmInterpreter.intPool = poolOfIntPools.get()
   109  	evmInterpreter.intPool.put(big.NewInt(-1337))
   110  	evmInterpreter.intPool.put(big.NewInt(-1337))
   111  	evmInterpreter.intPool.put(big.NewInt(-1337))
   112  
   113  	for i, test := range tests {
   114  		x := new(big.Int).SetBytes(common.Hex2Bytes(test.X))
   115  		y := new(big.Int).SetBytes(common.Hex2Bytes(test.Y))
   116  		expected := new(big.Int).SetBytes(common.Hex2Bytes(test.Expected))
   117  		stack.push(x)
   118  		stack.push(y)
   119  		opFn(&pc, env, nil, nil, stack)
   120  		actual := stack.pop()
   121  
   122  		if actual.Cmp(expected) != 0 {
   123  			t.Errorf("Testcase %v %d, %v(%x, %x): expected  %x, got %x", name, i, name, x, y, expected, actual)
   124  		}
   125  		// Check pool usage
   126  		// 1.pool is not allowed to contain anything on the stack
   127  		// 2.pool is not allowed to contain the same pointers twice
   128  		if evmInterpreter.intPool.pool.len() > 0 {
   129  
   130  			poolvals := make(map[*big.Int]struct{})
   131  			poolvals[actual] = struct{}{}
   132  
   133  			for evmInterpreter.intPool.pool.len() > 0 {
   134  				key := evmInterpreter.intPool.get()
   135  				if _, exist := poolvals[key]; exist {
   136  					t.Errorf("Testcase %v %d, pool contains double-entry", name, i)
   137  				}
   138  				poolvals[key] = struct{}{}
   139  			}
   140  		}
   141  	}
   142  	poolOfIntPools.put(evmInterpreter.intPool)
   143  }
   144  
   145  func TestByteOp(t *testing.T) {
   146  	tests := []TwoOperandTestcase{
   147  		{"ABCDEF0908070605040302010000000000000000000000000000000000000000", "00", "AB"},
   148  		{"ABCDEF0908070605040302010000000000000000000000000000000000000000", "01", "CD"},
   149  		{"00CDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff", "00", "00"},
   150  		{"00CDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff", "01", "CD"},
   151  		{"0000000000000000000000000000000000000000000000000000000000102030", "1F", "30"},
   152  		{"0000000000000000000000000000000000000000000000000000000000102030", "1E", "20"},
   153  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "20", "00"},
   154  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "FFFFFFFFFFFFFFFF", "00"},
   155  	}
   156  	testTwoOperandOp(t, tests, opByte, "byte")
   157  }
   158  
   159  func TestSHL(t *testing.T) {
   160  	// Testcases from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-145.md#shl-shift-left
   161  	tests := []TwoOperandTestcase{
   162  		{"0000000000000000000000000000000000000000000000000000000000000001", "01", "0000000000000000000000000000000000000000000000000000000000000002"},
   163  		{"0000000000000000000000000000000000000000000000000000000000000001", "ff", "8000000000000000000000000000000000000000000000000000000000000000"},
   164  		{"0000000000000000000000000000000000000000000000000000000000000001", "0100", "0000000000000000000000000000000000000000000000000000000000000000"},
   165  		{"0000000000000000000000000000000000000000000000000000000000000001", "0101", "0000000000000000000000000000000000000000000000000000000000000000"},
   166  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "00", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   167  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "01", "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"},
   168  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "ff", "8000000000000000000000000000000000000000000000000000000000000000"},
   169  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0100", "0000000000000000000000000000000000000000000000000000000000000000"},
   170  		{"0000000000000000000000000000000000000000000000000000000000000000", "01", "0000000000000000000000000000000000000000000000000000000000000000"},
   171  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "01", "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"},
   172  	}
   173  	testTwoOperandOp(t, tests, opSHL, "shl")
   174  }
   175  
   176  func TestSHR(t *testing.T) {
   177  	// Testcases from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-145.md#shr-logical-shift-right
   178  	tests := []TwoOperandTestcase{
   179  		{"0000000000000000000000000000000000000000000000000000000000000001", "00", "0000000000000000000000000000000000000000000000000000000000000001"},
   180  		{"0000000000000000000000000000000000000000000000000000000000000001", "01", "0000000000000000000000000000000000000000000000000000000000000000"},
   181  		{"8000000000000000000000000000000000000000000000000000000000000000", "01", "4000000000000000000000000000000000000000000000000000000000000000"},
   182  		{"8000000000000000000000000000000000000000000000000000000000000000", "ff", "0000000000000000000000000000000000000000000000000000000000000001"},
   183  		{"8000000000000000000000000000000000000000000000000000000000000000", "0100", "0000000000000000000000000000000000000000000000000000000000000000"},
   184  		{"8000000000000000000000000000000000000000000000000000000000000000", "0101", "0000000000000000000000000000000000000000000000000000000000000000"},
   185  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "00", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   186  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "01", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   187  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "ff", "0000000000000000000000000000000000000000000000000000000000000001"},
   188  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0100", "0000000000000000000000000000000000000000000000000000000000000000"},
   189  		{"0000000000000000000000000000000000000000000000000000000000000000", "01", "0000000000000000000000000000000000000000000000000000000000000000"},
   190  	}
   191  	testTwoOperandOp(t, tests, opSHR, "shr")
   192  }
   193  
   194  func TestSAR(t *testing.T) {
   195  	// Testcases from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-145.md#sar-arithmetic-shift-right
   196  	tests := []TwoOperandTestcase{
   197  		{"0000000000000000000000000000000000000000000000000000000000000001", "00", "0000000000000000000000000000000000000000000000000000000000000001"},
   198  		{"0000000000000000000000000000000000000000000000000000000000000001", "01", "0000000000000000000000000000000000000000000000000000000000000000"},
   199  		{"8000000000000000000000000000000000000000000000000000000000000000", "01", "c000000000000000000000000000000000000000000000000000000000000000"},
   200  		{"8000000000000000000000000000000000000000000000000000000000000000", "ff", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   201  		{"8000000000000000000000000000000000000000000000000000000000000000", "0100", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   202  		{"8000000000000000000000000000000000000000000000000000000000000000", "0101", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   203  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "00", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   204  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "01", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   205  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "ff", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   206  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0100", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
   207  		{"0000000000000000000000000000000000000000000000000000000000000000", "01", "0000000000000000000000000000000000000000000000000000000000000000"},
   208  		{"4000000000000000000000000000000000000000000000000000000000000000", "fe", "0000000000000000000000000000000000000000000000000000000000000001"},
   209  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "f8", "000000000000000000000000000000000000000000000000000000000000007f"},
   210  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "fe", "0000000000000000000000000000000000000000000000000000000000000001"},
   211  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "ff", "0000000000000000000000000000000000000000000000000000000000000000"},
   212  		{"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0100", "0000000000000000000000000000000000000000000000000000000000000000"},
   213  	}
   214  
   215  	testTwoOperandOp(t, tests, opSAR, "sar")
   216  }
   217  
   218  // getResult is a convenience function to generate the expected values
   219  func getResult(args []*twoOperandParams, opFn executionFunc) []TwoOperandTestcase {
   220  	var (
   221  		env         = NewEVM(Context{}, nil, params.TestChainConfig, &Config{})
   222  		stack       = newstack()
   223  		pc          = uint64(0)
   224  		interpreter = env.interpreter
   225  	)
   226  	interpreter.intPool = poolOfIntPools.get()
   227  	result := make([]TwoOperandTestcase, len(args))
   228  	for i, param := range args {
   229  		x := new(big.Int).SetBytes(common.Hex2Bytes(param.x))
   230  		y := new(big.Int).SetBytes(common.Hex2Bytes(param.y))
   231  		stack.push(x)
   232  		stack.push(y)
   233  		opFn(&pc, env, nil, nil, stack)
   234  		actual := stack.pop()
   235  		result[i] = TwoOperandTestcase{param.x, param.y, fmt.Sprintf("%064x", actual)}
   236  	}
   237  	return result
   238  }
   239  
   240  // utility function to fill the json-file with testcases
   241  // Enable this test to generate the 'testcases_xx.json' files
   242  func xTestWriteExpectedValues(t *testing.T) {
   243  	for name, method := range twoOpMethods {
   244  		data, err := json.Marshal(getResult(commonParams, method))
   245  		if err != nil {
   246  			t.Fatal(err)
   247  		}
   248  		_ = ioutil.WriteFile(fmt.Sprintf("testdata/testcases_%v.json", name), data, 0o644)
   249  		if err != nil {
   250  			t.Fatal(err)
   251  		}
   252  	}
   253  	t.Fatal("This test should not be activated")
   254  }
   255  
   256  // TestJsonTestcases runs through all the testcases defined as json-files
   257  func TestJsonTestcases(t *testing.T) {
   258  	for name := range twoOpMethods {
   259  		data, err := ioutil.ReadFile(fmt.Sprintf("testdata/testcases_%v.json", name))
   260  		if err != nil {
   261  			t.Fatal("Failed to read file", err)
   262  		}
   263  		var testcases []TwoOperandTestcase
   264  		json.Unmarshal(data, &testcases)
   265  		testTwoOperandOp(t, testcases, twoOpMethods[name], name)
   266  	}
   267  }
   268  
   269  func initStateDB(db database.DBManager) *state.StateDB {
   270  	sdb := state.NewDatabase(db)
   271  	statedb, _ := state.New(common.Hash{}, sdb, nil)
   272  
   273  	contractAddress := common.HexToAddress("0x18f30de96ce789fe778b9a5f420f6fdbbd9b34d8")
   274  	code := "60ca60205260005b612710811015630000004557602051506020515060205150602051506020515060205150602051506020515060205150602051506001016300000007565b00"
   275  	statedb.CreateSmartContractAccount(contractAddress, params.CodeFormatEVM, params.Rules{})
   276  	statedb.SetCode(contractAddress, common.Hex2Bytes(code))
   277  	stateHash := common.HexToHash("7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe")
   278  	statedb.SetState(contractAddress, stateHash, stateHash)
   279  	statedb.SetBalance(contractAddress, big.NewInt(1000))
   280  	statedb.SetNonce(contractAddress, uint64(1))
   281  
   282  	{
   283  		// create a contract having a STOP operation.
   284  		contractAddress := common.HexToAddress("0x18f30de96ce789fe778b9a5f420f6fdbbd9b34d9")
   285  		code := "00"
   286  		statedb.CreateSmartContractAccount(contractAddress, params.CodeFormatEVM, params.Rules{})
   287  		statedb.SetCode(contractAddress, common.Hex2Bytes(code))
   288  		statedb.SetBalance(contractAddress, big.NewInt(1000))
   289  		statedb.SetNonce(contractAddress, uint64(1))
   290  	}
   291  
   292  	// Commit and re-open to start with a clean state.
   293  	root, _ := statedb.Commit(false)
   294  	statedb, _ = state.New(root, sdb, nil)
   295  
   296  	return statedb
   297  }
   298  
   299  func opBenchmark(bench *testing.B, op func(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error), args ...string) {
   300  	var (
   301  		initialCall = true
   302  		canTransfer = func(db StateDB, address common.Address, amount *big.Int) bool {
   303  			if initialCall {
   304  				initialCall = false
   305  				return true
   306  			}
   307  			return db.GetBalance(address).Cmp(amount) >= 0
   308  		}
   309  
   310  		ctx = Context{
   311  			BlockNumber: big1024,
   312  			BlockScore:  big.NewInt(0),
   313  			Coinbase:    common.HexToAddress("0xf4b0cb429b7d341bf467f2d51c09b64cd9add37c"),
   314  			GasPrice:    big.NewInt(1),
   315  			BaseFee:     big.NewInt(1000000000000000000),
   316  			GasLimit:    uint64(1000000000000000),
   317  			Time:        big.NewInt(1488928920),
   318  			GetHash: func(num uint64) common.Hash {
   319  				return common.BytesToHash(crypto.Keccak256([]byte(big.NewInt(int64(num)).String())))
   320  			},
   321  			CanTransfer: canTransfer,
   322  			Transfer:    func(db StateDB, sender, recipient common.Address, amount *big.Int) {},
   323  		}
   324  
   325  		memDBManager = database.NewMemoryDBManager()
   326  		statedb      = initStateDB(memDBManager)
   327  
   328  		env            = NewEVM(ctx, statedb, params.TestChainConfig, &Config{})
   329  		stack          = newstack()
   330  		mem            = NewMemory()
   331  		evmInterpreter = NewEVMInterpreter(env, env.vmConfig)
   332  	)
   333  
   334  	env.Origin = common.HexToAddress("0x9d19bb4553940f422104b1d0c8e5704c5aab63c9")
   335  	env.callGasTemp = uint64(100000000000)
   336  	env.interpreter = evmInterpreter
   337  	evmInterpreter.intPool = poolOfIntPools.get()
   338  	evmInterpreter.returnData = []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
   339  	mem.Resize(64)
   340  	mem.Set(uint64(1), uint64(20), common.Hex2Bytes("000164865d7db79197021449b4a6aa650193b09e"))
   341  
   342  	// make contract
   343  	senderAddress := common.HexToAddress("0x91fb186da8f327f999782d1ae1ceacbd4fbbf146")
   344  	payerAddress := common.HexToAddress("0x18f30de96ce789fe778b9a5f420f6fdbbd9b34d8")
   345  
   346  	caller := types.NewAccountRefWithFeePayer(senderAddress, payerAddress)
   347  	object := types.NewAccountRefWithFeePayer(payerAddress, senderAddress)
   348  	contract := NewContract(caller, object, big.NewInt(0), uint64(1000))
   349  	contract.Input = senderAddress.Bytes()
   350  	contract.Gas = uint64(1000)
   351  	contract.Code = common.Hex2Bytes("60ca60205260005b612710811015630000004557602051506020515060205150602051506020515060205150602051506020515060205150602051506001016300000007565b00")
   352  
   353  	// convert args
   354  	byteArgs := make([][]byte, len(args))
   355  	for i, arg := range args {
   356  		byteArgs[i] = common.Hex2Bytes(arg)
   357  	}
   358  	pc := uint64(0)
   359  	bench.ResetTimer()
   360  	for i := 0; i < bench.N; i++ {
   361  		for _, arg := range byteArgs {
   362  			a := new(big.Int).SetBytes(arg)
   363  			stack.push(a)
   364  		}
   365  		op(&pc, env, contract, mem, stack)
   366  		if stack.len() > 0 {
   367  			stack.pop()
   368  		}
   369  	}
   370  	poolOfIntPools.put(evmInterpreter.intPool)
   371  }
   372  
   373  func BenchmarkOpAdd64(b *testing.B) {
   374  	x := "ffffffff"
   375  	y := "fd37f3e2bba2c4f"
   376  
   377  	opBenchmark(b, opAdd, x, y)
   378  }
   379  
   380  func BenchmarkOpAdd128(b *testing.B) {
   381  	x := "ffffffffffffffff"
   382  	y := "f5470b43c6549b016288e9a65629687"
   383  
   384  	opBenchmark(b, opAdd, x, y)
   385  }
   386  
   387  func BenchmarkOpAdd256(b *testing.B) {
   388  	x := "0802431afcbce1fc194c9eaa417b2fb67dc75a95db0bc7ec6b1c8af11df6a1da9"
   389  	y := "a1f5aac137876480252e5dcac62c354ec0d42b76b0642b6181ed099849ea1d57"
   390  
   391  	opBenchmark(b, opAdd, x, y)
   392  }
   393  
   394  func BenchmarkOpSub64(b *testing.B) {
   395  	x := "51022b6317003a9d"
   396  	y := "a20456c62e00753a"
   397  
   398  	opBenchmark(b, opSub, x, y)
   399  }
   400  
   401  func BenchmarkOpSub128(b *testing.B) {
   402  	x := "4dde30faaacdc14d00327aac314e915d"
   403  	y := "9bbc61f5559b829a0064f558629d22ba"
   404  
   405  	opBenchmark(b, opSub, x, y)
   406  }
   407  
   408  func BenchmarkOpSub256(b *testing.B) {
   409  	x := "4bfcd8bb2ac462735b48a17580690283980aa2d679f091c64364594df113ea37"
   410  	y := "97f9b1765588c4e6b69142eb00d20507301545acf3e1238c86c8b29be227d46e"
   411  
   412  	opBenchmark(b, opSub, x, y)
   413  }
   414  
   415  func BenchmarkOpMul(b *testing.B) {
   416  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   417  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   418  
   419  	opBenchmark(b, opMul, x, y)
   420  }
   421  
   422  func BenchmarkOpDiv256(b *testing.B) {
   423  	x := "ff3f9014f20db29ae04af2c2d265de17"
   424  	y := "fe7fb0d1f59dfe9492ffbf73683fd1e870eec79504c60144cc7f5fc2bad1e611"
   425  	opBenchmark(b, opDiv, x, y)
   426  }
   427  
   428  func BenchmarkOpDiv128(b *testing.B) {
   429  	x := "fdedc7f10142ff97"
   430  	y := "fbdfda0e2ce356173d1993d5f70a2b11"
   431  	opBenchmark(b, opDiv, x, y)
   432  }
   433  
   434  func BenchmarkOpDiv64(b *testing.B) {
   435  	x := "fcb34eb3"
   436  	y := "f97180878e839129"
   437  	opBenchmark(b, opDiv, x, y)
   438  }
   439  
   440  func BenchmarkOpSdiv(b *testing.B) {
   441  	x := "ff3f9014f20db29ae04af2c2d265de17"
   442  	y := "fe7fb0d1f59dfe9492ffbf73683fd1e870eec79504c60144cc7f5fc2bad1e611"
   443  
   444  	opBenchmark(b, opSdiv, x, y)
   445  }
   446  
   447  func BenchmarkOpMod(b *testing.B) {
   448  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   449  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   450  
   451  	opBenchmark(b, opMod, x, y)
   452  }
   453  
   454  func BenchmarkOpSmod(b *testing.B) {
   455  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   456  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   457  
   458  	opBenchmark(b, opSmod, x, y)
   459  }
   460  
   461  func BenchmarkOpExp(b *testing.B) {
   462  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   463  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   464  
   465  	opBenchmark(b, opExp, x, y)
   466  }
   467  
   468  func BenchmarkOpSignExtend(b *testing.B) {
   469  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   470  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   471  
   472  	opBenchmark(b, opSignExtend, x, y)
   473  }
   474  
   475  func BenchmarkOpLt(b *testing.B) {
   476  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   477  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   478  
   479  	opBenchmark(b, opLt, x, y)
   480  }
   481  
   482  func BenchmarkOpGt(b *testing.B) {
   483  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   484  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   485  
   486  	opBenchmark(b, opGt, x, y)
   487  }
   488  
   489  func BenchmarkOpSlt(b *testing.B) {
   490  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   491  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   492  
   493  	opBenchmark(b, opSlt, x, y)
   494  }
   495  
   496  func BenchmarkOpSgt(b *testing.B) {
   497  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   498  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   499  
   500  	opBenchmark(b, opSgt, x, y)
   501  }
   502  
   503  func BenchmarkOpEq(b *testing.B) {
   504  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   505  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   506  
   507  	opBenchmark(b, opEq, x, y)
   508  }
   509  
   510  func BenchmarkOpEq2(b *testing.B) {
   511  	x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff"
   512  	y := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201fffffffe"
   513  	opBenchmark(b, opEq, x, y)
   514  }
   515  
   516  func BenchmarkOpAnd(b *testing.B) {
   517  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   518  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   519  
   520  	opBenchmark(b, opAnd, x, y)
   521  }
   522  
   523  func BenchmarkOpOr(b *testing.B) {
   524  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   525  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   526  
   527  	opBenchmark(b, opOr, x, y)
   528  }
   529  
   530  func BenchmarkOpXor(b *testing.B) {
   531  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   532  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   533  
   534  	opBenchmark(b, opXor, x, y)
   535  }
   536  
   537  func BenchmarkOpByte(b *testing.B) {
   538  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   539  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   540  
   541  	opBenchmark(b, opByte, x, y)
   542  }
   543  
   544  func BenchmarkOpAddmod(b *testing.B) {
   545  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   546  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   547  	z := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   548  
   549  	opBenchmark(b, opAddmod, x, y, z)
   550  }
   551  
   552  func BenchmarkOpMulmod(b *testing.B) {
   553  	x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   554  	y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   555  	z := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
   556  
   557  	opBenchmark(b, opMulmod, x, y, z)
   558  }
   559  
   560  func BenchmarkOpSHL(b *testing.B) {
   561  	x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff"
   562  	y := "ff"
   563  
   564  	opBenchmark(b, opSHL, x, y)
   565  }
   566  
   567  func BenchmarkOpSHR(b *testing.B) {
   568  	x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff"
   569  	y := "ff"
   570  
   571  	opBenchmark(b, opSHR, x, y)
   572  }
   573  
   574  func BenchmarkOpSAR(b *testing.B) {
   575  	x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff"
   576  	y := "ff"
   577  
   578  	opBenchmark(b, opSAR, x, y)
   579  }
   580  
   581  func BenchmarkOpIsZero(b *testing.B) {
   582  	x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff"
   583  	opBenchmark(b, opIszero, x)
   584  }
   585  
   586  func TestOpMstore(t *testing.T) {
   587  	var (
   588  		env            = NewEVM(Context{}, nil, params.TestChainConfig, &Config{})
   589  		stack          = newstack()
   590  		mem            = NewMemory()
   591  		evmInterpreter = NewEVMInterpreter(env, env.vmConfig)
   592  	)
   593  
   594  	env.interpreter = evmInterpreter
   595  	evmInterpreter.intPool = poolOfIntPools.get()
   596  	mem.Resize(64)
   597  	pc := uint64(0)
   598  	v := "abcdef00000000000000abba000000000deaf000000c0de00100000000133700"
   599  	stack.pushN(new(big.Int).SetBytes(common.Hex2Bytes(v)), big.NewInt(0))
   600  	opMstore(&pc, env, nil, mem, stack)
   601  	if got := common.Bytes2Hex(mem.GetCopy(0, 32)); got != v {
   602  		t.Fatalf("Mstore fail, got %v, expected %v", got, v)
   603  	}
   604  	stack.pushN(big.NewInt(0x1), big.NewInt(0))
   605  	opMstore(&pc, env, nil, mem, stack)
   606  	if common.Bytes2Hex(mem.GetCopy(0, 32)) != "0000000000000000000000000000000000000000000000000000000000000001" {
   607  		t.Fatalf("Mstore failed to overwrite previous value")
   608  	}
   609  	poolOfIntPools.put(evmInterpreter.intPool)
   610  }
   611  
   612  func BenchmarkOpMstore(bench *testing.B) {
   613  	var (
   614  		env            = NewEVM(Context{}, nil, params.TestChainConfig, &Config{})
   615  		stack          = newstack()
   616  		mem            = NewMemory()
   617  		evmInterpreter = NewEVMInterpreter(env, env.vmConfig)
   618  	)
   619  
   620  	env.interpreter = evmInterpreter
   621  	evmInterpreter.intPool = poolOfIntPools.get()
   622  	mem.Resize(64)
   623  	pc := uint64(0)
   624  	memStart := big.NewInt(0)
   625  	value := big.NewInt(0x1337)
   626  
   627  	bench.ResetTimer()
   628  	for i := 0; i < bench.N; i++ {
   629  		stack.pushN(value, memStart)
   630  		opMstore(&pc, env, nil, mem, stack)
   631  	}
   632  	poolOfIntPools.put(evmInterpreter.intPool)
   633  }
   634  
   635  func BenchmarkOpSHA3(bench *testing.B) {
   636  	var (
   637  		env            = NewEVM(Context{}, nil, params.TestChainConfig, &Config{})
   638  		stack          = newstack()
   639  		mem            = NewMemory()
   640  		evmInterpreter = NewEVMInterpreter(env, env.vmConfig)
   641  	)
   642  	env.interpreter = evmInterpreter
   643  	evmInterpreter.intPool = poolOfIntPools.get()
   644  	mem.Resize(32)
   645  	pc := uint64(0)
   646  	start := big.NewInt(0)
   647  
   648  	bench.ResetTimer()
   649  	for i := 0; i < bench.N; i++ {
   650  		stack.pushN(big.NewInt(32), start)
   651  		opSha3(&pc, env, nil, mem, stack)
   652  	}
   653  	poolOfIntPools.put(evmInterpreter.intPool)
   654  }
   655  
   656  func TestCreate2Addreses(t *testing.T) {
   657  	type testcase struct {
   658  		origin   string
   659  		salt     string
   660  		code     string
   661  		expected string
   662  	}
   663  
   664  	for i, tt := range []testcase{
   665  		{
   666  			origin:   "0x0000000000000000000000000000000000000000",
   667  			salt:     "0x0000000000000000000000000000000000000000",
   668  			code:     "0x00",
   669  			expected: "0x4d1a2e2bb4f88f0250f26ffff098b0b30b26bf38",
   670  		},
   671  		{
   672  			origin:   "0xdeadbeef00000000000000000000000000000000",
   673  			salt:     "0x0000000000000000000000000000000000000000",
   674  			code:     "0x00",
   675  			expected: "0xB928f69Bb1D91Cd65274e3c79d8986362984fDA3",
   676  		},
   677  		{
   678  			origin:   "0xdeadbeef00000000000000000000000000000000",
   679  			salt:     "0xfeed000000000000000000000000000000000000",
   680  			code:     "0x00",
   681  			expected: "0xD04116cDd17beBE565EB2422F2497E06cC1C9833",
   682  		},
   683  		{
   684  			origin:   "0x0000000000000000000000000000000000000000",
   685  			salt:     "0x0000000000000000000000000000000000000000",
   686  			code:     "0xdeadbeef",
   687  			expected: "0x70f2b2914A2a4b783FaEFb75f459A580616Fcb5e",
   688  		},
   689  		{
   690  			origin:   "0x00000000000000000000000000000000deadbeef",
   691  			salt:     "0xcafebabe",
   692  			code:     "0xdeadbeef",
   693  			expected: "0x60f3f640a8508fC6a86d45DF051962668E1e8AC7",
   694  		},
   695  		{
   696  			origin:   "0x00000000000000000000000000000000deadbeef",
   697  			salt:     "0xcafebabe",
   698  			code:     "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
   699  			expected: "0x1d8bfDC5D46DC4f61D6b6115972536eBE6A8854C",
   700  		},
   701  		{
   702  			origin:   "0x0000000000000000000000000000000000000000",
   703  			salt:     "0x0000000000000000000000000000000000000000",
   704  			code:     "0x",
   705  			expected: "0xE33C0C7F7df4809055C3ebA6c09CFe4BaF1BD9e0",
   706  		},
   707  	} {
   708  
   709  		origin := common.BytesToAddress(common.FromHex(tt.origin))
   710  		salt := common.BytesToHash(common.FromHex(tt.salt))
   711  		code := common.FromHex(tt.code)
   712  		codeHash := crypto.Keccak256(code)
   713  		address := crypto.CreateAddress2(origin, salt, codeHash)
   714  		/*
   715  			stack          := newstack()
   716  			// salt, but we don't need that for this test
   717  			stack.push(big.NewInt(int64(len(code)))) //size
   718  			stack.push(big.NewInt(0)) // memstart
   719  			stack.push(big.NewInt(0)) // value
   720  			gas, _ := gasCreate2(params.GasTable{}, nil, nil, stack, nil, 0)
   721  			fmt.Printf("Example %d\n* address `0x%x`\n* salt `0x%x`\n* init_code `0x%x`\n* gas (assuming no mem expansion): `%v`\n* result: `%s`\n\n", i,origin, salt, code, gas, address.String())
   722  		*/
   723  		expected := common.BytesToAddress(common.FromHex(tt.expected))
   724  		if !bytes.Equal(expected.Bytes(), address.Bytes()) {
   725  			t.Errorf("test %d: expected %s, got %s", i, expected.String(), address.String())
   726  		}
   727  
   728  	}
   729  }
   730  
   731  func BenchmarkOpStop(b *testing.B) {
   732  	opBenchmark(b, opStop)
   733  }
   734  
   735  func BenchmarkOpNot(b *testing.B) {
   736  	x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff"
   737  	opBenchmark(b, opNot, x)
   738  }
   739  
   740  func BenchmarkOpAddress(b *testing.B) {
   741  	opBenchmark(b, opAddress)
   742  }
   743  
   744  func BenchmarkOpBalance(b *testing.B) {
   745  	addr := "18f30de96ce789fe778b9a5f420f6fdbbd9b34d8"
   746  	opBenchmark(b, opBalance, addr)
   747  }
   748  
   749  func BenchmarkOpOrigin(b *testing.B) {
   750  	opBenchmark(b, opOrigin)
   751  }
   752  
   753  func BenchmarkOpCaller(b *testing.B) {
   754  	opBenchmark(b, opCaller)
   755  }
   756  
   757  func BenchmarkOpCallValue(b *testing.B) {
   758  	opBenchmark(b, opCallValue)
   759  }
   760  
   761  func BenchmarkOpCallDataLoad(b *testing.B) {
   762  	x := "0000000000000000000000000000000000000000000000000000000000000001" // 1
   763  	opBenchmark(b, opCallDataLoad, x)
   764  }
   765  
   766  func BenchmarkOpCallDataSize(b *testing.B) {
   767  	opBenchmark(b, opCallDataSize)
   768  }
   769  
   770  func BenchmarkOpCallDataCopy(b *testing.B) {
   771  	length := "0000000000000000000000000000000000000000000000000000000000000013"     // 19
   772  	dataOffset := "0000000000000000000000000000000000000000000000000000000000000001" // 1
   773  	memOffset := "0000000000000000000000000000000000000000000000000000000000000001"  // 1
   774  	opBenchmark(b, opCallDataCopy, length, dataOffset, memOffset)
   775  }
   776  
   777  func BenchmarkOpReturnDataSize(b *testing.B) {
   778  	opBenchmark(b, opReturnDataSize)
   779  }
   780  
   781  func BenchmarkOpReturnDataCopy(b *testing.B) {
   782  	length := "0000000000000000000000000000000000000000000000000000000000000009"     // 9
   783  	dataOffset := "0000000000000000000000000000000000000000000000000000000000000001" // 1
   784  	memOffset := "0000000000000000000000000000000000000000000000000000000000000001"  // 1
   785  	opBenchmark(b, opReturnDataCopy, length, dataOffset, memOffset)
   786  }
   787  
   788  func BenchmarkOpExtCodeSize(b *testing.B) {
   789  	addr := "18f30de96ce789fe778b9a5f420f6fdbbd9b34d8"
   790  	opBenchmark(b, opExtCodeSize, addr)
   791  }
   792  
   793  func BenchmarkOpCodeSize(b *testing.B) {
   794  	opBenchmark(b, opCodeSize)
   795  }
   796  
   797  func BenchmarkOpCodeCopy(b *testing.B) {
   798  	length := "000000000000000000000000000000000000000000000000000000000000003c"     // 60
   799  	dataOffset := "0000000000000000000000000000000000000000000000000000000000000001" // 1
   800  	memOffset := "0000000000000000000000000000000000000000000000000000000000000001"  // 1
   801  	opBenchmark(b, opCodeCopy, length, dataOffset, memOffset)
   802  }
   803  
   804  func BenchmarkOpExtCodeCopy(b *testing.B) {
   805  	length := "000000000000000000000000000000000000000000000000000000000000003c"     // 60
   806  	codeOffset := "0000000000000000000000000000000000000000000000000000000000000001" // 1
   807  	memOffset := "0000000000000000000000000000000000000000000000000000000000000001"  // 1
   808  	addr := "18f30de96ce789fe778b9a5f420f6fdbbd9b34d8"
   809  	opBenchmark(b, opExtCodeCopy, length, codeOffset, memOffset, addr)
   810  }
   811  
   812  func BenchmarkOpExtCodeHash(b *testing.B) {
   813  	addr := "18f30de96ce789fe778b9a5f420f6fdbbd9b34d8"
   814  	opBenchmark(b, opExtCodeHash, addr)
   815  }
   816  
   817  func BenchmarkOpGasprice(b *testing.B) {
   818  	opBenchmark(b, opGasprice)
   819  }
   820  
   821  func BenchmarkOpBlockhash(b *testing.B) {
   822  	num := "00000000000000000000000000000000000000000000000000000000000003E8" // 1000
   823  	opBenchmark(b, opBlockhash, num)
   824  }
   825  
   826  func BenchmarkOpCoinbase(b *testing.B) {
   827  	opBenchmark(b, opCoinbase)
   828  }
   829  
   830  func BenchmarkOpTimestamp(b *testing.B) {
   831  	opBenchmark(b, opTimestamp)
   832  }
   833  
   834  func BenchmarkOpNumber(b *testing.B) {
   835  	opBenchmark(b, opNumber)
   836  }
   837  
   838  func BenchmarkOpDifficulty(b *testing.B) {
   839  	opBenchmark(b, opDifficulty)
   840  }
   841  
   842  func BenchmarkOpRandom(b *testing.B) {
   843  	opBenchmark(b, opRandom)
   844  }
   845  
   846  func BenchmarkOpGasLimit(b *testing.B) {
   847  	opBenchmark(b, opGasLimit)
   848  }
   849  
   850  func BenchmarkOpPop(b *testing.B) {
   851  	x := "7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"
   852  	opBenchmark(b, opPop, x)
   853  }
   854  
   855  func BenchmarkOpMload(b *testing.B) {
   856  	offset := "0000000000000000000000000000000000000000000000000000000000000001"
   857  	opBenchmark(b, opMload, offset)
   858  }
   859  
   860  func BenchmarkOpMstore8(b *testing.B) {
   861  	val := "7FFFFFFFFFFFFFFF"
   862  	off := "0000000000000000000000000000000000000000000000000000000000000001"
   863  	opBenchmark(b, opMstore8, val, off)
   864  }
   865  
   866  func BenchmarkOpSload(b *testing.B) {
   867  	loc := "7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"
   868  	opBenchmark(b, opSload, loc)
   869  }
   870  
   871  func BenchmarkOpSstore(bench *testing.B) {
   872  	var (
   873  		memDBManager = database.NewMemoryDBManager()
   874  		statedb      = initStateDB(memDBManager)
   875  
   876  		env            = NewEVM(Context{}, statedb, params.TestChainConfig, &Config{})
   877  		stack          = newstack()
   878  		evmInterpreter = NewEVMInterpreter(env, env.vmConfig)
   879  	)
   880  
   881  	env.interpreter = evmInterpreter
   882  	evmInterpreter.intPool = poolOfIntPools.get()
   883  
   884  	// make contract
   885  	senderAddress := common.HexToAddress("0x91fb186da8f327f999782d1ae1ceacbd4fbbf146")
   886  	payerAddress := common.HexToAddress("0x18f30de96ce789fe778b9a5f420f6fdbbd9b34d8")
   887  
   888  	caller := types.NewAccountRefWithFeePayer(senderAddress, payerAddress)
   889  	object := types.NewAccountRefWithFeePayer(payerAddress, senderAddress)
   890  	contract := NewContract(caller, object, big.NewInt(0), uint64(1000))
   891  
   892  	// convert args
   893  	byteArgs := make([][]byte, 2)
   894  	byteArgs[0] = common.Hex2Bytes("7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd") // val
   895  	byteArgs[1] = common.Hex2Bytes("7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")  // loc
   896  
   897  	pc := uint64(0)
   898  	bench.ResetTimer()
   899  	for i := 0; i < bench.N; i++ {
   900  		stack.push(new(big.Int).SetBytes(byteArgs[0]))
   901  		stack.push(new(big.Int).SetBytes(append(byteArgs[1], byte(i))))
   902  		opSstore(&pc, env, contract, nil, stack)
   903  		if stack.len() > 0 {
   904  			stack.pop()
   905  		}
   906  	}
   907  	poolOfIntPools.put(evmInterpreter.intPool)
   908  }
   909  
   910  func BenchmarkOpJump(b *testing.B) {
   911  	pos := "0000000000000000000000000000000000000000000000000000000000000045"
   912  	opBenchmark(b, opJump, pos)
   913  }
   914  
   915  func BenchmarkOpJumpi(b *testing.B) {
   916  	cond := "0000000000000000000000000000000000000000000000000000000000000001"
   917  	pos := "0000000000000000000000000000000000000000000000000000000000000045"
   918  	opBenchmark(b, opJumpi, cond, pos)
   919  }
   920  
   921  func BenchmarkOpJumpdest(b *testing.B) {
   922  	opBenchmark(b, opJumpdest)
   923  }
   924  
   925  func BenchmarkOpPc(b *testing.B) {
   926  	opBenchmark(b, opPc)
   927  }
   928  
   929  func BenchmarkOpMsize(b *testing.B) {
   930  	opBenchmark(b, opMsize)
   931  }
   932  
   933  func BenchmarkOpGas(b *testing.B) {
   934  	opBenchmark(b, opGas)
   935  }
   936  
   937  func BenchmarkOpCreate(b *testing.B) {
   938  	size := "0000000000000014"
   939  	offset := "0000000000000001"
   940  	value := "7FFFFFFFFFFFFFFF"
   941  	opBenchmark(b, opCreate, size, offset, value)
   942  }
   943  
   944  func BenchmarkOpCreate2(b *testing.B) {
   945  	salt := "7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"
   946  	size := "0000000000000014"
   947  	offset := "0000000000000001"
   948  	endowment := "7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"
   949  	opBenchmark(b, opCreate2, salt, size, offset, endowment)
   950  }
   951  
   952  func BenchmarkOpCall(b *testing.B) {
   953  	retSize := "0000000000000000000000000000000000000000000000000000000000000001"
   954  	retOffset := "0000000000000000000000000000000000000000000000000000000000000001"
   955  	inSize := "0000000000000014"
   956  	inOffset := "0000000000000001"
   957  	value := "0000000000000000000000000000000000000000000000000000000000000001"
   958  	addr := "18f30de96ce789fe778b9a5f420f6fdbbd9b34d9"
   959  	gas := "7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"
   960  	opBenchmark(b, opCall, retSize, retOffset, inSize, inOffset, value, addr, gas)
   961  }
   962  
   963  func BenchmarkOpCallCode(b *testing.B) {
   964  	retSize := "0000000000000000000000000000000000000000000000000000000000000001"
   965  	retOffset := "0000000000000000000000000000000000000000000000000000000000000001"
   966  	inSize := "0000000000000014"
   967  	inOffset := "0000000000000001"
   968  	value := "0000000000000000000000000000000000000000000000000000000000000001"
   969  	addr := "18f30de96ce789fe778b9a5f420f6fdbbd9b34d9"
   970  	gas := "7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"
   971  	opBenchmark(b, opCallCode, retSize, retOffset, inSize, inOffset, value, addr, gas)
   972  }
   973  
   974  func BenchmarkOpDelegateCall(b *testing.B) {
   975  	retSize := "0000000000000000000000000000000000000000000000000000000000000001"
   976  	retOffset := "0000000000000000000000000000000000000000000000000000000000000001"
   977  	inSize := "0000000000000014"
   978  	inOffset := "0000000000000001"
   979  	addr := "18f30de96ce789fe778b9a5f420f6fdbbd9b34d9"
   980  	gas := "7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"
   981  	opBenchmark(b, opDelegateCall, retSize, retOffset, inSize, inOffset, addr, gas)
   982  }
   983  
   984  func BenchmarkOpStaticCall(b *testing.B) {
   985  	retSize := "0000000000000000000000000000000000000000000000000000000000000001"
   986  	retOffset := "0000000000000000000000000000000000000000000000000000000000000001"
   987  	inSize := "0000000000000014"
   988  	inOffset := "0000000000000001"
   989  	addr := "18f30de96ce789fe778b9a5f420f6fdbbd9b34d9"
   990  	gas := "7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"
   991  	opBenchmark(b, opStaticCall, retSize, retOffset, inSize, inOffset, addr, gas)
   992  }
   993  
   994  func BenchmarkOpReturn(b *testing.B) {
   995  	size := "0000000000000014"
   996  	offset := "0000000000000001"
   997  	opBenchmark(b, opReturn, size, offset)
   998  }
   999  
  1000  func BenchmarkOpRevert(b *testing.B) {
  1001  	size := "0000000000000014"
  1002  	offset := "0000000000000001"
  1003  	opBenchmark(b, opRevert, size, offset)
  1004  }
  1005  
  1006  func BenchmarkOpSuicide(b *testing.B) {
  1007  	addr := "18f30de96ce789fe778b9a5f420f6fdbbd9b34d8"
  1008  	opBenchmark(b, opSuicide, addr)
  1009  }
  1010  
  1011  func BenchmarkOpPush1(b *testing.B) {
  1012  	opBenchmark(b, opPush1)
  1013  }
  1014  
  1015  func BenchmarkOpPush2(b *testing.B) {
  1016  	opBenchmark(b, makePush(uint64(2), 2))
  1017  }
  1018  
  1019  func BenchmarkOpPush3(b *testing.B) {
  1020  	opBenchmark(b, makePush(uint64(3), 3))
  1021  }
  1022  
  1023  func BenchmarkOpPush4(b *testing.B) {
  1024  	opBenchmark(b, makePush(uint64(4), 4))
  1025  }
  1026  
  1027  func BenchmarkOpPush5(b *testing.B) {
  1028  	opBenchmark(b, makePush(uint64(5), 5))
  1029  }
  1030  
  1031  func BenchmarkOpPush6(b *testing.B) {
  1032  	opBenchmark(b, makePush(uint64(6), 6))
  1033  }
  1034  
  1035  func BenchmarkOpPush7(b *testing.B) {
  1036  	opBenchmark(b, makePush(uint64(7), 7))
  1037  }
  1038  
  1039  func BenchmarkOpPush8(b *testing.B) {
  1040  	opBenchmark(b, makePush(uint64(8), 8))
  1041  }
  1042  
  1043  func BenchmarkOpPush9(b *testing.B) {
  1044  	opBenchmark(b, makePush(uint64(9), 9))
  1045  }
  1046  
  1047  func BenchmarkOpPush10(b *testing.B) {
  1048  	opBenchmark(b, makePush(uint64(10), 10))
  1049  }
  1050  
  1051  func BenchmarkOpPush11(b *testing.B) {
  1052  	opBenchmark(b, makePush(uint64(11), 11))
  1053  }
  1054  
  1055  func BenchmarkOpPush12(b *testing.B) {
  1056  	opBenchmark(b, makePush(uint64(12), 12))
  1057  }
  1058  
  1059  func BenchmarkOpPush13(b *testing.B) {
  1060  	opBenchmark(b, makePush(uint64(13), 13))
  1061  }
  1062  
  1063  func BenchmarkOpPush14(b *testing.B) {
  1064  	opBenchmark(b, makePush(uint64(14), 14))
  1065  }
  1066  
  1067  func BenchmarkOpPush15(b *testing.B) {
  1068  	opBenchmark(b, makePush(uint64(15), 15))
  1069  }
  1070  
  1071  func BenchmarkOpPush16(b *testing.B) {
  1072  	opBenchmark(b, makePush(uint64(16), 16))
  1073  }
  1074  
  1075  func BenchmarkOpPush17(b *testing.B) {
  1076  	opBenchmark(b, makePush(uint64(17), 17))
  1077  }
  1078  
  1079  func BenchmarkOpPush18(b *testing.B) {
  1080  	opBenchmark(b, makePush(uint64(18), 18))
  1081  }
  1082  
  1083  func BenchmarkOpPush19(b *testing.B) {
  1084  	opBenchmark(b, makePush(uint64(19), 19))
  1085  }
  1086  
  1087  func BenchmarkOpPush20(b *testing.B) {
  1088  	opBenchmark(b, makePush(uint64(20), 20))
  1089  }
  1090  
  1091  func BenchmarkOpPush21(b *testing.B) {
  1092  	opBenchmark(b, makePush(uint64(21), 21))
  1093  }
  1094  
  1095  func BenchmarkOpPush22(b *testing.B) {
  1096  	opBenchmark(b, makePush(uint64(22), 22))
  1097  }
  1098  
  1099  func BenchmarkOpPush23(b *testing.B) {
  1100  	opBenchmark(b, makePush(uint64(23), 23))
  1101  }
  1102  
  1103  func BenchmarkOpPush24(b *testing.B) {
  1104  	opBenchmark(b, makePush(uint64(24), 24))
  1105  }
  1106  
  1107  func BenchmarkOpPush25(b *testing.B) {
  1108  	opBenchmark(b, makePush(uint64(25), 25))
  1109  }
  1110  
  1111  func BenchmarkOpPush26(b *testing.B) {
  1112  	opBenchmark(b, makePush(uint64(26), 26))
  1113  }
  1114  
  1115  func BenchmarkOpPush27(b *testing.B) {
  1116  	opBenchmark(b, makePush(uint64(27), 27))
  1117  }
  1118  
  1119  func BenchmarkOpPush28(b *testing.B) {
  1120  	opBenchmark(b, makePush(uint64(28), 28))
  1121  }
  1122  
  1123  func BenchmarkOpPush29(b *testing.B) {
  1124  	opBenchmark(b, makePush(uint64(29), 29))
  1125  }
  1126  
  1127  func BenchmarkOpPush30(b *testing.B) {
  1128  	opBenchmark(b, makePush(uint64(30), 30))
  1129  }
  1130  
  1131  func BenchmarkOpPush31(b *testing.B) {
  1132  	opBenchmark(b, makePush(uint64(31), 31))
  1133  }
  1134  
  1135  func BenchmarkOpPush32(b *testing.B) {
  1136  	opBenchmark(b, makePush(uint64(32), 32))
  1137  }
  1138  
  1139  func BenchmarkOpDup1(b *testing.B) {
  1140  	size := 1
  1141  	stacks := genStacksForDup(size)
  1142  	opBenchmark(b, makeDup(int64(size)), stacks...)
  1143  }
  1144  
  1145  func BenchmarkOpDup2(b *testing.B) {
  1146  	size := 2
  1147  	stacks := genStacksForDup(size)
  1148  	opBenchmark(b, makeDup(int64(size)), stacks...)
  1149  }
  1150  
  1151  func BenchmarkOpDup3(b *testing.B) {
  1152  	size := 3
  1153  	stacks := genStacksForDup(size)
  1154  	opBenchmark(b, makeDup(int64(size)), stacks...)
  1155  }
  1156  
  1157  func BenchmarkOpDup4(b *testing.B) {
  1158  	size := 4
  1159  	stacks := genStacksForDup(size)
  1160  	opBenchmark(b, makeDup(int64(size)), stacks...)
  1161  }
  1162  
  1163  func BenchmarkOpDup5(b *testing.B) {
  1164  	size := 5
  1165  	stacks := genStacksForDup(size)
  1166  	opBenchmark(b, makeDup(int64(size)), stacks...)
  1167  }
  1168  
  1169  func BenchmarkOpDup6(b *testing.B) {
  1170  	size := 6
  1171  	stacks := genStacksForDup(size)
  1172  	opBenchmark(b, makeDup(int64(size)), stacks...)
  1173  }
  1174  
  1175  func BenchmarkOpDup7(b *testing.B) {
  1176  	size := 7
  1177  	stacks := genStacksForDup(size)
  1178  	opBenchmark(b, makeDup(int64(size)), stacks...)
  1179  }
  1180  
  1181  func BenchmarkOpDup8(b *testing.B) {
  1182  	size := 8
  1183  	stacks := genStacksForDup(size)
  1184  	opBenchmark(b, makeDup(int64(size)), stacks...)
  1185  }
  1186  
  1187  func BenchmarkOpDup9(b *testing.B) {
  1188  	size := 9
  1189  	stacks := genStacksForDup(size)
  1190  	opBenchmark(b, makeDup(int64(size)), stacks...)
  1191  }
  1192  
  1193  func BenchmarkOpDup10(b *testing.B) {
  1194  	size := 10
  1195  	stacks := genStacksForDup(size)
  1196  	opBenchmark(b, makeDup(int64(size)), stacks...)
  1197  }
  1198  
  1199  func BenchmarkOpDup11(b *testing.B) {
  1200  	size := 11
  1201  	stacks := genStacksForDup(size)
  1202  	opBenchmark(b, makeDup(int64(size)), stacks...)
  1203  }
  1204  
  1205  func BenchmarkOpDup12(b *testing.B) {
  1206  	size := 12
  1207  	stacks := genStacksForDup(size)
  1208  	opBenchmark(b, makeDup(int64(size)), stacks...)
  1209  }
  1210  
  1211  func BenchmarkOpDup13(b *testing.B) {
  1212  	size := 13
  1213  	stacks := genStacksForDup(size)
  1214  	opBenchmark(b, makeDup(int64(size)), stacks...)
  1215  }
  1216  
  1217  func BenchmarkOpDup14(b *testing.B) {
  1218  	size := 14
  1219  	stacks := genStacksForDup(size)
  1220  	opBenchmark(b, makeDup(int64(size)), stacks...)
  1221  }
  1222  
  1223  func BenchmarkOpDup15(b *testing.B) {
  1224  	size := 15
  1225  	stacks := genStacksForDup(size)
  1226  	opBenchmark(b, makeDup(int64(size)), stacks...)
  1227  }
  1228  
  1229  func BenchmarkOpDup16(b *testing.B) {
  1230  	size := 16
  1231  	stacks := genStacksForDup(size)
  1232  	opBenchmark(b, makeDup(int64(size)), stacks...)
  1233  }
  1234  
  1235  func BenchmarkOpSwap1(b *testing.B) {
  1236  	size := 1
  1237  	stacks := genStacksForSwap(size)
  1238  	opBenchmark(b, makeSwap(int64(size)), stacks...)
  1239  }
  1240  
  1241  func BenchmarkOpSwap2(b *testing.B) {
  1242  	size := 2
  1243  	stacks := genStacksForSwap(size)
  1244  	opBenchmark(b, makeSwap(int64(size)), stacks...)
  1245  }
  1246  
  1247  func BenchmarkOpSwap3(b *testing.B) {
  1248  	size := 3
  1249  	stacks := genStacksForSwap(size)
  1250  	opBenchmark(b, makeSwap(int64(size)), stacks...)
  1251  }
  1252  
  1253  func BenchmarkOpSwap4(b *testing.B) {
  1254  	size := 4
  1255  	stacks := genStacksForSwap(size)
  1256  	opBenchmark(b, makeSwap(int64(size)), stacks...)
  1257  }
  1258  
  1259  func BenchmarkOpSwap5(b *testing.B) {
  1260  	size := 5
  1261  	stacks := genStacksForSwap(size)
  1262  	opBenchmark(b, makeSwap(int64(size)), stacks...)
  1263  }
  1264  
  1265  func BenchmarkOpSwap6(b *testing.B) {
  1266  	size := 6
  1267  	stacks := genStacksForSwap(size)
  1268  	opBenchmark(b, makeSwap(int64(size)), stacks...)
  1269  }
  1270  
  1271  func BenchmarkOpSwap7(b *testing.B) {
  1272  	size := 7
  1273  	stacks := genStacksForSwap(size)
  1274  	opBenchmark(b, makeSwap(int64(size)), stacks...)
  1275  }
  1276  
  1277  func BenchmarkOpSwap8(b *testing.B) {
  1278  	size := 8
  1279  	stacks := genStacksForSwap(size)
  1280  	opBenchmark(b, makeSwap(int64(size)), stacks...)
  1281  }
  1282  
  1283  func BenchmarkOpSwap9(b *testing.B) {
  1284  	size := 9
  1285  	stacks := genStacksForSwap(size)
  1286  	opBenchmark(b, makeSwap(int64(size)), stacks...)
  1287  }
  1288  
  1289  func BenchmarkOpSwap10(b *testing.B) {
  1290  	size := 10
  1291  	stacks := genStacksForSwap(size)
  1292  	opBenchmark(b, makeSwap(int64(size)), stacks...)
  1293  }
  1294  
  1295  func BenchmarkOpSwap11(b *testing.B) {
  1296  	size := 11
  1297  	stacks := genStacksForSwap(size)
  1298  	opBenchmark(b, makeSwap(int64(size)), stacks...)
  1299  }
  1300  
  1301  func BenchmarkOpSwap12(b *testing.B) {
  1302  	size := 12
  1303  	stacks := genStacksForSwap(size)
  1304  	opBenchmark(b, makeSwap(int64(size)), stacks...)
  1305  }
  1306  
  1307  func BenchmarkOpSwap13(b *testing.B) {
  1308  	size := 13
  1309  	stacks := genStacksForSwap(size)
  1310  	opBenchmark(b, makeSwap(int64(size)), stacks...)
  1311  }
  1312  
  1313  func BenchmarkOpSwap14(b *testing.B) {
  1314  	size := 14
  1315  	stacks := genStacksForSwap(size)
  1316  	opBenchmark(b, makeSwap(int64(size)), stacks...)
  1317  }
  1318  
  1319  func BenchmarkOpSwap15(b *testing.B) {
  1320  	size := 15
  1321  	stacks := genStacksForSwap(size)
  1322  	opBenchmark(b, makeSwap(int64(size)), stacks...)
  1323  }
  1324  
  1325  func BenchmarkOpSwap16(b *testing.B) {
  1326  	size := 16
  1327  	stacks := genStacksForSwap(size)
  1328  	opBenchmark(b, makeSwap(int64(size)), stacks...)
  1329  }
  1330  
  1331  func BenchmarkOpLog0(b *testing.B) {
  1332  	size := 0
  1333  	stacks := genStacksForLog(size)
  1334  	opBenchmark(b, makeLog(size), stacks...)
  1335  }
  1336  
  1337  func BenchmarkOpLog1(b *testing.B) {
  1338  	size := 1
  1339  	stacks := genStacksForLog(size)
  1340  	opBenchmark(b, makeLog(size), stacks...)
  1341  }
  1342  
  1343  func BenchmarkOpLog2(b *testing.B) {
  1344  	size := 2
  1345  	stacks := genStacksForLog(size)
  1346  	opBenchmark(b, makeLog(size), stacks...)
  1347  }
  1348  
  1349  func BenchmarkOpLog3(b *testing.B) {
  1350  	size := 3
  1351  	stacks := genStacksForLog(size)
  1352  	opBenchmark(b, makeLog(size), stacks...)
  1353  }
  1354  
  1355  func BenchmarkOpLog4(b *testing.B) {
  1356  	size := 4
  1357  	stacks := genStacksForLog(size)
  1358  	opBenchmark(b, makeLog(size), stacks...)
  1359  }
  1360  
  1361  func BenchmarkOpChainID(b *testing.B) {
  1362  	opBenchmark(b, opChainID)
  1363  }
  1364  
  1365  func BenchmarkOpSelfBalance(b *testing.B) {
  1366  	opBenchmark(b, opSelfBalance)
  1367  }
  1368  
  1369  func BenchmarkOpBaseFee(b *testing.B) {
  1370  	opBenchmark(b, opBaseFee)
  1371  }
  1372  
  1373  func genStacksForDup(size int) []string {
  1374  	stacks := make([]string, size)
  1375  	return fillStacks(stacks, size)
  1376  }
  1377  
  1378  func genStacksForSwap(size int) []string {
  1379  	stacks := make([]string, size+1)
  1380  	fillStacks(stacks, size)
  1381  	stacks[len(stacks)-1] = "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
  1382  	return stacks
  1383  }
  1384  
  1385  func genStacksForLog(size int) []string {
  1386  	stacks := make([]string, size+2)
  1387  	fillStacks(stacks, size)
  1388  	stacks[len(stacks)-2] = "0000000000000000000000000000000000000000000000000000000000000014" // 20
  1389  	stacks[len(stacks)-1] = "0000000000000000000000000000000000000000000000000000000000000001" // 1
  1390  	return stacks
  1391  }
  1392  
  1393  func fillStacks(stacks []string, n int) []string {
  1394  	for i := 0; i < n; i++ {
  1395  		stacks[i] = "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff"
  1396  	}
  1397  	return stacks
  1398  }