Browse Source

Merge branch 'develop' of https://github.com/ethereum/cpp-ethereum into

bc2

Conflicts:
	libethereum/EthereumHost.cpp
cl-refactor
arkpar 10 years ago
parent
commit
936e26dfe8
  1. 8
      alethzero/MainWin.cpp
  2. 2
      alethzero/Transact.cpp
  3. 39
      ethkey/KeyAux.h
  4. 4
      evmjit/libevmjit-cpp/JitVM.cpp
  5. 2
      evmjit/libevmjit-cpp/JitVM.h
  6. 2
      libdevcore/Common.cpp
  7. 42
      libdevcore/CommonData.cpp
  8. 2
      libdevcore/CommonData.h
  9. 2
      libdevcrypto/Common.cpp
  10. 2
      libdevcrypto/Common.h
  11. 2
      libdevcrypto/SecretStore.cpp
  12. 23
      libethcore/KeyManager.cpp
  13. 11
      libethcore/KeyManager.h
  14. 3
      libethereum/Client.cpp
  15. 6
      libethereum/CommonNet.h
  16. 4
      libethereum/EthereumHost.cpp
  17. 4
      libethereum/EthereumPeer.cpp
  18. 63
      libethereum/Executive.cpp
  19. 15
      libethereum/Executive.h
  20. 1
      libethereum/ExtVM.cpp
  21. 43
      libethereum/Precompiled.cpp
  22. 2
      libethereum/Precompiled.h
  23. 4
      libethereum/State.cpp
  24. 17
      libethereum/Transaction.h
  25. 4
      libevm/SmartVM.cpp
  26. 2
      libevm/SmartVM.h
  27. 9
      libevm/VM.cpp
  28. 2
      libevm/VM.h
  29. 18
      libevm/VMFace.h
  30. 5
      mix/MixClient.cpp
  31. 4
      test/fuzzTesting/checkRandomVMTest.cpp
  32. 2
      test/fuzzTesting/createRandomVMTest.cpp
  33. 4
      test/libevm/vm.cpp
  34. 4
      test/libsolidity/solidityExecutionFramework.h

8
alethzero/MainWin.cpp

@ -2116,14 +2116,14 @@ void Main::on_reencryptKey_triggered()
auto pw = [&](){ auto pw = [&](){
auto p = QInputDialog::getText(this, "Re-Encrypt Key", "Enter the original password for this key.\nHint: " + QString::fromStdString(m_keyManager.hint(a)), QLineEdit::Password, QString()).toStdString(); auto p = QInputDialog::getText(this, "Re-Encrypt Key", "Enter the original password for this key.\nHint: " + QString::fromStdString(m_keyManager.hint(a)), QLineEdit::Password, QString()).toStdString();
if (p.empty()) if (p.empty())
throw UnknownPassword(); throw PasswordUnknown();
return p; return p;
}; };
while (!(password.empty() ? m_keyManager.recode(a, SemanticPassword::Master, pw, kdf) : m_keyManager.recode(a, password, hint, pw, kdf))) while (!(password.empty() ? m_keyManager.recode(a, SemanticPassword::Master, pw, kdf) : m_keyManager.recode(a, password, hint, pw, kdf)))
if (QMessageBox::question(this, "Re-Encrypt Key", "Password given is incorrect. Would you like to try again?", QMessageBox::Retry, QMessageBox::Cancel) == QMessageBox::Cancel) if (QMessageBox::question(this, "Re-Encrypt Key", "Password given is incorrect. Would you like to try again?", QMessageBox::Retry, QMessageBox::Cancel) == QMessageBox::Cancel)
return; return;
} }
catch (UnknownPassword&) {} catch (PasswordUnknown&) {}
} }
} }
@ -2139,13 +2139,13 @@ void Main::on_reencryptAll_triggered()
while (!m_keyManager.recode(a, SemanticPassword::Existing, [&](){ while (!m_keyManager.recode(a, SemanticPassword::Existing, [&](){
auto p = QInputDialog::getText(nullptr, "Re-Encrypt Key", QString("Enter the original password for key %1.\nHint: %2").arg(QString::fromStdString(pretty(a))).arg(QString::fromStdString(m_keyManager.hint(a))), QLineEdit::Password, QString()).toStdString(); auto p = QInputDialog::getText(nullptr, "Re-Encrypt Key", QString("Enter the original password for key %1.\nHint: %2").arg(QString::fromStdString(pretty(a))).arg(QString::fromStdString(m_keyManager.hint(a))), QLineEdit::Password, QString()).toStdString();
if (p.empty()) if (p.empty())
throw UnknownPassword(); throw PasswordUnknown();
return p; return p;
}, (KDF)kdfs.indexOf(kdf))) }, (KDF)kdfs.indexOf(kdf)))
if (QMessageBox::question(this, "Re-Encrypt Key", "Password given is incorrect. Would you like to try again?", QMessageBox::Retry, QMessageBox::Cancel) == QMessageBox::Cancel) if (QMessageBox::question(this, "Re-Encrypt Key", "Password given is incorrect. Would you like to try again?", QMessageBox::Retry, QMessageBox::Cancel) == QMessageBox::Cancel)
return; return;
} }
catch (UnknownPassword&) {} catch (PasswordUnknown&) {}
} }
void Main::on_go_triggered() void Main::on_go_triggered()

2
alethzero/Transact.cpp

@ -360,7 +360,7 @@ void Transact::rejigData()
return; return;
} }
else else
gasNeeded = (qint64)min<bigint>(ethereum()->gasLimitRemaining(), ((b - value()) / gasPrice())); gasNeeded = (qint64)min<bigint>(ethereum()->gasLimitRemaining(), ((b - value()) / max<u256>(gasPrice(), 1)));
// Dry-run execution to determine gas requirement and any execution errors // Dry-run execution to determine gas requirement and any execution errors
Address to; Address to;

39
ethkey/KeyAux.h

