github.com/theQRL/go-zond@v0.1.1/core/vm/jump_table.go (about)

     1  // Copyright 2015 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  	"fmt"
    21  
    22  	"github.com/theQRL/go-zond/params"
    23  )
    24  
    25  type (
    26  	executionFunc func(pc *uint64, interpreter *EVMInterpreter, callContext *ScopeContext) ([]byte, error)
    27  	gasFunc       func(*EVM, *Contract, *Stack, *Memory, uint64) (uint64, error) // last parameter is the requested memory size as a uint64
    28  	// memorySizeFunc returns the required size, and whether the operation overflowed a uint64
    29  	memorySizeFunc func(*Stack) (size uint64, overflow bool)
    30  )
    31  
    32  type operation struct {
    33  	// execute is the operation function
    34  	execute     executionFunc
    35  	constantGas uint64
    36  	dynamicGas  gasFunc
    37  	// minStack tells how many stack items are required
    38  	minStack int
    39  	// maxStack specifies the max length the stack can have for this operation
    40  	// to not overflow the stack.
    41  	maxStack int
    42  
    43  	// memorySize returns the memory size required for the operation
    44  	memorySize memorySizeFunc
    45  }
    46  
    47  var (
    48  	frontierInstructionSet         = newFrontierInstructionSet()
    49  	homesteadInstructionSet        = newHomesteadInstructionSet()
    50  	tangerineWhistleInstructionSet = newTangerineWhistleInstructionSet()
    51  	spuriousDragonInstructionSet   = newSpuriousDragonInstructionSet()
    52  	byzantiumInstructionSet        = newByzantiumInstructionSet()
    53  	constantinopleInstructionSet   = newConstantinopleInstructionSet()
    54  	istanbulInstructionSet         = newIstanbulInstructionSet()
    55  	berlinInstructionSet           = newBerlinInstructionSet()
    56  	londonInstructionSet           = newLondonInstructionSet()
    57  	mergeInstructionSet            = newMergeInstructionSet()
    58  	shanghaiInstructionSet         = newShanghaiInstructionSet()
    59  	cancunInstructionSet           = newCancunInstructionSet()
    60  )
    61  
    62  // JumpTable contains the EVM opcodes supported at a given fork.
    63  type JumpTable [256]*operation
    64  
    65  func validate(jt JumpTable) JumpTable {
    66  	for i, op := range jt {
    67  		if op == nil {
    68  			panic(fmt.Sprintf("op %#x is not set", i))
    69  		}
    70  		// The interpreter has an assumption that if the memorySize function is
    71  		// set, then the dynamicGas function is also set. This is a somewhat
    72  		// arbitrary assumption, and can be removed if we need to -- but it
    73  		// allows us to avoid a condition check. As long as we have that assumption
    74  		// in there, this little sanity check prevents us from merging in a
    75  		// change which violates it.
    76  		if op.memorySize != nil && op.dynamicGas == nil {
    77  			panic(fmt.Sprintf("op %v has dynamic memory but not dynamic gas", OpCode(i).String()))
    78  		}
    79  	}
    80  	return jt
    81  }
    82  
    83  func newCancunInstructionSet() JumpTable {
    84  	instructionSet := newShanghaiInstructionSet()
    85  	enable4844(&instructionSet) // EIP-4844 (DATAHASH opcode)
    86  	enable1153(&instructionSet) // EIP-1153 "Transient Storage"
    87  	enable5656(&instructionSet) // EIP-5656 (MCOPY opcode)
    88  	enable6780(&instructionSet) // EIP-6780 SELFDESTRUCT only in same transaction
    89  	return validate(instructionSet)
    90  }
    91  
    92  func newShanghaiInstructionSet() JumpTable {
    93  	instructionSet := newMergeInstructionSet()
    94  	enable3855(&instructionSet) // PUSH0 instruction
    95  	enable3860(&instructionSet) // Limit and meter initcode
    96  
    97  	return validate(instructionSet)
    98  }
    99  
   100  func newMergeInstructionSet() JumpTable {
   101  	instructionSet := newLondonInstructionSet()
   102  	instructionSet[PREVRANDAO] = &operation{
   103  		execute:     opRandom,
   104  		constantGas: GasQuickStep,
   105  		minStack:    minStack(0, 1),
   106  		maxStack:    maxStack(0, 1),
   107  	}
   108  	return validate(instructionSet)
   109  }
   110  
   111  // newLondonInstructionSet returns the frontier, homestead, byzantium,
   112  // constantinople, istanbul, petersburg, berlin and london instructions.
   113  func newLondonInstructionSet() JumpTable {
   114  	instructionSet := newBerlinInstructionSet()
   115  	enable3529(&instructionSet) // EIP-3529: Reduction in refunds https://eips.ethereum.org/EIPS/eip-3529
   116  	enable3198(&instructionSet) // Base fee opcode https://eips.ethereum.org/EIPS/eip-3198
   117  	return validate(instructionSet)
   118  }
   119  
   120  // newBerlinInstructionSet returns the frontier, homestead, byzantium,
   121  // constantinople, istanbul, petersburg and berlin instructions.
   122  func newBerlinInstructionSet() JumpTable {
   123  	instructionSet := newIstanbulInstructionSet()
   124  	enable2929(&instructionSet) // Access lists for trie accesses https://eips.ethereum.org/EIPS/eip-2929
   125  	return validate(instructionSet)
   126  }
   127  
   128  // newIstanbulInstructionSet returns the frontier, homestead, byzantium,
   129  // constantinople, istanbul and petersburg instructions.
   130  func newIstanbulInstructionSet() JumpTable {
   131  	instructionSet := newConstantinopleInstructionSet()
   132  
   133  	enable1344(&instructionSet) // ChainID opcode - https://eips.ethereum.org/EIPS/eip-1344
   134  	enable1884(&instructionSet) // Reprice reader opcodes - https://eips.ethereum.org/EIPS/eip-1884
   135  	enable2200(&instructionSet) // Net metered SSTORE - https://eips.ethereum.org/EIPS/eip-2200
   136  
   137  	return validate(instructionSet)
   138  }
   139  
   140  // newConstantinopleInstructionSet returns the frontier, homestead,
   141  // byzantium and constantinople instructions.
   142  func newConstantinopleInstructionSet() JumpTable {
   143  	instructionSet := newByzantiumInstructionSet()
   144  	instructionSet[SHL] = &operation{
   145  		execute:     opSHL,
   146  		constantGas: GasFastestStep,
   147  		minStack:    minStack(2, 1),
   148  		maxStack:    maxStack(2, 1),
   149  	}
   150  	instructionSet[SHR] = &operation{
   151  		execute:     opSHR,
   152  		constantGas: GasFastestStep,
   153  		minStack:    minStack(2, 1),
   154  		maxStack:    maxStack(2, 1),
   155  	}
   156  	instructionSet[SAR] = &operation{
   157  		execute:     opSAR,
   158  		constantGas: GasFastestStep,
   159  		minStack:    minStack(2, 1),
   160  		maxStack:    maxStack(2, 1),
   161  	}
   162  	instructionSet[EXTCODEHASH] = &operation{
   163  		execute:     opExtCodeHash,
   164  		constantGas: params.ExtcodeHashGasConstantinople,
   165  		minStack:    minStack(1, 1),
   166  		maxStack:    maxStack(1, 1),
   167  	}
   168  	instructionSet[CREATE2] = &operation{
   169  		execute:     opCreate2,
   170  		constantGas: params.Create2Gas,
   171  		dynamicGas:  gasCreate2,
   172  		minStack:    minStack(4, 1),
   173  		maxStack:    maxStack(4, 1),
   174  		memorySize:  memoryCreate2,
   175  	}
   176  	return validate(instructionSet)
   177  }
   178  
   179  // newByzantiumInstructionSet returns the frontier, homestead and
   180  // byzantium instructions.
   181  func newByzantiumInstructionSet() JumpTable {
   182  	instructionSet := newSpuriousDragonInstructionSet()
   183  	instructionSet[STATICCALL] = &operation{
   184  		execute:     opStaticCall,
   185  		constantGas: params.CallGasEIP150,
   186  		dynamicGas:  gasStaticCall,
   187  		minStack:    minStack(6, 1),
   188  		maxStack:    maxStack(6, 1),
   189  		memorySize:  memoryStaticCall,
   190  	}
   191  	instructionSet[RETURNDATASIZE] = &operation{
   192  		execute:     opReturnDataSize,
   193  		constantGas: GasQuickStep,
   194  		minStack:    minStack(0, 1),
   195  		maxStack:    maxStack(0, 1),
   196  	}
   197  	instructionSet[RETURNDATACOPY] = &operation{
   198  		execute:     opReturnDataCopy,
   199  		constantGas: GasFastestStep,
   200  		dynamicGas:  gasReturnDataCopy,
   201  		minStack:    minStack(3, 0),
   202  		maxStack:    maxStack(3, 0),
   203  		memorySize:  memoryReturnDataCopy,
   204  	}
   205  	instructionSet[REVERT] = &operation{
   206  		execute:    opRevert,
   207  		dynamicGas: gasRevert,
   208  		minStack:   minStack(2, 0),
   209  		maxStack:   maxStack(2, 0),
   210  		memorySize: memoryRevert,
   211  	}
   212  	return validate(instructionSet)
   213  }
   214  
   215  // EIP 158 a.k.a Spurious Dragon
   216  func newSpuriousDragonInstructionSet() JumpTable {
   217  	instructionSet := newTangerineWhistleInstructionSet()
   218  	instructionSet[EXP].dynamicGas = gasExpEIP158
   219  	return validate(instructionSet)
   220  }
   221  
   222  // EIP 150 a.k.a Tangerine Whistle
   223  func newTangerineWhistleInstructionSet() JumpTable {
   224  	instructionSet := newHomesteadInstructionSet()
   225  	instructionSet[BALANCE].constantGas = params.BalanceGasEIP150
   226  	instructionSet[EXTCODESIZE].constantGas = params.ExtcodeSizeGasEIP150
   227  	instructionSet[SLOAD].constantGas = params.SloadGasEIP150
   228  	instructionSet[EXTCODECOPY].constantGas = params.ExtcodeCopyBaseEIP150
   229  	instructionSet[CALL].constantGas = params.CallGasEIP150
   230  	instructionSet[CALLCODE].constantGas = params.CallGasEIP150
   231  	instructionSet[DELEGATECALL].constantGas = params.CallGasEIP150
   232  	return validate(instructionSet)
   233  }
   234  
   235  // newHomesteadInstructionSet returns the frontier and homestead
   236  // instructions that can be executed during the homestead phase.
   237  func newHomesteadInstructionSet() JumpTable {
   238  	instructionSet := newFrontierInstructionSet()
   239  	instructionSet[DELEGATECALL] = &operation{
   240  		execute:     opDelegateCall,
   241  		dynamicGas:  gasDelegateCall,
   242  		constantGas: params.CallGasFrontier,
   243  		minStack:    minStack(6, 1),
   244  		maxStack:    maxStack(6, 1),
   245  		memorySize:  memoryDelegateCall,
   246  	}
   247  	return validate(instructionSet)
   248  }
   249  
   250  // newFrontierInstructionSet returns the frontier instructions
   251  // that can be executed during the frontier phase.
   252  func newFrontierInstructionSet() JumpTable {
   253  	tbl := JumpTable{
   254  		STOP: {
   255  			execute:     opStop,
   256  			constantGas: 0,
   257  			minStack:    minStack(0, 0),
   258  			maxStack:    maxStack(0, 0),
   259  		},
   260  		ADD: {
   261  			execute:     opAdd,
   262  			constantGas: GasFastestStep,
   263  			minStack:    minStack(2, 1),
   264  			maxStack:    maxStack(2, 1),
   265  		},
   266  		MUL: {
   267  			execute:     opMul,
   268  			constantGas: GasFastStep,
   269  			minStack:    minStack(2, 1),
   270  			maxStack:    maxStack(2, 1),
   271  		},
   272  		SUB: {
   273  			execute:     opSub,
   274  			constantGas: GasFastestStep,
   275  			minStack:    minStack(2, 1),
   276  			maxStack:    maxStack(2, 1),
   277  		},
   278  		DIV: {
   279  			execute:     opDiv,
   280  			constantGas: GasFastStep,
   281  			minStack:    minStack(2, 1),
   282  			maxStack:    maxStack(2, 1),
   283  		},
   284  		SDIV: {
   285  			execute:     opSdiv,
   286  			constantGas: GasFastStep,
   287  			minStack:    minStack(2, 1),
   288  			maxStack:    maxStack(2, 1),
   289  		},
   290  		MOD: {
   291  			execute:     opMod,
   292  			constantGas: GasFastStep,
   293  			minStack:    minStack(2, 1),
   294  			maxStack:    maxStack(2, 1),
   295  		},
   296  		SMOD: {
   297  			execute:     opSmod,
   298  			constantGas: GasFastStep,
   299  			minStack:    minStack(2, 1),
   300  			maxStack:    maxStack(2, 1),
   301  		},
   302  		ADDMOD: {
   303  			execute:     opAddmod,
   304  			constantGas: GasMidStep,
   305  			minStack:    minStack(3, 1),
   306  			maxStack:    maxStack(3, 1),
   307  		},
   308  		MULMOD: {
   309  			execute:     opMulmod,
   310  			constantGas: GasMidStep,
   311  			minStack:    minStack(3, 1),
   312  			maxStack:    maxStack(3, 1),
   313  		},
   314  		EXP: {
   315  			execute:    opExp,
   316  			dynamicGas: gasExpFrontier,
   317  			minStack:   minStack(2, 1),
   318  			maxStack:   maxStack(2, 1),
   319  		},
   320  		SIGNEXTEND: {
   321  			execute:     opSignExtend,
   322  			constantGas: GasFastStep,
   323  			minStack:    minStack(2, 1),
   324  			maxStack:    maxStack(2, 1),
   325  		},
   326  		LT: {
   327  			execute:     opLt,
   328  			constantGas: GasFastestStep,
   329  			minStack:    minStack(2, 1),
   330  			maxStack:    maxStack(2, 1),
   331  		},
   332  		GT: {
   333  			execute:     opGt,
   334  			constantGas: GasFastestStep,
   335  			minStack:    minStack(2, 1),
   336  			maxStack:    maxStack(2, 1),
   337  		},
   338  		SLT: {
   339  			execute:     opSlt,
   340  			constantGas: GasFastestStep,
   341  			minStack:    minStack(2, 1),
   342  			maxStack:    maxStack(2, 1),
   343  		},
   344  		SGT: {
   345  			execute:     opSgt,
   346  			constantGas: GasFastestStep,
   347  			minStack:    minStack(2, 1),
   348  			maxStack:    maxStack(2, 1),
   349  		},
   350  		EQ: {
   351  			execute:     opEq,
   352  			constantGas: GasFastestStep,
   353  			minStack:    minStack(2, 1),
   354  			maxStack:    maxStack(2, 1),
   355  		},
   356  		ISZERO: {
   357  			execute:     opIszero,
   358  			constantGas: GasFastestStep,
   359  			minStack:    minStack(1, 1),
   360  			maxStack:    maxStack(1, 1),
   361  		},
   362  		AND: {
   363  			execute:     opAnd,
   364  			constantGas: GasFastestStep,
   365  			minStack:    minStack(2, 1),
   366  			maxStack:    maxStack(2, 1),
   367  		},
   368  		XOR: {
   369  			execute:     opXor,
   370  			constantGas: GasFastestStep,
   371  			minStack:    minStack(2, 1),
   372  			maxStack:    maxStack(2, 1),
   373  		},
   374  		OR: {
   375  			execute:     opOr,
   376  			constantGas: GasFastestStep,
   377  			minStack:    minStack(2, 1),
   378  			maxStack:    maxStack(2, 1),
   379  		},
   380  		NOT: {
   381  			execute:     opNot,
   382  			constantGas: GasFastestStep,
   383  			minStack:    minStack(1, 1),
   384  			maxStack:    maxStack(1, 1),
   385  		},
   386  		BYTE: {
   387  			execute:     opByte,
   388  			constantGas: GasFastestStep,
   389  			minStack:    minStack(2, 1),
   390  			maxStack:    maxStack(2, 1),
   391  		},
   392  		KECCAK256: {
   393  			execute:     opKeccak256,
   394  			constantGas: params.Keccak256Gas,
   395  			dynamicGas:  gasKeccak256,
   396  			minStack:    minStack(2, 1),
   397  			maxStack:    maxStack(2, 1),
   398  			memorySize:  memoryKeccak256,
   399  		},
   400  		ADDRESS: {
   401  			execute:     opAddress,
   402  			constantGas: GasQuickStep,
   403  			minStack:    minStack(0, 1),
   404  			maxStack:    maxStack(0, 1),
   405  		},
   406  		BALANCE: {
   407  			execute:     opBalance,
   408  			constantGas: params.BalanceGasFrontier,
   409  			minStack:    minStack(1, 1),
   410  			maxStack:    maxStack(1, 1),
   411  		},
   412  		ORIGIN: {
   413  			execute:     opOrigin,
   414  			constantGas: GasQuickStep,
   415  			minStack:    minStack(0, 1),
   416  			maxStack:    maxStack(0, 1),
   417  		},
   418  		CALLER: {
   419  			execute:     opCaller,
   420  			constantGas: GasQuickStep,
   421  			minStack:    minStack(0, 1),
   422  			maxStack:    maxStack(0, 1),
   423  		},
   424  		CALLVALUE: {
   425  			execute:     opCallValue,
   426  			constantGas: GasQuickStep,
   427  			minStack:    minStack(0, 1),
   428  			maxStack:    maxStack(0, 1),
   429  		},
   430  		CALLDATALOAD: {
   431  			execute:     opCallDataLoad,
   432  			constantGas: GasFastestStep,
   433  			minStack:    minStack(1, 1),
   434  			maxStack:    maxStack(1, 1),
   435  		},
   436  		CALLDATASIZE: {
   437  			execute:     opCallDataSize,
   438  			constantGas: GasQuickStep,
   439  			minStack:    minStack(0, 1),
   440  			maxStack:    maxStack(0, 1),
   441  		},
   442  		CALLDATACOPY: {
   443  			execute:     opCallDataCopy,
   444  			constantGas: GasFastestStep,
   445  			dynamicGas:  gasCallDataCopy,
   446  			minStack:    minStack(3, 0),
   447  			maxStack:    maxStack(3, 0),
   448  			memorySize:  memoryCallDataCopy,
   449  		},
   450  		CODESIZE: {
   451  			execute:     opCodeSize,
   452  			constantGas: GasQuickStep,
   453  			minStack:    minStack(0, 1),
   454  			maxStack:    maxStack(0, 1),
   455  		},
   456  		CODECOPY: {
   457  			execute:     opCodeCopy,
   458  			constantGas: GasFastestStep,
   459  			dynamicGas:  gasCodeCopy,
   460  			minStack:    minStack(3, 0),
   461  			maxStack:    maxStack(3, 0),
   462  			memorySize:  memoryCodeCopy,
   463  		},
   464  		GASPRICE: {
   465  			execute:     opGasprice,
   466  			constantGas: GasQuickStep,
   467  			minStack:    minStack(0, 1),
   468  			maxStack:    maxStack(0, 1),
   469  		},
   470  		EXTCODESIZE: {
   471  			execute:     opExtCodeSize,
   472  			constantGas: params.ExtcodeSizeGasFrontier,
   473  			minStack:    minStack(1, 1),
   474  			maxStack:    maxStack(1, 1),
   475  		},
   476  		EXTCODECOPY: {
   477  			execute:     opExtCodeCopy,
   478  			constantGas: params.ExtcodeCopyBaseFrontier,
   479  			dynamicGas:  gasExtCodeCopy,
   480  			minStack:    minStack(4, 0),
   481  			maxStack:    maxStack(4, 0),
   482  			memorySize:  memoryExtCodeCopy,
   483  		},
   484  		BLOCKHASH: {
   485  			execute:     opBlockhash,
   486  			constantGas: GasExtStep,
   487  			minStack:    minStack(1, 1),
   488  			maxStack:    maxStack(1, 1),
   489  		},
   490  		COINBASE: {
   491  			execute:     opCoinbase,
   492  			constantGas: GasQuickStep,
   493  			minStack:    minStack(0, 1),
   494  			maxStack:    maxStack(0, 1),
   495  		},
   496  		TIMESTAMP: {
   497  			execute:     opTimestamp,
   498  			constantGas: GasQuickStep,
   499  			minStack:    minStack(0, 1),
   500  			maxStack:    maxStack(0, 1),
   501  		},
   502  		NUMBER: {
   503  			execute:     opNumber,
   504  			constantGas: GasQuickStep,
   505  			minStack:    minStack(0, 1),
   506  			maxStack:    maxStack(0, 1),
   507  		},
   508  		DIFFICULTY: {
   509  			execute:     opDifficulty,
   510  			constantGas: GasQuickStep,
   511  			minStack:    minStack(0, 1),
   512  			maxStack:    maxStack(0, 1),
   513  		},
   514  		GASLIMIT: {
   515  			execute:     opGasLimit,
   516  			constantGas: GasQuickStep,
   517  			minStack:    minStack(0, 1),
   518  			maxStack:    maxStack(0, 1),
   519  		},
   520  		POP: {
   521  			execute:     opPop,
   522  			constantGas: GasQuickStep,
   523  			minStack:    minStack(1, 0),
   524  			maxStack:    maxStack(1, 0),
   525  		},
   526  		MLOAD: {
   527  			execute:     opMload,
   528  			constantGas: GasFastestStep,
   529  			dynamicGas:  gasMLoad,
   530  			minStack:    minStack(1, 1),
   531  			maxStack:    maxStack(1, 1),
   532  			memorySize:  memoryMLoad,
   533  		},
   534  		MSTORE: {
   535  			execute:     opMstore,
   536  			constantGas: GasFastestStep,
   537  			dynamicGas:  gasMStore,
   538  			minStack:    minStack(2, 0),
   539  			maxStack:    maxStack(2, 0),
   540  			memorySize:  memoryMStore,
   541  		},
   542  		MSTORE8: {
   543  			execute:     opMstore8,
   544  			constantGas: GasFastestStep,
   545  			dynamicGas:  gasMStore8,
   546  			memorySize:  memoryMStore8,
   547  			minStack:    minStack(2, 0),
   548  			maxStack:    maxStack(2, 0),
   549  		},
   550  		SLOAD: {
   551  			execute:     opSload,
   552  			constantGas: params.SloadGasFrontier,
   553  			minStack:    minStack(1, 1),
   554  			maxStack:    maxStack(1, 1),
   555  		},
   556  		SSTORE: {
   557  			execute:    opSstore,
   558  			dynamicGas: gasSStore,
   559  			minStack:   minStack(2, 0),
   560  			maxStack:   maxStack(2, 0),
   561  		},
   562  		JUMP: {
   563  			execute:     opJump,
   564  			constantGas: GasMidStep,
   565  			minStack:    minStack(1, 0),
   566  			maxStack:    maxStack(1, 0),
   567  		},
   568  		JUMPI: {
   569  			execute:     opJumpi,
   570  			constantGas: GasSlowStep,
   571  			minStack:    minStack(2, 0),
   572  			maxStack:    maxStack(2, 0),
   573  		},
   574  		PC: {
   575  			execute:     opPc,
   576  			constantGas: GasQuickStep,
   577  			minStack:    minStack(0, 1),
   578  			maxStack:    maxStack(0, 1),
   579  		},
   580  		MSIZE: {
   581  			execute:     opMsize,
   582  			constantGas: GasQuickStep,
   583  			minStack:    minStack(0, 1),
   584  			maxStack:    maxStack(0, 1),
   585  		},
   586  		GAS: {
   587  			execute:     opGas,
   588  			constantGas: GasQuickStep,
   589  			minStack:    minStack(0, 1),
   590  			maxStack:    maxStack(0, 1),
   591  		},
   592  		JUMPDEST: {
   593  			execute:     opJumpdest,
   594  			constantGas: params.JumpdestGas,
   595  			minStack:    minStack(0, 0),
   596  			maxStack:    maxStack(0, 0),
   597  		},
   598  		PUSH1: {
   599  			execute:     opPush1,
   600  			constantGas: GasFastestStep,
   601  			minStack:    minStack(0, 1),
   602  			maxStack:    maxStack(0, 1),
   603  		},
   604  		PUSH2: {
   605  			execute:     makePush(2, 2),
   606  			constantGas: GasFastestStep,
   607  			minStack:    minStack(0, 1),
   608  			maxStack:    maxStack(0, 1),
   609  		},
   610  		PUSH3: {
   611  			execute:     makePush(3, 3),
   612  			constantGas: GasFastestStep,
   613  			minStack:    minStack(0, 1),
   614  			maxStack:    maxStack(0, 1),
   615  		},
   616  		PUSH4: {
   617  			execute:     makePush(4, 4),
   618  			constantGas: GasFastestStep,
   619  			minStack:    minStack(0, 1),
   620  			maxStack:    maxStack(0, 1),
   621  		},
   622  		PUSH5: {
   623  			execute:     makePush(5, 5),
   624  			constantGas: GasFastestStep,
   625  			minStack:    minStack(0, 1),
   626  			maxStack:    maxStack(0, 1),
   627  		},
   628  		PUSH6: {
   629  			execute:     makePush(6, 6),
   630  			constantGas: GasFastestStep,
   631  			minStack:    minStack(0, 1),
   632  			maxStack:    maxStack(0, 1),
   633  		},
   634  		PUSH7: {
   635  			execute:     makePush(7, 7),
   636  			constantGas: GasFastestStep,
   637  			minStack:    minStack(0, 1),
   638  			maxStack:    maxStack(0, 1),
   639  		},
   640  		PUSH8: {
   641  			execute:     makePush(8, 8),
   642  			constantGas: GasFastestStep,
   643  			minStack:    minStack(0, 1),
   644  			maxStack:    maxStack(0, 1),
   645  		},
   646  		PUSH9: {
   647  			execute:     makePush(9, 9),
   648  			constantGas: GasFastestStep,
   649  			minStack:    minStack(0, 1),
   650  			maxStack:    maxStack(0, 1),
   651  		},
   652  		PUSH10: {
   653  			execute:     makePush(10, 10),
   654  			constantGas: GasFastestStep,
   655  			minStack:    minStack(0, 1),
   656  			maxStack:    maxStack(0, 1),
   657  		},
   658  		PUSH11: {
   659  			execute:     makePush(11, 11),
   660  			constantGas: GasFastestStep,
   661  			minStack:    minStack(0, 1),
   662  			maxStack:    maxStack(0, 1),
   663  		},
   664  		PUSH12: {
   665  			execute:     makePush(12, 12),
   666  			constantGas: GasFastestStep,
   667  			minStack:    minStack(0, 1),
   668  			maxStack:    maxStack(0, 1),
   669  		},
   670  		PUSH13: {
   671  			execute:     makePush(13, 13),
   672  			constantGas: GasFastestStep,
   673  			minStack:    minStack(0, 1),
   674  			maxStack:    maxStack(0, 1),
   675  		},
   676  		PUSH14: {
   677  			execute:     makePush(14, 14),
   678  			constantGas: GasFastestStep,
   679  			minStack:    minStack(0, 1),
   680  			maxStack:    maxStack(0, 1),
   681  		},
   682  		PUSH15: {
   683  			execute:     makePush(15, 15),
   684  			constantGas: GasFastestStep,
   685  			minStack:    minStack(0, 1),
   686  			maxStack:    maxStack(0, 1),
   687  		},
   688  		PUSH16: {
   689  			execute:     makePush(16, 16),
   690  			constantGas: GasFastestStep,
   691  			minStack:    minStack(0, 1),
   692  			maxStack:    maxStack(0, 1),
   693  		},
   694  		PUSH17: {
   695  			execute:     makePush(17, 17),
   696  			constantGas: GasFastestStep,
   697  			minStack:    minStack(0, 1),
   698  			maxStack:    maxStack(0, 1),
   699  		},
   700  		PUSH18: {
   701  			execute:     makePush(18, 18),
   702  			constantGas: GasFastestStep,
   703  			minStack:    minStack(0, 1),
   704  			maxStack:    maxStack(0, 1),
   705  		},
   706  		PUSH19: {
   707  			execute:     makePush(19, 19),
   708  			constantGas: GasFastestStep,
   709  			minStack:    minStack(0, 1),
   710  			maxStack:    maxStack(0, 1),
   711  		},
   712  		PUSH20: {
   713  			execute:     makePush(20, 20),
   714  			constantGas: GasFastestStep,
   715  			minStack:    minStack(0, 1),
   716  			maxStack:    maxStack(0, 1),
   717  		},
   718  		PUSH21: {
   719  			execute:     makePush(21, 21),
   720  			constantGas: GasFastestStep,
   721  			minStack:    minStack(0, 1),
   722  			maxStack:    maxStack(0, 1),
   723  		},
   724  		PUSH22: {
   725  			execute:     makePush(22, 22),
   726  			constantGas: GasFastestStep,
   727  			minStack:    minStack(0, 1),
   728  			maxStack:    maxStack(0, 1),
   729  		},
   730  		PUSH23: {
   731  			execute:     makePush(23, 23),
   732  			constantGas: GasFastestStep,
   733  			minStack:    minStack(0, 1),
   734  			maxStack:    maxStack(0, 1),
   735  		},
   736  		PUSH24: {
   737  			execute:     makePush(24, 24),
   738  			constantGas: GasFastestStep,
   739  			minStack:    minStack(0, 1),
   740  			maxStack:    maxStack(0, 1),
   741  		},
   742  		PUSH25: {
   743  			execute:     makePush(25, 25),
   744  			constantGas: GasFastestStep,
   745  			minStack:    minStack(0, 1),
   746  			maxStack:    maxStack(0, 1),
   747  		},
   748  		PUSH26: {
   749  			execute:     makePush(26, 26),
   750  			constantGas: GasFastestStep,
   751  			minStack:    minStack(0, 1),
   752  			maxStack:    maxStack(0, 1),
   753  		},
   754  		PUSH27: {
   755  			execute:     makePush(27, 27),
   756  			constantGas: GasFastestStep,
   757  			minStack:    minStack(0, 1),
   758  			maxStack:    maxStack(0, 1),
   759  		},
   760  		PUSH28: {
   761  			execute:     makePush(28, 28),
   762  			constantGas: GasFastestStep,
   763  			minStack:    minStack(0, 1),
   764  			maxStack:    maxStack(0, 1),
   765  		},
   766  		PUSH29: {
   767  			execute:     makePush(29, 29),
   768  			constantGas: GasFastestStep,
   769  			minStack:    minStack(0, 1),
   770  			maxStack:    maxStack(0, 1),
   771  		},
   772  		PUSH30: {
   773  			execute:     makePush(30, 30),
   774  			constantGas: GasFastestStep,
   775  			minStack:    minStack(0, 1),
   776  			maxStack:    maxStack(0, 1),
   777  		},
   778  		PUSH31: {
   779  			execute:     makePush(31, 31),
   780  			constantGas: GasFastestStep,
   781  			minStack:    minStack(0, 1),
   782  			maxStack:    maxStack(0, 1),
   783  		},
   784  		PUSH32: {
   785  			execute:     makePush(32, 32),
   786  			constantGas: GasFastestStep,
   787  			minStack:    minStack(0, 1),
   788  			maxStack:    maxStack(0, 1),
   789  		},
   790  		DUP1: {
   791  			execute:     makeDup(1),
   792  			constantGas: GasFastestStep,
   793  			minStack:    minDupStack(1),
   794  			maxStack:    maxDupStack(1),
   795  		},
   796  		DUP2: {
   797  			execute:     makeDup(2),
   798  			constantGas: GasFastestStep,
   799  			minStack:    minDupStack(2),
   800  			maxStack:    maxDupStack(2),
   801  		},
   802  		DUP3: {
   803  			execute:     makeDup(3),
   804  			constantGas: GasFastestStep,
   805  			minStack:    minDupStack(3),
   806  			maxStack:    maxDupStack(3),
   807  		},
   808  		DUP4: {
   809  			execute:     makeDup(4),
   810  			constantGas: GasFastestStep,
   811  			minStack:    minDupStack(4),
   812  			maxStack:    maxDupStack(4),
   813  		},
   814  		DUP5: {
   815  			execute:     makeDup(5),
   816  			constantGas: GasFastestStep,
   817  			minStack:    minDupStack(5),
   818  			maxStack:    maxDupStack(5),
   819  		},
   820  		DUP6: {
   821  			execute:     makeDup(6),
   822  			constantGas: GasFastestStep,
   823  			minStack:    minDupStack(6),
   824  			maxStack:    maxDupStack(6),
   825  		},
   826  		DUP7: {
   827  			execute:     makeDup(7),
   828  			constantGas: GasFastestStep,
   829  			minStack:    minDupStack(7),
   830  			maxStack:    maxDupStack(7),
   831  		},
   832  		DUP8: {
   833  			execute:     makeDup(8),
   834  			constantGas: GasFastestStep,
   835  			minStack:    minDupStack(8),
   836  			maxStack:    maxDupStack(8),
   837  		},
   838  		DUP9: {
   839  			execute:     makeDup(9),
   840  			constantGas: GasFastestStep,
   841  			minStack:    minDupStack(9),
   842  			maxStack:    maxDupStack(9),
   843  		},
   844  		DUP10: {
   845  			execute:     makeDup(10),
   846  			constantGas: GasFastestStep,
   847  			minStack:    minDupStack(10),
   848  			maxStack:    maxDupStack(10),
   849  		},
   850  		DUP11: {
   851  			execute:     makeDup(11),
   852  			constantGas: GasFastestStep,
   853  			minStack:    minDupStack(11),
   854  			maxStack:    maxDupStack(11),
   855  		},
   856  		DUP12: {
   857  			execute:     makeDup(12),
   858  			constantGas: GasFastestStep,
   859  			minStack:    minDupStack(12),
   860  			maxStack:    maxDupStack(12),
   861  		},
   862  		DUP13: {
   863  			execute:     makeDup(13),
   864  			constantGas: GasFastestStep,
   865  			minStack:    minDupStack(13),
   866  			maxStack:    maxDupStack(13),
   867  		},
   868  		DUP14: {
   869  			execute:     makeDup(14),
   870  			constantGas: GasFastestStep,
   871  			minStack:    minDupStack(14),
   872  			maxStack:    maxDupStack(14),
   873  		},
   874  		DUP15: {
   875  			execute:     makeDup(15),
   876  			constantGas: GasFastestStep,
   877  			minStack:    minDupStack(15),
   878  			maxStack:    maxDupStack(15),
   879  		},
   880  		DUP16: {
   881  			execute:     makeDup(16),
   882  			constantGas: GasFastestStep,
   883  			minStack:    minDupStack(16),
   884  			maxStack:    maxDupStack(16),
   885  		},
   886  		SWAP1: {
   887  			execute:     makeSwap(1),
   888  			constantGas: GasFastestStep,
   889  			minStack:    minSwapStack(2),
   890  			maxStack:    maxSwapStack(2),
   891  		},
   892  		SWAP2: {
   893  			execute:     makeSwap(2),
   894  			constantGas: GasFastestStep,
   895  			minStack:    minSwapStack(3),
   896  			maxStack:    maxSwapStack(3),
   897  		},
   898  		SWAP3: {
   899  			execute:     makeSwap(3),
   900  			constantGas: GasFastestStep,
   901  			minStack:    minSwapStack(4),
   902  			maxStack:    maxSwapStack(4),
   903  		},
   904  		SWAP4: {
   905  			execute:     makeSwap(4),
   906  			constantGas: GasFastestStep,
   907  			minStack:    minSwapStack(5),
   908  			maxStack:    maxSwapStack(5),
   909  		},
   910  		SWAP5: {
   911  			execute:     makeSwap(5),
   912  			constantGas: GasFastestStep,
   913  			minStack:    minSwapStack(6),
   914  			maxStack:    maxSwapStack(6),
   915  		},
   916  		SWAP6: {
   917  			execute:     makeSwap(6),
   918  			constantGas: GasFastestStep,
   919  			minStack:    minSwapStack(7),
   920  			maxStack:    maxSwapStack(7),
   921  		},
   922  		SWAP7: {
   923  			execute:     makeSwap(7),
   924  			constantGas: GasFastestStep,
   925  			minStack:    minSwapStack(8),
   926  			maxStack:    maxSwapStack(8),
   927  		},
   928  		SWAP8: {
   929  			execute:     makeSwap(8),
   930  			constantGas: GasFastestStep,
   931  			minStack:    minSwapStack(9),
   932  			maxStack:    maxSwapStack(9),
   933  		},
   934  		SWAP9: {
   935  			execute:     makeSwap(9),
   936  			constantGas: GasFastestStep,
   937  			minStack:    minSwapStack(10),
   938  			maxStack:    maxSwapStack(10),
   939  		},
   940  		SWAP10: {
   941  			execute:     makeSwap(10),
   942  			constantGas: GasFastestStep,
   943  			minStack:    minSwapStack(11),
   944  			maxStack:    maxSwapStack(11),
   945  		},
   946  		SWAP11: {
   947  			execute:     makeSwap(11),
   948  			constantGas: GasFastestStep,
   949  			minStack:    minSwapStack(12),
   950  			maxStack:    maxSwapStack(12),
   951  		},
   952  		SWAP12: {
   953  			execute:     makeSwap(12),
   954  			constantGas: GasFastestStep,
   955  			minStack:    minSwapStack(13),
   956  			maxStack:    maxSwapStack(13),
   957  		},
   958  		SWAP13: {
   959  			execute:     makeSwap(13),
   960  			constantGas: GasFastestStep,
   961  			minStack:    minSwapStack(14),
   962  			maxStack:    maxSwapStack(14),
   963  		},
   964  		SWAP14: {
   965  			execute:     makeSwap(14),
   966  			constantGas: GasFastestStep,
   967  			minStack:    minSwapStack(15),
   968  			maxStack:    maxSwapStack(15),
   969  		},
   970  		SWAP15: {
   971  			execute:     makeSwap(15),
   972  			constantGas: GasFastestStep,
   973  			minStack:    minSwapStack(16),
   974  			maxStack:    maxSwapStack(16),
   975  		},
   976  		SWAP16: {
   977  			execute:     makeSwap(16),
   978  			constantGas: GasFastestStep,
   979  			minStack:    minSwapStack(17),
   980  			maxStack:    maxSwapStack(17),
   981  		},
   982  		LOG0: {
   983  			execute:    makeLog(0),
   984  			dynamicGas: makeGasLog(0),
   985  			minStack:   minStack(2, 0),
   986  			maxStack:   maxStack(2, 0),
   987  			memorySize: memoryLog,
   988  		},
   989  		LOG1: {
   990  			execute:    makeLog(1),
   991  			dynamicGas: makeGasLog(1),
   992  			minStack:   minStack(3, 0),
   993  			maxStack:   maxStack(3, 0),
   994  			memorySize: memoryLog,
   995  		},
   996  		LOG2: {
   997  			execute:    makeLog(2),
   998  			dynamicGas: makeGasLog(2),
   999  			minStack:   minStack(4, 0),
  1000  			maxStack:   maxStack(4, 0),
  1001  			memorySize: memoryLog,
  1002  		},
  1003  		LOG3: {
  1004  			execute:    makeLog(3),
  1005  			dynamicGas: makeGasLog(3),
  1006  			minStack:   minStack(5, 0),
  1007  			maxStack:   maxStack(5, 0),
  1008  			memorySize: memoryLog,
  1009  		},
  1010  		LOG4: {
  1011  			execute:    makeLog(4),
  1012  			dynamicGas: makeGasLog(4),
  1013  			minStack:   minStack(6, 0),
  1014  			maxStack:   maxStack(6, 0),
  1015  			memorySize: memoryLog,
  1016  		},
  1017  		CREATE: {
  1018  			execute:     opCreate,
  1019  			constantGas: params.CreateGas,
  1020  			dynamicGas:  gasCreate,
  1021  			minStack:    minStack(3, 1),
  1022  			maxStack:    maxStack(3, 1),
  1023  			memorySize:  memoryCreate,
  1024  		},
  1025  		CALL: {
  1026  			execute:     opCall,
  1027  			constantGas: params.CallGasFrontier,
  1028  			dynamicGas:  gasCall,
  1029  			minStack:    minStack(7, 1),
  1030  			maxStack:    maxStack(7, 1),
  1031  			memorySize:  memoryCall,
  1032  		},
  1033  		CALLCODE: {
  1034  			execute:     opCallCode,
  1035  			constantGas: params.CallGasFrontier,
  1036  			dynamicGas:  gasCallCode,
  1037  			minStack:    minStack(7, 1),
  1038  			maxStack:    maxStack(7, 1),
  1039  			memorySize:  memoryCall,
  1040  		},
  1041  		RETURN: {
  1042  			execute:    opReturn,
  1043  			dynamicGas: gasReturn,
  1044  			minStack:   minStack(2, 0),
  1045  			maxStack:   maxStack(2, 0),
  1046  			memorySize: memoryReturn,
  1047  		},
  1048  		SELFDESTRUCT: {
  1049  			execute:    opSelfdestruct,
  1050  			dynamicGas: gasSelfdestruct,
  1051  			minStack:   minStack(1, 0),
  1052  			maxStack:   maxStack(1, 0),
  1053  		},
  1054  	}
  1055  
  1056  	// Fill all unassigned slots with opUndefined.
  1057  	for i, entry := range tbl {
  1058  		if entry == nil {
  1059  			tbl[i] = &operation{execute: opUndefined, maxStack: maxStack(0, 0)}
  1060  		}
  1061  	}
  1062  
  1063  	return validate(tbl)
  1064  }
  1065  
  1066  func copyJumpTable(source *JumpTable) *JumpTable {
  1067  	dest := *source
  1068  	for i, op := range source {
  1069  		if op != nil {
  1070  			opCopy := *op
  1071  			dest[i] = &opCopy
  1072  		}
  1073  	}
  1074  	return &dest
  1075  }