github.com/neatio-net/neatio@v1.7.3-0.20231114194659-f4d7a2226baa/chain/core/vm/opcodes.go (about) 1 package vm 2 3 import ( 4 "fmt" 5 ) 6 7 type OpCode byte 8 9 func (op OpCode) IsPush() bool { 10 switch op { 11 case PUSH1, PUSH2, PUSH3, PUSH4, PUSH5, PUSH6, PUSH7, PUSH8, PUSH9, PUSH10, PUSH11, PUSH12, PUSH13, PUSH14, PUSH15, PUSH16, PUSH17, PUSH18, PUSH19, PUSH20, PUSH21, PUSH22, PUSH23, PUSH24, PUSH25, PUSH26, PUSH27, PUSH28, PUSH29, PUSH30, PUSH31, PUSH32: 12 return true 13 } 14 return false 15 } 16 17 func (op OpCode) IsStaticJump() bool { 18 return op == JUMP 19 } 20 21 const ( 22 STOP OpCode = iota 23 ADD 24 MUL 25 SUB 26 DIV 27 SDIV 28 MOD 29 SMOD 30 ADDMOD 31 MULMOD 32 EXP 33 SIGNEXTEND 34 ) 35 36 const ( 37 LT OpCode = iota + 0x10 38 GT 39 SLT 40 SGT 41 EQ 42 ISZERO 43 AND 44 OR 45 XOR 46 NOT 47 BYTE 48 SHL 49 SHR 50 SAR 51 52 SHA3 = 0x20 53 ) 54 55 const ( 56 ADDRESS OpCode = 0x30 + iota 57 BALANCE 58 ORIGIN 59 CALLER 60 CALLVALUE 61 CALLDATALOAD 62 CALLDATASIZE 63 CALLDATACOPY 64 CODESIZE 65 CODECOPY 66 GASPRICE 67 EXTCODESIZE 68 EXTCODECOPY 69 RETURNDATASIZE 70 RETURNDATACOPY 71 EXTCODEHASH 72 ) 73 74 const ( 75 BLOCKHASH OpCode = 0x40 + iota 76 COINBASE 77 TIMESTAMP 78 NUMBER 79 DIFFICULTY 80 GASLIMIT 81 CHAINID = 0x46 82 SELFBALANCE = 0x47 83 ) 84 85 const ( 86 POP OpCode = 0x50 + iota 87 MLOAD 88 MSTORE 89 MSTORE8 90 SLOAD 91 SSTORE 92 JUMP 93 JUMPI 94 PC 95 MSIZE 96 GAS 97 JUMPDEST 98 ) 99 100 const ( 101 PUSH1 OpCode = 0x60 + iota 102 PUSH2 103 PUSH3 104 PUSH4 105 PUSH5 106 PUSH6 107 PUSH7 108 PUSH8 109 PUSH9 110 PUSH10 111 PUSH11 112 PUSH12 113 PUSH13 114 PUSH14 115 PUSH15 116 PUSH16 117 PUSH17 118 PUSH18 119 PUSH19 120 PUSH20 121 PUSH21 122 PUSH22 123 PUSH23 124 PUSH24 125 PUSH25 126 PUSH26 127 PUSH27 128 PUSH28 129 PUSH29 130 PUSH30 131 PUSH31 132 PUSH32 133 DUP1 134 DUP2 135 DUP3 136 DUP4 137 DUP5 138 DUP6 139 DUP7 140 DUP8 141 DUP9 142 DUP10 143 DUP11 144 DUP12 145 DUP13 146 DUP14 147 DUP15 148 DUP16 149 SWAP1 150 SWAP2 151 SWAP3 152 SWAP4 153 SWAP5 154 SWAP6 155 SWAP7 156 SWAP8 157 SWAP9 158 SWAP10 159 SWAP11 160 SWAP12 161 SWAP13 162 SWAP14 163 SWAP15 164 SWAP16 165 ) 166 167 const ( 168 LOG0 OpCode = 0xa0 + iota 169 LOG1 170 LOG2 171 LOG3 172 LOG4 173 ) 174 175 const ( 176 PUSH OpCode = 0xb0 + iota 177 DUP 178 SWAP 179 ) 180 181 const ( 182 CREATE OpCode = 0xf0 + iota 183 CALL 184 CALLCODE 185 RETURN 186 DELEGATECALL 187 CREATE2 188 STATICCALL = 0xfa 189 190 REVERT = 0xfd 191 SELFDESTRUCT = 0xff 192 ) 193 194 var opCodeToString = map[OpCode]string{ 195 196 STOP: "STOP", 197 ADD: "ADD", 198 MUL: "MUL", 199 SUB: "SUB", 200 DIV: "DIV", 201 SDIV: "SDIV", 202 MOD: "MOD", 203 SMOD: "SMOD", 204 EXP: "EXP", 205 NOT: "NOT", 206 LT: "LT", 207 GT: "GT", 208 SLT: "SLT", 209 SGT: "SGT", 210 EQ: "EQ", 211 ISZERO: "ISZERO", 212 SIGNEXTEND: "SIGNEXTEND", 213 214 AND: "AND", 215 OR: "OR", 216 XOR: "XOR", 217 BYTE: "BYTE", 218 SHL: "SHL", 219 SHR: "SHR", 220 SAR: "SAR", 221 ADDMOD: "ADDMOD", 222 MULMOD: "MULMOD", 223 224 SHA3: "SHA3", 225 226 ADDRESS: "ADDRESS", 227 BALANCE: "BALANCE", 228 ORIGIN: "ORIGIN", 229 CALLER: "CALLER", 230 CALLVALUE: "CALLVALUE", 231 CALLDATALOAD: "CALLDATALOAD", 232 CALLDATASIZE: "CALLDATASIZE", 233 CALLDATACOPY: "CALLDATACOPY", 234 CODESIZE: "CODESIZE", 235 CODECOPY: "CODECOPY", 236 GASPRICE: "GASPRICE", 237 EXTCODESIZE: "EXTCODESIZE", 238 EXTCODECOPY: "EXTCODECOPY", 239 RETURNDATASIZE: "RETURNDATASIZE", 240 RETURNDATACOPY: "RETURNDATACOPY", 241 EXTCODEHASH: "EXTCODEHASH", 242 243 BLOCKHASH: "BLOCKHASH", 244 COINBASE: "COINBASE", 245 TIMESTAMP: "TIMESTAMP", 246 NUMBER: "NUMBER", 247 DIFFICULTY: "DIFFICULTY", 248 GASLIMIT: "GASLIMIT", 249 CHAINID: "CHAINID", 250 SELFBALANCE: "SELFBALANCE", 251 252 POP: "POP", 253 254 MLOAD: "MLOAD", 255 MSTORE: "MSTORE", 256 MSTORE8: "MSTORE8", 257 SLOAD: "SLOAD", 258 SSTORE: "SSTORE", 259 JUMP: "JUMP", 260 JUMPI: "JUMPI", 261 PC: "PC", 262 MSIZE: "MSIZE", 263 GAS: "GAS", 264 JUMPDEST: "JUMPDEST", 265 266 PUSH1: "PUSH1", 267 PUSH2: "PUSH2", 268 PUSH3: "PUSH3", 269 PUSH4: "PUSH4", 270 PUSH5: "PUSH5", 271 PUSH6: "PUSH6", 272 PUSH7: "PUSH7", 273 PUSH8: "PUSH8", 274 PUSH9: "PUSH9", 275 PUSH10: "PUSH10", 276 PUSH11: "PUSH11", 277 PUSH12: "PUSH12", 278 PUSH13: "PUSH13", 279 PUSH14: "PUSH14", 280 PUSH15: "PUSH15", 281 PUSH16: "PUSH16", 282 PUSH17: "PUSH17", 283 PUSH18: "PUSH18", 284 PUSH19: "PUSH19", 285 PUSH20: "PUSH20", 286 PUSH21: "PUSH21", 287 PUSH22: "PUSH22", 288 PUSH23: "PUSH23", 289 PUSH24: "PUSH24", 290 PUSH25: "PUSH25", 291 PUSH26: "PUSH26", 292 PUSH27: "PUSH27", 293 PUSH28: "PUSH28", 294 PUSH29: "PUSH29", 295 PUSH30: "PUSH30", 296 PUSH31: "PUSH31", 297 PUSH32: "PUSH32", 298 299 DUP1: "DUP1", 300 DUP2: "DUP2", 301 DUP3: "DUP3", 302 DUP4: "DUP4", 303 DUP5: "DUP5", 304 DUP6: "DUP6", 305 DUP7: "DUP7", 306 DUP8: "DUP8", 307 DUP9: "DUP9", 308 DUP10: "DUP10", 309 DUP11: "DUP11", 310 DUP12: "DUP12", 311 DUP13: "DUP13", 312 DUP14: "DUP14", 313 DUP15: "DUP15", 314 DUP16: "DUP16", 315 316 SWAP1: "SWAP1", 317 SWAP2: "SWAP2", 318 SWAP3: "SWAP3", 319 SWAP4: "SWAP4", 320 SWAP5: "SWAP5", 321 SWAP6: "SWAP6", 322 SWAP7: "SWAP7", 323 SWAP8: "SWAP8", 324 SWAP9: "SWAP9", 325 SWAP10: "SWAP10", 326 SWAP11: "SWAP11", 327 SWAP12: "SWAP12", 328 SWAP13: "SWAP13", 329 SWAP14: "SWAP14", 330 SWAP15: "SWAP15", 331 SWAP16: "SWAP16", 332 LOG0: "LOG0", 333 LOG1: "LOG1", 334 LOG2: "LOG2", 335 LOG3: "LOG3", 336 LOG4: "LOG4", 337 338 CREATE: "CREATE", 339 CALL: "CALL", 340 RETURN: "RETURN", 341 CALLCODE: "CALLCODE", 342 DELEGATECALL: "DELEGATECALL", 343 CREATE2: "CREATE2", 344 STATICCALL: "STATICCALL", 345 REVERT: "REVERT", 346 SELFDESTRUCT: "SELFDESTRUCT", 347 348 PUSH: "PUSH", 349 DUP: "DUP", 350 SWAP: "SWAP", 351 } 352 353 func (op OpCode) String() string { 354 str := opCodeToString[op] 355 if len(str) == 0 { 356 return fmt.Sprintf("Missing opcode 0x%x", int(op)) 357 } 358 359 return str 360 } 361 362 var stringToOp = map[string]OpCode{ 363 "STOP": STOP, 364 "ADD": ADD, 365 "MUL": MUL, 366 "SUB": SUB, 367 "DIV": DIV, 368 "SDIV": SDIV, 369 "MOD": MOD, 370 "SMOD": SMOD, 371 "EXP": EXP, 372 "NOT": NOT, 373 "LT": LT, 374 "GT": GT, 375 "SLT": SLT, 376 "SGT": SGT, 377 "EQ": EQ, 378 "ISZERO": ISZERO, 379 "SIGNEXTEND": SIGNEXTEND, 380 "AND": AND, 381 "OR": OR, 382 "XOR": XOR, 383 "BYTE": BYTE, 384 "SHL": SHL, 385 "SHR": SHR, 386 "SAR": SAR, 387 "ADDMOD": ADDMOD, 388 "MULMOD": MULMOD, 389 "SHA3": SHA3, 390 "ADDRESS": ADDRESS, 391 "BALANCE": BALANCE, 392 "ORIGIN": ORIGIN, 393 "CALLER": CALLER, 394 "CALLVALUE": CALLVALUE, 395 "CALLDATALOAD": CALLDATALOAD, 396 "CALLDATASIZE": CALLDATASIZE, 397 "CALLDATACOPY": CALLDATACOPY, 398 "CHAINID": CHAINID, 399 "DELEGATECALL": DELEGATECALL, 400 "STATICCALL": STATICCALL, 401 "CODESIZE": CODESIZE, 402 "CODECOPY": CODECOPY, 403 "GASPRICE": GASPRICE, 404 "EXTCODESIZE": EXTCODESIZE, 405 "EXTCODECOPY": EXTCODECOPY, 406 "RETURNDATASIZE": RETURNDATASIZE, 407 "RETURNDATACOPY": RETURNDATACOPY, 408 "EXTCODEHASH": EXTCODEHASH, 409 "BLOCKHASH": BLOCKHASH, 410 "COINBASE": COINBASE, 411 "TIMESTAMP": TIMESTAMP, 412 "NUMBER": NUMBER, 413 "DIFFICULTY": DIFFICULTY, 414 "GASLIMIT": GASLIMIT, 415 "SELFBALANCE": SELFBALANCE, 416 "POP": POP, 417 "MLOAD": MLOAD, 418 "MSTORE": MSTORE, 419 "MSTORE8": MSTORE8, 420 "SLOAD": SLOAD, 421 "SSTORE": SSTORE, 422 "JUMP": JUMP, 423 "JUMPI": JUMPI, 424 "PC": PC, 425 "MSIZE": MSIZE, 426 "GAS": GAS, 427 "JUMPDEST": JUMPDEST, 428 "PUSH1": PUSH1, 429 "PUSH2": PUSH2, 430 "PUSH3": PUSH3, 431 "PUSH4": PUSH4, 432 "PUSH5": PUSH5, 433 "PUSH6": PUSH6, 434 "PUSH7": PUSH7, 435 "PUSH8": PUSH8, 436 "PUSH9": PUSH9, 437 "PUSH10": PUSH10, 438 "PUSH11": PUSH11, 439 "PUSH12": PUSH12, 440 "PUSH13": PUSH13, 441 "PUSH14": PUSH14, 442 "PUSH15": PUSH15, 443 "PUSH16": PUSH16, 444 "PUSH17": PUSH17, 445 "PUSH18": PUSH18, 446 "PUSH19": PUSH19, 447 "PUSH20": PUSH20, 448 "PUSH21": PUSH21, 449 "PUSH22": PUSH22, 450 "PUSH23": PUSH23, 451 "PUSH24": PUSH24, 452 "PUSH25": PUSH25, 453 "PUSH26": PUSH26, 454 "PUSH27": PUSH27, 455 "PUSH28": PUSH28, 456 "PUSH29": PUSH29, 457 "PUSH30": PUSH30, 458 "PUSH31": PUSH31, 459 "PUSH32": PUSH32, 460 "DUP1": DUP1, 461 "DUP2": DUP2, 462 "DUP3": DUP3, 463 "DUP4": DUP4, 464 "DUP5": DUP5, 465 "DUP6": DUP6, 466 "DUP7": DUP7, 467 "DUP8": DUP8, 468 "DUP9": DUP9, 469 "DUP10": DUP10, 470 "DUP11": DUP11, 471 "DUP12": DUP12, 472 "DUP13": DUP13, 473 "DUP14": DUP14, 474 "DUP15": DUP15, 475 "DUP16": DUP16, 476 "SWAP1": SWAP1, 477 "SWAP2": SWAP2, 478 "SWAP3": SWAP3, 479 "SWAP4": SWAP4, 480 "SWAP5": SWAP5, 481 "SWAP6": SWAP6, 482 "SWAP7": SWAP7, 483 "SWAP8": SWAP8, 484 "SWAP9": SWAP9, 485 "SWAP10": SWAP10, 486 "SWAP11": SWAP11, 487 "SWAP12": SWAP12, 488 "SWAP13": SWAP13, 489 "SWAP14": SWAP14, 490 "SWAP15": SWAP15, 491 "SWAP16": SWAP16, 492 "LOG0": LOG0, 493 "LOG1": LOG1, 494 "LOG2": LOG2, 495 "LOG3": LOG3, 496 "LOG4": LOG4, 497 "CREATE": CREATE, 498 "CREATE2": CREATE2, 499 "CALL": CALL, 500 "RETURN": RETURN, 501 "CALLCODE": CALLCODE, 502 "REVERT": REVERT, 503 "SELFDESTRUCT": SELFDESTRUCT, 504 } 505 506 func StringToOp(str string) OpCode { 507 return stringToOp[str] 508 }