Fabcoin Core  0.16.2
P2P Digital Currency
ExtVM.h
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
22 #pragma once
23 
24 #include <map>
25 #include <functional>
26 #include <libethcore/Common.h>
27 #include <libevm/ExtVMFace.h>
28 #include <libethcore/SealEngine.h>
29 #include "State.h"
30 #include "Executive.h"
31 
32 namespace dev
33 {
34 namespace eth
35 {
36 
37 class SealEngineFace;
38 
42 class ExtVM: public ExtVMFace
43 {
44 public:
46  ExtVM(State& _s, EnvInfo const& _envInfo, SealEngineFace const& _sealEngine, Address _myAddress, Address _caller, Address _origin, u256 _value, u256 _gasPrice, bytesConstRef _data, bytesConstRef _code, h256 const& _codeHash, unsigned _depth = 0):
47  ExtVMFace(_envInfo, _myAddress, _caller, _origin, _value, _gasPrice, _data, _code.toBytes(), _codeHash, _depth), m_s(_s), m_sealEngine(_sealEngine)
48  {
49  // Contract: processing account must exist. In case of CALL, the ExtVM
50  // is created only if an account has code (so exist). In case of CREATE
51  // the account must be created first.
52  assert(m_s.addressInUse(_myAddress));
53  }
54 
56  virtual u256 store(u256 _n) override final { return m_s.storage(myAddress, _n); }
57 
59  virtual void setStore(u256 _n, u256 _v) override final;
60 
62  virtual bytes const& codeAt(Address _a) override final { return m_s.code(_a); }
63 
65  virtual size_t codeSizeAt(Address _a) override final;
66 
68  virtual h160 create(u256 _endowment, u256& io_gas, bytesConstRef _code, OnOpFunc const& _onOp = {}) override final;
69 
71  virtual boost::optional<owning_bytes_ref> call(CallParameters& _params) override final;
72 
74  virtual u256 balance(Address _a) override final { return m_s.balance(_a); }
75 
77  virtual bool exists(Address _a) override final
78  {
79  if (evmSchedule().emptinessIsNonexistence())
81  else
82  return m_s.addressInUse(_a);
83  }
84 
86  virtual void suicide(Address _a) override final;
87 
89  virtual EVMSchedule const& evmSchedule() const override final { return m_sealEngine.evmSchedule(envInfo()); }
90 
91  State const& state() const { return m_s; }
92 
93 private:
96 };
97 
98 }
99 }
100 
bool addressInUse(Address const &_address) const
Check if the address is in use.
Definition: State.cpp:245
u256 balance(Address const &_id) const
Get an account&#39;s balance.
Definition: State.cpp:266
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
bool accountNonemptyAndExisting(Address const &_address) const
Check if the account exists in the state and is non empty (nonce > 0 || balance > 0 || code nonempty)...
Definition: State.cpp:250
virtual bool exists(Address _a) overridefinal
Does the account exist?
Definition: ExtVM.h:77
virtual boost::optional< owning_bytes_ref > call(CallParameters &_params) overridefinal
Create a new message call. Leave _myAddressOverride as the default to use the present address as call...
Definition: ExtVM.cpp:95
State & m_s
A reference to the base state.
Definition: ExtVM.h:94
virtual void suicide(Address _a) overridefinal
Suicide the associated contract to the given address.
Definition: ExtVM.cpp:133
EnvInfo const & envInfo() const
Get the execution environment information.
Definition: ExtVMFace.h:313
ExtVM(State &_s, EnvInfo const &_envInfo, SealEngineFace const &_sealEngine, Address _myAddress, Address _caller, Address _origin, u256 _value, u256 _gasPrice, bytesConstRef _data, bytesConstRef _code, h256 const &_codeHash, unsigned _depth=0)
Full constructor.
Definition: ExtVM.h:46
assert(len-trim+(2 *lenIndices)<=WIDTH)
Model of an Ethereum state, essentially a facade for the trie.
Definition: State.h:161
virtual EVMSchedule const & evmSchedule() const overridefinal
Return the EVM gas-price schedule for this execution context.
Definition: ExtVM.h:89
virtual h160 create(u256 _endowment, u256 &io_gas, bytesConstRef _code, OnOpFunc const &_onOp={}) overridefinal
Create a new contract.
Definition: ExtVM.cpp:121
virtual u256 balance(Address _a) overridefinal
Read address&#39;s balance.
Definition: ExtVM.h:74
virtual size_t codeSizeAt(Address _a) overridefinal
Definition: ExtVM.cpp:111
std::vector< byte > bytes
Definition: Common.h:75
u256 storage(Address const &_contract, u256 const &_memory) const
Get the value of a storage position of an account.
Definition: State.cpp:353
Fixed-size raw-byte array container type, with an API optimised for storing hashes.
Definition: FixedHash.h:47
std::function< void(uint64_t, uint64_t, Instruction, bigint, bigint, bigint, VM *, ExtVMFace const *)> OnOpFunc
Definition: ExtVMFace.h:193
virtual bytes const & codeAt(Address _a) overridefinal
Read address&#39;s code.
Definition: ExtVM.h:62
bytes const & code(Address const &_addr) const
Get the code of an account.
Definition: State.cpp:423
virtual u256 store(u256 _n) overridefinal
Read storage location.
Definition: ExtVM.h:56
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
Definition: Common.h:125
SealEngineFace const & m_sealEngine
Definition: ExtVM.h:95
Interface and null implementation of the class for specifying VM externalities.
Definition: ExtVMFace.h:265
virtual EVMSchedule const & evmSchedule(EnvInfo const &) const =0
Address myAddress
Address associated with executing code (a contract, or contract-to-be).
Definition: ExtVMFace.h:323
Externality interface for the Virtual Machine providing access to world state.
Definition: ExtVM.h:42
State const & state() const
Definition: ExtVM.h:91
virtual void setStore(u256 _n, u256 _v) overridefinal
Write a value in storage.
Definition: ExtVM.cpp:116