Ethereum  PoC-8
The C++ Implementation of Ethereum
Executive.cpp
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3  cpp-ethereum is free software: you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation, either version 3 of the License, or
6  (at your option) any later version.
7  cpp-ethereum is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11  You should have received a copy of the GNU General Public License
12  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
13 */
14 
15 #include "Executive.h"
16 
17 #include "Block.h"
18 #include "BlockChain.h"
19 #include "ExtVM.h"
20 #include "Interface.h"
21 #include "State.h"
22 
23 #include <libdevcore/CommonIO.h>
24 #include <libethcore/CommonJS.h>
25 #include <libevm/LegacyVM.h>
26 #include <libevm/VMFactory.h>
27 
28 #include <json/json.h>
29 #include <boost/timer.hpp>
30 
31 #include <numeric>
32 
33 using namespace std;
34 using namespace dev;
35 using namespace dev::eth;
36 
37 namespace
38 {
39 std::string dumpStackAndMemory(LegacyVM const& _vm)
40 {
41  ostringstream o;
42  o << "\n STACK\n";
43  for (auto i : _vm.stack())
44  o << (h256)i << "\n";
45  o << " MEMORY\n"
46  << ((_vm.memory().size() > 1000) ? " mem size greater than 1000 bytes " :
47  memDump(_vm.memory()));
48  return o.str();
49 };
50 
51 std::string dumpStorage(ExtVM const& _ext)
52 {
53  ostringstream o;
54  o << " STORAGE\n";
55  for (auto const& i : _ext.state().storage(_ext.myAddress))
56  o << showbase << hex << i.second.first << ": " << i.second.second << "\n";
57  return o.str();
58 };
59 
60 
61 } // namespace
62 
63 StandardTrace::StandardTrace():
64  m_trace(Json::arrayValue)
65 {}
66 
68 {
69  return
70  _inst == Instruction::MSTORE ||
71  _inst == Instruction::MSTORE8 ||
72  _inst == Instruction::MLOAD ||
73  _inst == Instruction::CREATE ||
74  _inst == Instruction::CALL ||
75  _inst == Instruction::CALLCODE ||
76  _inst == Instruction::SHA3 ||
77  _inst == Instruction::CALLDATACOPY ||
78  _inst == Instruction::CODECOPY ||
79  _inst == Instruction::EXTCODECOPY ||
81 }
82 
84 {
85  return _inst == Instruction::SSTORE;
86 }
87 
88 void StandardTrace::operator()(uint64_t _steps, uint64_t PC, Instruction inst, bigint newMemSize,
89  bigint gasCost, bigint gas, VMFace const* _vm, ExtVMFace const* voidExt)
90 {
91  (void)_steps;
92 
93  ExtVM const& ext = dynamic_cast<ExtVM const&>(*voidExt);
94  auto vm = dynamic_cast<LegacyVM const*>(_vm);
95 
96  Json::Value r(Json::objectValue);
97 
98  Json::Value stack(Json::arrayValue);
99  if (vm && !m_options.disableStack)
100  {
101  // Try extracting information about the stack from the VM is supported.
102  for (auto const& i : vm->stack())
103  stack.append(toCompactHexPrefixed(i, 1));
104  r["stack"] = stack;
105  }
106 
107  bool newContext = false;
108  Instruction lastInst = Instruction::STOP;
109 
110  if (m_lastInst.size() == ext.depth)
111  {
112  // starting a new context
113  assert(m_lastInst.size() == ext.depth);
114  m_lastInst.push_back(inst);
115  newContext = true;
116  }
117  else if (m_lastInst.size() == ext.depth + 2)
118  {
119  m_lastInst.pop_back();
120  lastInst = m_lastInst.back();
121  }
122  else if (m_lastInst.size() == ext.depth + 1)
123  {
124  // continuing in previous context
125  lastInst = m_lastInst.back();
126  m_lastInst.back() = inst;
127  }
128  else
129  {
130  cwarn << "GAA!!! Tracing VM and more than one new/deleted stack frame between steps!";
131  cwarn << "Attmepting naive recovery...";
132  m_lastInst.resize(ext.depth + 1);
133  }
134 
135  Json::Value memJson(Json::arrayValue);
136  if (vm && !m_options.disableMemory && (changesMemory(lastInst) || newContext))
137  {
138  for (unsigned i = 0; i < vm->memory().size(); i += 32)
139  {
140  bytesConstRef memRef(vm->memory().data() + i, 32);
141  memJson.append(toHex(memRef));
142  }
143  r["memory"] = memJson;
144  }
145 
146  if (!m_options.disableStorage && (m_options.fullStorage || changesStorage(lastInst) || newContext))
147  {
148  Json::Value storage(Json::objectValue);
149  for (auto const& i: ext.state().storage(ext.myAddress))
150  storage[toCompactHexPrefixed(i.second.first, 1)] = toCompactHexPrefixed(i.second.second, 1);
151  r["storage"] = storage;
152  }
153 
154  if (m_showMnemonics)
155  r["op"] = instructionInfo(inst).name;
156  r["pc"] = toString(PC);
157  r["gas"] = toString(gas);
158  r["gasCost"] = toString(gasCost);
159  r["depth"] = toString(ext.depth);
160  if (!!newMemSize)
161  r["memexpand"] = toString(newMemSize);
162 
163  m_trace.append(r);
164 }
165 
166 std::string StandardTrace::styledJson() const
167 {
168  return Json::StyledWriter().write(m_trace);
169 }
170 
172 {
173  if (m_trace.empty())
174  return {};
175 
176  // Each opcode trace on a separate line
177  return std::accumulate(std::next(m_trace.begin()), m_trace.end(),
178  Json::FastWriter().write(m_trace[0]),
179  [](std::string a, Json::Value b) { return a + Json::FastWriter().write(b); });
180 }
181 
182 Executive::Executive(Block& _s, BlockChain const& _bc, unsigned _level):
183  m_s(_s.mutableState()),
184  m_envInfo(_s.info(), _bc.lastBlockHashes(), 0),
185  m_depth(_level),
186  m_sealEngine(*_bc.sealEngine())
187 {
188 }
189 
190 Executive::Executive(Block& _s, LastBlockHashesFace const& _lh, unsigned _level):
191  m_s(_s.mutableState()),
192  m_envInfo(_s.info(), _lh, 0),
193  m_depth(_level),
194  m_sealEngine(*_s.sealEngine())
195 {
196 }
197 
198 Executive::Executive(State& io_s, Block const& _block, unsigned _txIndex, BlockChain const& _bc, unsigned _level):
199  m_s(createIntermediateState(io_s, _block, _txIndex, _bc)),
200  m_envInfo(_block.info(), _bc.lastBlockHashes(), _txIndex ? _block.receipt(_txIndex - 1).cumulativeGasUsed() : 0),
201  m_depth(_level),
202  m_sealEngine(*_bc.sealEngine())
203 {
204 }
205 
207 {
208  return m_t.gas() - m_gas;
209 }
210 
211 void Executive::accrueSubState(SubState& _parentContext)
212 {
213  if (m_ext)
214  _parentContext += m_ext->sub;
215 }
216 
217 void Executive::initialize(Transaction const& _transaction)
218 {
219  m_t = _transaction;
220  m_baseGasRequired = m_t.baseGasRequired(m_sealEngine.evmSchedule(m_envInfo.number()));
221  try
222  {
223  m_sealEngine.verifyTransaction(ImportRequirements::Everything, m_t, m_envInfo.header(), m_envInfo.gasUsed());
224  }
225  catch (Exception const& ex)
226  {
227  m_excepted = toTransactionException(ex);
228  throw;
229  }
230 
231  if (!m_t.hasZeroSignature())
232  {
233  // Avoid invalid transactions.
234  u256 nonceReq;
235  try
236  {
237  nonceReq = m_s.getNonce(m_t.sender());
238  }
239  catch (InvalidSignature const&)
240  {
241  LOG(m_execLogger) << "Invalid Signature";
243  throw;
244  }
245  if (m_t.nonce() != nonceReq)
246  {
247  LOG(m_execLogger) << "Sender: " << m_t.sender().hex() << " Invalid Nonce: Require "
248  << nonceReq << " Got " << m_t.nonce();
250  BOOST_THROW_EXCEPTION(InvalidNonce() << RequirementError((bigint)nonceReq, (bigint)m_t.nonce()));
251  }
252 
253  // Avoid unaffordable transactions.
254  bigint gasCost = (bigint)m_t.gas() * m_t.gasPrice();
255  bigint totalCost = m_t.value() + gasCost;
256  if (m_s.balance(m_t.sender()) < totalCost)
257  {
258  LOG(m_execLogger) << "Not enough cash: Require > " << totalCost << " = " << m_t.gas()
259  << " * " << m_t.gasPrice() << " + " << m_t.value() << " Got"
260  << m_s.balance(m_t.sender()) << " for sender: " << m_t.sender();
263  BOOST_THROW_EXCEPTION(NotEnoughCash() << RequirementError(totalCost, (bigint)m_s.balance(m_t.sender())) << errinfo_comment(m_t.sender().hex()));
264  }
265  m_gasCost = (u256)gasCost; // Convert back to 256-bit, safe now.
266  }
267 }
268 
270 {
271  // Entry point for a user-executed transaction.
272 
273  // Pay...
274  LOG(m_detailsLogger) << "Paying " << formatBalance(m_gasCost) << " from sender for gas ("
275  << m_t.gas() << " gas at " << formatBalance(m_t.gasPrice()) << ")";
276  m_s.subBalance(m_t.sender(), m_gasCost);
277 
278  assert(m_t.gas() >= (u256)m_baseGasRequired);
279  if (m_t.isCreation())
280  return create(m_t.sender(), m_t.value(), m_t.gasPrice(), m_t.gas() - (u256)m_baseGasRequired, &m_t.data(), m_t.sender());
281  else
282  return call(m_t.receiveAddress(), m_t.sender(), m_t.value(), m_t.gasPrice(), bytesConstRef(&m_t.data()), m_t.gas() - (u256)m_baseGasRequired);
283 }
284 
285 bool Executive::call(Address const& _receiveAddress, Address const& _senderAddress, u256 const& _value, u256 const& _gasPrice, bytesConstRef _data, u256 const& _gas)
286 {
287  CallParameters params{_senderAddress, _receiveAddress, _receiveAddress, _value, _value, _gas, _data, {}};
288  return call(params, _gasPrice, _senderAddress);
289 }
290 
291 bool Executive::call(CallParameters const& _p, u256 const& _gasPrice, Address const& _origin)
292 {
293  // If external transaction.
294  if (m_t)
295  {
296  // FIXME: changelog contains unrevertable balance change that paid
297  // for the transaction.
298  // Increment associated nonce for sender.
299  if (_p.senderAddress != MaxAddress ||
300  m_envInfo.number() < m_sealEngine.chainParams().experimentalForkBlock) // EIP86
301  m_s.incNonce(_p.senderAddress);
302  }
303 
304  m_savepoint = m_s.savepoint();
305 
306  if (m_sealEngine.isPrecompiled(_p.codeAddress, m_envInfo.number()))
307  {
308  bigint g = m_sealEngine.costOfPrecompiled(_p.codeAddress, _p.data, m_envInfo.number());
309  if (_p.gas < g)
310  {
312  // Bail from exception.
313 
314  // Empty precompiled contracts need to be deleted even in case of OOG
315  // because the bug in both Geth and Parity led to deleting RIPEMD precompiled in this case
316  // see https://github.com/ethereum/go-ethereum/pull/3341/files#diff-2433aa143ee4772026454b8abd76b9dd
317  // We mark the account as touched here, so that is can be removed among other touched empty accounts (after tx finalization)
318  if (m_envInfo.number() >= m_sealEngine.chainParams().EIP158ForkBlock)
319  m_s.addBalance(_p.codeAddress, 0);
320 
321  return true; // true actually means "all finished - nothing more to be done regarding go().
322  }
323  else
324  {
325  m_gas = (u256)(_p.gas - g);
326  bytes output;
327  bool success;
328  tie(success, output) = m_sealEngine.executePrecompiled(_p.codeAddress, _p.data, m_envInfo.number());
329  size_t outputSize = output.size();
330  m_output = owning_bytes_ref{std::move(output), 0, outputSize};
331  if (!success)
332  {
333  m_gas = 0;
334  m_excepted = TransactionException::OutOfGas;
335  return true; // true means no need to run go().
336  }
337  }
338  }
339  else
340  {
341  m_gas = _p.gas;
342  if (m_s.addressHasCode(_p.codeAddress))
343  {
344  bytes const& c = m_s.code(_p.codeAddress);
345  h256 codeHash = m_s.codeHash(_p.codeAddress);
346  m_ext = make_shared<ExtVM>(m_s, m_envInfo, m_sealEngine, _p.receiveAddress,
347  _p.senderAddress, _origin, _p.apparentValue, _gasPrice, _p.data, &c, codeHash,
348  m_depth, false, _p.staticCall);
349  }
350  }
351 
352  // Transfer ether.
354  return !m_ext;
355 }
356 
357 bool Executive::create(Address const& _txSender, u256 const& _endowment, u256 const& _gasPrice, u256 const& _gas, bytesConstRef _init, Address const& _origin)
358 {
359  // Contract creation by an external account is the same as CREATE opcode
360  return createOpcode(_txSender, _endowment, _gasPrice, _gas, _init, _origin);
361 }
362 
363 bool Executive::createOpcode(Address const& _sender, u256 const& _endowment, u256 const& _gasPrice, u256 const& _gas, bytesConstRef _init, Address const& _origin)
364 {
365  u256 nonce = m_s.getNonce(_sender);
366  m_newAddress = right160(sha3(rlpList(_sender, nonce)));
367  return executeCreate(_sender, _endowment, _gasPrice, _gas, _init, _origin);
368 }
369 
370 bool Executive::create2Opcode(Address const& _sender, u256 const& _endowment, u256 const& _gasPrice, u256 const& _gas, bytesConstRef _init, Address const& _origin, u256 const& _salt)
371 {
372  m_newAddress = right160(sha3(bytes{0xff} +_sender.asBytes() + toBigEndian(_salt) + sha3(_init)));
373  return executeCreate(_sender, _endowment, _gasPrice, _gas, _init, _origin);
374 }
375 
376 bool Executive::executeCreate(Address const& _sender, u256 const& _endowment, u256 const& _gasPrice, u256 const& _gas, bytesConstRef _init, Address const& _origin)
377 {
378  if (_sender != MaxAddress ||
379  m_envInfo.number() < m_sealEngine.chainParams().experimentalForkBlock) // EIP86
380  m_s.incNonce(_sender);
381 
382  m_savepoint = m_s.savepoint();
383 
384  m_isCreation = true;
385 
386  // We can allow for the reverted state (i.e. that with which m_ext is constructed) to contain the m_orig.address, since
387  // we delete it explicitly if we decide we need to revert.
388 
389  m_gas = _gas;
390  bool accountAlreadyExist = (m_s.addressHasCode(m_newAddress) || m_s.getNonce(m_newAddress) > 0);
391  if (accountAlreadyExist)
392  {
393  LOG(m_detailsLogger) << "Address already used: " << m_newAddress;
394  m_gas = 0;
396  revert();
397  m_ext = {}; // cancel the _init execution if there are any scheduled.
398  return !m_ext;
399  }
400 
401  // Transfer ether before deploying the code. This will also create new
402  // account if it does not exist yet.
403  m_s.transferBalance(_sender, m_newAddress, _endowment);
404 
405  u256 newNonce = m_s.requireAccountStartNonce();
406  if (m_envInfo.number() >= m_sealEngine.chainParams().EIP158ForkBlock)
407  newNonce += 1;
408  m_s.setNonce(m_newAddress, newNonce);
409 
410  m_s.clearStorage(m_newAddress);
411 
412  // Schedule _init execution if not empty.
413  if (!_init.empty())
414  m_ext = make_shared<ExtVM>(m_s, m_envInfo, m_sealEngine, m_newAddress, _sender, _origin,
415  _endowment, _gasPrice, bytesConstRef(), _init, sha3(_init), m_depth, true, false);
416 
417  return !m_ext;
418 }
419 
421 {
422  Logger& traceLogger = m_vmTraceLogger;
423 
424  return [&traceLogger](uint64_t steps, uint64_t PC, Instruction inst, bigint newMemSize,
425  bigint gasCost, bigint gas, VMFace const* _vm, ExtVMFace const* voidExt) {
426  ExtVM const& ext = *static_cast<ExtVM const*>(voidExt);
427  auto vm = dynamic_cast<LegacyVM const*>(_vm);
428 
429  ostringstream o;
430  if (vm)
431  LOG(traceLogger) << dumpStackAndMemory(*vm);
432  LOG(traceLogger) << dumpStorage(ext);
433  LOG(traceLogger) << " < " << dec << ext.depth << " : " << ext.myAddress << " : #" << steps
434  << " : " << hex << setw(4) << setfill('0') << PC << " : "
435  << instructionInfo(inst).name << " : " << dec << gas << " : -" << dec
436  << gasCost << " : " << newMemSize << "x32"
437  << " >";
438  };
439 }
440 
441 bool Executive::go(OnOpFunc const& _onOp)
442 {
443  if (m_ext)
444  {
445 #if ETH_TIMED_EXECUTIONS
446  Timer t;
447 #endif
448  try
449  {
450  // Create VM instance. Force Interpreter if tracing requested.
451  auto vm = VMFactory::create();
452  if (m_isCreation)
453  {
454  auto out = vm->exec(m_gas, *m_ext, _onOp);
455  if (m_res)
456  {
457  m_res->gasForDeposit = m_gas;
458  m_res->depositSize = out.size();
459  }
460  if (out.size() > m_ext->evmSchedule().maxCodeSize)
461  BOOST_THROW_EXCEPTION(OutOfGas());
462  else if (out.size() * m_ext->evmSchedule().createDataGas <= m_gas)
463  {
464  if (m_res)
466  m_gas -= out.size() * m_ext->evmSchedule().createDataGas;
467  }
468  else
469  {
470  if (m_ext->evmSchedule().exceptionalFailedCodeDeposit)
471  BOOST_THROW_EXCEPTION(OutOfGas());
472  else
473  {
474  if (m_res)
476  out = {};
477  }
478  }
479  if (m_res)
480  m_res->output = out.toVector(); // copy output to execution result
481  m_s.setCode(m_ext->myAddress, out.toVector());
482  }
483  else
484  m_output = vm->exec(m_gas, *m_ext, _onOp);
485  }
486  catch (RevertInstruction& _e)
487  {
488  revert();
489  m_output = _e.output();
491  }
492  catch (VMException const& _e)
493  {
494  LOG(m_detailsLogger) << "Safe VM Exception. " << diagnostic_information(_e);
495  m_gas = 0;
496  m_excepted = toTransactionException(_e);
497  revert();
498  }
499  catch (InternalVMError const& _e)
500  {
501  cerror << "Internal VM Error (EVMC status code: "
502  << *boost::get_error_info<errinfo_evmcStatusCode>(_e) << ")";
503  revert();
504  throw;
505  }
506  catch (Exception const& _e)
507  {
508  // TODO: AUDIT: check that this can never reasonably happen. Consider what to do if it does.
509  cerror << "Unexpected exception in VM. There may be a bug in this implementation. "
510  << diagnostic_information(_e);
511  exit(1);
512  // Another solution would be to reject this transaction, but that also
513  // has drawbacks. Essentially, the amount of ram has to be increased here.
514  }
515  catch (std::exception const& _e)
516  {
517  // TODO: AUDIT: check that this can never reasonably happen. Consider what to do if it does.
518  cerror << "Unexpected std::exception in VM. Not enough RAM? " << _e.what();
519  exit(1);
520  // Another solution would be to reject this transaction, but that also
521  // has drawbacks. Essentially, the amount of ram has to be increased here.
522  }
523 
524  if (m_res && m_output)
525  // Copy full output:
526  m_res->output = m_output.toVector();
527 
528 #if ETH_TIMED_EXECUTIONS
529  cnote << "VM took:" << t.elapsed() << "; gas used: " << (sgas - m_endGas);
530 #endif
531  }
532  return true;
533 }
534 
536 {
537  if (m_ext)
538  {
539  // Accumulate refunds for suicides.
540  m_ext->sub.refunds += m_ext->evmSchedule().suicideRefundGas * m_ext->sub.suicides.size();
541 
542  // Refunds must be applied before the miner gets the fees.
543  assert(m_ext->sub.refunds >= 0);
544  int64_t maxRefund = (static_cast<int64_t>(m_t.gas()) - static_cast<int64_t>(m_gas)) / 2;
545  m_gas += min(maxRefund, m_ext->sub.refunds);
546  }
547 
548  if (m_t)
549  {
550  m_s.addBalance(m_t.sender(), m_gas * m_t.gasPrice());
551 
552  u256 feesEarned = (m_t.gas() - m_gas) * m_t.gasPrice();
553  m_s.addBalance(m_envInfo.author(), feesEarned);
554  }
555 
556  // Suicides...
557  if (m_ext)
558  for (auto a: m_ext->sub.suicides)
559  m_s.kill(a);
560 
561  // Logs..
562  if (m_ext)
563  m_logs = m_ext->sub.logs;
564 
565  if (m_res) // Collect results
566  {
567  m_res->gasUsed = gasUsed();
568  m_res->excepted = m_excepted; // TODO: m_except is used only in ExtVM::call
569  m_res->newAddress = m_newAddress;
570  m_res->gasRefunded = m_ext ? m_ext->sub.refunds : 0;
571  }
572  return (m_excepted == TransactionException::None);
573 }
574 
576 {
577  if (m_ext)
578  m_ext->sub.clear();
579 
580  // Set result address to the null one.
581  m_newAddress = {};
582  m_s.rollback(m_savepoint);
583 }
dev::eth::TransactionException::InvalidSignature
@ InvalidSignature
dev::eth::SubState
Definition: ExtVMFace.h:90
dev::eth::TransactionBase::value
u256 value() const
Definition: TransactionBase.h:115
dev::eth::OnOpFunc
std::function< void(uint64_t, uint64_t, Instruction, bigint, bigint, bigint, VMFace const *, ExtVMFace const *)> OnOpFunc
Definition: ExtVMFace.h:115
dev::eth::Executive::go
bool go(OnOpFunc const &_onOp=OnOpFunc())
Definition: Executive.cpp:441
dev::eth::formatBalance
std::string formatBalance(bigint const &_b)
User-friendly string representation of the amount _b in wei.
Definition: Common.cpp:96
cerror
#define cerror
dev::eth::TransactionBase::gas
u256 gas() const
Definition: TransactionBase.h:121
dev::MaxAddress
Address const MaxAddress
The last address.
Definition: Address.cpp:23
dev::eth::Transaction
Encodes a transaction, ready to be exported to or freshly imported from RLP.
Definition: Transaction.h:86
dev::eth::State::subBalance
void subBalance(Address const &_addr, u256 const &_value)
Definition: State.cpp:371
dev::eth::ExecutionResult::gasForDeposit
u256 gasForDeposit
Amount of gas remaining for the code deposit phase.
Definition: Transaction.h:79
dev::eth::ImportRequirements::Everything
@ Everything
Definition: Common.h:127
dev::toBigEndian
void toBigEndian(T _val, Out &o_out)
Definition: CommonData.h:124
dev::eth::EnvInfo::header
BlockHeader const & header() const
Definition: ExtVMFace.h:157
dev::vector_ref< byte const >
CommonJS.h
dev::vector_ref::toVector
std::vector< mutable_value_type > toVector() const
Definition: vector_ref.h:42
dev::eth::State::setNonce
void setNonce(Address const &_addr, u256 const &_newNonce)
Set the account nonce.
Definition: State.cpp:333
dev::eth::Instruction::CREATE
@ CREATE
create a new account with associated code
dev::eth::ExecutionResult::gasUsed
u256 gasUsed
Definition: Transaction.h:72
dev::eth::TransactionBase::receiveAddress
Address receiveAddress() const
Definition: TransactionBase.h:124
dev::eth::StandardTrace::DebugOptions::disableStack
bool disableStack
Definition: Executive.h:53
dev::eth::State::kill
void kill(Address _a)
Delete an account (used for processing suicides).
Definition: State.cpp:407
dev::sha3
bool sha3(bytesConstRef _input, bytesRef o_output) noexcept
Definition: SHA3.cpp:28
dev::eth::State::code
bytes const & code(Address const &_addr) const
Definition: State.cpp:503
dev::eth::Instruction::DELEGATECALL
@ DELEGATECALL
like CALLCODE but keeps caller's value and sender
dev::eth::createIntermediateState
State & createIntermediateState(State &o_s, Block const &_block, unsigned _txIndex, BlockChain const &_bc)
Definition: State.cpp:744
dev::eth::Instruction::SSTORE
@ SSTORE
save word to storage
dev::Timer
Definition: Common.h:256
dev::eth::ChainOperationParams::experimentalForkBlock
u256 experimentalForkBlock
Definition: ChainOperationParams.h:98
dev::eth::TransactionException::AddressAlreadyUsed
@ AddressAlreadyUsed
dev::eth::EnvInfo::author
Address const & author() const
Definition: ExtVMFace.h:160
dev::eth::VMFactory::create
static VMPtr create()
Creates a VM instance of the global kind (controlled by the –vm command line option).
Definition: VMFactory.cpp:177
dev::h256
FixedHash< 32 > h256
Definition: FixedHash.h:356
dev::eth::Executive::create
bool create(Address const &_txSender, u256 const &_endowment, u256 const &_gasPrice, u256 const &_gas, bytesConstRef _code, Address const &_originAddress)
Definition: Executive.cpp:357
dev::eth::CallParameters::staticCall
bool staticCall
Definition: ExtVMFace.h:138
dev::eth::State::getNonce
u256 getNonce(Address const &_addr) const
Definition: State.cpp:414
dev::eth::State::incNonce
void incNonce(Address const &_id)
Increament the account nonce.
Definition: State.cpp:320
dev::eth::CallParameters::codeAddress
Address codeAddress
Definition: ExtVMFace.h:132
dev::eth::owning_bytes_ref
Definition: ExtVMFace.h:58
dev::eth
Definition: BasicAuthority.h:32
dev::eth::SealEngineFace::chainParams
ChainOperationParams const & chainParams() const
Definition: SealEngine.h:80
dev::toString
std::string toString(std::chrono::time_point< T > const &_e, std::string const &_format="%F %T")
Definition: CommonIO.h:86
dev::eth::Executive::gasUsed
u256 gasUsed() const
Definition: Executive.cpp:206
dev::eth::VMFace
EVM Virtual Machine interface.
Definition: VMFace.h:64
dev::eth::ChainOperationParams::EIP158ForkBlock
u256 EIP158ForkBlock
Definition: ChainOperationParams.h:92
dev::eth::ExtVMFace
Interface and null implementation of the class for specifying VM externalities.
Definition: ExtVMFace.h:204
dev::eth::StandardTrace::DebugOptions::disableMemory
bool disableMemory
Definition: Executive.h:52
dev::FixedHash< 20 >
dev::eth::Executive::call
bool call(Address const &_receiveAddress, Address const &_txSender, u256 const &_txValue, u256 const &_gasPrice, bytesConstRef _txData, u256 const &_gas)
Definition: Executive.cpp:285
dev::eth::Instruction::CALLCODE
@ CALLCODE
message-call with another account's code only
dev::eth::LegacyVM::memory
bytes const & memory() const
Definition: LegacyVM.h:40
dev::eth::CallParameters::apparentValue
u256 apparentValue
Definition: ExtVMFace.h:135
dev::eth::Executive::initialize
void initialize(bytesConstRef _transaction)
Initializes the executive for evaluating a transaction. You must call finalize() at some point follow...
Definition: Executive.h:132
dev::eth::Executive::simpleTrace
OnOpFunc simpleTrace()
Operation function for providing a simple trace of the VM execution.
Definition: Executive.cpp:420
dev::eth::State::addBalance
void addBalance(Address const &_id, u256 const &_amount)
Definition: State.cpp:346
dev::right160
h160 right160(h256 const &_t)
Convert the given value into h160 (160-bit unsigned integer) using the right 20 bytes.
Definition: FixedHash.h:369
dev::eth::Instruction::MLOAD
@ MLOAD
load word from memory
dev::Exception
Base class for all exceptions.
Definition: Exceptions.h:39
LOG
#define LOG
Definition: Log.h:63
dev::eth::Executive::revert
void revert()
Revert all changes made to the state by this execution.
Definition: Executive.cpp:575
dev::eth::State::clearStorage
void clearStorage(Address const &_contract)
Clear the storage root hash of an account to the hash of the empty trie.
Definition: State.cpp:444
dev::eth::Instruction::CALLDATACOPY
@ CALLDATACOPY
copy input data in current environment to memory
dev::eth::SealEngineFace::verifyTransaction
virtual void verifyTransaction(ImportRequirements::value _ir, TransactionBase const &_t, BlockHeader const &_header, u256 const &_startGasUsed) const
Additional verification for transactions in blocks.
Definition: SealEngine.cpp:131
dev::eth::ExtVMFace::myAddress
Address myAddress
Address associated with executing code (a contract, or contract-to-be).
Definition: ExtVMFace.h:266
dev::toCompactHexPrefixed
std::string toCompactHexPrefixed(u256 _val, unsigned _min=0)
Definition: CommonData.h:187
dev::eth::VMException
Definition: VMFace.h:28
dev::eth::Instruction::STOP
@ STOP
halts execution
dev::eth::StandardTrace::DebugOptions::fullStorage
bool fullStorage
Definition: Executive.h:54
dev::eth::ExecutionResult::newAddress
Address newAddress
Definition: Transaction.h:74
dev::eth::StandardTrace::multilineTrace
std::string multilineTrace() const
Definition: Executive.cpp:171
dev::eth::Executive::gas
u256 gas() const
Definition: Executive.h:175
CommonIO.h
dev::Logger
boost::log::sources::severity_channel_logger<> Logger
Definition: Log.h:124
cnote
#define cnote
dev::eth::TransactionException::None
@ None
Block.h
ExtVM.h
dev::eth::EnvInfo::gasUsed
u256 const & gasUsed() const
Definition: ExtVMFace.h:165
Interface.h
dev::eth::StandardTrace::styledJson
std::string styledJson() const
Definition: Executive.cpp:166
dev::eth::ExtVMFace::depth
unsigned depth
Depth of the present call.
Definition: ExtVMFace.h:276
dev::eth::LegacyVM
Definition: LegacyVM.h:30
dev::eth::TransactionBase::hasZeroSignature
bool hasZeroSignature() const
Definition: TransactionBase.h:145
dev::eth::SealEngineFace::costOfPrecompiled
virtual bigint costOfPrecompiled(Address const &_a, bytesConstRef _in, u256 const &) const
Definition: SealEngine.h:90
dev::bytes
std::vector< byte > bytes
Definition: Common.h:72
dev::eth::CodeDeposit::Success
@ Success
VMFactory.h
dev::bytesConstRef
vector_ref< byte const > bytesConstRef
Definition: Common.h:74
dev::eth::Instruction::MSTORE
@ MSTORE
save word to memory
dev::eth::BlockChain
Implements the blockchain database. All data this gives is disk-backed. @threadsafe.
Definition: BlockChain.h:105
dev::eth::TransactionBase::gasPrice
u256 gasPrice() const
Definition: TransactionBase.h:118
Executive.h
dev::eth::ExtVM
Externality interface for the Virtual Machine providing access to world state.
Definition: ExtVM.h:39
dev::eth::TransactionException::OutOfGasBase
@ OutOfGasBase
Too little gas to pay for the base transaction cost.
dev::eth::SealEngineFace::isPrecompiled
virtual bool isPrecompiled(Address const &_a, u256 const &_blockNumber) const
Definition: SealEngine.h:86
dev::eth::CallParameters::valueTransfer
u256 valueTransfer
Definition: ExtVMFace.h:134
dev::eth::TransactionBase::baseGasRequired
int64_t baseGasRequired(EVMSchedule const &_es) const
Definition: TransactionBase.h:157
BlockChain.h
dev::eth::State::addressHasCode
bool addressHasCode(Address const &_address) const
Check if the address contains executable code.
Definition: State.cpp:304
dev::eth::Instruction::CALL
@ CALL
message-call into an account
dev::eth::TransactionException::NotEnoughCash
@ NotEnoughCash
dev::vector_ref::empty
bool empty() const
Definition: vector_ref.h:54
dev::eth::CallParameters::senderAddress
Address senderAddress
Definition: ExtVMFace.h:131
dev::eth::InternalVMError
Definition: VMFace.h:40
dev::eth::RevertInstruction::output
owning_bytes_ref && output()
Definition: VMFace.h:55
dev::eth::InstructionInfo::name
char const *const name
The name of the instruction.
Definition: Instruction.h:250
changesMemory
bool changesMemory(Instruction _inst)
Definition: Executive.cpp:67
dev::eth::Instruction
Instruction
Virtual machine bytecode instruction.
Definition: Instruction.h:29
dev::bigint
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<> > bigint
Definition: Common.h:118
Json
Definition: Executive.h:27
dev::eth::State::transferBalance
void transferBalance(Address const &_from, Address const &_to, u256 const &_value)
Transfers "the balance _value between two accounts.
Definition: State.h:251
dev::eth::SealEngineFace::executePrecompiled
virtual std::pair< bool, bytes > executePrecompiled(Address const &_a, bytesConstRef _in, u256 const &) const
Definition: SealEngine.h:91
dev::eth::Executive::finalize
bool finalize()
Definition: Executive.cpp:535
dev::eth::State::requireAccountStartNonce
u256 const & requireAccountStartNonce() const
Definition: State.cpp:110
dev::eth::ExecutionResult::gasRefunded
u256 gasRefunded
Definition: Transaction.h:77
dev::eth::CallParameters::data
bytesConstRef data
Definition: ExtVMFace.h:137
LegacyVM.h
dev::eth::TransactionBase::sender
Address const & sender() const
Definition: TransactionBase.cpp:116
dev::eth::EnvInfo::number
int64_t number() const
Definition: ExtVMFace.h:159
dev::eth::CallParameters
Definition: ExtVMFace.h:118
std
Definition: FixedHash.h:393
dev::eth::State
Definition: State.h:160
dev::u256
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void > > u256
Definition: Common.h:121
dev::eth::State::savepoint
size_t savepoint() const
Definition: State.cpp:555
dev::eth::TransactionBase::data
bytes const & data() const
Definition: TransactionBase.h:133
dev::memDump
string memDump(bytes const &_bytes, unsigned _width, bool _html)
Definition: CommonIO.cpp:55
dev::eth::CallParameters::gas
u256 gas
Definition: ExtVMFace.h:136
dev::eth::Executive::create2Opcode
bool create2Opcode(Address const &_sender, u256 const &_endowment, u256 const &_gasPrice, u256 const &_gas, bytesConstRef _code, Address const &_originAddress, u256 const &_salt)
Definition: Executive.cpp:370
changesStorage
bool changesStorage(Instruction _inst)
Definition: Executive.cpp:83
dev
Definition: Address.cpp:21
dev::eth::State::setCode
void setCode(Address const &_address, bytes &&_code)
Sets the code of the account. Must only be called during / after contract creation.
Definition: State.cpp:520
dev::eth::TransactionBase::nonce
u256 nonce() const
Definition: TransactionBase.h:136
dev::eth::ExecutionResult::depositSize
unsigned depositSize
Amount of code of the creation's attempted deposit.
Definition: Transaction.h:78
dev::eth::ExtVM::state
State const & state() const
Definition: ExtVM.h:105
dev::RequirementError
boost::tuple< errinfo_required, errinfo_got > RequirementError
Definition: Exceptions.h:87
dev::rlpList
bytes rlpList()
Export a list of items in RLP format, returning a byte array.
Definition: RLP.h:456
dev::eth::State::balance
u256 balance(Address const &_id) const
Definition: State.cpp:312
dev::eth::TransactionException::RevertInstruction
@ RevertInstruction
dev::eth::toTransactionException
TransactionException toTransactionException(Exception const &_e)
Definition: Transaction.cpp:42
dev::eth::State::codeHash
h256 codeHash(Address const &_contract) const
Definition: State.cpp:526
dev::eth::Instruction::CODECOPY
@ CODECOPY
copy code running in current environment to memory
dev::eth::Instruction::SHA3
@ SHA3
compute SHA3-256 hash
dev::eth::Executive::t
Transaction const & t() const
Definition: Executive.h:143
dev::FixedHash::hex
std::string hex() const
Definition: FixedHash.h:129
dev::eth::instructionInfo
InstructionInfo instructionInfo(Instruction _inst)
Information on all the instructions.
Definition: Instruction.cpp:220
cwarn
#define cwarn
dev::eth::TransactionException::OutOfGas
@ OutOfGas
Ran out of gas executing code of the transaction.
dev::eth::ExecutionResult::excepted
TransactionException excepted
Definition: Transaction.h:73
dev::eth::Instruction::MSTORE8
@ MSTORE8
save byte to memory
dev::eth::State::rollback
void rollback(size_t _savepoint)
Revert all recent changes up to the given _savepoint savepoint.
Definition: State.cpp:560
dev::FixedHash::asBytes
bytes asBytes() const
Definition: FixedHash.h:150
dev::eth::SealEngineFace::evmSchedule
virtual EVMSchedule const & evmSchedule(u256 const &_blockNumber) const =0
dev::eth::TransactionBase::isCreation
bool isCreation() const
Definition: TransactionBase.h:102
dev::eth::CallParameters::receiveAddress
Address receiveAddress
Definition: ExtVMFace.h:133
dev::toHex
std::string toHex(Iterator _it, Iterator _end, std::string const &_prefix)
Definition: CommonData.h:46
dev::eth::RevertInstruction
Definition: VMFace.h:46
dev::eth::Executive::accrueSubState
void accrueSubState(SubState &_parentContext)
Finalise an operation through accruing the substate into the parent context.
Definition: Executive.cpp:211
dev::eth::State::storage
u256 storage(Address const &_contract, u256 const &_memory) const
Definition: State.cpp:422
dev::eth::TransactionException::InvalidNonce
@ InvalidNonce
dev::eth::Executive::createOpcode
bool createOpcode(Address const &_sender, u256 const &_endowment, u256 const &_gasPrice, u256 const &_gas, bytesConstRef _code, Address const &_originAddress)
Definition: Executive.cpp:363
dev::eth::LastBlockHashesFace
Interface for getting a list of recent block hashes @threadsafe.
Definition: LastBlockHashesFace.h:37
dev::eth::LegacyVM::stack
u256s stack() const
Definition: LegacyVM.h:41
dev::eth::ExecutionResult::codeDeposit
CodeDeposit codeDeposit
Failed if an attempted deposit failed due to lack of gas.
Definition: Transaction.h:76
dev::eth::Instruction::EXTCODECOPY
@ EXTCODECOPY
copy external code (from another contract)
dev::eth::CodeDeposit::Failed
@ Failed
dev::eth::Block
Active model of a block within the block chain. Keeps track of all transactions, receipts and state f...
Definition: Block.h:69
dev::eth::ExecutionResult::output
bytes output
Definition: Transaction.h:75
dev::eth::Executive::execute
bool execute()
Definition: Executive.cpp:269
dev::eth::StandardTrace::DebugOptions::disableStorage
bool disableStorage
Definition: Executive.h:51
dev::errinfo_comment
boost::error_info< struct tag_comment, std::string > errinfo_comment
Definition: Assertions.h:69
State.h
dev::eth::Executive::Executive
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.
Definition: Executive.h:107
dev::eth::Instruction::PC
@ PC
get the program counter
dev::eth::StandardTrace::operator()
void operator()(uint64_t _steps, uint64_t _PC, Instruction _inst, bigint _newMemSize, bigint _gasCost, bigint _gas, VMFace const *_vm, ExtVMFace const *_extVM)
Definition: Executive.cpp:88