evm.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #ifndef CAPSTONE_EVM_H
  2. #define CAPSTONE_EVM_H
  3. /* Capstone Disassembly Engine */
  4. /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2018 */
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. #include "platform.h"
  9. #ifdef _MSC_VER
  10. #pragma warning(disable:4201)
  11. #endif
  12. /// Instruction structure
  13. typedef struct cs_evm {
  14. unsigned char pop; ///< number of items popped from the stack
  15. unsigned char push; ///< number of items pushed into the stack
  16. unsigned int fee; ///< gas fee for the instruction
  17. } cs_evm;
  18. /// EVM instruction
  19. typedef enum evm_insn {
  20. EVM_INS_STOP = 0,
  21. EVM_INS_ADD = 1,
  22. EVM_INS_MUL = 2,
  23. EVM_INS_SUB = 3,
  24. EVM_INS_DIV = 4,
  25. EVM_INS_SDIV = 5,
  26. EVM_INS_MOD = 6,
  27. EVM_INS_SMOD = 7,
  28. EVM_INS_ADDMOD = 8,
  29. EVM_INS_MULMOD = 9,
  30. EVM_INS_EXP = 10,
  31. EVM_INS_SIGNEXTEND = 11,
  32. EVM_INS_LT = 16,
  33. EVM_INS_GT = 17,
  34. EVM_INS_SLT = 18,
  35. EVM_INS_SGT = 19,
  36. EVM_INS_EQ = 20,
  37. EVM_INS_ISZERO = 21,
  38. EVM_INS_AND = 22,
  39. EVM_INS_OR = 23,
  40. EVM_INS_XOR = 24,
  41. EVM_INS_NOT = 25,
  42. EVM_INS_BYTE = 26,
  43. EVM_INS_SHA3 = 32,
  44. EVM_INS_ADDRESS = 48,
  45. EVM_INS_BALANCE = 49,
  46. EVM_INS_ORIGIN = 50,
  47. EVM_INS_CALLER = 51,
  48. EVM_INS_CALLVALUE = 52,
  49. EVM_INS_CALLDATALOAD = 53,
  50. EVM_INS_CALLDATASIZE = 54,
  51. EVM_INS_CALLDATACOPY = 55,
  52. EVM_INS_CODESIZE = 56,
  53. EVM_INS_CODECOPY = 57,
  54. EVM_INS_GASPRICE = 58,
  55. EVM_INS_EXTCODESIZE = 59,
  56. EVM_INS_EXTCODECOPY = 60,
  57. EVM_INS_RETURNDATASIZE = 61,
  58. EVM_INS_RETURNDATACOPY = 62,
  59. EVM_INS_BLOCKHASH = 64,
  60. EVM_INS_COINBASE = 65,
  61. EVM_INS_TIMESTAMP = 66,
  62. EVM_INS_NUMBER = 67,
  63. EVM_INS_DIFFICULTY = 68,
  64. EVM_INS_GASLIMIT = 69,
  65. EVM_INS_POP = 80,
  66. EVM_INS_MLOAD = 81,
  67. EVM_INS_MSTORE = 82,
  68. EVM_INS_MSTORE8 = 83,
  69. EVM_INS_SLOAD = 84,
  70. EVM_INS_SSTORE = 85,
  71. EVM_INS_JUMP = 86,
  72. EVM_INS_JUMPI = 87,
  73. EVM_INS_PC = 88,
  74. EVM_INS_MSIZE = 89,
  75. EVM_INS_GAS = 90,
  76. EVM_INS_JUMPDEST = 91,
  77. EVM_INS_PUSH1 = 96,
  78. EVM_INS_PUSH2 = 97,
  79. EVM_INS_PUSH3 = 98,
  80. EVM_INS_PUSH4 = 99,
  81. EVM_INS_PUSH5 = 100,
  82. EVM_INS_PUSH6 = 101,
  83. EVM_INS_PUSH7 = 102,
  84. EVM_INS_PUSH8 = 103,
  85. EVM_INS_PUSH9 = 104,
  86. EVM_INS_PUSH10 = 105,
  87. EVM_INS_PUSH11 = 106,
  88. EVM_INS_PUSH12 = 107,
  89. EVM_INS_PUSH13 = 108,
  90. EVM_INS_PUSH14 = 109,
  91. EVM_INS_PUSH15 = 110,
  92. EVM_INS_PUSH16 = 111,
  93. EVM_INS_PUSH17 = 112,
  94. EVM_INS_PUSH18 = 113,
  95. EVM_INS_PUSH19 = 114,
  96. EVM_INS_PUSH20 = 115,
  97. EVM_INS_PUSH21 = 116,
  98. EVM_INS_PUSH22 = 117,
  99. EVM_INS_PUSH23 = 118,
  100. EVM_INS_PUSH24 = 119,
  101. EVM_INS_PUSH25 = 120,
  102. EVM_INS_PUSH26 = 121,
  103. EVM_INS_PUSH27 = 122,
  104. EVM_INS_PUSH28 = 123,
  105. EVM_INS_PUSH29 = 124,
  106. EVM_INS_PUSH30 = 125,
  107. EVM_INS_PUSH31 = 126,
  108. EVM_INS_PUSH32 = 127,
  109. EVM_INS_DUP1 = 128,
  110. EVM_INS_DUP2 = 129,
  111. EVM_INS_DUP3 = 130,
  112. EVM_INS_DUP4 = 131,
  113. EVM_INS_DUP5 = 132,
  114. EVM_INS_DUP6 = 133,
  115. EVM_INS_DUP7 = 134,
  116. EVM_INS_DUP8 = 135,
  117. EVM_INS_DUP9 = 136,
  118. EVM_INS_DUP10 = 137,
  119. EVM_INS_DUP11 = 138,
  120. EVM_INS_DUP12 = 139,
  121. EVM_INS_DUP13 = 140,
  122. EVM_INS_DUP14 = 141,
  123. EVM_INS_DUP15 = 142,
  124. EVM_INS_DUP16 = 143,
  125. EVM_INS_SWAP1 = 144,
  126. EVM_INS_SWAP2 = 145,
  127. EVM_INS_SWAP3 = 146,
  128. EVM_INS_SWAP4 = 147,
  129. EVM_INS_SWAP5 = 148,
  130. EVM_INS_SWAP6 = 149,
  131. EVM_INS_SWAP7 = 150,
  132. EVM_INS_SWAP8 = 151,
  133. EVM_INS_SWAP9 = 152,
  134. EVM_INS_SWAP10 = 153,
  135. EVM_INS_SWAP11 = 154,
  136. EVM_INS_SWAP12 = 155,
  137. EVM_INS_SWAP13 = 156,
  138. EVM_INS_SWAP14 = 157,
  139. EVM_INS_SWAP15 = 158,
  140. EVM_INS_SWAP16 = 159,
  141. EVM_INS_LOG0 = 160,
  142. EVM_INS_LOG1 = 161,
  143. EVM_INS_LOG2 = 162,
  144. EVM_INS_LOG3 = 163,
  145. EVM_INS_LOG4 = 164,
  146. EVM_INS_CREATE = 240,
  147. EVM_INS_CALL = 241,
  148. EVM_INS_CALLCODE = 242,
  149. EVM_INS_RETURN = 243,
  150. EVM_INS_DELEGATECALL = 244,
  151. EVM_INS_CALLBLACKBOX = 245,
  152. EVM_INS_STATICCALL = 250,
  153. EVM_INS_REVERT = 253,
  154. EVM_INS_SUICIDE = 255,
  155. EVM_INS_INVALID = 512,
  156. EVM_INS_ENDING, // <-- mark the end of the list of instructions
  157. } evm_insn;
  158. /// Group of EVM instructions
  159. typedef enum evm_insn_group {
  160. EVM_GRP_INVALID = 0, ///< = CS_GRP_INVALID
  161. EVM_GRP_JUMP, ///< all jump instructions
  162. EVM_GRP_MATH = 8, ///< math instructions
  163. EVM_GRP_STACK_WRITE, ///< instructions write to stack
  164. EVM_GRP_STACK_READ, ///< instructions read from stack
  165. EVM_GRP_MEM_WRITE, ///< instructions write to memory
  166. EVM_GRP_MEM_READ, ///< instructions read from memory
  167. EVM_GRP_STORE_WRITE, ///< instructions write to storage
  168. EVM_GRP_STORE_READ, ///< instructions read from storage
  169. EVM_GRP_HALT, ///< instructions halt execution
  170. EVM_GRP_ENDING, ///< <-- mark the end of the list of groups
  171. } evm_insn_group;
  172. #ifdef __cplusplus
  173. }
  174. #endif
  175. #endif