From 721abb8f0fe23de40493f19b99e2224560661f02 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Mon, 27 Oct 2014 12:13:14 +0100 Subject: [PATCH] PoC-7 Exception severity uniform. --- libethereum/Executive.cpp | 7 +++++-- libethereum/State.cpp | 20 ++++++++++++++------ libevm/VM.h | 2 +- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index 193010cfa..d1ed3da11 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -187,14 +187,17 @@ bool Executive::go(OnOpFunc const& _onOp) { clog(StateChat) << "VM Exception: " << diagnostic_information(_e); m_endGas = m_vm->gas(); + revert = true; } catch (Exception const& _e) { - clog(StateChat) << "Exception in VM: " << diagnostic_information(_e); + // 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); } catch (std::exception const& _e) { - clog(StateChat) << "std::exception in VM: " << _e.what(); + // 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(); } cnote << "VM took:" << t.elapsed() << "; gas used: " << (sgas - m_endGas); diff --git a/libethereum/State.cpp b/libethereum/State.cpp index 931ee2cf6..0f0d5dc90 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -1168,6 +1168,7 @@ bool State::call(Address _receiveAddress, Address _codeAddress, Address _senderA catch (VMException const& _e) { clog(StateChat) << "VM Exception: " << diagnostic_information(_e); + revert = true; } catch (Exception const& _e) { @@ -1230,25 +1231,32 @@ h160 State::create(Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas, catch (VMException const& _e) { clog(StateChat) << "VM Exception: " << diagnostic_information(_e); + revert = true; } catch (Exception const& _e) { - clog(StateChat) << "Exception in VM: " << diagnostic_information(_e); + // 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); } catch (std::exception const& _e) { - clog(StateChat) << "std::exception in VM: " << _e.what(); + // 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(); } // TODO: CHECK: IS THIS CORRECT?! (esp. given account created prior to revertion init.) // Write state out only in the case of a non-out-of-gas transaction. if (revert) + { evm.revert(); - - // Set code. - if (addressInUse(newAddress)) - m_cache[newAddress].setCode(out); + m_cache.erase(newAddress); + newAddress = Address(); + } + else + // Set code. + if (addressInUse(newAddress)) + m_cache[newAddress].setCode(out); *_gas = vm.gas(); diff --git a/libevm/VM.h b/libevm/VM.h index ce8001bbf..3ea9d1b87 100644 --- a/libevm/VM.h +++ b/libevm/VM.h @@ -41,7 +41,7 @@ struct BreakPointHit: virtual VMException {}; struct BadInstruction: virtual VMException {}; struct BadJumpDestination: virtual VMException {}; struct OutOfGas: virtual VMException {}; -class StackTooSmall: virtual public VMException { public: StackTooSmall(u256 _req, u256 _got): req(_req), got(_got) {} u256 req; u256 got; }; +struct StackTooSmall: virtual public VMException { StackTooSmall(u256 _req, u256 _got): req(_req), got(_got) {} u256 req; u256 got; }; // Convert from a 256-bit integer stack/memory entry into a 160-bit Address hash. // Currently we just pull out the right (low-order in BE) 160-bits.