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

Commit

Permalink
Distinguish between INVALID opcode and unknown opcodes in aleth… (#5666)
Browse files Browse the repository at this point in the history
Distinguish between INVALID opcode and unknown opcodes in aleth-interpreter
  • Loading branch information
gumb0 authored Jul 15, 2019
2 parents 2b11ce5 + e042a52 commit 39a9e43
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
- Fixed: [#5644](https://github.com/ethereum/aleth/pull/5644) Avoid attempting to sync with disconnected peers.
- Fixed: [#5647](https://github.com/ethereum/aleth/pull/5647) test_importRawBlock RPC method correctly fails in case of import failure.
- Fixed: [#5664](https://github.com/ethereum/aleth/pull/5664) Behavior in corner case tests about touching empty Precompiles now agrees with geth's results.
- Fixed: [#5662](https://github.com/ethereum/aleth/pull/5662) Correct depth value when aleth-interpreter invokes `evmc_host_interface::call` callback.
- Fixed: [#5666](https://github.com/ethereum/aleth/pull/5666) aleth-interpreter returns `EVMC_INVALID_INSTRUCTION` when `INVALID` opcode is encountered and `EVMC_UNKNOWN_INSTRUCTION` for undefined opcodes.

## [1.6.0] - 2019-04-16

Expand Down
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)
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

0 comments on commit 39a9e43

Please sign in to comment.