op.h (5337B)
1 2 #ifndef BCS_OP_H 3 #define BCS_OP_H 4 5 #include "misc.h" 6 #include "stack.h" 7 #include "val.h" 8 #include <stdio.h> 9 #include <math.h> 10 11 enum opcode 12 { 13 // push value 14 OP_0 = 0x00, 15 OP_FALSE = OP_0, 16 OP_PUSHDATA1 = 0x4c, 17 OP_PUSHDATA2 = 0x4d, 18 OP_PUSHDATA4 = 0x4e, 19 OP_1NEGATE = 0x4f, 20 OP_RESERVED = 0x50, 21 OP_1 = 0x51, 22 OP_TRUE=OP_1, 23 OP_2 = 0x52, 24 OP_3 = 0x53, 25 OP_4 = 0x54, 26 OP_5 = 0x55, 27 OP_6 = 0x56, 28 OP_7 = 0x57, 29 OP_8 = 0x58, 30 OP_9 = 0x59, 31 OP_10 = 0x5a, 32 OP_11 = 0x5b, 33 OP_12 = 0x5c, 34 OP_13 = 0x5d, 35 OP_14 = 0x5e, 36 OP_15 = 0x5f, 37 OP_16 = 0x60, 38 39 // control 40 OP_NOP = 0x61, 41 OP_VER = 0x62, 42 OP_IF = 0x63, 43 OP_NOTIF = 0x64, 44 OP_VERIF = 0x65, 45 OP_VERNOTIF = 0x66, 46 OP_ELSE = 0x67, 47 OP_ENDIF = 0x68, 48 OP_VERIFY = 0x69, 49 OP_RETURN = 0x6a, 50 51 // stack ops 52 OP_TOALTSTACK = 0x6b, 53 OP_FROMALTSTACK = 0x6c, 54 OP_2DROP = 0x6d, 55 OP_2DUP = 0x6e, 56 OP_3DUP = 0x6f, 57 OP_2OVER = 0x70, 58 OP_2ROT = 0x71, 59 OP_2SWAP = 0x72, 60 OP_IFDUP = 0x73, 61 OP_DEPTH = 0x74, 62 OP_DROP = 0x75, 63 OP_DUP = 0x76, 64 OP_NIP = 0x77, 65 OP_OVER = 0x78, 66 OP_PICK = 0x79, 67 OP_ROLL = 0x7a, 68 OP_ROT = 0x7b, 69 OP_SWAP = 0x7c, 70 OP_TUCK = 0x7d, 71 72 // splice ops 73 OP_CAT = 0x7e, 74 OP_SUBSTR = 0x7f, 75 OP_LEFT = 0x80, 76 OP_RIGHT = 0x81, 77 OP_SIZE = 0x82, 78 79 // bit logic 80 OP_INVERT = 0x83, 81 OP_AND = 0x84, 82 OP_OR = 0x85, 83 OP_XOR = 0x86, 84 OP_EQUAL = 0x87, 85 OP_EQUALVERIFY = 0x88, 86 OP_RESERVED1 = 0x89, 87 OP_RESERVED2 = 0x8a, 88 89 // numeric 90 OP_1ADD = 0x8b, 91 OP_1SUB = 0x8c, 92 OP_2MUL = 0x8d, 93 OP_2DIV = 0x8e, 94 OP_NEGATE = 0x8f, 95 OP_ABS = 0x90, 96 OP_NOT = 0x91, 97 OP_0NOTEQUAL = 0x92, 98 99 OP_ADD = 0x93, 100 OP_SUB = 0x94, 101 OP_MUL = 0x95, 102 OP_DIV = 0x96, 103 OP_MOD = 0x97, 104 OP_LSHIFT = 0x98, 105 OP_RSHIFT = 0x99, 106 107 OP_BOOLAND = 0x9a, 108 OP_BOOLOR = 0x9b, 109 OP_NUMEQUAL = 0x9c, 110 OP_NUMEQUALVERIFY = 0x9d, 111 OP_NUMNOTEQUAL = 0x9e, 112 OP_LESSTHAN = 0x9f, 113 OP_GREATERTHAN = 0xa0, 114 OP_LESSTHANOREQUAL = 0xa1, 115 OP_GREATERTHANOREQUAL = 0xa2, 116 OP_MIN = 0xa3, 117 OP_MAX = 0xa4, 118 119 OP_WITHIN = 0xa5, 120 121 // crypto 122 OP_RIPEMD160 = 0xa6, 123 OP_SHA1 = 0xa7, 124 OP_SHA256 = 0xa8, 125 OP_HASH160 = 0xa9, 126 OP_HASH256 = 0xaa, 127 OP_CODESEPARATOR = 0xab, 128 OP_CHECKSIG = 0xac, 129 OP_CHECKSIGVERIFY = 0xad, 130 OP_CHECKMULTISIG = 0xae, 131 OP_CHECKMULTISIGVERIFY = 0xaf, 132 133 // expansion 134 OP_NOP1 = 0xb0, 135 OP_CHECKLOCKTIMEVERIFY = 0xb1, 136 OP_NOP2 = OP_CHECKLOCKTIMEVERIFY, 137 OP_CHECKSEQUENCEVERIFY = 0xb2, 138 OP_NOP3 = OP_CHECKSEQUENCEVERIFY, 139 OP_NOP4 = 0xb3, 140 OP_NOP5 = 0xb4, 141 OP_NOP6 = 0xb5, 142 OP_NOP7 = 0xb6, 143 OP_NOP8 = 0xb7, 144 OP_NOP9 = 0xb8, 145 OP_NOP10 = 0xb9, 146 147 148 // template matching params 149 OP_SMALLINTEGER = 0xfa, 150 OP_PUBKEYS = 0xfb, 151 OP_PUBKEYHASH = 0xfd, 152 OP_PUBKEY = 0xfe, 153 154 OP_INVALIDOPCODE = 0xff, 155 }; 156 157 158 enum opcode_token 159 { 160 // push value 161 _OP_0=1, 162 _OP_FALSE, 163 _OP_PUSHDATA1, 164 _OP_PUSHDATA2, 165 _OP_PUSHDATA4, 166 _OP_1NEGATE, 167 _OP_RESERVED, 168 _OP_1, 169 _OP_TRUE, 170 _OP_2, 171 _OP_3, 172 _OP_4, 173 _OP_5, 174 _OP_6, 175 _OP_7, 176 _OP_8, 177 _OP_9, 178 _OP_10, 179 _OP_11, 180 _OP_12, 181 _OP_13, 182 _OP_14, 183 _OP_15, 184 _OP_16, 185 186 // control 187 _OP_NOP, 188 _OP_VER, 189 _OP_IF, 190 _OP_NOTIF, 191 _OP_VERIF, 192 _OP_VERNOTIF, 193 _OP_ELSE, 194 _OP_ENDIF, 195 _OP_VERIFY, 196 _OP_RETURN, 197 198 // stack ops 199 _OP_TOALTSTACK, 200 _OP_FROMALTSTACK, 201 _OP_2DROP, 202 _OP_2DUP, 203 _OP_3DUP, 204 _OP_2OVER, 205 _OP_2ROT, 206 _OP_2SWAP, 207 _OP_IFDUP, 208 _OP_DEPTH, 209 _OP_DROP, 210 _OP_DUP, 211 _OP_NIP, 212 _OP_OVER, 213 _OP_PICK, 214 _OP_ROLL, 215 _OP_ROT, 216 _OP_SWAP, 217 _OP_TUCK, 218 219 // splice ops 220 _OP_CAT, 221 _OP_SUBSTR, 222 _OP_LEFT, 223 _OP_RIGHT, 224 _OP_SIZE, 225 226 // bit logic 227 _OP_INVERT, 228 _OP_AND, 229 _OP_OR, 230 _OP_XOR, 231 _OP_EQUAL, 232 _OP_EQUALVERIFY, 233 _OP_RESERVED1, 234 _OP_RESERVED2, 235 236 // numeric 237 _OP_1ADD, 238 _OP_1SUB, 239 _OP_2MUL, 240 _OP_2DIV, 241 _OP_NEGATE, 242 _OP_ABS, 243 _OP_NOT, 244 _OP_0NOTEQUAL, 245 246 _OP_ADD, 247 _OP_SUB, 248 _OP_MUL, 249 _OP_DIV, 250 _OP_MOD, 251 _OP_LSHIFT, 252 _OP_RSHIFT, 253 254 _OP_BOOLAND, 255 _OP_BOOLOR, 256 _OP_NUMEQUAL, 257 _OP_NUMEQUALVERIFY, 258 _OP_NUMNOTEQUAL, 259 _OP_LESSTHAN, 260 _OP_GREATERTHAN, 261 _OP_LESSTHANOREQUAL, 262 _OP_GREATERTHANOREQUAL, 263 _OP_MIN, 264 _OP_MAX, 265 266 _OP_WITHIN, 267 268 // crypto 269 _OP_RIPEMD160, 270 _OP_SHA1, 271 _OP_SHA256, 272 _OP_HASH160, 273 _OP_HASH256, 274 _OP_CODESEPARATOR, 275 _OP_CHECKSIG, 276 _OP_CHECKSIGVERIFY, 277 _OP_CHECKMULTISIG, 278 _OP_CHECKMULTISIGVERIFY, 279 280 // expansion 281 _OP_NOP1, 282 _OP_CHECKLOCKTIMEVERIFY, 283 _OP_NOP2, 284 _OP_CHECKSEQUENCEVERIFY, 285 _OP_NOP3, 286 _OP_NOP4, 287 _OP_NOP5, 288 _OP_NOP6, 289 _OP_NOP7, 290 _OP_NOP8, 291 _OP_NOP9, 292 _OP_NOP10, 293 294 295 // template matching params 296 _OP_SMALLINTEGER, 297 _OP_PUBKEYS, 298 _OP_PUBKEYHASH, 299 _OP_PUBKEY, 300 301 _OP_INVALIDOPCODE, 302 }; 303 304 // Maximum value that an opcode can be 305 static const unsigned int MAX_OPCODE = OP_NOP10; 306 307 void op_add(enum opcode); 308 const char * op_name(enum opcode); 309 enum opcode op_tokenize(char *); 310 void val_print(struct val); 311 const char * val_name(struct val); 312 313 314 315 #endif /* BCS_OP_H */