Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion libaleth-interpreter/VM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ evmc_result execute(evmc_instance* _instance, evmc_context* _context, evmc_revis
result.gas_left = vm->m_io_gas;
output = ex.output(); // This moves the output from the exception!
}
catch (dev::eth::InvalidInstruction const&)
{
result.status_code = EVMC_INVALID_INSTRUCTION;
}
catch (dev::eth::BadInstruction const&)
{
result.status_code = EVMC_UNDEFINED_INSTRUCTION;
Expand Down Expand Up @@ -1416,7 +1420,10 @@ void VM::interpretCases()
CASE(INVALID)
DEFAULT
{
throwBadInstruction();
if (m_OP == Instruction::INVALID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouln't it be just

CASE(INVALID)
  throwInvalidInstruction();
DEFAULT
  throwUndefinedInstruction();

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this doesn't work on gcc/clang, because the jump table is populated with INVALID opcode for all unknown ones

static const void* const jumpTable[256] = { \

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we change that by having &&UNDEFINED everywhere and &&INVALID in

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no such thing as UNDEFINED, and this enum is 8 bit-wide

enum class Instruction : uint8_t

So we can't really add UNDEFINED unless we change the width

throwInvalidInstruction();
else
throwBadInstruction();
}
}
WHILE_CASES
Expand Down
1 change: 1 addition & 0 deletions libaleth-interpreter/VM.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class VM
const evmc_tx_context& getTxContext();

void throwOutOfGas();
void throwInvalidInstruction();
void throwBadInstruction();
void throwBadJumpDestination();
void throwBadStack(int _removed, int _added);
Expand Down
5 changes: 5 additions & 0 deletions libaleth-interpreter/VMCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ void VM::throwOutOfGas()
BOOST_THROW_EXCEPTION(OutOfGas());
}

void VM::throwInvalidInstruction()
{
BOOST_THROW_EXCEPTION(InvalidInstruction());
}

void VM::throwBadInstruction()
{
BOOST_THROW_EXCEPTION(BadInstruction());
Expand Down
1 change: 1 addition & 0 deletions libevm/VMFace.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace eth

struct VMException: Exception {};
#define ETH_SIMPLE_EXCEPTION_VM(X) struct X: VMException { const char* what() const noexcept override { return #X; } }
ETH_SIMPLE_EXCEPTION_VM(InvalidInstruction);
ETH_SIMPLE_EXCEPTION_VM(BadInstruction);
ETH_SIMPLE_EXCEPTION_VM(BadJumpDestination);
ETH_SIMPLE_EXCEPTION_VM(OutOfGas);
Expand Down