github.com/r8d8/go-ethereum@v5.5.2+incompatible/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 "math/big"
    20  
    21  type jumpPtr struct {
    22  	fn    instrFn
    23  	valid bool
    24  }
    25  
    26  type vmJumpTable [256]jumpPtr
    27  
    28  func newJumpTable(ruleset RuleSet, blockNumber *big.Int) vmJumpTable {
    29  	var jumpTable vmJumpTable
    30  
    31  	// when initialising a new VM execution we must first check the homestead
    32  	// changes.
    33  	if ruleset.IsHomestead(blockNumber) {
    34  		jumpTable[DELEGATECALL] = jumpPtr{opDelegateCall, true}
    35  	}
    36  
    37  	jumpTable[ADD] = jumpPtr{opAdd, true}
    38  	jumpTable[SUB] = jumpPtr{opSub, true}
    39  	jumpTable[MUL] = jumpPtr{opMul, true}
    40  	jumpTable[DIV] = jumpPtr{opDiv, true}
    41  	jumpTable[SDIV] = jumpPtr{opSdiv, true}
    42  	jumpTable[MOD] = jumpPtr{opMod, true}
    43  	jumpTable[SMOD] = jumpPtr{opSmod, true}
    44  	jumpTable[EXP] = jumpPtr{opExp, true}
    45  	jumpTable[SIGNEXTEND] = jumpPtr{opSignExtend, true}
    46  	jumpTable[NOT] = jumpPtr{opNot, true}
    47  	jumpTable[LT] = jumpPtr{opLt, true}
    48  	jumpTable[GT] = jumpPtr{opGt, true}
    49  	jumpTable[SLT] = jumpPtr{opSlt, true}
    50  	jumpTable[SGT] = jumpPtr{opSgt, true}
    51  	jumpTable[EQ] = jumpPtr{opEq, true}
    52  	jumpTable[ISZERO] = jumpPtr{opIszero, true}
    53  	jumpTable[AND] = jumpPtr{opAnd, true}
    54  	jumpTable[OR] = jumpPtr{opOr, true}
    55  	jumpTable[XOR] = jumpPtr{opXor, true}
    56  	jumpTable[BYTE] = jumpPtr{opByte, true}
    57  	jumpTable[ADDMOD] = jumpPtr{opAddmod, true}
    58  	jumpTable[MULMOD] = jumpPtr{opMulmod, true}
    59  	jumpTable[SHA3] = jumpPtr{opSha3, true}
    60  	jumpTable[ADDRESS] = jumpPtr{opAddress, true}
    61  	jumpTable[BALANCE] = jumpPtr{opBalance, true}
    62  	jumpTable[ORIGIN] = jumpPtr{opOrigin, true}
    63  	jumpTable[CALLER] = jumpPtr{opCaller, true}
    64  	jumpTable[CALLVALUE] = jumpPtr{opCallValue, true}
    65  	jumpTable[CALLDATALOAD] = jumpPtr{opCalldataLoad, true}
    66  	jumpTable[CALLDATASIZE] = jumpPtr{opCalldataSize, true}
    67  	jumpTable[CALLDATACOPY] = jumpPtr{opCalldataCopy, true}
    68  	jumpTable[CODESIZE] = jumpPtr{opCodeSize, true}
    69  	jumpTable[EXTCODESIZE] = jumpPtr{opExtCodeSize, true}
    70  	jumpTable[CODECOPY] = jumpPtr{opCodeCopy, true}
    71  	jumpTable[EXTCODECOPY] = jumpPtr{opExtCodeCopy, true}
    72  	jumpTable[GASPRICE] = jumpPtr{opGasprice, true}
    73  	jumpTable[BLOCKHASH] = jumpPtr{opBlockhash, true}
    74  	jumpTable[COINBASE] = jumpPtr{opCoinbase, true}
    75  	jumpTable[TIMESTAMP] = jumpPtr{opTimestamp, true}
    76  	jumpTable[NUMBER] = jumpPtr{opNumber, true}
    77  	jumpTable[DIFFICULTY] = jumpPtr{opDifficulty, true}
    78  	jumpTable[GASLIMIT] = jumpPtr{opGasLimit, true}
    79  	jumpTable[POP] = jumpPtr{opPop, true}
    80  	jumpTable[MLOAD] = jumpPtr{opMload, true}
    81  	jumpTable[MSTORE] = jumpPtr{opMstore, true}
    82  	jumpTable[MSTORE8] = jumpPtr{opMstore8, true}
    83  	jumpTable[SLOAD] = jumpPtr{opSload, true}
    84  	jumpTable[SSTORE] = jumpPtr{opSstore, true}
    85  	jumpTable[JUMPDEST] = jumpPtr{opJumpdest, true}
    86  	jumpTable[PC] = jumpPtr{nil, true}
    87  	jumpTable[MSIZE] = jumpPtr{opMsize, true}
    88  	jumpTable[GAS] = jumpPtr{opGas, true}
    89  	jumpTable[CREATE] = jumpPtr{opCreate, true}
    90  	jumpTable[CALL] = jumpPtr{opCall, true}
    91  	jumpTable[CALLCODE] = jumpPtr{opCallCode, true}
    92  	jumpTable[LOG0] = jumpPtr{makeLog(0), true}
    93  	jumpTable[LOG1] = jumpPtr{makeLog(1), true}
    94  	jumpTable[LOG2] = jumpPtr{makeLog(2), true}
    95  	jumpTable[LOG3] = jumpPtr{makeLog(3), true}
    96  	jumpTable[LOG4] = jumpPtr{makeLog(4), true}
    97  	jumpTable[SWAP1] = jumpPtr{makeSwap(1), true}
    98  	jumpTable[SWAP2] = jumpPtr{makeSwap(2), true}
    99  	jumpTable[SWAP3] = jumpPtr{makeSwap(3), true}
   100  	jumpTable[SWAP4] = jumpPtr{makeSwap(4), true}
   101  	jumpTable[SWAP5] = jumpPtr{makeSwap(5), true}
   102  	jumpTable[SWAP6] = jumpPtr{makeSwap(6), true}
   103  	jumpTable[SWAP7] = jumpPtr{makeSwap(7), true}
   104  	jumpTable[SWAP8] = jumpPtr{makeSwap(8), true}
   105  	jumpTable[SWAP9] = jumpPtr{makeSwap(9), true}
   106  	jumpTable[SWAP10] = jumpPtr{makeSwap(10), true}
   107  	jumpTable[SWAP11] = jumpPtr{makeSwap(11), true}
   108  	jumpTable[SWAP12] = jumpPtr{makeSwap(12), true}
   109  	jumpTable[SWAP13] = jumpPtr{makeSwap(13), true}
   110  	jumpTable[SWAP14] = jumpPtr{makeSwap(14), true}
   111  	jumpTable[SWAP15] = jumpPtr{makeSwap(15), true}
   112  	jumpTable[SWAP16] = jumpPtr{makeSwap(16), true}
   113  	jumpTable[PUSH1] = jumpPtr{makePush(1, big.NewInt(1)), true}
   114  	jumpTable[PUSH2] = jumpPtr{makePush(2, big.NewInt(2)), true}
   115  	jumpTable[PUSH3] = jumpPtr{makePush(3, big.NewInt(3)), true}
   116  	jumpTable[PUSH4] = jumpPtr{makePush(4, big.NewInt(4)), true}
   117  	jumpTable[PUSH5] = jumpPtr{makePush(5, big.NewInt(5)), true}
   118  	jumpTable[PUSH6] = jumpPtr{makePush(6, big.NewInt(6)), true}
   119  	jumpTable[PUSH7] = jumpPtr{makePush(7, big.NewInt(7)), true}
   120  	jumpTable[PUSH8] = jumpPtr{makePush(8, big.NewInt(8)), true}
   121  	jumpTable[PUSH9] = jumpPtr{makePush(9, big.NewInt(9)), true}
   122  	jumpTable[PUSH10] = jumpPtr{makePush(10, big.NewInt(10)), true}
   123  	jumpTable[PUSH11] = jumpPtr{makePush(11, big.NewInt(11)), true}
   124  	jumpTable[PUSH12] = jumpPtr{makePush(12, big.NewInt(12)), true}
   125  	jumpTable[PUSH13] = jumpPtr{makePush(13, big.NewInt(13)), true}
   126  	jumpTable[PUSH14] = jumpPtr{makePush(14, big.NewInt(14)), true}
   127  	jumpTable[PUSH15] = jumpPtr{makePush(15, big.NewInt(15)), true}
   128  	jumpTable[PUSH16] = jumpPtr{makePush(16, big.NewInt(16)), true}
   129  	jumpTable[PUSH17] = jumpPtr{makePush(17, big.NewInt(17)), true}
   130  	jumpTable[PUSH18] = jumpPtr{makePush(18, big.NewInt(18)), true}
   131  	jumpTable[PUSH19] = jumpPtr{makePush(19, big.NewInt(19)), true}
   132  	jumpTable[PUSH20] = jumpPtr{makePush(20, big.NewInt(20)), true}
   133  	jumpTable[PUSH21] = jumpPtr{makePush(21, big.NewInt(21)), true}
   134  	jumpTable[PUSH22] = jumpPtr{makePush(22, big.NewInt(22)), true}
   135  	jumpTable[PUSH23] = jumpPtr{makePush(23, big.NewInt(23)), true}
   136  	jumpTable[PUSH24] = jumpPtr{makePush(24, big.NewInt(24)), true}
   137  	jumpTable[PUSH25] = jumpPtr{makePush(25, big.NewInt(25)), true}
   138  	jumpTable[PUSH26] = jumpPtr{makePush(26, big.NewInt(26)), true}
   139  	jumpTable[PUSH27] = jumpPtr{makePush(27, big.NewInt(27)), true}
   140  	jumpTable[PUSH28] = jumpPtr{makePush(28, big.NewInt(28)), true}
   141  	jumpTable[PUSH29] = jumpPtr{makePush(29, big.NewInt(29)), true}
   142  	jumpTable[PUSH30] = jumpPtr{makePush(30, big.NewInt(30)), true}
   143  	jumpTable[PUSH31] = jumpPtr{makePush(31, big.NewInt(31)), true}
   144  	jumpTable[PUSH32] = jumpPtr{makePush(32, big.NewInt(32)), true}
   145  	jumpTable[DUP1] = jumpPtr{makeDup(1), true}
   146  	jumpTable[DUP2] = jumpPtr{makeDup(2), true}
   147  	jumpTable[DUP3] = jumpPtr{makeDup(3), true}
   148  	jumpTable[DUP4] = jumpPtr{makeDup(4), true}
   149  	jumpTable[DUP5] = jumpPtr{makeDup(5), true}
   150  	jumpTable[DUP6] = jumpPtr{makeDup(6), true}
   151  	jumpTable[DUP7] = jumpPtr{makeDup(7), true}
   152  	jumpTable[DUP8] = jumpPtr{makeDup(8), true}
   153  	jumpTable[DUP9] = jumpPtr{makeDup(9), true}
   154  	jumpTable[DUP10] = jumpPtr{makeDup(10), true}
   155  	jumpTable[DUP11] = jumpPtr{makeDup(11), true}
   156  	jumpTable[DUP12] = jumpPtr{makeDup(12), true}
   157  	jumpTable[DUP13] = jumpPtr{makeDup(13), true}
   158  	jumpTable[DUP14] = jumpPtr{makeDup(14), true}
   159  	jumpTable[DUP15] = jumpPtr{makeDup(15), true}
   160  	jumpTable[DUP16] = jumpPtr{makeDup(16), true}
   161  
   162  	jumpTable[RETURN] = jumpPtr{nil, true}
   163  	jumpTable[SUICIDE] = jumpPtr{nil, true}
   164  	jumpTable[JUMP] = jumpPtr{nil, true}
   165  	jumpTable[JUMPI] = jumpPtr{nil, true}
   166  	jumpTable[STOP] = jumpPtr{nil, true}
   167  
   168  	return jumpTable
   169  }