Skip to content

Commit 428b2f3

Browse files
committed
Implement DATASIZE instruction
1 parent aefb67e commit 428b2f3

File tree

5 files changed

+10
-1
lines changed

5 files changed

+10
-1
lines changed

lib/evmone/instructions.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,11 @@ inline evmc_status_code dataload(StackTop stack, ExecutionState& state) noexcept
915915
return EVMC_SUCCESS;
916916
}
917917

918+
inline void datasize(StackTop stack, ExecutionState& state) noexcept
919+
{
920+
stack.push(state.data.size());
921+
}
922+
918923
template <size_t NumTopics>
919924
inline evmc_status_code log(StackTop stack, ExecutionState& state) noexcept
920925
{

lib/evmone/instructions_opcodes.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ enum Opcode : uint8_t
164164
OP_SWAPN = 0xb6,
165165

166166
OP_DATALOAD = 0xb7,
167+
OP_DATASIZE = 0xb8,
167168

168169
OP_CREATE = 0xf0,
169170
OP_CALL = 0xf1,

lib/evmone/instructions_traits.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ constexpr inline GasCostTable gas_costs = []() noexcept {
172172
table[EVMC_CANCUN][OP_CALLF] = 5;
173173
table[EVMC_CANCUN][OP_RETF] = 3;
174174
table[EVMC_CANCUN][OP_DATALOAD] = 3;
175+
table[EVMC_CANCUN][OP_DATASIZE] = 2;
175176

176177
table[EVMC_PRAGUE] = table[EVMC_CANCUN];
177178

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

381383
table[OP_CREATE] = {"CREATE", 0, false, 3, -2, EVMC_FRONTIER};
382384
table[OP_CALL] = {"CALL", 0, false, 7, -6, EVMC_FRONTIER};

lib/evmone/instructions_xmacro.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@
227227
ON_OPCODE_IDENTIFIER(OP_DUPN, dupn) \
228228
ON_OPCODE_IDENTIFIER(OP_SWAPN, swapn) \
229229
ON_OPCODE_IDENTIFIER(OP_DATALOAD, dataload) \
230-
ON_OPCODE_UNDEFINED(0xb8) \
230+
ON_OPCODE_IDENTIFIER(OP_DATASIZE, datasize) \
231231
ON_OPCODE_UNDEFINED(0xb9) \
232232
ON_OPCODE_UNDEFINED(0xba) \
233233
ON_OPCODE_UNDEFINED(0xbb) \

test/unittests/instructions_test.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ constexpr bool instruction_only_in_evmone(evmc_revision rev, Opcode op) noexcept
111111
case OP_DUPN:
112112
case OP_SWAPN:
113113
case OP_DATALOAD:
114+
case OP_DATASIZE:
114115
return true;
115116
default:
116117
return false;

0 commit comments

Comments
 (0)