Coverage Summary for Class: OpCode (org.ethereum.vm)

Class Method, % Line, %
OpCode 84.6% (11/13) 98.9% (177/179)
OpCode$Tier 100% (4/4) 100% (14/14)
Total 88.2% (15/17) 99% (191/193)


1 /* 2  * This file is part of RskJ 3  * Copyright (C) 2017 RSK Labs Ltd. 4  * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>) 5  * 6  * This program is free software: you can redistribute it and/or modify 7  * it under the terms of the GNU Lesser General Public License as published by 8  * the Free Software Foundation, either version 3 of the License, or 9  * (at your option) any later version. 10  * 11  * This program is distributed in the hope that it will be useful, 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14  * GNU Lesser General Public License for more details. 15  * 16  * You should have received a copy of the GNU Lesser General Public License 17  * along with this program. If not, see <http://www.gnu.org/licenses/>. 18  */ 19  20 package org.ethereum.vm; 21  22 import java.util.HashMap; 23 import java.util.Map; 24  25 import static org.ethereum.vm.OpCode.Tier.*; 26  27  28 /** 29  * Instruction set for the Ethereum Virtual Machine 30  * See Yellow Paper: http://www.gavwood.com/Paper.pdf 31  * - Appendix G. Virtual Machine Specification 32  */ 33 public enum OpCode { 34  // code, in-args,out-args, cost 35  /** 36  * Halts execution (0x00) 37  */ 38  STOP(0x00, 0, 0, ZERO_TIER), 39  40  /* Arithmetic Operations */ 41  42  /** 43  * (0x01) Addition operation 44  */ 45  ADD(0x01, 2, 1, VERY_LOW_TIER), 46  /** 47  * (0x02) Multiplication operation 48  */ 49  MUL(0x02, 2, 1, LOW_TIER), 50  /** 51  * (0x03) Subtraction operations 52  */ 53  SUB(0x03, 2, 1, VERY_LOW_TIER), 54  /** 55  * (0x04) Integer division operation 56  */ 57  DIV(0x04, 2, 1, LOW_TIER), 58  /** 59  * (0x05) Signed integer division operation 60  */ 61  SDIV(0x05, 2, 1, LOW_TIER), 62  /** 63  * (0x06) Modulo remainder operation 64  */ 65  MOD(0x06, 2, 1, LOW_TIER), 66  /** 67  * (0x07) Signed modulo remainder operation 68  */ 69  SMOD(0x07, 2, 1, LOW_TIER), 70  /** 71  * (0x08) Addition combined with modulo 72  * remainder operation 73  */ 74  ADDMOD(0x08, 3, 1, MID_TIER), 75  /** 76  * (0x09) Multiplication combined with modulo 77  * remainder operation 78  */ 79  MULMOD(0x09, 3, 1, MID_TIER), 80  /** 81  * (0x0a) Exponential operation 82  */ 83  EXP(0x0a, 2, 1, SPECIAL_TIER), 84  /** 85  * (0x0b) Extend length of signed integer 86  */ 87  SIGNEXTEND(0x0b, 2, 1, LOW_TIER), 88  89  /* Bitwise Logic & Comparison Operations */ 90  91  /** 92  * (0x10) Less-than comparison 93  */ 94  LT(0X10, 2, 1, VERY_LOW_TIER), 95  /** 96  * (0x11) Greater-than comparison 97  */ 98  GT(0X11, 2, 1, VERY_LOW_TIER), 99  /** 100  * (0x12) Signed less-than comparison 101  */ 102  SLT(0X12, 2, 1, VERY_LOW_TIER), 103  /** 104  * (0x13) Signed greater-than comparison 105  */ 106  SGT(0X13, 2, 1, VERY_LOW_TIER), 107  /** 108  * (0x14) Equality comparison 109  */ 110  EQ(0X14, 2, 1, VERY_LOW_TIER), 111  /** 112  * (0x15) Negation operation 113  */ 114  ISZERO(0x15, 1, 1, VERY_LOW_TIER), 115  /** 116  * (0x16) Bitwise AND operation 117  */ 118  AND(0x16, 2, 1, VERY_LOW_TIER), 119  /** 120  * (0x17) Bitwise OR operation 121  */ 122  OR(0x17, 2, 1, VERY_LOW_TIER), 123  /** 124  * (0x18) Bitwise XOR operation 125  */ 126  XOR(0x18, 2, 1, VERY_LOW_TIER), 127  /** 128  * (0x19) Bitwise NOT operationr 129  */ 130  NOT(0x19, 1, 1, VERY_LOW_TIER), 131  /** 132  * (0x1a) Retrieve single byte from word 133  */ 134  BYTE(0x1a, 2, 1, VERY_LOW_TIER), 135  /** 136  * (0x1b) Bitwise SHIFT LEFT operation 137  */ 138  SHL(0x1b, 2, 1, VERY_LOW_TIER), 139  /** 140  * (0x1c) Bitwise SHIFT RIGHT operation 141  */ 142  SHR(0x1c, 2, 1, VERY_LOW_TIER), 143  /** 144  * (0x1d) Bitwise ARITHMETIC SHIFT RIGHT operation 145  */ 146  SAR(0x1d, 2, 1, VERY_LOW_TIER), 147  148  /* Cryptographic Operations */ 149  150  /** 151  * (0x20) Compute SHA3-256 hash 152  */ 153  SHA3(0x20, 2, 1, SPECIAL_TIER), 154  155  /* Environmental Information */ 156  157  /** 158  * (0x30) Get address of currently 159  * executing account 160  */ 161  ADDRESS(0x30, 0, 1, BASE_TIER), 162  /** 163  * (0x31) Get balance of the given account 164  */ 165  BALANCE(0x31, 1, 1, EXT_TIER), 166  /** 167  * (0x32) Get execution origination address 168  */ 169  ORIGIN(0x32, 0, 1, BASE_TIER), 170  /** 171  * (0x33) Get caller address 172  */ 173  CALLER(0x33, 0, 1, BASE_TIER), 174  /** 175  * (0x34) Get deposited value by the 176  * instruction/transaction responsible 177  * for this execution 178  */ 179  CALLVALUE(0x34, 0, 1, BASE_TIER), 180  /** 181  * (0x35) Get input data of current 182  * environment 183  */ 184  CALLDATALOAD(0x35, 1, 1, VERY_LOW_TIER), 185  /** 186  * (0x36) Get size of input data in current 187  * environment 188  */ 189  CALLDATASIZE(0x36, 0, 1, BASE_TIER), 190  /** 191  * (0x37) Copy input data in current 192  * environment to memory 193  */ 194  CALLDATACOPY(0x37, 3, 0, VERY_LOW_TIER), 195  /** 196  * (0x38) Get size of code running in 197  * current environment 198  */ 199  CODESIZE(0x38, 0, 1, BASE_TIER), 200  /** 201  * (0x39) Copy code running in current 202  * environment to memory 203  */ 204  CODECOPY(0x39, 3, 0, VERY_LOW_TIER), // [len code_start mem_start CODECOPY] 205  /** 206  * (0x3a) Get price of gas in current 207  * environment 208  */ 209  GASPRICE(0x3a, 0, 1, BASE_TIER), 210  /** 211  * (0x3b) Get size of code running in 212  * current environment with given offset 213  */ 214  EXTCODESIZE(0x3b, 1, 1, EXT_TIER), 215  /** 216  * (0x3c) Copy code running in current 217  * environment to memory with given offset 218  */ 219  EXTCODECOPY(0x3c, 4, 0, EXT_TIER), 220  /** 221  * (0x3d and 0x3e) A mechanism to allow 222  * returning arbitrary-length data. 223  * After a call, return data is kept inside 224  * a virtual buffer from which the caller 225  * can copy it (or parts thereof) into 226  * memory. At the next call, the buffer is 227  * overwritten. 228  */ 229  RETURNDATASIZE(0x3d, 0, 1, BASE_TIER), 230  RETURNDATACOPY(0x3e, 3, 0, VERY_LOW_TIER), 231  232  /** 233  * (0x3f) Get hash of code running in current 234  * environment 235  */ 236  EXTCODEHASH(0x3f, 1, 1, EXT_TIER), 237  238  /* Block Information */ 239  240  /** 241  * (0x40) Get hash of most recent 242  * complete block 243  */ 244  BLOCKHASH(0x40, 1, 1, EXT_TIER), 245  /** 246  * (0x41) Get the block’s coinbase address 247  */ 248  COINBASE(0x41, 0, 1, BASE_TIER), 249  /** 250  * (x042) Get the block’s timestamp 251  */ 252  TIMESTAMP(0x42, 0, 1, BASE_TIER), 253  /** 254  * (0x43) Get the block’s number 255  */ 256  NUMBER(0x43, 0, 1, BASE_TIER), 257  /** 258  * (0x44) Get the block’s difficulty 259  */ 260  DIFFICULTY(0x44, 0, 1, BASE_TIER), 261  /** 262  * (0x45) Get the block’s gas limit 263  */ 264  GASLIMIT(0x45, 0, 1, BASE_TIER), 265  /** 266  * (0x47) Get the senders balance 267  */ 268  SELFBALANCE(0x47, 0, 1, LOW_TIER), 269  270  /** 271  * (0x46) Get the chain id 272  */ 273  CHAINID(0x46, 0, 1, BASE_TIER), 274  275  /* Memory, Storage and Flow Operations */ 276  277  /** 278  * (0x50) Remove item from stack 279  */ 280  POP(0x50, 1, 0, BASE_TIER), 281  /** 282  * (0x51) Load word from memory 283  */ 284  MLOAD(0x51, 1, 1, VERY_LOW_TIER), 285  /** 286  * (0x52) Save word to memory 287  */ 288  MSTORE(0x52, 2, 0, VERY_LOW_TIER), 289  /** 290  * `(0x53) Save byte to memory 291  */ 292  MSTORE8(0x53, 2, 0, VERY_LOW_TIER), 293  /** 294  * (0x54) Load word from storage 295  */ 296  SLOAD(0x54, 1, 1, SPECIAL_TIER), 297  /** 298  * (0x55) Save word to storage 299  */ 300  SSTORE(0x55, 2, 0, SPECIAL_TIER), 301  /** 302  * (0x56) Alter the program counter 303  */ 304  JUMP(0x56, 1, 0, MID_TIER), 305  /** 306  * (0x57) Conditionally alter the program 307  * counter 308  */ 309  JUMPI(0x57, 2, 0, HIGH_TIER), 310  /** 311  * (0x58) Get the program counter 312  */ 313  PC(0x58, 0, 1, BASE_TIER), 314  /** 315  * (0x59) Get the size of active memory 316  */ 317  MSIZE(0x59, 0, 1, BASE_TIER), 318  /** 319  * (0x5a) Get the amount of available gas 320  */ 321  GAS(0x5a, 0, 1, BASE_TIER), 322  /** 323  * (0x5b) 324  */ 325  JUMPDEST(0x5b, 0, 0, SPECIAL_TIER), 326  327  328  /* Push Operations */ 329  330  /** 331  * (0x60) Place 1-byte item on stack 332  */ 333  PUSH1(0x60, 0, 1, VERY_LOW_TIER), 334  /** 335  * (0x61) Place 2-byte item on stack 336  */ 337  PUSH2(0x61, 0, 1, VERY_LOW_TIER), 338  /** 339  * (0x62) Place 3-byte item on stack 340  */ 341  PUSH3(0x62, 0, 1, VERY_LOW_TIER), 342  /** 343  * (0x63) Place 4-byte item on stack 344  */ 345  PUSH4(0x63, 0, 1, VERY_LOW_TIER), 346  /** 347  * (0x64) Place 5-byte item on stack 348  */ 349  PUSH5(0x64, 0, 1, VERY_LOW_TIER), 350  /** 351  * (0x65) Place 6-byte item on stack 352  */ 353  PUSH6(0x65, 0, 1, VERY_LOW_TIER), 354  /** 355  * (0x66) Place 7-byte item on stack 356  */ 357  PUSH7(0x66, 0, 1, VERY_LOW_TIER), 358  /** 359  * (0x67) Place 8-byte item on stack 360  */ 361  PUSH8(0x67, 0, 1, VERY_LOW_TIER), 362  /** 363  * (0x68) Place 9-byte item on stack 364  */ 365  PUSH9(0x68, 0, 1, VERY_LOW_TIER), 366  /** 367  * (0x69) Place 10-byte item on stack 368  */ 369  PUSH10(0x69, 0, 1, VERY_LOW_TIER), 370  /** 371  * (0x6a) Place 11-byte item on stack 372  */ 373  PUSH11(0x6a, 0, 1, VERY_LOW_TIER), 374  /** 375  * (0x6b) Place 12-byte item on stack 376  */ 377  PUSH12(0x6b, 0, 1, VERY_LOW_TIER), 378  /** 379  * (0x6c) Place 13-byte item on stack 380  */ 381  PUSH13(0x6c, 0, 1, VERY_LOW_TIER), 382  /** 383  * (0x6d) Place 14-byte item on stack 384  */ 385  PUSH14(0x6d, 0, 1, VERY_LOW_TIER), 386  /** 387  * (0x6e) Place 15-byte item on stack 388  */ 389  PUSH15(0x6e, 0, 1, VERY_LOW_TIER), 390  /** 391  * (0x6f) Place 16-byte item on stack 392  */ 393  PUSH16(0x6f, 0, 1, VERY_LOW_TIER), 394  /** 395  * (0x70) Place 17-byte item on stack 396  */ 397  PUSH17(0x70, 0, 1, VERY_LOW_TIER), 398  /** 399  * (0x71) Place 18-byte item on stack 400  */ 401  PUSH18(0x71, 0, 1, VERY_LOW_TIER), 402  /** 403  * (0x72) Place 19-byte item on stack 404  */ 405  PUSH19(0x72, 0, 1, VERY_LOW_TIER), 406  /** 407  * (0x73) Place 20-byte item on stack 408  */ 409  PUSH20(0x73, 0, 1, VERY_LOW_TIER), 410  /** 411  * (0x74) Place 21-byte item on stack 412  */ 413  PUSH21(0x74, 0, 1, VERY_LOW_TIER), 414  /** 415  * (0x75) Place 22-byte item on stack 416  */ 417  PUSH22(0x75, 0, 1, VERY_LOW_TIER), 418  /** 419  * (0x76) Place 23-byte item on stack 420  */ 421  PUSH23(0x76, 0, 1, VERY_LOW_TIER), 422  /** 423  * (0x77) Place 24-byte item on stack 424  */ 425  PUSH24(0x77, 0, 1, VERY_LOW_TIER), 426  /** 427  * (0x78) Place 25-byte item on stack 428  */ 429  PUSH25(0x78, 0, 1, VERY_LOW_TIER), 430  /** 431  * (0x79) Place 26-byte item on stack 432  */ 433  PUSH26(0x79, 0, 1, VERY_LOW_TIER), 434  /** 435  * (0x7a) Place 27-byte item on stack 436  */ 437  PUSH27(0x7a, 0, 1, VERY_LOW_TIER), 438  /** 439  * (0x7b) Place 28-byte item on stack 440  */ 441  PUSH28(0x7b, 0, 1, VERY_LOW_TIER), 442  /** 443  * (0x7c) Place 29-byte item on stack 444  */ 445  PUSH29(0x7c, 0, 1, VERY_LOW_TIER), 446  /** 447  * (0x7d) Place 30-byte item on stack 448  */ 449  PUSH30(0x7d, 0, 1, VERY_LOW_TIER), 450  /** 451  * (0x7e) Place 31-byte item on stack 452  */ 453  PUSH31(0x7e, 0, 1, VERY_LOW_TIER), 454  /** 455  * (0x7f) Place 32-byte (full word) 456  * item on stack 457  */ 458  PUSH32(0x7f, 0, 1, VERY_LOW_TIER), 459  460  /* Duplicate Nth item from the stack */ 461  462  /* DUPn code "consumes" n elements from stack and pushes (n+1) elements */ 463  464  /** 465  * (0x80) Duplicate 1st item on stack 466  */ 467  DUP1(0x80, 1, 2, VERY_LOW_TIER), 468  /** 469  * (0x81) Duplicate 2nd item on stack 470  */ 471  DUP2(0x81, 2, 3, VERY_LOW_TIER), 472  /** 473  * (0x82) Duplicate 3rd item on stack 474  */ 475  DUP3(0x82, 3, 4, VERY_LOW_TIER), 476  /** 477  * (0x83) Duplicate 4th item on stack 478  */ 479  DUP4(0x83, 4, 5, VERY_LOW_TIER), 480  /** 481  * (0x84) Duplicate 5th item on stack 482  */ 483  DUP5(0x84, 5, 6, VERY_LOW_TIER), 484  /** 485  * (0x85) Duplicate 6th item on stack 486  */ 487  DUP6(0x85, 6, 7, VERY_LOW_TIER), 488  /** 489  * (0x86) Duplicate 7th item on stack 490  */ 491  DUP7(0x86, 7, 8, VERY_LOW_TIER), 492  /** 493  * (0x87) Duplicate 8th item on stack 494  */ 495  DUP8(0x87, 8, 9, VERY_LOW_TIER), 496  /** 497  * (0x88) Duplicate 9th item on stack 498  */ 499  DUP9(0x88, 9, 10, VERY_LOW_TIER), 500  /** 501  * (0x89) Duplicate 10th item on stack 502  */ 503  DUP10(0x89, 10, 11, VERY_LOW_TIER), 504  /** 505  * (0x8a) Duplicate 11th item on stack 506  */ 507  DUP11(0x8a, 11, 12, VERY_LOW_TIER), 508  /** 509  * (0x8b) Duplicate 12th item on stack 510  */ 511  DUP12(0x8b, 12, 13, VERY_LOW_TIER), 512  /** 513  * (0x8c) Duplicate 13th item on stack 514  */ 515  DUP13(0x8c, 13, 14, VERY_LOW_TIER), 516  /** 517  * (0x8d) Duplicate 14th item on stack 518  */ 519  DUP14(0x8d, 14, 15, VERY_LOW_TIER), 520  /** 521  * (0x8e) Duplicate 15th item on stack 522  */ 523  DUP15(0x8e, 15, 16, VERY_LOW_TIER), 524  /** 525  * (0x8f) Duplicate 16th item on stack 526  */ 527  DUP16(0x8f, 16, 17, VERY_LOW_TIER), 528  529  /* Swap the Nth item from the stack with the top */ 530  531  /** 532  * (0x90) Exchange 2nd item from stack with the top 533  */ 534  SWAP1(0x90, 2, 2, VERY_LOW_TIER), 535  /** 536  * (0x91) Exchange 3rd item from stack with the top 537  */ 538  SWAP2(0x91, 3, 3, VERY_LOW_TIER), 539  /** 540  * (0x92) Exchange 4th item from stack with the top 541  */ 542  SWAP3(0x92, 4, 4, VERY_LOW_TIER), 543  /** 544  * (0x93) Exchange 5th item from stack with the top 545  */ 546  SWAP4(0x93, 5, 5, VERY_LOW_TIER), 547  /** 548  * (0x94) Exchange 6th item from stack with the top 549  */ 550  SWAP5(0x94, 6, 6, VERY_LOW_TIER), 551  /** 552  * (0x95) Exchange 7th item from stack with the top 553  */ 554  SWAP6(0x95, 7, 7, VERY_LOW_TIER), 555  /** 556  * (0x96) Exchange 8th item from stack with the top 557  */ 558  SWAP7(0x96, 8, 8, VERY_LOW_TIER), 559  /** 560  * (0x97) Exchange 9th item from stack with the top 561  */ 562  SWAP8(0x97, 9, 9, VERY_LOW_TIER), 563  /** 564  * (0x98) Exchange 10th item from stack with the top 565  */ 566  SWAP9(0x98, 10, 10, VERY_LOW_TIER), 567  /** 568  * (0x99) Exchange 11th item from stack with the top 569  */ 570  SWAP10(0x99, 11, 11, VERY_LOW_TIER), 571  /** 572  * (0x9a) Exchange 12th item from stack with the top 573  */ 574  SWAP11(0x9a, 12, 12, VERY_LOW_TIER), 575  /** 576  * (0x9b) Exchange 13th item from stack with the top 577  */ 578  SWAP12(0x9b, 13, 13, VERY_LOW_TIER), 579  /** 580  * (0x9c) Exchange 14th item from stack with the top 581  */ 582  SWAP13(0x9c, 14, 14, VERY_LOW_TIER), 583  /** 584  * (0x9d) Exchange 15th item from stack with the top 585  */ 586  SWAP14(0x9d, 15, 15, VERY_LOW_TIER), 587  /** 588  * (0x9e) Exchange 16th item from stack with the top 589  */ 590  SWAP15(0x9e, 16, 16, VERY_LOW_TIER), 591  /** 592  * (0x9f) Exchange 17th item from stack with the top 593  */ 594  SWAP16(0x9f, 17, 17, VERY_LOW_TIER), 595  596  /** 597  * (0xa[n]) log some data for some addres with 0..n tags [addr [tag0..tagn] data] 598  */ 599  LOG0(0xa0, 2, 0, SPECIAL_TIER), 600  LOG1(0xa1, 3, 0, SPECIAL_TIER), 601  LOG2(0xa2, 4, 0, SPECIAL_TIER), 602  LOG3(0xa3, 5, 0, SPECIAL_TIER), 603  LOG4(0xa4, 6, 0, SPECIAL_TIER), 604  605  606  /** 607  * DUPN 608  */ 609  DUPN(0xa8, 2, 2, VERY_LOW_TIER), 610  611  /** 612  * SWAPN 613  */ 614  SWAPN(0xa9, 3, 2, VERY_LOW_TIER), 615  616  /** 617  * TXINDEX 618  */ 619  TXINDEX(0xaa, 0, 1, BASE_TIER), 620  621  /* System operations */ 622  623  /** 624  * (0xf0) Create a new account with associated code 625  */ 626  CREATE(0xf0, 3, 1, SPECIAL_TIER), // [in_size] [in_offs] [gas_val] CREATE 627  /** 628  * (cxf1) Message-call into an account 629  */ 630  CALL(0xf1, 7, 1, SPECIAL_TIER), // [out_data_size] [out_data_start] [in_data_size] [in_data_start] [value] [to_addr] 631  // [gas] CALL 632  /** 633  * (0xf2) Calls self, but grabbing the code from the 634  * TO argument instead of from one's own address 635  */ 636  CALLCODE(0xf2, 7, 1, SPECIAL_TIER), 637  /** 638  * (0xf3) Halt execution returning output data 639  */ 640  RETURN(0xf3, 2, 0, ZERO_TIER), 641  642  /** 643  * (0xf4) similar in idea to CALLCODE, except that it propagates the sender and value 644  * from the parent scope to the child scope, ie. the call created has the same sender 645  * and value as the original call. 646  * also the Value parameter is omitted for this code 647  */ 648  DELEGATECALL(0xf4, 6, 1, SPECIAL_TIER), 649  650  /** 651  * (0xf5) Skinny CREATE2, same as CREATE but with deterministic address 652  */ 653  CREATE2(0xf5, 4, 1, SPECIAL_TIER), 654  655  /** 656  * (0xfc) Halt execution as an invalid opcode 657  * setting version==256 assures it's never considered valid. 658  * (because scriptVersion range is 0..255) 659  */ 660  HEADER(0xfc, 0, 0, ZERO_TIER,256), 661  662  /** 663  * opcode that can be used to call another contract (or itself) while disallowing any 664  * modifications to the state during the call (and its subcalls, if present). 665  * Any opcode that attempts to perform such a modification (see below for details) 666  * will result in an exception instead of performing the modification. 667  */ 668  STATICCALL(0xfa, 6, 1, SPECIAL_TIER), 669  /** 670  * (0xfd) The `REVERT` instruction will stop execution, roll back all state changes done so far 671  * and provide a pointer to a memory section, which can be interpreted as an error code or message. 672  * While doing so, it will not consume all the remaining gas. 673  */ 674  REVERT(0xfd, 2, 0, ZERO_TIER), 675  676  /** 677  * (0xff) Halt execution and register account for 678  * later deletion 679  */ 680  SUICIDE(0xff, 1, 0, ZERO_TIER); 681  682  private final byte code; 683  private final int require; 684  private final Tier tier; 685  private final int ret; 686  private final int scriptVersion; 687  688  private static final Map<String, Byte> stringToByteMap = new HashMap<>(); 689  private static final OpCode[] intToTypeFastMap = new OpCode[256]; // 690  static { 691  for (OpCode type : OpCode.values()) { 692  if (type.code <0) { 693  intToTypeFastMap[256+type.code]=type; 694  } else { 695  intToTypeFastMap[type.code]=type; 696  } 697  698  stringToByteMap.put(type.name(), type.code); 699  } 700  } 701  702  //require = required elements 703  //return = required return 704  OpCode(int code, int require, int ret, Tier tier) { 705  this.code = (byte) code; 706  this.require = require; 707  this.tier = tier; 708  this.ret = ret; 709  scriptVersion = 0; 710  } 711  712  OpCode(int code, int require, int ret, Tier tier, int scriptVersion) { 713  this.code = (byte) code; 714  this.require = require; 715  this.tier = tier; 716  this.ret = ret; 717  this.scriptVersion = scriptVersion; 718  } 719  720  public byte val() { 721  return code; 722  } 723  724  /** 725  * Returns the mininum amount of items required on the stack for this operation 726  * 727  * @return minimum amount of expected items on the stack 728  */ 729  public int require() { 730  return require; 731  } 732  733  public int ret() { 734  return ret; 735  } 736  737  public int asInt() { 738  return code; 739  } 740  741  public int scriptVersion() { return scriptVersion; } 742  743  public static boolean contains(String code) { 744  return stringToByteMap.containsKey(code.trim()); 745  } 746  747  public static byte byteVal(String code) { 748  return stringToByteMap.get(code); 749  } 750  751  public static OpCode code(byte code) { 752  if (code<0) { 753  return intToTypeFastMap[256+code]; 754  } else { 755  return intToTypeFastMap[code]; 756  } 757  } 758  759  public Tier getTier() { 760  return this.tier; 761  } 762  763  public enum Tier { 764  ZERO_TIER(0), 765  BASE_TIER(2), 766  VERY_LOW_TIER(3), 767  LOW_TIER(5), 768  MID_TIER(8), 769  HIGH_TIER(10), 770  EXT_TIER(20), 771  SPECIAL_TIER(1), 772  INVALID_TIER(0); 773  774  775  private final int level; 776  777  Tier(int level) { 778  this.level = level; 779  } 780  781  public int asInt() { 782  return level; 783  } 784  } 785 } 786  787