Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
interpreter: Simplify REVERT output handling
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Oct 28, 2019
1 parent c0b0700 commit cc169fe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 25 deletions.
20 changes: 6 additions & 14 deletions libaleth-interpreter/VM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (...)
{
Expand Down Expand Up @@ -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;

Expand Down
13 changes: 6 additions & 7 deletions libaleth-interpreter/VM.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@

#include "VMConfig.h"

#include <libevm/VMFace.h>
#include <intx/intx.hpp>

#include <evmc/evmc.h>
#include <evmc/instructions.h>

#include <boost/optional.hpp>

#include <libevm/ExtVMFace.h>

namespace dev
{
namespace eth
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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();

Expand Down
7 changes: 3 additions & 4 deletions libaleth-interpreter/VMCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit cc169fe

Please sign in to comment.