diff --git a/lib/evmone/instructions.hpp b/lib/evmone/instructions.hpp index 19772a4bb7..f6598da8c2 100644 --- a/lib/evmone/instructions.hpp +++ b/lib/evmone/instructions.hpp @@ -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 inline evmc_status_code log(StackTop stack, ExecutionState& state) noexcept { diff --git a/lib/evmone/instructions_opcodes.hpp b/lib/evmone/instructions_opcodes.hpp index 7dfee579a4..614bce7531 100644 --- a/lib/evmone/instructions_opcodes.hpp +++ b/lib/evmone/instructions_opcodes.hpp @@ -164,6 +164,7 @@ enum Opcode : uint8_t OP_SWAPN = 0xb6, OP_DATALOAD = 0xb7, + OP_DATASIZE = 0xb8, OP_CREATE = 0xf0, OP_CALL = 0xf1, diff --git a/lib/evmone/instructions_traits.hpp b/lib/evmone/instructions_traits.hpp index 428b22d7eb..78ec994312 100644 --- a/lib/evmone/instructions_traits.hpp +++ b/lib/evmone/instructions_traits.hpp @@ -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]; @@ -377,6 +378,7 @@ constexpr inline std::array 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}; diff --git a/lib/evmone/instructions_xmacro.hpp b/lib/evmone/instructions_xmacro.hpp index 342aae0d12..b8c9caaff1 100644 --- a/lib/evmone/instructions_xmacro.hpp +++ b/lib/evmone/instructions_xmacro.hpp @@ -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) \ diff --git a/test/unittests/instructions_test.cpp b/test/unittests/instructions_test.cpp index 84c6062743..5469722035 100644 --- a/test/unittests/instructions_test.cpp +++ b/test/unittests/instructions_test.cpp @@ -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;