-
Notifications
You must be signed in to change notification settings - Fork 314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EVM instructions table #33
Changes from all commits
d4562dc
d5ac5ce
765adc2
889f8d7
534f634
fd57846
c90be58
bc00d6e
e590d1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
/* EVMC: Ethereum Client-VM Connector API. | ||
* Copyright 2018 Pawel Bylica. | ||
* Licensed under the MIT License. See the LICENSE file. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <evmc/evmc.h> | ||
|
||
#include <stdint.h> | ||
|
||
#if __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* The list of EVM 1 instructions from every EVM revision. | ||
*/ | ||
enum evmc_instruction | ||
{ | ||
STOP = 0x00, | ||
ADD, | ||
MUL, | ||
SUB, | ||
DIV, | ||
SDIV, | ||
MOD, | ||
SMOD, | ||
ADDMOD, | ||
MULMOD, | ||
EXP, | ||
SIGNEXTEND, | ||
|
||
LT = 0x10, | ||
GT, | ||
SLT, | ||
SGT, | ||
EQ, | ||
ISZERO, | ||
AND, | ||
OR, | ||
XOR, | ||
NOT, | ||
BYTE, | ||
SHL, | ||
SHR, | ||
SAR, | ||
|
||
SHA3 = 0x20, | ||
|
||
ADDRESS = 0x30, | ||
BALANCE, | ||
ORIGIN, | ||
CALLER, | ||
CALLVALUE, | ||
CALLDATALOAD, | ||
CALLDATASIZE, | ||
CALLDATACOPY, | ||
CODESIZE, | ||
CODECOPY, | ||
GASPRICE, | ||
EXTCODESIZE, | ||
EXTCODECOPY, | ||
RETURNDATASIZE = 0x3d, | ||
RETURNDATACOPY = 0x3e, | ||
|
||
BLOCKHASH = 0x40, | ||
COINBASE, | ||
TIMESTAMP, | ||
NUMBER, | ||
DIFFICULTY, | ||
GASLIMIT, | ||
|
||
POP = 0x50, | ||
MLOAD, | ||
MSTORE, | ||
MSTORE8, | ||
SLOAD, | ||
SSTORE, | ||
JUMP, | ||
JUMPI, | ||
PC, | ||
MSIZE, | ||
GAS, | ||
JUMPDEST, | ||
|
||
PUSH1 = 0x60, | ||
PUSH2, | ||
PUSH3, | ||
PUSH4, | ||
PUSH5, | ||
PUSH6, | ||
PUSH7, | ||
PUSH8, | ||
PUSH9, | ||
PUSH10, | ||
PUSH11, | ||
PUSH12, | ||
PUSH13, | ||
PUSH14, | ||
PUSH15, | ||
PUSH16, | ||
PUSH17, | ||
PUSH18, | ||
PUSH19, | ||
PUSH20, | ||
PUSH21, | ||
PUSH22, | ||
PUSH23, | ||
PUSH24, | ||
PUSH25, | ||
PUSH26, | ||
PUSH27, | ||
PUSH28, | ||
PUSH29, | ||
PUSH30, | ||
PUSH31, | ||
PUSH32, | ||
|
||
DUP1 = 0x80, | ||
DUP2, | ||
DUP3, | ||
DUP4, | ||
DUP5, | ||
DUP6, | ||
DUP7, | ||
DUP8, | ||
DUP9, | ||
DUP10, | ||
DUP11, | ||
DUP12, | ||
DUP13, | ||
DUP14, | ||
DUP15, | ||
DUP16, | ||
|
||
SWAP1 = 0x90, | ||
SWAP2, | ||
SWAP3, | ||
SWAP4, | ||
SWAP5, | ||
SWAP6, | ||
SWAP7, | ||
SWAP8, | ||
SWAP9, | ||
SWAP10, | ||
SWAP11, | ||
SWAP12, | ||
SWAP13, | ||
SWAP14, | ||
SWAP15, | ||
SWAP16, | ||
|
||
LOG0 = 0xa0, | ||
LOG1, | ||
LOG2, | ||
LOG3, | ||
LOG4, | ||
|
||
CREATE = 0xf0, | ||
CALL, | ||
CALLCODE, | ||
RETURN, | ||
DELEGATECALL, | ||
STATICCALL = 0xfa, | ||
|
||
REVERT = 0xfd, | ||
INVALID = 0xfe, | ||
SELFDESTRUCT = 0xff, | ||
}; | ||
|
||
/** | ||
* Metrics for an EVM 1 instruction. | ||
* | ||
* Small integer types are used here to make the tables of metrics cache friendly. | ||
*/ | ||
struct evmc_instruction_metrics | ||
{ | ||
/** The instruction gas cost. Value -1 indicates undefined instruction. */ | ||
int16_t gas_cost; | ||
|
||
/** The number of items the instruction pops from the EVM stack before execution. */ | ||
int8_t num_stack_arguments; | ||
|
||
/** The number of items the instruction pushes to the EVM stack after execution. */ | ||
int8_t num_stack_returned_items; | ||
}; | ||
|
||
/** | ||
* Get the table of the EVM 1 instructions metrics. | ||
* | ||
* @param revision The EVM revision. | ||
* @return The pointer to the array of 256 instruction metrics. | ||
*/ | ||
const struct evmc_instruction_metrics* evmc_get_instruction_metrics_table( | ||
enum evmc_revision revision); | ||
|
||
/** | ||
* Get the table of the EVM 1 instruction names. | ||
* | ||
* This table is EVM revision independent and contains the superset of the names of the instructions | ||
* from all EVM revisions. Use evmc_get_instruction_metrics_table() to know if an instruction | ||
* is present in the given EVM revision. | ||
* | ||
* The entries for undefined instructions contain null pointers. | ||
* | ||
* @return The pointer to the array of 256 instruction names. | ||
*/ | ||
const char* const* evmc_get_instruction_name_table(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this also have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it has names for all opcodes, i.e. from the latest revision. I think it's good enough for debugging. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would a good middle ground be a helper which based on the revision generates a table relevant to that revision? It would do that every time, so the callee would need to ensure it stores the result. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. I will just add the revision here as well if there is the use case for it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do like the idea of having this static const table too. |
||
|
||
#if __cplusplus | ||
} | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# EVMC: Ethereum Client-VM Connector API. | ||
# Copyright 2018 Pawel Bylica. | ||
# Licensed under the MIT License. See the LICENSE file. | ||
|
||
add_subdirectory(instructions) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# EVMC: Ethereum Client-VM Connector API. | ||
# Copyright 2018 Pawel Bylica. | ||
# Licensed under the MIT License. See the LICENSE file. | ||
|
||
add_library(instructions ${include_dir}/evmc/instructions.h instructions.c) | ||
add_library(evmc::instructions ALIAS instructions) | ||
target_include_directories(instructions PUBLIC ${include_dir}) | ||
|
||
install(TARGETS instructions EXPORT evmcTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought this was the reason for the decision, but it seems a bit convoluted.