21 #include <boost/timer.hpp> 23 #include <json/json.h> 42 StandardTrace::StandardTrace()
45 StandardTrace::StandardTrace():
46 m_trace(
Json::arrayValue)
78 ExtVM const& ext =
dynamic_cast<ExtVM const&
>(*voidExt);
86 for (
auto const& i: vm.
stack())
91 bool newContext =
false;
114 cwarn <<
"GAA!!! Tracing VM and more than one new/deleted stack frame between steps!";
115 cwarn <<
"Attmepting naive recovery...";
122 for (
unsigned i = 0; i < vm.
memory().size(); i += 32)
127 r[
"memory"] = memJson;
135 r[
"storage"] = storage;
144 r[
"memexpand"] =
toString(newMemSize);
155 return _styled ? Json::StyledWriter().write(
m_trace) : Json::FastWriter().write(
m_trace);
160 m_s(_s.mutableState()),
161 m_envInfo(_s.info(), _bc.
lastHashes(_s.info().parentHash())),
163 m_sealEngine(*_bc.sealEngine())
168 m_s(_s.mutableState()),
176 m_s(_s = _block.fromPending(_txIndex)),
191 _parentContext +=
m_ext->sub;
263 CallParameters params{_senderAddress, _receiveAddress, _receiveAddress, _value, _value, _gas, _data, {}};
264 return call(params, _gasPrice, _senderAddress);
308 size_t outputSize = output.size();
319 m_ext = make_shared<ExtVM>(
m_s,
m_envInfo,
m_sealEngine, _p.
receiveAddress, _p.
senderAddress, _origin, _p.
apparentValue, _gasPrice, _p.
data, &
c,
codeHash,
m_depth);
356 m_ext = make_shared<ExtVM>(
m_s,
m_envInfo,
m_sealEngine,
m_newAddress, _sender, _origin, _endowment, _gasPrice,
bytesConstRef(), _init,
sha3(_init),
m_depth);
370 ExtVM const& ext = *
static_cast<ExtVM const*
>(voidExt);
374 o << endl <<
" STACK" << endl;
375 for (
auto i: vm.
stack())
376 o << (
h256)i << endl;
377 o <<
" MEMORY" << endl << ((vm.
memory().size() > 1000) ?
" mem size greater than 1000 bytes " :
memDump(vm.
memory()));
378 o <<
" STORAGE" << endl;
380 o << showbase << hex << i.second.first <<
": " << i.second.second << endl;
390 #if ETH_TIMED_EXECUTIONS 405 if (out.size() >
m_ext->evmSchedule().maxCodeSize)
407 else if (out.size() *
m_ext->evmSchedule().createDataGas <=
m_gas)
411 m_gas -= out.size() *
m_ext->evmSchedule().createDataGas;
415 if (
m_ext->evmSchedule().exceptionalFailedCodeDeposit)
446 cwarn <<
"Unexpected exception in VM. There may be a bug in this implementation. " << diagnostic_information(_e);
451 catch (std::exception
const& _e)
454 cwarn <<
"Unexpected std::exception in VM. Not enough RAM? " << _e.what();
459 #if ETH_TIMED_EXECUTIONS 460 cnote <<
"VM took:" << t.
elapsed() <<
"; gas used: " << (sgas - m_endGas);
470 m_ext->sub.refunds +=
m_ext->evmSchedule().suicideRefundGas *
m_ext->sub.suicides.size();
487 for (
auto a:
m_ext->sub.suicides)
bool addressInUse(Address const &_address) const
Check if the address is in use.
u256 balance(Address const &_id) const
Get an account's balance.
CodeDeposit codeDeposit
Failed if an attempted deposit failed due to lack of gas.
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
bool call(Address _receiveAddress, Address _txSender, u256 _txValue, u256 _gasPrice, bytesConstRef _txData, u256 _gas)
Set up the executive for evaluating a bare CALL (message call) operation.
bool create(Address _txSender, u256 _endowment, u256 _gasPrice, u256 _gas, bytesConstRef _code, Address _originAddress)
Set up the executive for evaluating a bare CREATE (contract-creation) operation.
std::string toHex(T const &_data, int _w=2, HexPrefix _prefix=HexPrefix::DontAdd)
ChainOperationParams const & chainParams() const
Implements the blockchain database.
h160 right160(h256 const &_t)
Convert the given value into h160 (160-bit unsigned integer) using the right 20 bytes.
void setNewCode(Address const &_address, bytes &&_code)
Sets the code of the account. Must only be called during / after contract creation.
copy input data in current environment to memory
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<>> bigint
void rollback(size_t _savepoint)
Revert all recent changes up to the given _savepoint savepoint.
u256 m_refunded
The amount of gas refunded.
Address const & author() const
Address const & sender() const
std::hash for asio::adress
assert(len-trim+(2 *lenIndices)<=WIDTH)
virtual std::pair< bool, bytes > executePrecompiled(Address const &_a, bytesConstRef _in, u256 const &) const
u256 const & gasUsed() const
static std::unique_ptr< VMFace > create()
Creates a VM instance of global kind (controlled by setKind() function).
std::string toString(string32 const &_s)
Make normal string from fixed-length string.
owning_bytes_ref m_output
Execution output.
int64_t baseGasRequired(EVMSchedule const &_es) const
std::shared_ptr< ExtVM > m_ext
The VM externality object for the VM execution or null if no VM is required. shared_ptr used only to ...
u256 const & number() const
std::vector< Instruction > m_lastInst
void accrueSubState(SubState &_parentContext)
Finalise an operation through accruing the substate into the parent context.
Model of an Ethereum state, essentially a facade for the trie.
bool go(OnOpFunc const &_onOp=OnOpFunc())
Executes (or continues execution of) the VM.
void revert()
Revert all changes made to the state by this execution.
Executive(State &_s, EnvInfo const &_envInfo, SealEngineFace const &_sealEngine, unsigned _level=0)
Simple constructor; executive will operate on given state, with the given environment info...
TransactionException m_excepted
Details if the VM's execution resulted in an exception.
u256 m_gas
The gas for EVM code execution. Initial amount before go() execution, final amount after go() executi...
int64_t m_baseGasRequired
The base amount of gas requried for executing this transaction.
std::vector< mutable_value_type > toVector() const
InstructionInfo instructionInfo(Instruction _inst)
Information on all the instructions.
Transaction const & t() const
Active model of a block within the block chain.
Ran out of gas executing code of the transaction.
LogEntries m_logs
The log entries created by this transaction. Set by finalize().
std::vector< h256 > LastHashes
virtual void kill(Address _a)
Delete an account (used for processing suicides).
std::string json(bool _styled=false) const
Base class for all exceptions.
std::string name
The name of the instruction.
EnvInfo m_envInfo
Information on the runtime environment.
void finalize()
Finalise a transaction previously set up with initialize().
message-call with another account's code only
std::vector< byte > bytes
vector_ref< byte const > bytesConstRef
bytes toCompactBigEndian(T _val, unsigned _min=0)
Convenience function for toBigEndian.
bytes const & memory() const
u256 storage(Address const &_contract, u256 const &_memory) const
Get the value of a storage position of an account.
u256 getNonce(Address const &_addr) const
Get the account nonce – the number of transactions it has sent.
Fixed-size raw-byte array container type, with an API optimised for storing hashes.
std::function< void(uint64_t, uint64_t, Instruction, bigint, bigint, bigint, VM *, ExtVMFace const *)> OnOpFunc
unsigned depth
Depth of the present call.
bytes const & data() const
bytes const & code(Address const &_addr) const
Get the code of an account.
copy code running in current environment to memory
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
std::string formatBalance(bigint const &_b)
User-friendly string representation of the amount _b in wei.
like CALLCODE but keeps caller's value and sender
Encodes a transaction, ready to be exported to or freshly imported from RLP.
TransactionException excepted
Instruction
Virtual machine bytecode instruction.
bytes rlpList()
Export a list of items in RLP format, returning a byte array.
copy external code (from another contract)
bool changesStorage(Instruction _inst)
void initialize(bytesConstRef _transaction)
Initializes the executive for evaluating a transaction. You must call finalize() at some point follow...
Interface and null implementation of the class for specifying VM externalities.
virtual EVMSchedule const & evmSchedule(EnvInfo const &) const =0
u256 u256Param(std::string const &_name) const
Convenience method to get an otherParam as a u256 int.
u256 gasForDeposit
Amount of gas remaining for the code deposit phase.
Address myAddress
Address associated with executing code (a contract, or contract-to-be).
Reference to a slice of buffer that also owns the buffer.
std::set< Address > deleteAddresses
bool execute()
Begins execution of a transaction.
bool changesMemory(Instruction _inst)
virtual void transferBalance(Address const &_from, Address const &_to, u256 const &_value)
Transfers "the balance _value between two accounts.
State & m_s
The state to which this operation/transaction is applied.
LastHashes lastHashes(u256 _currentBlockNumber)
virtual bigint costOfPrecompiled(Address const &_a, bytesConstRef _in, u256 const &) const
boost::error_info< struct tag_comment, std::string > errinfo_comment
bool sha3(bytesConstRef _input, bytesRef o_output)
Calculate SHA3-256 hash of the given input and load it into the given output.
virtual void addBalance(Address const &_id, u256 const &_amount)
Add some amount to balance.
unsigned depositSize
Amount of code of the creation's attempted deposit.
message-call into an account
ExecutionResult * m_res
Optional storage for execution results.
Externality interface for the Virtual Machine providing access to world state.
std::string abridged() const
virtual bool isPrecompiled(Address const &_a, u256 const &_blockNumber) const
unsigned m_depth
The context's call-depth.
Transaction m_t
The original transaction. Set by setup().
std::string memDump(bytes const &_bytes, unsigned _width=8, bool _html=false)
Nicely renders the given bytes to a string, optionally as HTML.
State const & state() const
boost::tuple< errinfo_required, errinfo_got > RequirementError
static OnOpFunc simpleTrace()
Operation function for providing a simple trace of the VM execution.
size_t savepoint() const
Create a savepoint in the state changelog.
SealEngineFace const & m_sealEngine
Too little gas to pay for the base transaction cost.
void subBalance(Address const &_addr, u256 const &_value)
Subtract the _value amount from the balance of _addr account.
bool addressHasCode(Address const &_address) const
Check if the address contains executable code.
void operator()(uint64_t _steps, uint64_t _PC, Instruction _inst, bigint _newMemSize, bigint _gasCost, bigint _gas, VM *_vm, ExtVMFace const *_extVM)
create a new account with associated code
Logging class, iostream-like, that can be shifted to.
Address receiveAddress() const
TransactionException toTransactionException(Exception const &_e)
void incNonce(Address const &_id)
Increament the account nonce.
h256 codeHash(Address const &_contract) const
Get the code hash of an account.