@ -102,6 +102,7 @@ public:
List, List,
New, New,
Import, Import,
ImportWithAddress,
Export, Export,
Recode, Recode,
Kill Kill
@ -159,6 +160,13 @@ public:
m_inputs = strings(1, argv[++i]); m_inputs = strings(1, argv[++i]);
m_name = argv[++i]; m_name = argv[++i];
} }
else if ((arg == "-i" || arg == "--import-with-address") && i + 3 < argc)
{
m_mode = OperationMode::ImportWithAddress;
m_inputs = strings(1, argv[++i]);
m_address = Address(argv[++i]);
m_name = argv[++i];
}
else if (arg == "--export") else if (arg == "--export")
m_mode = OperationMode::Export; m_mode = OperationMode::Export;
else if (arg == "--recode") else if (arg == "--recode")
@ -314,6 +322,33 @@ public:
cout << " ICAP: " << ICAP(k.address()).encoded() << endl; cout << " ICAP: " << ICAP(k.address()).encoded() << endl;
break; break;
} }
case OperationMode::ImportWithAddress:
{
string const& i = m_inputs[0];
h128 u;
bytes b;
b = fromHex(i);
if (b.size() != 32)
{
std::string s = contentsString(i);
b = fromHex(s);
if (b.size() != 32)
u = wallet.store().importKey(i);
}
if (!u && b.size() == 32)
u = wallet.store().importSecret(b, lockPassword(toAddress(Secret(b)).abridged()));
if (!u)
{
cerr << "Cannot import " << i << " not a file or secret." << endl;
break;
}
wallet.importExisting(u, m_name, m_address);
cout << "Successfully imported " << i << ":" << endl;
cout << " Name: " << m_name << endl;
cout << " Address: " << m_address << endl;
cout << " UUID: " << toUUID(u) << endl;
break;
}
case OperationMode::List: case OperationMode::List:
{ {
vector<u128> bare; vector<u128> bare;
@ -369,6 +404,7 @@ public:
<< " -l,--list List all keys available in wallet." << endl << " -l,--list List all keys available in wallet." << endl
<< " -n,--new <name> Create a new key with given name and add it in the wallet." << endl << " -n,--new <name> Create a new key with given name and add it in the wallet." << endl
<< " -i,--import [<uuid>|<file>|<secret-hex>] <name> Import keys from given source and place in wallet." << endl << " -i,--import [<uuid>|<file>|<secret-hex>] <name> Import keys from given source and place in wallet." << endl
<< " --import-with-address [<uuid>|<file>|<secret-hex>] <address> <name> Import keys from given source with given address and place in wallet." << endl
<< " -e,--export [ <address>|<uuid> , ... ] Export given keys." << endl << " -e,--export [ <address>|<uuid> , ... ] Export given keys." << endl
<< " -r,--recode [ <address>|<uuid>|<file> , ... ] Decrypt and re-encrypt given keys." << endl << " -r,--recode [ <address>|<uuid>|<file> , ... ] Decrypt and re-encrypt given keys." << endl
<< "Wallet configuration:" << endl << "Wallet configuration:" << endl
@ -418,8 +454,9 @@ private:
string m_lockHint; string m_lockHint;
bool m_icap = true; bool m_icap = true;
/// Creating /// Creating/importing
string m_name; string m_name;
Address m_address;
/// Importing /// Importing
strings m_inputs; strings m_inputs;

4
evmjit/libevmjit-cpp/JitVM.cpp

@ -18,7 +18,7 @@ namespace eth
extern "C" void env_sload(); // fake declaration for linker symbol stripping workaround, see a call below extern "C" void env_sload(); // fake declaration for linker symbol stripping workaround, see a call below
bytesConstRef JitVM::go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _step) bytesConstRef JitVM::execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp)
{ {
using namespace jit; using namespace jit;
@ -33,7 +33,7 @@ bytesConstRef JitVM::go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, ui
{ {
cwarn << "Execution rejected by EVM JIT (gas limit: " << io_gas << "), executing with interpreter"; cwarn << "Execution rejected by EVM JIT (gas limit: " << io_gas << "), executing with interpreter";
m_fallbackVM = VMFactory::create(VMKind::Interpreter); m_fallbackVM = VMFactory::create(VMKind::Interpreter);
return m_fallbackVM->go(io_gas, _ext, _onOp, _step); return m_fallbackVM->execImpl(io_gas, _ext, _onOp);
} }
m_data.gas = static_cast<decltype(m_data.gas)>(io_gas); m_data.gas = static_cast<decltype(m_data.gas)>(io_gas);

2
evmjit/libevmjit-cpp/JitVM.h

@ -11,7 +11,7 @@ namespace eth
class JitVM: public VMFace class JitVM: public VMFace
{ {
public: public:
virtual bytesConstRef go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp = {}, uint64_t _steps = (uint64_t)-1) override final; virtual bytesConstRef execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp) override final;
private: private:
jit::RuntimeData m_data; jit::RuntimeData m_data;

2
libdevcore/Common.cpp

@ -28,7 +28,7 @@ using namespace dev;
namespace dev namespace dev
{ {
char const* Version = "0.9.23"; char const* Version = "0.9.24";
const u256 UndefinedU256 = ~(u256)0; const u256 UndefinedU256 = ~(u256)0;

42
libdevcore/CommonData.cpp

@ -67,7 +67,7 @@ std::string dev::randomWord()
return ret; return ret;
} }
int dev::fromHex(char _i) int dev::fromHex(char _i, WhenError _throw)
{ {
if (_i >= '0' && _i <= '9') if (_i >= '0' && _i <= '9')
return _i - '0'; return _i - '0';
@ -75,7 +75,10 @@ int dev::fromHex(char _i)
return _i - 'a' + 10; return _i - 'a' + 10;
if (_i >= 'A' && _i <= 'F') if (_i >= 'A' && _i <= 'F')
return _i - 'A' + 10; return _i - 'A' + 10;
if (_throw == WhenError::Throw)
BOOST_THROW_EXCEPTION(BadHexCharacter() << errinfo_invalidSymbol(_i)); BOOST_THROW_EXCEPTION(BadHexCharacter() << errinfo_invalidSymbol(_i));
else
return -1;
} }
bytes dev::fromHex(std::string const& _s, WhenError _throw) bytes dev::fromHex(std::string const& _s, WhenError _throw)
@ -85,32 +88,25 @@ bytes dev::fromHex(std::string const& _s, WhenError _throw)
ret.reserve((_s.size() - s + 1) / 2); ret.reserve((_s.size() - s + 1) / 2);
if (_s.size() % 2) if (_s.size() % 2)
try
{ {
ret.push_back(fromHex(_s[s++])); int h = fromHex(_s[s++], WhenError::DontThrow);
} if (h != -1)
catch (...) ret.push_back(h);
{ else if (_throw == WhenError::Throw)
ret.push_back(0); throw BadHexCharacter();
// msvc does not support it else
#ifndef BOOST_NO_EXCEPTIONS return bytes();
cwarn << boost::current_exception_diagnostic_information();
#endif
if (_throw == WhenError::Throw)
throw;
} }
for (unsigned i = s; i < _s.size(); i += 2) for (unsigned i = s; i < _s.size(); i += 2)
try
{ {
ret.push_back((byte)(fromHex(_s[i]) * 16 + fromHex(_s[i + 1]))); int h = fromHex(_s[i], WhenError::DontThrow);
} int l = fromHex(_s[i + 1], WhenError::DontThrow);
catch (...){ if (h != -1 && l != -1)
ret.push_back(0); ret.push_back((byte)(h * 16 + l));
#ifndef BOOST_NO_EXCEPTIONS else if (_throw == WhenError::Throw)
cwarn << boost::current_exception_diagnostic_information(); throw BadHexCharacter();
#endif else
if (_throw == WhenError::Throw) return bytes();
throw;
} }
return ret; return ret;
} }

