Fabcoin Core  0.16.2
P2P Digital Currency
JIT.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cstdint>
4 #include <cstring>
5 #include <functional>
6 #include <type_traits>
7 
8 #include <evmjit.h>
9 
10 namespace dev
11 {
12 namespace evmjit
13 {
14 
15 using byte = uint8_t;
16 using bytes_ref = std::tuple<byte const*, size_t>;
17 
19 struct i256
20 {
21  uint64_t words[4];
22 
23  i256() = default;
24 };
25 
26 // TODO: Merge with ExecutionContext
28 {
29  enum Index
30  {
31  Gas,
35  ApparentCallValue, // value of msg.value - different during DELEGATECALL
38 
39  ReturnData = CallData,
40  ReturnDataSize = CallDataSize,
41  };
42 
43  static size_t const numElements = CodeSize + 1;
44 
45  int64_t gas = 0;
46  int64_t gasPrice = 0;
47  byte const* callData = nullptr;
48  uint64_t callDataSize = 0;
50  byte const* code = nullptr;
51  uint64_t codeSize = 0;
52 };
53 
55 {
56  // TODO: Move to constexpr once all our target compilers support it.
57  typedef std::integral_constant<uint64_t, 1024> stackLimit;
58  typedef std::integral_constant<uint64_t, 0> stepGas0;
59  typedef std::integral_constant<uint64_t, 2> stepGas1;
60  typedef std::integral_constant<uint64_t, 3> stepGas2;
61  typedef std::integral_constant<uint64_t, 5> stepGas3;
62  typedef std::integral_constant<uint64_t, 8> stepGas4;
63  typedef std::integral_constant<uint64_t, 10> stepGas5;
64  typedef std::integral_constant<uint64_t, 20> stepGas6;
65  typedef std::integral_constant<uint64_t, 0> stepGas7;
66  typedef std::integral_constant<uint64_t, 10> expByteGas;
67  typedef std::integral_constant<uint64_t, 30> sha3Gas;
68  typedef std::integral_constant<uint64_t, 6> sha3WordGas;
69  typedef std::integral_constant<uint64_t, 50> sloadGas;
70  typedef std::integral_constant<uint64_t, 20000> sstoreSetGas;
71  typedef std::integral_constant<uint64_t, 5000> sstoreResetGas;
72  typedef std::integral_constant<uint64_t, 5000> sstoreClearGas;
73  typedef std::integral_constant<uint64_t, 1> jumpdestGas;
74  typedef std::integral_constant<uint64_t, 375> logGas;
75  typedef std::integral_constant<uint64_t, 8> logDataGas;
76  typedef std::integral_constant<uint64_t, 375> logTopicGas;
77  typedef std::integral_constant<uint64_t, 32000> createGas;
78  typedef std::integral_constant<uint64_t, 40> callGas;
79  typedef std::integral_constant<uint64_t, 3> memoryGas;
80  typedef std::integral_constant<uint64_t, 3> copyGas;
81  typedef std::integral_constant<uint64_t, 9000> valueTransferGas;
82  typedef std::integral_constant<uint64_t, 2300> callStipend;
83  typedef std::integral_constant<uint64_t, 25000> callNewAccount;
84 };
85 
86 enum class ReturnCode
87 {
88  // Success codes
89  Stop = 0,
90  Return = 1,
91 
92  // Standard error codes
93  OutOfGas = -1,
94 
95  // Internal error codes
96  LLVMError = -101,
97 
98  UnexpectedException = -111,
99 };
100 
102 {
103 public:
104  ExecutionContext() = default;
105  ExecutionContext(RuntimeData& _data, evm_env* _env) { init(_data, _env); }
106  ExecutionContext(ExecutionContext const&) = delete;
107  ExecutionContext& operator=(ExecutionContext const&) = delete;
108  ~ExecutionContext() noexcept;
109 
110  void init(RuntimeData& _data, evm_env* _env) { m_data = &_data; m_env = _env; }
111 
112  byte const* code() const { return m_data->code; }
113  uint64_t codeSize() const { return m_data->codeSize; }
114 
115  bytes_ref getReturnData() const;
116 
117 public:
118  RuntimeData* m_data = nullptr;
119  evm_env* m_env = nullptr;
120  byte* m_memData = nullptr;
121  uint64_t m_memSize = 0;
122  uint64_t m_memCap = 0;
123 
124 public:
127 };
128 
129 }
130 }
std::integral_constant< uint64_t, 10 > stepGas5
Definition: JIT.h:63
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
uint8_t byte
Definition: Common.h:57
uint64_t words[4]
Definition: JIT.h:21
std::integral_constant< uint64_t, 0 > stepGas0
Definition: JIT.h:58
std::integral_constant< uint64_t, 2300 > callStipend
Definition: JIT.h:82
std::integral_constant< uint64_t, 0 > stepGas7
Definition: JIT.h:65
byte const * code() const
Definition: JIT.h:112
std::integral_constant< uint64_t, 3 > memoryGas
Definition: JIT.h:79
std::integral_constant< uint64_t, 3 > stepGas2
Definition: JIT.h:60
std::integral_constant< uint64_t, 8 > logDataGas
Definition: JIT.h:75
std::integral_constant< uint64_t, 375 > logTopicGas
Definition: JIT.h:76
std::integral_constant< uint64_t, 5 > stepGas3
Definition: JIT.h:61
std::integral_constant< uint64_t, 50 > sloadGas
Definition: JIT.h:69
std::integral_constant< uint64_t, 30 > sha3Gas
Definition: JIT.h:67
std::integral_constant< uint64_t, 1 > jumpdestGas
Definition: JIT.h:73
bytes code
Definition: SmartVM.cpp:45
bytes_ref returnData
Reference to returned data (RETURN opcode used)
Definition: JIT.h:126
void init(RuntimeData &_data, evm_env *_env)
Definition: JIT.h:110
std::integral_constant< uint64_t, 8 > stepGas4
Definition: JIT.h:62
std::integral_constant< uint64_t, 3 > copyGas
Definition: JIT.h:80
std::integral_constant< uint64_t, 40 > callGas
Definition: JIT.h:78
std::integral_constant< uint64_t, 9000 > valueTransferGas
Definition: JIT.h:81
std::integral_constant< uint64_t, 1024 > stackLimit
Definition: JIT.h:57
std::integral_constant< uint64_t, 25000 > callNewAccount
Definition: JIT.h:83
std::integral_constant< uint64_t, 20 > stepGas6
Definition: JIT.h:64
std::integral_constant< uint64_t, 375 > logGas
Definition: JIT.h:74
ReturnCode
Definition: JIT.h:86
ExecutionContext(RuntimeData &_data, evm_env *_env)
Definition: JIT.h:105
std::tuple< byte const *, size_t > bytes_ref
Definition: JIT.h:16
std::integral_constant< uint64_t, 6 > sha3WordGas
Definition: JIT.h:68
uint64_t codeSize() const
Definition: JIT.h:113
uint8_t byte
Definition: Common.h:10
Representation of 256-bit value binary compatible with LLVM i256.
Definition: JIT.h:19
std::integral_constant< uint64_t, 5000 > sstoreResetGas
Definition: JIT.h:71
std::integral_constant< uint64_t, 5000 > sstoreClearGas
Definition: JIT.h:72
std::integral_constant< uint64_t, 32000 > createGas
Definition: JIT.h:77
std::integral_constant< uint64_t, 2 > stepGas1
Definition: JIT.h:59
std::integral_constant< uint64_t, 10 > expByteGas
Definition: JIT.h:66
std::integral_constant< uint64_t, 20000 > sstoreSetGas
Definition: JIT.h:70