Skip to content

Commit

Permalink
Implement DATASIZE instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Mar 18, 2023
1 parent 00d3c12 commit 72f771d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/evmone/instructions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,11 @@ inline evmc_status_code dataload(StackTop stack, ExecutionState& state) noexcept
return EVMC_SUCCESS;
}

inline void datasize(StackTop stack, ExecutionState& state) noexcept
{
stack.push(state.data.size());
}

template <size_t NumTopics>
inline evmc_status_code log(StackTop stack, ExecutionState& state) noexcept
{
Expand Down
1 change: 1 addition & 0 deletions lib/evmone/instructions_opcodes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ enum Opcode : uint8_t
OP_SWAPN = 0xb6,

OP_DATALOAD = 0xb7,
OP_DATASIZE = 0xb8,

OP_CREATE = 0xf0,
OP_CALL = 0xf1,
Expand Down
2 changes: 2 additions & 0 deletions lib/evmone/instructions_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ constexpr inline GasCostTable gas_costs = []() noexcept {
table[EVMC_CANCUN][OP_CALLF] = 5;
table[EVMC_CANCUN][OP_RETF] = 3;
table[EVMC_CANCUN][OP_DATALOAD] = 3;
table[EVMC_CANCUN][OP_DATASIZE] = 2;

table[EVMC_PRAGUE] = table[EVMC_CANCUN];

Expand Down Expand Up @@ -377,6 +378,7 @@ constexpr inline std::array<Traits, 256> traits = []() noexcept {
table[OP_DUPN] = {"DUPN", 1, false, 0, 1, EVMC_CANCUN};
table[OP_SWAPN] = {"SWAPN", 1, false, 0, 0, EVMC_CANCUN};
table[OP_DATALOAD] = {"DATALOAD", 0, false, 1, 0, EVMC_CANCUN};
table[OP_DATASIZE] = {"DATASIZE", 0, false, 0, 1, EVMC_CANCUN};

table[OP_CREATE] = {"CREATE", 0, false, 3, -2, EVMC_FRONTIER};
table[OP_CALL] = {"CALL", 0, false, 7, -6, EVMC_FRONTIER};
Expand Down
2 changes: 1 addition & 1 deletion lib/evmone/instructions_xmacro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
ON_OPCODE_IDENTIFIER(OP_DUPN, dupn) \
ON_OPCODE_IDENTIFIER(OP_SWAPN, swapn) \
ON_OPCODE_IDENTIFIER(OP_DATALOAD, dataload) \
ON_OPCODE_UNDEFINED(0xb8) \
ON_OPCODE_IDENTIFIER(OP_DATASIZE, datasize) \
ON_OPCODE_UNDEFINED(0xb9) \
ON_OPCODE_UNDEFINED(0xba) \
ON_OPCODE_UNDEFINED(0xbb) \
Expand Down
1 change: 1 addition & 0 deletions test/unittests/instructions_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ constexpr bool instruction_only_in_evmone(evmc_revision rev, Opcode op) noexcept
case OP_DUPN:
case OP_SWAPN:
case OP_DATALOAD:
case OP_DATASIZE:
return true;
default:
return false;
Expand Down

0 comments on commit 72f771d

Please sign in to comment.