2
libdevcore/CommonData.h

@ -61,7 +61,7 @@ std::string toHex(_T const& _data, int _w = 2, HexPrefix _prefix = HexPrefix::Do
/// Converts a (printable) ASCII hex character into the correspnding integer value. /// Converts a (printable) ASCII hex character into the correspnding integer value.
/// @example fromHex('A') == 10 && fromHex('f') == 15 && fromHex('5') == 5 /// @example fromHex('A') == 10 && fromHex('f') == 15 && fromHex('5') == 5
int fromHex(char _i); int fromHex(char _i, WhenError _throw);
/// Converts a (printable) ASCII hex string into the corresponding byte stream. /// Converts a (printable) ASCII hex string into the corresponding byte stream.
/// @example fromHex("41626261") == asBytes("Abba") /// @example fromHex("41626261") == asBytes("Abba")

2
libdevcrypto/Common.cpp

@ -37,7 +37,7 @@ using namespace dev::crypto;
static Secp256k1 s_secp256k1; static Secp256k1 s_secp256k1;
bool dev::SignatureStruct::isValid() const bool dev::SignatureStruct::isValid() const noexcept
{ {
if (v > 1 || if (v > 1 ||
r >= h256("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141") || r >= h256("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141") ||

2
libdevcrypto/Common.h

@ -51,7 +51,7 @@ struct SignatureStruct
operator Signature() const { return *(h520 const*)this; } operator Signature() const { return *(h520 const*)this; }
/// @returns true if r,s,v values are valid, otherwise false /// @returns true if r,s,v values are valid, otherwise false
bool isValid() const; bool isValid() const noexcept;
h256 r; h256 r;
h256 s; h256 s;

2
libdevcrypto/SecretStore.cpp

@ -164,7 +164,7 @@ void SecretStore::load(std::string const& _keysPath)
h128 SecretStore::readKey(std::string const& _file, bool _deleteFile) h128 SecretStore::readKey(std::string const& _file, bool _deleteFile)
{ {
cdebug << "Reading" << _file; cnote << "Reading" << _file;
return readKeyContent(contentsString(_file), _deleteFile ? _file : string()); return readKeyContent(contentsString(_file), _deleteFile ? _file : string());
} }

23
libethcore/KeyManager.cpp

@ -89,18 +89,18 @@ bool KeyManager::load(std::string const& _pass)
for (auto const& i: s[1]) for (auto const& i: s[1])
{ {
m_keyInfo[m_addrLookup[(Address)i[0]] = (h128)i[1]] = KeyInfo((h256)i[2], (std::string)i[3]); m_keyInfo[m_addrLookup[(Address)i[0]] = (h128)i[1]] = KeyInfo((h256)i[2], (std::string)i[3]);
cdebug << toString((Address)i[0]) << toString((h128)i[1]) << toString((h256)i[2]) << (std::string)i[3]; // cdebug << toString((Address)i[0]) << toString((h128)i[1]) << toString((h256)i[2]) << (std::string)i[3];
} }
for (auto const& i: s[2]) for (auto const& i: s[2])
m_passwordInfo[(h256)i[0]] = (std::string)i[1]; m_passwordInfo[(h256)i[0]] = (std::string)i[1];
m_password = (string)s[3]; m_password = (string)s[3];
} }
cdebug << hashPassword(m_password) << toHex(m_password); // cdebug << hashPassword(m_password) << toHex(m_password);
m_cachedPasswords[hashPassword(m_password)] = m_password; m_cachedPasswords[hashPassword(m_password)] = m_password;
cdebug << hashPassword(asString(m_key.ref())) << m_key.hex(); // cdebug << hashPassword(asString(m_key.ref())) << m_key.hex();
m_cachedPasswords[hashPassword(asString(m_key.ref()))] = asString(m_key.ref()); m_cachedPasswords[hashPassword(asString(m_key.ref()))] = asString(m_key.ref());
cdebug << hashPassword(_pass) << _pass; // cdebug << hashPassword(_pass) << _pass;
m_cachedPasswords[m_master = hashPassword(_pass)] = _pass; m_cachedPasswords[m_master = hashPassword(_pass)] = _pass;
return true; return true;
} }
@ -141,7 +141,7 @@ std::string KeyManager::getPassword(h256 const& _passHash, function<std::string(
std::string p = _pass(); std::string p = _pass();
if (p.empty()) if (p.empty())
break; break;
if (hashPassword(p) == _passHash || !_passHash) if (hashPassword(p) == _passHash || _passHash == UnknownPassword)
{ {
m_cachedPasswords[hashPassword(p)] = p; m_cachedPasswords[hashPassword(p)] = p;
return p; return p;
@ -186,12 +186,17 @@ void KeyManager::importExisting(h128 const& _uuid, std::string const& _info, std
return; return;
Address a = KeyPair(Secret(key)).address(); Address a = KeyPair(Secret(key)).address();
auto passHash = hashPassword(_pass); auto passHash = hashPassword(_pass);
if (!m_passwordInfo.count(passHash))
m_passwordInfo[passHash] = _passInfo;
if (!m_cachedPasswords.count(passHash)) if (!m_cachedPasswords.count(passHash))
m_cachedPasswords[passHash] = _pass; m_cachedPasswords[passHash] = _pass;
m_addrLookup[a] = _uuid; importExisting(_uuid, _info, a, passHash, _passInfo);
m_keyInfo[_uuid].passHash = passHash; }
void KeyManager::importExisting(h128 const& _uuid, std::string const& _info, Address const& _address, h256 const& _passHash, std::string const& _passInfo)
{
if (!m_passwordInfo.count(_passHash))
m_passwordInfo[_passHash] = _passInfo;
m_addrLookup[_address] = _uuid;
m_keyInfo[_uuid].passHash = _passHash;
m_keyInfo[_uuid].info = _info; m_keyInfo[_uuid].info = _info;
write(m_keysFile); write(m_keysFile);
} }

11
libethcore/KeyManager.h

@ -30,17 +30,19 @@ namespace dev
{ {
namespace eth namespace eth
{ {
class UnknownPassword: public Exception {}; class PasswordUnknown: public Exception {};
struct KeyInfo struct KeyInfo
{ {
KeyInfo() = default; KeyInfo() = default;
KeyInfo(h256 const& _passHash, std::string const& _info): passHash(_passHash), info(_info) {} KeyInfo(h256 const& _passHash, std::string const& _info): passHash(_passHash), info(_info) {}
h256 passHash;
std::string info; h256 passHash; ///< Hash of the password or h256() if unknown.
std::string info; ///< Name of the key, or JSON key info if begins with '{'.
}; };
static const auto DontKnowThrow = [](){ throw UnknownPassword(); return std::string(); }; static const h256 UnknownPassword;
static const auto DontKnowThrow = [](){ throw PasswordUnknown(); return std::string(); };
enum class SemanticPassword enum class SemanticPassword
{ {
@ -89,6 +91,7 @@ public:
SecretStore& store() { return m_store; } SecretStore& store() { return m_store; }
void importExisting(h128 const& _uuid, std::string const& _info, std::string const& _pass, std::string const& _passInfo); void importExisting(h128 const& _uuid, std::string const& _info, std::string const& _pass, std::string const& _passInfo);
void importExisting(h128 const& _uuid, std::string const& _info) { importExisting(_uuid, _info, defaultPassword(), std::string()); } void importExisting(h128 const& _uuid, std::string const& _info) { importExisting(_uuid, _info, defaultPassword(), std::string()); }
void importExisting(h128 const& _uuid, std::string const& _info, Address const& _addr, h256 const& _passHash = h256(), std::string const& _passInfo = std::string());
Secret secret(Address const& _address, std::function<std::string()> const& _pass = DontKnowThrow) const; Secret secret(Address const& _address, std::function<std::string()> const& _pass = DontKnowThrow) const;
Secret secret(h128 const& _uuid, std::function<std::string()> const& _pass = DontKnowThrow) const; Secret secret(h128 const& _uuid, std::function<std::string()> const& _pass = DontKnowThrow) const;

3
libethereum/Client.cpp

@ -429,9 +429,10 @@ ExecutionResult Client::call(Address _dest, bytes const& _data, u256 _gas, u256
temp = m_postMine; temp = m_postMine;
temp.addBalance(_from, _value + _gasPrice * _gas); temp.addBalance(_from, _value + _gasPrice * _gas);
Executive e(temp, LastHashes(), 0); Executive e(temp, LastHashes(), 0);
e.setResultRecipient(ret);
if (!e.call(_dest, _from, _value, _gasPrice, &_data, _gas)) if (!e.call(_dest, _from, _value, _gasPrice, &_data, _gas))
e.go(); e.go();
ret = e.executionResult(); e.finalize();
} }
catch (...) catch (...)
{ {

6
libethereum/CommonNet.h

@ -38,14 +38,16 @@ namespace eth
#if ETH_DEBUG #if ETH_DEBUG
static const unsigned c_maxHashes = 2048; ///< Maximum number of hashes BlockHashes will ever send. static const unsigned c_maxHashes = 2048; ///< Maximum number of hashes BlockHashes will ever send.
static const unsigned c_maxHashesAsk = 2048; ///< Maximum number of hashes GetBlockHashes will ever ask for. static const unsigned c_maxHashesAsk = 256; ///< Maximum number of hashes GetBlockHashes will ever ask for.
static const unsigned c_maxBlocks = 128; ///< Maximum number of blocks Blocks will ever send. static const unsigned c_maxBlocks = 128; ///< Maximum number of blocks Blocks will ever send.
static const unsigned c_maxBlocksAsk = 128; ///< Maximum number of blocks we ask to receive in Blocks (when using GetChain). static const unsigned c_maxBlocksAsk = 8; ///< Maximum number of blocks we ask to receive in Blocks (when using GetChain).
static const unsigned c_maxPayload = 262144; ///< Maximum size of packet for us to send.
#else #else
static const unsigned c_maxHashes = 2048; ///< Maximum number of hashes BlockHashes will ever send. static const unsigned c_maxHashes = 2048; ///< Maximum number of hashes BlockHashes will ever send.
static const unsigned c_maxHashesAsk = 2048; ///< Maximum number of hashes GetBlockHashes will ever ask for. static const unsigned c_maxHashesAsk = 2048; ///< Maximum number of hashes GetBlockHashes will ever ask for.
static const unsigned c_maxBlocks = 128; ///< Maximum number of blocks Blocks will ever send. static const unsigned c_maxBlocks = 128; ///< Maximum number of blocks Blocks will ever send.
static const unsigned c_maxBlocksAsk = 128; ///< Maximum number of blocks we ask to receive in Blocks (when using GetChain). static const unsigned c_maxBlocksAsk = 128; ///< Maximum number of blocks we ask to receive in Blocks (when using GetChain).
static const unsigned c_maxPayload = 262144; ///< Maximum size of packet for us to send.
#endif #endif
class BlockChain; class BlockChain;

4
libethereum/EthereumHost.cpp

@ -255,7 +255,9 @@ void EthereumHost::onPeerStatus(EthereumPeer* _peer)
else else
{ {
if (_peer->m_latestBlockNumber > m_chain.number()) if (_peer->m_latestBlockNumber > m_chain.number())
_peer->m_expectedHashes = (unsigned)_peer->m_latestBlockNumber - m_chain.number(); _peer->m_expectedHashes = (unsigned)_peer->m_latestBlockNumber - m_chain.number() + 1000;
else
_peer->m_expectedHashes = 1000;
if (m_hashMan.chainSize() < _peer->m_expectedHashes) if (m_hashMan.chainSize() < _peer->m_expectedHashes)
m_hashMan.resetToRange(m_chain.number() + 1, _peer->m_expectedHashes); m_hashMan.resetToRange(m_chain.number() + 1, _peer->m_expectedHashes);
} }

4
libethereum/EthereumPeer.cpp

@ -262,7 +262,7 @@ bool EthereumPeer::interpret(unsigned _id, RLP const& _r)
// return the requested blocks. // return the requested blocks.
bytes rlp; bytes rlp;
unsigned n = 0; unsigned n = 0;
for (unsigned i = 0; i < min(count, c_maxBlocks); ++i) for (unsigned i = 0; i < min(count, c_maxBlocks) && rlp.size() < c_maxPayload; ++i)
{ {
auto h = _r[i].toHash<h256>(); auto h = _r[i].toHash<h256>();
if (host()->chain().isKnown(h)) if (host()->chain().isKnown(h))
@ -285,7 +285,7 @@ bool EthereumPeer::interpret(unsigned _id, RLP const& _r)
case BlocksPacket: case BlocksPacket:
{ {
if (m_asking != Asking::Blocks) if (m_asking != Asking::Blocks)
clog(NetWarn) << "Peer giving us blocks when we didn't ask for them."; clog(NetImpolite) << "Peer giving us blocks when we didn't ask for them.";
else else
{ {
setAsking(Asking::Nothing); setAsking(Asking::Nothing);

63
libethereum/Executive.cpp

@ -45,11 +45,6 @@ u256 Executive::gasUsed() const
return m_t.gas() - m_gas; return m_t.gas() - m_gas;
} }
ExecutionResult Executive::executionResult() const
{
return ExecutionResult(gasUsed(), m_excepted, m_newAddress, m_out, m_codeDeposit, m_ext ? m_ext->sub.refunds : 0, m_depositSize, m_gasForDeposit);
}
void Executive::accrueSubState(SubState& _parentContext) void Executive::accrueSubState(SubState& _parentContext)
{ {
if (m_ext) if (m_ext)
@ -146,8 +141,7 @@ bool Executive::call(CallParameters const& _p, u256 const& _gasPrice, Address co
else else
{ {
m_gas = (u256)(_p.gas - g); m_gas = (u256)(_p.gas - g);
m_precompiledOut = it->second.exec(_p.data); it->second.exec(_p.data, _p.out);
m_out = &m_precompiledOut;
} }
} }
else else
@ -155,7 +149,7 @@ bool Executive::call(CallParameters const& _p, u256 const& _gasPrice, Address co
m_gas = _p.gas; m_gas = _p.gas;
if (m_s.addressHasCode(_p.codeAddress)) if (m_s.addressHasCode(_p.codeAddress))
{ {
m_vm = VMFactory::create(); m_outRef = _p.out; // Save ref to expected output buffer to be used in go()
bytes const& c = m_s.code(_p.codeAddress); bytes const& c = m_s.code(_p.codeAddress);
m_ext = make_shared<ExtVM>(m_s, m_lastHashes, _p.receiveAddress, _p.senderAddress, _origin, _p.value, _gasPrice, _p.data, &c, m_depth); m_ext = make_shared<ExtVM>(m_s, m_lastHashes, _p.receiveAddress, _p.senderAddress, _origin, _p.value, _gasPrice, _p.data, &c, m_depth);
} }
@ -177,10 +171,7 @@ bool Executive::create(Address _sender, u256 _endowment, u256 _gasPrice, u256 _g
// Execute _init. // Execute _init.
if (!_init.empty()) if (!_init.empty())
{
m_vm = VMFactory::create();
m_ext = make_shared<ExtVM>(m_s, m_lastHashes, m_newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _init, m_depth); m_ext = make_shared<ExtVM>(m_s, m_lastHashes, m_newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _init, m_depth);
}
m_s.m_cache[m_newAddress] = Account(m_s.balance(m_newAddress), Account::ContractConception); m_s.m_cache[m_newAddress] = Account(m_s.balance(m_newAddress), Account::ContractConception);
m_s.transferBalance(_sender, m_newAddress, _endowment); m_s.transferBalance(_sender, m_newAddress, _endowment);
@ -231,36 +222,48 @@ OnOpFunc Executive::standardTrace(ostream& o_output)
bool Executive::go(OnOpFunc const& _onOp) bool Executive::go(OnOpFunc const& _onOp)
{ {
if (m_vm) if (m_ext)
{ {
#if ETH_TIMED_EXECUTIONS #if ETH_TIMED_EXECUTIONS
boost::timer t; boost::timer t;
#endif #endif
try try
{ {
m_out = m_vm->go(m_gas, *m_ext, _onOp); auto vm = VMFactory::create();
if (m_isCreation) if (m_isCreation)
{ {
m_gasForDeposit = m_gas; auto out = vm->exec(m_gas, *m_ext, _onOp);
m_depositSize = m_out.size(); if (m_res)
if (m_out.size() * c_createDataGas <= m_gas)
{ {
m_codeDeposit = CodeDeposit::Success; m_res->gasForDeposit = m_gas;
m_gas -= m_out.size() * c_createDataGas; m_res->depositSize = out.size();
} }
else if (out.size() * c_createDataGas <= m_gas)
{ {
if (m_res)
m_codeDeposit = CodeDeposit::Failed; m_res->codeDeposit = CodeDeposit::Success;
m_out.reset(); m_gas -= out.size() * c_createDataGas;
} }
m_s.m_cache[m_newAddress].setCode(m_out.toBytes()); else
{
if (m_res)
m_res->codeDeposit = CodeDeposit::Failed;
out.clear();
} }
if (m_res)
m_res->output = out; // copy output to execution result
m_s.m_cache[m_newAddress].setCode(std::move(out)); // FIXME: Set only if Success?
} }
catch (StepsDone const&) else
{
if (m_res)
{ {
return false; m_res->output = vm->exec(m_gas, *m_ext, _onOp); // take full output
bytesConstRef{&m_res->output}.copyTo(m_outRef);
}
else
vm->exec(m_gas, *m_ext, m_outRef, _onOp); // take only expected output
}
} }
catch (VMException const& _e) catch (VMException const& _e)
{ {
@ -314,4 +317,12 @@ void Executive::finalize()
// Logs.. // Logs..
if (m_ext) if (m_ext)
m_logs = m_ext->sub.logs; m_logs = m_ext->sub.logs;
if (m_res) // Collect results
{
m_res->gasUsed = gasUsed();
m_res->excepted = m_excepted; // TODO: m_except is used only in ExtVM::call
m_res->newAddress = m_newAddress;
m_res->gasRefunded = m_ext ? m_ext->sub.refunds : 0;
}
} }

15
libethereum/Executive.h

@ -112,30 +112,25 @@ public:
/// @returns gas remaining after the transaction/operation. Valid after the transaction has been executed. /// @returns gas remaining after the transaction/operation. Valid after the transaction has been executed.
u256 gas() const { return m_gas; } u256 gas() const { return m_gas; }
/// @returns output data of the transaction/operation.
bytesConstRef out() const { return m_out; }
/// @returns the new address for the created contract in the CREATE operation. /// @returns the new address for the created contract in the CREATE operation.
h160 newAddress() const { return m_newAddress; } h160 newAddress() const { return m_newAddress; }
/// @returns true iff the operation ended with a VM exception. /// @returns true iff the operation ended with a VM exception.
bool excepted() const { return m_excepted != TransactionException::None; } bool excepted() const { return m_excepted != TransactionException::None; }
/// Get the above in an amalgamated fashion. /// Collect execution results in the result storage provided.
ExecutionResult executionResult() const; void setResultRecipient(ExecutionResult& _res) { m_res = &_res; }
private: private:
State& m_s; ///< The state to which this operation/transaction is applied. State& m_s; ///< The state to which this operation/transaction is applied.
LastHashes m_lastHashes; LastHashes m_lastHashes;
std::shared_ptr<ExtVM> m_ext; ///< The VM externality object for the VM execution or null if no VM is required. std::shared_ptr<ExtVM> m_ext; ///< The VM externality object for the VM execution or null if no VM is required.
std::unique_ptr<VMFace> m_vm; ///< The VM object or null if no VM is required. bytesRef m_outRef; ///< Reference to "expected output" buffer.
bytes m_precompiledOut; ///< Used for the output when there is no VM for a contract (i.e. precompiled). ExecutionResult* m_res = nullptr; ///< Optional storage for execution results.
bytesConstRef m_out; ///< The copyable output.
Address m_newAddress; ///< The address of the created contract in the case of create() being called. Address m_newAddress; ///< The address of the created contract in the case of create() being called.
unsigned m_depth = 0; ///< The context's call-depth. unsigned m_depth = 0; ///< The context's call-depth.
bool m_isCreation = false; ///< True if the transaction creates a contract, or if create() is called. bool m_isCreation = false; ///< True if the transaction creates a contract, or if create() is called.
unsigned m_depositSize = 0; ///< Amount of code of the creation's attempted deposit.
u256 m_gasForDeposit; ///< Amount of gas remaining for the code deposit phase.
CodeDeposit m_codeDeposit = CodeDeposit::None; ///< True if an attempted deposit failed due to lack of gas.
TransactionException m_excepted = TransactionException::None; ///< Details if the VM's execution resulted in an exception. TransactionException m_excepted = TransactionException::None; ///< Details if the VM's execution resulted in an exception.
u256 m_gas = 0; ///< The gas for EVM code execution. Initial amount before go() execution, final amount after go() execution. u256 m_gas = 0; ///< The gas for EVM code execution. Initial amount before go() execution, final amount after go() execution.

1
libethereum/ExtVM.cpp

@ -35,7 +35,6 @@ bool ExtVM::call(CallParameters& _p)
e.accrueSubState(sub); e.accrueSubState(sub);
} }
_p.gas = e.gas(); _p.gas = e.gas();
e.out().copyTo(_p.out);
return !e.excepted(); return !e.excepted();
} }

43
libethereum/Precompiled.cpp

@ -31,7 +31,10 @@ using namespace std;
using namespace dev; using namespace dev;
using namespace dev::eth; using namespace dev::eth;
static bytes ecrecoverCode(bytesConstRef _in) namespace
{
void ecrecoverCode(bytesConstRef _in, bytesRef _out)
{ {
struct inType struct inType
{ {
@ -44,38 +47,43 @@ static bytes ecrecoverCode(bytesConstRef _in)
memcpy(&in, _in.data(), min(_in.size(), sizeof(in))); memcpy(&in, _in.data(), min(_in.size(), sizeof(in)));
h256 ret; h256 ret;
u256 v = (u256)in.v;
if ((u256)in.v > 28) if (v >= 27 && v <= 28)
return ret.asBytes(); {
SignatureStruct sig(in.r, in.s, (byte)((int)(u256)in.v - 27)); SignatureStruct sig(in.r, in.s, (byte)((int)v - 27));
if (!sig.isValid()) if (sig.isValid())
return ret.asBytes(); {
try try
{ {
ret = dev::sha3(recover(sig, in.hash)); ret = sha3(recover(sig, in.hash));
} }
catch (...) {} catch (...) {}
}
}
memset(ret.data(), 0, 12); memset(ret.data(), 0, 12);
return ret.asBytes(); ret.ref().copyTo(_out);
} }
static bytes sha256Code(bytesConstRef _in) void sha256Code(bytesConstRef _in, bytesRef _out)
{ {
return sha256(_in).asBytes(); sha256(_in).ref().copyTo(_out);
} }
static bytes ripemd160Code(bytesConstRef _in) void ripemd160Code(bytesConstRef _in, bytesRef _out)
{ {
return h256(ripemd160(_in), h256::AlignRight).asBytes(); h256(ripemd160(_in), h256::AlignRight).ref().copyTo(_out);
} }
static bytes identityCode(bytesConstRef _in) void identityCode(bytesConstRef _in, bytesRef _out)
{ {
return _in.toBytes(); _in.copyTo(_out);
} }
}
std::unordered_map<unsigned, PrecompiledAddress> const& dev::eth::precompiled()
{
static const std::unordered_map<unsigned, PrecompiledAddress> c_precompiled = static const std::unordered_map<unsigned, PrecompiledAddress> c_precompiled =
{ {
{ 1, { [](bytesConstRef) -> bigint { return c_ecrecoverGas; }, ecrecoverCode }}, { 1, { [](bytesConstRef) -> bigint { return c_ecrecoverGas; }, ecrecoverCode }},
@ -83,8 +91,5 @@ static const std::unordered_map<unsigned, PrecompiledAddress> c_precompiled =
{ 3, { [](bytesConstRef i) -> bigint { return c_ripemd160Gas + (i.size() + 31) / 32 * c_ripemd160WordGas; }, ripemd160Code }}, { 3, { [](bytesConstRef i) -> bigint { return c_ripemd160Gas + (i.size() + 31) / 32 * c_ripemd160WordGas; }, ripemd160Code }},
{ 4, { [](bytesConstRef i) -> bigint { return c_identityGas + (i.size() + 31) / 32 * c_identityWordGas; }, identityCode }} { 4, { [](bytesConstRef i) -> bigint { return c_identityGas + (i.size() + 31) / 32 * c_identityWordGas; }, identityCode }}
}; };
std::unordered_map<unsigned, PrecompiledAddress> const& dev::eth::precompiled()
{
return c_precompiled; return c_precompiled;
} }

2
libethereum/Precompiled.h

@ -34,7 +34,7 @@ namespace eth
struct PrecompiledAddress struct PrecompiledAddress
{ {
std::function<bigint(bytesConstRef)> gas; std::function<bigint(bytesConstRef)> gas;
std::function<bytes(bytesConstRef)> exec; std::function<void(bytesConstRef, bytesRef)> exec;
}; };
/// Info on precompiled contract accounts baked into the protocol. /// Info on precompiled contract accounts baked into the protocol.

4
libethereum/State.cpp

@ -1171,6 +1171,8 @@ ExecutionResult State::execute(LastHashes const& _lh, Transaction const& _t, Per
// Create and initialize the executive. This will throw fairly cheaply and quickly if the // Create and initialize the executive. This will throw fairly cheaply and quickly if the
// transaction is bad in any way. // transaction is bad in any way.
Executive e(*this, _lh, 0); Executive e(*this, _lh, 0);
ExecutionResult res;
e.setResultRecipient(res);
e.initialize(_t); e.initialize(_t);
// Uncommitting is a non-trivial operation - only do it once we've verified as much of the // Uncommitting is a non-trivial operation - only do it once we've verified as much of the
@ -1230,7 +1232,7 @@ ExecutionResult State::execute(LastHashes const& _lh, Transaction const& _t, Per
m_transactionSet.insert(e.t().sha3()); m_transactionSet.insert(e.t().sha3());
} }
return e.executionResult(); return res;
} }
State State::fromPending(unsigned _i) const State State::fromPending(unsigned _i) const

17
libethereum/Transaction.h

@ -74,25 +74,14 @@ TransactionException toTransactionException(VMException const& _e);
/// Description of the result of executing a transaction. /// Description of the result of executing a transaction.
struct ExecutionResult struct ExecutionResult
{ {
ExecutionResult() = default;
ExecutionResult(u256 const& _gasUsed, TransactionException _excepted, Address const& _newAddress, bytesConstRef _output, CodeDeposit _codeDeposit, u256 const& _gasRefund, unsigned _depositSize, u256 const& _gasForDeposit):
gasUsed(_gasUsed),
excepted(_excepted),
newAddress(_newAddress),
output(_output.toBytes()),
codeDeposit(_codeDeposit),
gasRefunded(_gasRefund),
depositSize(_depositSize),
gasForDeposit(_gasForDeposit)
{}
u256 gasUsed = 0; u256 gasUsed = 0;
TransactionException excepted = TransactionException::Unknown; TransactionException excepted = TransactionException::Unknown;
Address newAddress; Address newAddress;
bytes output; bytes output;
CodeDeposit codeDeposit = CodeDeposit::None; CodeDeposit codeDeposit = CodeDeposit::None; ///< Failed if an attempted deposit failed due to lack of gas.
u256 gasRefunded = 0; u256 gasRefunded = 0;
unsigned depositSize = 0; unsigned depositSize = 0; ///< Amount of code of the creation's attempted deposit.
u256 gasForDeposit; u256 gasForDeposit; ///< Amount of gas remaining for the code deposit phase.
}; };
std::ostream& operator<<(std::ostream& _out, ExecutionResult const& _er); std::ostream& operator<<(std::ostream& _out, ExecutionResult const& _er);

4
libevm/SmartVM.cpp

@ -41,7 +41,7 @@ namespace
} }
} }
bytesConstRef SmartVM::go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps) bytesConstRef SmartVM::execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp)
{ {
auto codeHash = sha3(_ext.code); auto codeHash = sha3(_ext.code);
auto vmKind = VMKind::Interpreter; // default VM auto vmKind = VMKind::Interpreter; // default VM
@ -68,7 +68,7 @@ bytesConstRef SmartVM::go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp,
// TODO: Selected VM must be kept only because it returns reference to its internal memory. // TODO: Selected VM must be kept only because it returns reference to its internal memory.
// VM implementations should be stateless, without escaping memory reference. // VM implementations should be stateless, without escaping memory reference.
m_selectedVM = VMFactory::create(vmKind); m_selectedVM = VMFactory::create(vmKind);
return m_selectedVM->go(io_gas, _ext, _onOp, _steps); return m_selectedVM->execImpl(io_gas, _ext, _onOp);
} }
} }

2
libevm/SmartVM.h

@ -31,7 +31,7 @@ namespace eth
class SmartVM: public VMFace class SmartVM: public VMFace
{ {
public: public:
virtual bytesConstRef go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp = {}, uint64_t _steps = (uint64_t)-1) override final; virtual bytesConstRef execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp) override final;
private: private:
std::unique_ptr<VMFace> m_selectedVM; std::unique_ptr<VMFace> m_selectedVM;

9
libevm/VM.cpp

@ -45,7 +45,7 @@ static array<InstructionMetric, 256> metrics()
return s_ret; return s_ret;
} }
bytesConstRef VM::go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps) bytesConstRef VM::execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp)
{ {
// Reset leftovers from possible previous run // Reset leftovers from possible previous run
m_curPC = 0; m_curPC = 0;
@ -73,8 +73,7 @@ bytesConstRef VM::go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint6
i += _ext.code[i] - (unsigned)Instruction::PUSH1 + 1; i += _ext.code[i] - (unsigned)Instruction::PUSH1 + 1;
} }
u256 nextPC = m_curPC + 1; u256 nextPC = m_curPC + 1;
auto osteps = _steps; for (uint64_t steps = 0; true; m_curPC = nextPC, nextPC = m_curPC + 1, ++steps)
for (bool stopped = false; !stopped && _steps--; m_curPC = nextPC, nextPC = m_curPC + 1)
{ {
// INSTRUCTION... // INSTRUCTION...
Instruction inst = (Instruction)_ext.getCode(m_curPC); Instruction inst = (Instruction)_ext.getCode(m_curPC);
@ -97,7 +96,7 @@ bytesConstRef VM::go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint6
auto onOperation = [&]() auto onOperation = [&]()
{ {
if (_onOp) if (_onOp)
_onOp(osteps - _steps - 1, inst, newTempSize > m_temp.size() ? (newTempSize - m_temp.size()) / 32 : bigint(0), runGas, io_gas, this, &_ext); _onOp(steps, inst, newTempSize > m_temp.size() ? (newTempSize - m_temp.size()) / 32 : bigint(0), runGas, io_gas, this, &_ext);
}; };
switch (inst) switch (inst)
@ -670,7 +669,5 @@ bytesConstRef VM::go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp, uint6
} }
} }
if (_steps == (uint64_t)-1)
BOOST_THROW_EXCEPTION(StepsDone());
return bytesConstRef(); return bytesConstRef();
} }

2
libevm/VM.h

@ -52,7 +52,7 @@ inline u256 fromAddress(Address _a)
class VM: public VMFace class VM: public VMFace
{ {
public: public:
virtual bytesConstRef go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp = {}, uint64_t _steps = (uint64_t)-1) override final; virtual bytesConstRef execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp) override final;
u256 curPC() const { return m_curPC; } u256 curPC() const { return m_curPC; }

18
libevm/VMFace.h

@ -26,7 +26,6 @@ namespace eth
{ {
struct VMException: virtual Exception {}; struct VMException: virtual Exception {};
struct StepsDone: virtual VMException {};
struct BreakPointHit: virtual VMException {}; struct BreakPointHit: virtual VMException {};
struct BadInstruction: virtual VMException {}; struct BadInstruction: virtual VMException {};
struct BadJumpDestination: virtual VMException {}; struct BadJumpDestination: virtual VMException {};
@ -43,7 +42,22 @@ public:
VMFace(VMFace const&) = delete; VMFace(VMFace const&) = delete;
VMFace& operator=(VMFace const&) = delete; VMFace& operator=(VMFace const&) = delete;
virtual bytesConstRef go(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp = {}, uint64_t _steps = (uint64_t)-1) = 0; /// Execute EVM code by VM.
///
/// @param _out Expected output
void exec(u256& io_gas, ExtVMFace& _ext, bytesRef _out, OnOpFunc const& _onOp = {})
{
execImpl(io_gas, _ext, _onOp).copyTo(_out);
}
/// The same as above but returns a copy of full output.
bytes exec(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp = {})
{
return execImpl(io_gas, _ext, _onOp).toVector();
}
/// VM implementation
virtual bytesConstRef execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp) = 0;
}; };
} }

