diff --git a/libaleth-interpreter/VM.cpp b/libaleth-interpreter/VM.cpp index 37e66252c0e..e1e45785208 100644 --- a/libaleth-interpreter/VM.cpp +++ b/libaleth-interpreter/VM.cpp @@ -42,16 +42,11 @@ evmc_result execute(evmc_vm* _instance, evmc_host_context* _context, evmc_revisi catch (evmc_status_code statusCode) { result.status_code = statusCode; - } - catch (dev::eth::RevertInstruction& ex) - { - result.status_code = EVMC_REVERT; - result.gas_left = vm->m_io_gas; - output = ex.output(); // This moves the output from the exception! - } - catch (dev::eth::VMException const&) - { - result.status_code = EVMC_FAILURE; + if (statusCode == EVMC_REVERT) + { + result.gas_left = vm->m_io_gas; + output = std::move(vm->m_output); + } } catch (...) { @@ -302,10 +297,7 @@ void VM::interpretCases() updateMem(memNeed(m_SP[0], m_SP[1])); updateIOGas(); - uint64_t b = (uint64_t)m_SP[0]; - uint64_t s = (uint64_t)m_SP[1]; - owning_bytes_ref output{std::move(m_mem), b, s}; - throwRevertInstruction(std::move(output)); + throwRevertInstruction((uint64_t)m_SP[0], (uint64_t)m_SP[1]); } BREAK; diff --git a/libaleth-interpreter/VM.h b/libaleth-interpreter/VM.h index 9b68b35be4d..9b3658d876b 100644 --- a/libaleth-interpreter/VM.h +++ b/libaleth-interpreter/VM.h @@ -5,14 +5,13 @@ #include "VMConfig.h" -#include #include - #include #include - #include +#include + namespace dev { namespace eth @@ -56,6 +55,9 @@ class VM owning_bytes_ref exec(evmc_host_context* _context, evmc_revision _rev, const evmc_message* _msg, uint8_t const* _code, size_t _codeSize); + // return bytes + owning_bytes_ref m_output; + uint64_t m_io_gas = 0; private: evmc_host_context* m_context = nullptr; @@ -69,9 +71,6 @@ class VM MemFnPtr m_bounce = nullptr; uint64_t m_nSteps = 0; - // return bytes - owning_bytes_ref m_output; - // space for memory bytes m_mem; @@ -124,7 +123,7 @@ class VM static void throwBadInstruction(); static void throwBadJumpDestination(); void throwBadStack(int _removed); - static void throwRevertInstruction(owning_bytes_ref&& _output); + void throwRevertInstruction(uint64_t _offset, uint64_t _size); static void throwDisallowedStateChange(); static void throwBufferOverrun(); diff --git a/libaleth-interpreter/VMCalls.cpp b/libaleth-interpreter/VMCalls.cpp index a53faebf73a..1108192d467 100644 --- a/libaleth-interpreter/VMCalls.cpp +++ b/libaleth-interpreter/VMCalls.cpp @@ -61,11 +61,10 @@ void VM::throwBadStack(int _required) throw EVMC_STACK_OVERFLOW; } -void VM::throwRevertInstruction(owning_bytes_ref&& _output) +void VM::throwRevertInstruction(uint64_t _offset, uint64_t _size) { - // We can't use BOOST_THROW_EXCEPTION here because it makes a copy of exception inside and - // RevertInstruction has no copy constructor - throw RevertInstruction(std::move(_output)); + m_output = owning_bytes_ref{std::move(m_mem), _offset, _size}; + throw EVMC_REVERT; } void VM::throwBufferOverrun()