github.com/ontio/ontology@v1.14.4/vm/neovm/opcode.go (about) 1 /* 2 * Copyright (C) 2018 The ontology Authors 3 * This file is part of The ontology library. 4 * 5 * The ontology 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 ontology 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 ontology. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 package neovm 20 21 type OpCode byte 22 23 const ( 24 // Constants 25 PUSH0 OpCode = 0x00 // An empty array of bytes is pushed onto the stack. 26 PUSHF OpCode = PUSH0 27 PUSHBYTES1 OpCode = 0x01 // 0x01-0x4B The next opcode bytes is data to be pushed onto the stack 28 PUSHBYTES75 OpCode = 0x4B 29 PUSHDATA1 OpCode = 0x4C // The next byte contains the number of bytes to be pushed onto the stack. 30 PUSHDATA2 OpCode = 0x4D // The next two bytes contain the number of bytes to be pushed onto the stack. 31 PUSHDATA4 OpCode = 0x4E // The next four bytes contain the number of bytes to be pushed onto the stack. 32 PUSHM1 OpCode = 0x4F // The number -1 is pushed onto the stack. 33 PUSH1 OpCode = 0x51 // The number 1 is pushed onto the stack. 34 PUSHT OpCode = PUSH1 35 PUSH2 OpCode = 0x52 // The number 2 is pushed onto the stack. 36 PUSH3 OpCode = 0x53 // The number 3 is pushed onto the stack. 37 PUSH4 OpCode = 0x54 // The number 4 is pushed onto the stack. 38 PUSH5 OpCode = 0x55 // The number 5 is pushed onto the stack. 39 PUSH6 OpCode = 0x56 // The number 6 is pushed onto the stack. 40 PUSH7 OpCode = 0x57 // The number 7 is pushed onto the stack. 41 PUSH8 OpCode = 0x58 // The number 8 is pushed onto the stack. 42 PUSH9 OpCode = 0x59 // The number 9 is pushed onto the stack. 43 PUSH10 OpCode = 0x5A // The number 10 is pushed onto the stack. 44 PUSH11 OpCode = 0x5B // The number 11 is pushed onto the stack. 45 PUSH12 OpCode = 0x5C // The number 12 is pushed onto the stack. 46 PUSH13 OpCode = 0x5D // The number 13 is pushed onto the stack. 47 PUSH14 OpCode = 0x5E // The number 14 is pushed onto the stack. 48 PUSH15 OpCode = 0x5F // The number 15 is pushed onto the stack. 49 PUSH16 OpCode = 0x60 // The number 16 is pushed onto the stack. 50 51 // Flow control 52 NOP OpCode = 0x61 // Does nothing. 53 JMP OpCode = 0x62 54 JMPIF OpCode = 0x63 55 JMPIFNOT OpCode = 0x64 56 CALL OpCode = 0x65 57 RET OpCode = 0x66 58 APPCALL OpCode = 0x67 59 SYSCALL OpCode = 0x68 60 TAILCALL OpCode = 0x69 61 62 // Stack 63 DUPFROMALTSTACK OpCode = 0x6A 64 TOALTSTACK OpCode = 0x6B // Puts the input onto the top of the alt stack. Removes it from the main stack. 65 FROMALTSTACK OpCode = 0x6C // Puts the input onto the top of the main stack. Removes it from the alt stack. 66 XDROP OpCode = 0x6D 67 DCALL OpCode = 0x6E 68 XSWAP OpCode = 0x72 69 XTUCK OpCode = 0x73 70 DEPTH OpCode = 0x74 // Puts the number of stack items onto the stack. 71 DROP OpCode = 0x75 // Removes the top stack item. 72 DUP OpCode = 0x76 // Duplicates the top stack item. 73 NIP OpCode = 0x77 // Removes the second top stack item. 74 OVER OpCode = 0x78 // Copies the second top stack item to the top. 75 PICK OpCode = 0x79 // The item n back in the stack is copied to the top. 76 ROLL OpCode = 0x7A // The item n back in the stack is moved to the top. 77 ROT OpCode = 0x7B // Move third top item on the top of stack. 78 SWAP OpCode = 0x7C // The top two items on the stack are swapped. 79 TUCK OpCode = 0x7D // The item at the top of the stack is copied and inserted before the second-to-top item. 80 81 // Splice 82 CAT OpCode = 0x7E // Concatenates two strings. 83 SUBSTR OpCode = 0x7F // Returns a section of a string. 84 LEFT OpCode = 0x80 // Keeps only characters left of the specified point in a string. 85 RIGHT OpCode = 0x81 // Keeps only characters right of the specified point in a string. 86 SIZE OpCode = 0x82 // Returns the length of the input string. 87 88 // Bitwise logic 89 INVERT OpCode = 0x83 // Flips all of the bits in the input. 90 AND OpCode = 0x84 // Boolean and between each bit in the inputs. 91 OR OpCode = 0x85 // Boolean or between each bit in the inputs. 92 XOR OpCode = 0x86 // Boolean exclusive or between each bit in the inputs. 93 EQUAL OpCode = 0x87 // Returns 1 if the inputs are exactly equal, 0 otherwise. 94 // EQUALVERIFY = 0x88 // Same as EQUAL, but runs VERIFY afterward. 95 // RESERVED1 = 0x89 // Transaction is invalid unless occurring in an unexecuted IF branch 96 // RESERVED2 = 0x8A // Transaction is invalid unless occurring in an unexecuted IF branch 97 98 // Arithmetic 99 // Note: Arithmetic inputs are limited to signed 32-bit integers, but may overflow their output. 100 INC OpCode = 0x8B // 1 is added to the input. 101 DEC OpCode = 0x8C // 1 is subtracted from the input. 102 SIGN OpCode = 0x8D 103 NEGATE OpCode = 0x8F // The sign of the input is flipped. 104 ABS OpCode = 0x90 // The input is made positive. 105 NOT OpCode = 0x91 // If the input is 0 or 1, it is flipped. Otherwise the output will be 0. 106 NZ OpCode = 0x92 // Returns 0 if the input is 0. 1 otherwise. 107 ADD OpCode = 0x93 // a is added to b. 108 SUB OpCode = 0x94 // b is subtracted from a. 109 MUL OpCode = 0x95 // a is multiplied by b. 110 DIV OpCode = 0x96 // a is divided by b. 111 MOD OpCode = 0x97 // Returns the remainder after dividing a by b. 112 SHL OpCode = 0x98 // Shifts a left b bits, preserving sign. 113 SHR OpCode = 0x99 // Shifts a right b bits, preserving sign. 114 BOOLAND OpCode = 0x9A // If both a and b are not 0, the output is 1. Otherwise 0. 115 BOOLOR OpCode = 0x9B // If a or b is not 0, the output is 1. Otherwise 0. 116 NUMEQUAL OpCode = 0x9C // Returns 1 if the numbers are equal, 0 otherwise. 117 NUMNOTEQUAL OpCode = 0x9E // Returns 1 if the numbers are not equal, 0 otherwise. 118 LT OpCode = 0x9F // Returns 1 if a is less than b, 0 otherwise. 119 GT OpCode = 0xA0 // Returns 1 if a is greater than b, 0 otherwise. 120 LTE OpCode = 0xA1 // Returns 1 if a is less than or equal to b, 0 otherwise. 121 GTE OpCode = 0xA2 // Returns 1 if a is greater than or equal to b, 0 otherwise. 122 MIN OpCode = 0xA3 // Returns the smaller of a and b. 123 MAX OpCode = 0xA4 // Returns the larger of a and b. 124 WITHIN OpCode = 0xA5 // Returns 1 if x is within the specified range (left-inclusive), 0 otherwise. 125 126 // Crypto 127 //RIPEMD160 = 0xA6 // The input is hashed using RIPEMD-160. 128 SHA1 OpCode = 0xA7 // The input is hashed using SHA-1. 129 SHA256 OpCode = 0xA8 // The input is hashed using SHA-256. 130 HASH160 OpCode = 0xA9 131 HASH256 OpCode = 0xAA 132 CHECKSIG OpCode = 0xAC // The entire transaction's outputs inputs and script (from the most recently-executed CODESEPARATOR to the end) are hashed. The signature used by CHECKSIG must be a valid signature for this hash and public key. If it is 1 is returned 0 otherwise. 133 VERIFY OpCode = 0xAD 134 CHECKMULTISIG OpCode = 0xAE // For each signature and public key pair CHECKSIG is executed. If more public keys than signatures are listed some key/sig pairs can fail. All signatures need to match a public key. If all signatures are valid 1 is returned 0 otherwise. Due to a bug one extra unused value is removed from the stack. 135 136 // Array 137 ARRAYSIZE OpCode = 0xC0 138 PACK OpCode = 0xC1 139 UNPACK OpCode = 0xC2 140 PICKITEM OpCode = 0xC3 141 SETITEM OpCode = 0xC4 142 NEWARRAY OpCode = 0xC5 143 NEWSTRUCT OpCode = 0xC6 144 NEWMAP OpCode = 0xC7 145 APPEND OpCode = 0xC8 146 REVERSE OpCode = 0xC9 147 REMOVE OpCode = 0xCA 148 HASKEY OpCode = 0xCB 149 KEYS OpCode = 0xCC 150 VALUES OpCode = 0xCD 151 152 //Exception 153 THROW = 0xF0 154 THROWIFNOT = 0xF1 155 )