github.com/karalabe/go-ethereum@v0.8.5/vm/types.go (about) 1 package vm 2 3 import ( 4 "fmt" 5 ) 6 7 type OpCode byte 8 9 // Op codes 10 const ( 11 // 0x0 range - arithmetic ops 12 STOP OpCode = iota 13 ADD 14 MUL 15 SUB 16 DIV 17 SDIV 18 MOD 19 SMOD 20 ADDMOD 21 MULMOD 22 EXP 23 SIGNEXTEND 24 ) 25 26 const ( 27 LT OpCode = iota + 0x10 28 GT 29 SLT 30 SGT 31 EQ 32 ISZERO 33 AND 34 OR 35 XOR 36 NOT 37 BYTE 38 39 SHA3 = 0x20 40 ) 41 42 const ( 43 // 0x30 range - closure state 44 ADDRESS OpCode = 0x30 + iota 45 BALANCE 46 ORIGIN 47 CALLER 48 CALLVALUE 49 CALLDATALOAD 50 CALLDATASIZE 51 CALLDATACOPY 52 CODESIZE 53 CODECOPY 54 GASPRICE 55 EXTCODESIZE 56 EXTCODECOPY 57 ) 58 59 const ( 60 61 // 0x40 range - block operations 62 BLOCKHASH OpCode = 0x40 + iota 63 COINBASE 64 TIMESTAMP 65 NUMBER 66 DIFFICULTY 67 GASLIMIT 68 ) 69 70 const ( 71 // 0x50 range - 'storage' and execution 72 POP OpCode = 0x50 + iota 73 MLOAD 74 MSTORE 75 MSTORE8 76 SLOAD 77 SSTORE 78 JUMP 79 JUMPI 80 PC 81 MSIZE 82 GAS 83 JUMPDEST 84 ) 85 86 const ( 87 // 0x60 range 88 PUSH1 OpCode = 0x60 + iota 89 PUSH2 90 PUSH3 91 PUSH4 92 PUSH5 93 PUSH6 94 PUSH7 95 PUSH8 96 PUSH9 97 PUSH10 98 PUSH11 99 PUSH12 100 PUSH13 101 PUSH14 102 PUSH15 103 PUSH16 104 PUSH17 105 PUSH18 106 PUSH19 107 PUSH20 108 PUSH21 109 PUSH22 110 PUSH23 111 PUSH24 112 PUSH25 113 PUSH26 114 PUSH27 115 PUSH28 116 PUSH29 117 PUSH30 118 PUSH31 119 PUSH32 120 DUP1 121 DUP2 122 DUP3 123 DUP4 124 DUP5 125 DUP6 126 DUP7 127 DUP8 128 DUP9 129 DUP10 130 DUP11 131 DUP12 132 DUP13 133 DUP14 134 DUP15 135 DUP16 136 SWAP1 137 SWAP2 138 SWAP3 139 SWAP4 140 SWAP5 141 SWAP6 142 SWAP7 143 SWAP8 144 SWAP9 145 SWAP10 146 SWAP11 147 SWAP12 148 SWAP13 149 SWAP14 150 SWAP15 151 SWAP16 152 ) 153 154 const ( 155 LOG0 OpCode = 0xa0 + iota 156 LOG1 157 LOG2 158 LOG3 159 LOG4 160 ) 161 162 const ( 163 // 0xf0 range - closures 164 CREATE OpCode = 0xf0 + iota 165 CALL 166 CALLCODE 167 RETURN 168 169 // 0x70 range - other 170 SUICIDE = 0xff 171 ) 172 173 // Since the opcodes aren't all in order we can't use a regular slice 174 var opCodeToString = map[OpCode]string{ 175 // 0x0 range - arithmetic ops 176 STOP: "STOP", 177 ADD: "ADD", 178 MUL: "MUL", 179 SUB: "SUB", 180 DIV: "DIV", 181 SDIV: "SDIV", 182 MOD: "MOD", 183 SMOD: "SMOD", 184 EXP: "EXP", 185 NOT: "NOT", 186 LT: "LT", 187 GT: "GT", 188 SLT: "SLT", 189 SGT: "SGT", 190 EQ: "EQ", 191 ISZERO: "ISZERO", 192 SIGNEXTEND: "SIGNEXTEND", 193 194 // 0x10 range - bit ops 195 AND: "AND", 196 OR: "OR", 197 XOR: "XOR", 198 BYTE: "BYTE", 199 ADDMOD: "ADDMOD", 200 MULMOD: "MULMOD", 201 202 // 0x20 range - crypto 203 SHA3: "SHA3", 204 205 // 0x30 range - closure state 206 ADDRESS: "ADDRESS", 207 BALANCE: "BALANCE", 208 ORIGIN: "ORIGIN", 209 CALLER: "CALLER", 210 CALLVALUE: "CALLVALUE", 211 CALLDATALOAD: "CALLDATALOAD", 212 CALLDATASIZE: "CALLDATASIZE", 213 CALLDATACOPY: "CALLDATACOPY", 214 CODESIZE: "CODESIZE", 215 CODECOPY: "CODECOPY", 216 GASPRICE: "TXGASPRICE", 217 218 // 0x40 range - block operations 219 BLOCKHASH: "BLOCKHASH", 220 COINBASE: "COINBASE", 221 TIMESTAMP: "TIMESTAMP", 222 NUMBER: "NUMBER", 223 DIFFICULTY: "DIFFICULTY", 224 GASLIMIT: "GASLIMIT", 225 EXTCODESIZE: "EXTCODESIZE", 226 EXTCODECOPY: "EXTCODECOPY", 227 228 // 0x50 range - 'storage' and execution 229 POP: "POP", 230 //DUP: "DUP", 231 //SWAP: "SWAP", 232 MLOAD: "MLOAD", 233 MSTORE: "MSTORE", 234 MSTORE8: "MSTORE8", 235 SLOAD: "SLOAD", 236 SSTORE: "SSTORE", 237 JUMP: "JUMP", 238 JUMPI: "JUMPI", 239 PC: "PC", 240 MSIZE: "MSIZE", 241 GAS: "GAS", 242 JUMPDEST: "JUMPDEST", 243 244 // 0x60 range - push 245 PUSH1: "PUSH1", 246 PUSH2: "PUSH2", 247 PUSH3: "PUSH3", 248 PUSH4: "PUSH4", 249 PUSH5: "PUSH5", 250 PUSH6: "PUSH6", 251 PUSH7: "PUSH7", 252 PUSH8: "PUSH8", 253 PUSH9: "PUSH9", 254 PUSH10: "PUSH10", 255 PUSH11: "PUSH11", 256 PUSH12: "PUSH12", 257 PUSH13: "PUSH13", 258 PUSH14: "PUSH14", 259 PUSH15: "PUSH15", 260 PUSH16: "PUSH16", 261 PUSH17: "PUSH17", 262 PUSH18: "PUSH18", 263 PUSH19: "PUSH19", 264 PUSH20: "PUSH20", 265 PUSH21: "PUSH21", 266 PUSH22: "PUSH22", 267 PUSH23: "PUSH23", 268 PUSH24: "PUSH24", 269 PUSH25: "PUSH25", 270 PUSH26: "PUSH26", 271 PUSH27: "PUSH27", 272 PUSH28: "PUSH28", 273 PUSH29: "PUSH29", 274 PUSH30: "PUSH30", 275 PUSH31: "PUSH31", 276 PUSH32: "PUSH32", 277 278 DUP1: "DUP1", 279 DUP2: "DUP2", 280 DUP3: "DUP3", 281 DUP4: "DUP4", 282 DUP5: "DUP5", 283 DUP6: "DUP6", 284 DUP7: "DUP7", 285 DUP8: "DUP8", 286 DUP9: "DUP9", 287 DUP10: "DUP10", 288 DUP11: "DUP11", 289 DUP12: "DUP12", 290 DUP13: "DUP13", 291 DUP14: "DUP14", 292 DUP15: "DUP15", 293 DUP16: "DUP16", 294 295 SWAP1: "SWAP1", 296 SWAP2: "SWAP2", 297 SWAP3: "SWAP3", 298 SWAP4: "SWAP4", 299 SWAP5: "SWAP5", 300 SWAP6: "SWAP6", 301 SWAP7: "SWAP7", 302 SWAP8: "SWAP8", 303 SWAP9: "SWAP9", 304 SWAP10: "SWAP10", 305 SWAP11: "SWAP11", 306 SWAP12: "SWAP12", 307 SWAP13: "SWAP13", 308 SWAP14: "SWAP14", 309 SWAP15: "SWAP15", 310 SWAP16: "SWAP16", 311 LOG0: "LOG0", 312 LOG1: "LOG1", 313 LOG2: "LOG2", 314 LOG3: "LOG3", 315 LOG4: "LOG4", 316 317 // 0xf0 range 318 CREATE: "CREATE", 319 CALL: "CALL", 320 RETURN: "RETURN", 321 CALLCODE: "CALLCODE", 322 323 // 0x70 range - other 324 SUICIDE: "SUICIDE", 325 } 326 327 func (o OpCode) String() string { 328 str := opCodeToString[o] 329 if len(str) == 0 { 330 return fmt.Sprintf("Missing opcode 0x%x", int(o)) 331 } 332 333 return str 334 }