5
mix/MixClient.cpp

@ -130,7 +130,9 @@ void MixClient::executeTransaction(Transaction const& _t, State& _state, bool _c
State execState = _state; State execState = _state;
execState.addBalance(t.sender(), t.gas() * t.gasPrice()); //give it enough balance for gas estimation execState.addBalance(t.sender(), t.gas() * t.gasPrice()); //give it enough balance for gas estimation
eth::ExecutionResult er;
Executive execution(execState, lastHashes, 0); Executive execution(execState, lastHashes, 0);
execution.setResultRecipient(er);
execution.initialize(t); execution.initialize(t);
execution.execute(); execution.execute();
std::vector<MachineState> machineStates; std::vector<MachineState> machineStates;
@ -198,7 +200,6 @@ void MixClient::executeTransaction(Transaction const& _t, State& _state, bool _c
execution.go(onOp); execution.go(onOp);
execution.finalize(); execution.finalize();
dev::eth::ExecutionResult er = execution.executionResult();
switch (er.excepted) switch (er.excepted)
{ {
@ -225,7 +226,7 @@ void MixClient::executeTransaction(Transaction const& _t, State& _state, bool _c
}; };
ExecutionResult d; ExecutionResult d;
d.result = execution.executionResult(); d.result = er;
d.machineStates = machineStates; d.machineStates = machineStates;
d.executionCode = std::move(codes); d.executionCode = std::move(codes);
d.transactionData = std::move(data); d.transactionData = std::move(data);

4
test/fuzzTesting/checkRandomVMTest.cpp

@ -98,9 +98,9 @@ bool doVMTest(mValue& _v)
try try
{ {
auto vm = eth::VMFactory::create(); auto vm = eth::VMFactory::create();
output = vm->go(fev.gas, fev, fev.simpleTrace()).toBytes(); output = vm->exec(fev.gas, fev, fev.simpleTrace());
} }
catch (eth::VMException) catch (eth::VMException const&)
{ {
cnote << "Safe VM Exception"; cnote << "Safe VM Exception";
vmExceptionOccured = true; vmExceptionOccured = true;

2
test/fuzzTesting/createRandomVMTest.cpp

@ -160,7 +160,7 @@ void doMyTests(json_spirit::mValue& _v)
bool vmExceptionOccured = false; bool vmExceptionOccured = false;
try try
{ {
output = vm->go(fev.gas, fev, fev.simpleTrace()).toBytes(); output = vm->exec(fev.gas, fev, fev.simpleTrace());
} }
catch (eth::VMException const& _e) catch (eth::VMException const& _e)
{ {

4
test/libevm/vm.cpp

@ -330,12 +330,10 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
{ {
auto vm = eth::VMFactory::create(); auto vm = eth::VMFactory::create();
auto vmtrace = Options::get().vmtrace ? fev.simpleTrace() : OnOpFunc{}; auto vmtrace = Options::get().vmtrace ? fev.simpleTrace() : OnOpFunc{};
auto outputRef = bytesConstRef{};
{ {
Listener::ExecTimeGuard guard{i.first}; Listener::ExecTimeGuard guard{i.first};
outputRef = vm->go(fev.gas, fev, vmtrace); output = vm->exec(fev.gas, fev, vmtrace);
} }
output = outputRef.toBytes();
} }
catch (VMException const&) catch (VMException const&)
{ {

4
test/libsolidity/solidityExecutionFramework.h

@ -148,6 +148,8 @@ protected:
{ {
m_state.addBalance(m_sender, _value); // just in case m_state.addBalance(m_sender, _value); // just in case
eth::Executive executive(m_state, eth::LastHashes(), 0); eth::Executive executive(m_state, eth::LastHashes(), 0);
eth::ExecutionResult res;
executive.setResultRecipient(res);
eth::Transaction t = eth::Transaction t =
_isCreation ? _isCreation ?
eth::Transaction(_value, m_gasPrice, m_gas, _data, 0, KeyPair::create().sec()) : eth::Transaction(_value, m_gasPrice, m_gas, _data, 0, KeyPair::create().sec()) :
@ -176,7 +178,7 @@ protected:
m_state.noteSending(m_sender); m_state.noteSending(m_sender);
executive.finalize(); executive.finalize();
m_gasUsed = executive.gasUsed(); m_gasUsed = executive.gasUsed();
m_output = executive.out().toVector(); m_output = std::move(res.output); // FIXME: Looks like Framework needs ExecutiveResult embedded
m_logs = executive.logs(); m_logs = executive.logs();
} }

Loading…
Cancel
Save