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

Commit cc169fe

Browse files
committedOct 28, 2019
interpreter: Simplify REVERT output handling
1 parent c0b0700 commit cc169fe

File tree

3 files changed

+15
-25
lines changed

3 files changed

+15
-25
lines changed
 

‎libaleth-interpreter/VM.cpp

+6-14
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,11 @@ evmc_result execute(evmc_vm* _instance, evmc_host_context* _context, evmc_revisi
4242
catch (evmc_status_code statusCode)
4343
{
4444
result.status_code = statusCode;
45-
}
46-
catch (dev::eth::RevertInstruction& ex)
47-
{
48-
result.status_code = EVMC_REVERT;
49-
result.gas_left = vm->m_io_gas;
50-
output = ex.output(); // This moves the output from the exception!
51-
}
52-
catch (dev::eth::VMException const&)
53-
{
54-
result.status_code = EVMC_FAILURE;
45+
if (statusCode == EVMC_REVERT)
46+
{
47+
result.gas_left = vm->m_io_gas;
48+
output = std::move(vm->m_output);
49+
}
5550
}
5651
catch (...)
5752
{
@@ -302,10 +297,7 @@ void VM::interpretCases()
302297
updateMem(memNeed(m_SP[0], m_SP[1]));
303298
updateIOGas();
304299

305-
uint64_t b = (uint64_t)m_SP[0];
306-
uint64_t s = (uint64_t)m_SP[1];
307-
owning_bytes_ref output{std::move(m_mem), b, s};
308-
throwRevertInstruction(std::move(output));
300+
throwRevertInstruction((uint64_t)m_SP[0], (uint64_t)m_SP[1]);
309301
}
310302
BREAK;
311303

‎libaleth-interpreter/VM.h

+6-7
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55

66
#include "VMConfig.h"
77

8-
#include <libevm/VMFace.h>
98
#include <intx/intx.hpp>
10-
119
#include <evmc/evmc.h>
1210
#include <evmc/instructions.h>
13-
1411
#include <boost/optional.hpp>
1512

13+
#include <libevm/ExtVMFace.h>
14+
1615
namespace dev
1716
{
1817
namespace eth
@@ -56,6 +55,9 @@ class VM
5655
owning_bytes_ref exec(evmc_host_context* _context, evmc_revision _rev, const evmc_message* _msg,
5756
uint8_t const* _code, size_t _codeSize);
5857

58+
// return bytes
59+
owning_bytes_ref m_output;
60+
5961
uint64_t m_io_gas = 0;
6062
private:
6163
evmc_host_context* m_context = nullptr;
@@ -69,9 +71,6 @@ class VM
6971
MemFnPtr m_bounce = nullptr;
7072
uint64_t m_nSteps = 0;
7173

72-
// return bytes
73-
owning_bytes_ref m_output;
74-
7574
// space for memory
7675
bytes m_mem;
7776

@@ -124,7 +123,7 @@ class VM
124123
static void throwBadInstruction();
125124
static void throwBadJumpDestination();
126125
void throwBadStack(int _removed);
127-
static void throwRevertInstruction(owning_bytes_ref&& _output);
126+
void throwRevertInstruction(uint64_t _offset, uint64_t _size);
128127
static void throwDisallowedStateChange();
129128
static void throwBufferOverrun();
130129

‎libaleth-interpreter/VMCalls.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,10 @@ void VM::throwBadStack(int _required)
6161
throw EVMC_STACK_OVERFLOW;
6262
}
6363

64-
void VM::throwRevertInstruction(owning_bytes_ref&& _output)
64+
void VM::throwRevertInstruction(uint64_t _offset, uint64_t _size)
6565
{
66-
// We can't use BOOST_THROW_EXCEPTION here because it makes a copy of exception inside and
67-
// RevertInstruction has no copy constructor
68-
throw RevertInstruction(std::move(_output));
66+
m_output = owning_bytes_ref{std::move(m_mem), _offset, _size};
67+
throw EVMC_REVERT;
6968
}
7069

7170
void VM::throwBufferOverrun()

0 commit comments

Comments
 (0)