diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index 2146a6d84..15190ae3c 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -113,12 +113,13 @@ bool Executive::call(Address _receiveAddress, Address _senderAddress, u256 _valu auto it = !(_receiveAddress & ~h160(0xffffffff)) ? State::precompiled().find((unsigned)(u160)_receiveAddress) : State::precompiled().end(); if (it != State::precompiled().end()) { - if (_gas < it->second.gas(_data)) + bigint g = it->second.gas(_data); + if (_gas < g) { m_endGas = 0; return false; } - m_endGas = (u256)(_gas - it->second.gas(_data)); + m_endGas = (u256)(_gas - g); it->second.exec(_data, bytesRef()); return true; } diff --git a/libethereum/State.cpp b/libethereum/State.cpp index 8664c0c52..9d8efbbb5 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -1216,8 +1216,6 @@ bool State::call(Address _receiveAddress, Address _codeAddress, Address _senderA { VM vm(*_gas); ExtVM evm(*this, _receiveAddress, _senderAddress, _originAddress, _value, _gasPrice, _data, &code(_codeAddress), o_ms, _level); - bool revert = false; - try { auto out = vm.go(evm, _onOp); @@ -1227,29 +1225,30 @@ bool State::call(Address _receiveAddress, Address _codeAddress, Address _senderA if (o_ms) o_ms->output = out.toBytes(); *_gas = vm.gas(); + // Write state out only in the case of a non-excepted transaction. + return true; } catch (VMException const& _e) { clog(StateChat) << "Safe VM Exception: " << diagnostic_information(_e); - revert = true; + evm.revert(); *_gas = 0; + return false; } catch (Exception const& _e) { cwarn << "Unexpected exception in VM: " << diagnostic_information(_e) << ". This is exceptionally bad."; // TODO: use fallback known-safe VM. + // AUDIT: THIS SHOULD NEVER HAPPEN! PROVE IT! + throw; } catch (std::exception const& _e) { cwarn << "Unexpected exception in VM: " << _e.what() << ". This is exceptionally bad."; // TODO: use fallback known-safe VM. + // AUDIT: THIS SHOULD NEVER HAPPEN! PROVE IT! + throw; } - - // Write state out only in the case of a non-excepted transaction. - if (revert) - evm.revert(); - - return !revert; } return true; } @@ -1305,11 +1304,13 @@ h160 State::create(Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas, { // TODO: AUDIT: check that this can never reasonably happen. Consider what to do if it does. cwarn << "Unexpected exception in VM. There may be a bug in this implementation. " << diagnostic_information(_e); + throw; } catch (std::exception const& _e) { // TODO: AUDIT: check that this can never reasonably happen. Consider what to do if it does. cwarn << "Unexpected std::exception in VM. This is probably unrecoverable. " << _e.what(); + throw; } return newAddress;