Ethereum  PoC-8
The C++ Implementation of Ethereum
EVMC.h
Go to the documentation of this file.
1 // Copyright 2018 cpp-ethereum Authors.
2 // Licensed under the GNU General Public License v3. See the LICENSE file.
3 
4 #pragma once
5 
6 #include <libevm/VMFace.h>
7 
8 #include <evmc/evmc.h>
9 #include <evmc/helpers.h>
10 
11 namespace dev
12 {
13 namespace eth
14 {
15 
17 class EVM
18 {
19 public:
20  explicit EVM(evmc_instance* _instance) noexcept;
21 
22  ~EVM() { evmc_destroy(m_instance); }
23 
24  EVM(EVM const&) = delete;
25  EVM& operator=(EVM) = delete;
26 
27  char const* name() const noexcept { return evmc_vm_name(m_instance); }
28 
29  char const* version() const noexcept { return evmc_vm_version(m_instance); }
30 
31  class Result
32  {
33  public:
34  explicit Result(evmc_result const& _result):
35  m_result(_result)
36  {}
37 
39  {
40  if (m_result.release)
41  m_result.release(&m_result);
42  }
43 
44  Result(Result&& _other) noexcept:
45  m_result(_other.m_result)
46  {
47  // Disable releaser of the rvalue object.
48  _other.m_result.release = nullptr;
49  }
50 
51  Result(Result const&) = delete;
52  Result& operator=(Result const&) = delete;
53 
54  evmc_status_code status() const
55  {
56  return m_result.status_code;
57  }
58 
59  int64_t gasLeft() const
60  {
61  return m_result.gas_left;
62  }
63 
65  {
66  return {m_result.output_data, m_result.output_size};
67  }
68 
69  private:
70  evmc_result m_result;
71  };
72 
74  Result execute(ExtVMFace& _ext, int64_t gas);
75 
77  static evmc_revision toRevision(EVMSchedule const& _schedule);
78 
79 private:
81  evmc_instance* m_instance = nullptr;
82 };
83 
84 
86 class EVMC : public EVM, public VMFace
87 {
88 public:
89  explicit EVMC(evmc_instance* _instance) : EVM(_instance) {}
90 
91  owning_bytes_ref exec(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp) final;
92 };
93 }
94 }
owning_bytes_ref exec(u256 &io_gas, ExtVMFace &_ext, OnOpFunc const &_onOp) final
VM implementation.
Definition: EVMC.cpp:52
Definition: Address.cpp:20
std::function< void(uint64_t, uint64_t, Instruction, bigint, bigint, bigint, VMFace const *, ExtVMFace const *)> OnOpFunc
Definition: ExtVMFace.h:115
Result(evmc_result const &_result)
Definition: EVMC.h:34
EVMC(evmc_instance *_instance)
Definition: EVMC.h:89
evmc_status_code status() const
Definition: EVMC.h:54
char const * version() const noexcept
Definition: EVMC.h:29
static evmc_revision toRevision(EVMSchedule const &_schedule)
Translate the EVMSchedule to EVMC revision.
Definition: EVMC.cpp:119
bytesConstRef output() const
Definition: EVMC.h:64
EVM(evmc_instance *_instance) noexcept
Definition: EVMC.cpp:13
Result & operator=(Result const &)=delete
int64_t gasLeft() const
Definition: EVMC.h:59
Result execute(ExtVMFace &_ext, int64_t gas)
Handy wrapper for evmc_execute().
Definition: EVMC.cpp:39
char const * name() const noexcept
Definition: EVMC.h:27
EVM Virtual Machine interface.
Definition: VMFace.h:63
Interface and null implementation of the class for specifying VM externalities.
Definition: ExtVMFace.h:203
EVM & operator=(EVM)=delete
The RAII wrapper for an EVMC instance.
Definition: EVMC.h:17
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void > > u256
Definition: Common.h:121
The wrapper implementing the VMFace interface with a EVMC VM as a backend.
Definition: EVMC.h:86
Result(Result &&_other) noexcept
Definition: EVMC.h:44