From 18499f4f56d965f43712f0ae5a154b1e6f17169e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 26 Apr 2021 14:30:54 +0200 Subject: [PATCH 1/2] Upgrade EVMC to 8.0.0 --- evmc | 2 +- lib/evmone/baseline.cpp | 2 +- lib/evmone/instruction_traits.hpp | 4 ++-- lib/evmone/instructions.cpp | 2 +- test/unittests/evm_test.cpp | 4 ++-- test/utils/bytecode.hpp | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/evmc b/evmc index 56650cd567..b1f4f2338f 160000 --- a/evmc +++ b/evmc @@ -1 +1 @@ -Subproject commit 56650cd56708f2ab8136f352c6b500fbd08b7ab1 +Subproject commit b1f4f2338f652e55398dd661e75186ad6fae4d82 diff --git a/lib/evmone/baseline.cpp b/lib/evmone/baseline.cpp index 7c3d86b5de..05c3c7ccdf 100644 --- a/lib/evmone/baseline.cpp +++ b/lib/evmone/baseline.cpp @@ -214,7 +214,7 @@ evmc_result baseline_execute(ExecutionState& state, const JumpdestMap& jumpdest_ sar(state.stack); break; - case OP_SHA3: + case OP_KECCAK256: { const auto status_code = sha3(state); if (status_code != EVMC_SUCCESS) diff --git a/lib/evmone/instruction_traits.hpp b/lib/evmone/instruction_traits.hpp index ba79bc6144..ba384cf2d5 100644 --- a/lib/evmone/instruction_traits.hpp +++ b/lib/evmone/instruction_traits.hpp @@ -67,7 +67,7 @@ constexpr inline std::array traits = []() noexcept { table[OP_SHR] = {"SHR", 2, -1}; table[OP_SAR] = {"SAR", 2, -1}; - table[OP_SHA3] = {"SHA3", 2, -1}; + table[OP_KECCAK256] = {"KECCAK256", 2, -1}; table[OP_ADDRESS] = {"ADDRESS", 0, 1}; table[OP_BALANCE] = {"BALANCE", 1, 0}; @@ -233,7 +233,7 @@ constexpr inline std::array gas_costs = []() noexce table[OP_XOR] = 3; table[OP_NOT] = 3; table[OP_BYTE] = 3; - table[OP_SHA3] = 30; + table[OP_KECCAK256] = 30; table[OP_ADDRESS] = 2; table[OP_BALANCE] = 20; table[OP_ORIGIN] = 2; diff --git a/lib/evmone/instructions.cpp b/lib/evmone/instructions.cpp index 6567fe6d34..d61a06b250 100644 --- a/lib/evmone/instructions.cpp +++ b/lib/evmone/instructions.cpp @@ -227,7 +227,7 @@ constexpr std::array instruction_implementations = []( table[OP_SHR] = op; table[OP_SAR] = op; - table[OP_SHA3] = op; + table[OP_KECCAK256] = op; table[OP_ADDRESS] = op
; table[OP_BALANCE] = op; diff --git a/test/unittests/evm_test.cpp b/test/unittests/evm_test.cpp index 6bd0946dfc..28aa430500 100644 --- a/test/unittests/evm_test.cpp +++ b/test/unittests/evm_test.cpp @@ -610,7 +610,7 @@ TEST_P(evm, sha3) TEST_P(evm, sha3_empty) { - auto code = push(0) + OP_DUP1 + OP_SHA3 + ret_top(); + auto code = push(0) + OP_DUP1 + OP_KECCAK256 + ret_top(); execute(code); ASSERT_EQ(result.output_size, 32); auto keccak256_empty = "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"; @@ -894,7 +894,7 @@ struct memory_access_params }; memory_access_opcode memory_access_opcodes[] = { - {OP_SHA3, 0, 1}, + {OP_KECCAK256, 0, 1}, {OP_CALLDATACOPY, 0, 2}, {OP_CODECOPY, 0, 2}, {OP_MLOAD, 0, -1}, diff --git a/test/utils/bytecode.hpp b/test/utils/bytecode.hpp index ed3c2fb315..7f20cd8aef 100644 --- a/test/utils/bytecode.hpp +++ b/test/utils/bytecode.hpp @@ -190,7 +190,7 @@ inline bytecode ret(bytecode c) inline bytecode sha3(bytecode index, bytecode size) { - return size + index + OP_SHA3; + return size + index + OP_KECCAK256; } inline bytecode calldataload(bytecode index) From 3c9ea6de400782475103c4964ac6f5174e13c524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 26 Apr 2021 14:32:58 +0200 Subject: [PATCH 2/2] Rename sha3() instruction to keccak256() --- lib/evmone/baseline.cpp | 2 +- lib/evmone/instructions.cpp | 2 +- lib/evmone/instructions.hpp | 2 +- test/unittests/evm_test.cpp | 10 +++++----- test/utils/bytecode.hpp | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/evmone/baseline.cpp b/lib/evmone/baseline.cpp index 05c3c7ccdf..63d53d6f72 100644 --- a/lib/evmone/baseline.cpp +++ b/lib/evmone/baseline.cpp @@ -216,7 +216,7 @@ evmc_result baseline_execute(ExecutionState& state, const JumpdestMap& jumpdest_ case OP_KECCAK256: { - const auto status_code = sha3(state); + const auto status_code = keccak256(state); if (status_code != EVMC_SUCCESS) { state.status = status_code; diff --git a/lib/evmone/instructions.cpp b/lib/evmone/instructions.cpp index d61a06b250..06ab6f8b96 100644 --- a/lib/evmone/instructions.cpp +++ b/lib/evmone/instructions.cpp @@ -227,7 +227,7 @@ constexpr std::array instruction_implementations = []( table[OP_SHR] = op; table[OP_SAR] = op; - table[OP_KECCAK256] = op; + table[OP_KECCAK256] = op; table[OP_ADDRESS] = op
; table[OP_BALANCE] = op; diff --git a/lib/evmone/instructions.hpp b/lib/evmone/instructions.hpp index f3d109255f..3372d22382 100644 --- a/lib/evmone/instructions.hpp +++ b/lib/evmone/instructions.hpp @@ -253,7 +253,7 @@ inline void sar(evm_stack& stack) noexcept } -inline evmc_status_code sha3(ExecutionState& state) noexcept +inline evmc_status_code keccak256(ExecutionState& state) noexcept { const auto index = state.stack.pop(); auto& size = state.stack.top(); diff --git a/test/unittests/evm_test.cpp b/test/unittests/evm_test.cpp index 28aa430500..a002cd61c1 100644 --- a/test/unittests/evm_test.cpp +++ b/test/unittests/evm_test.cpp @@ -598,7 +598,7 @@ TEST_P(evm, invalid) EXPECT_EQ(result.gas_left, 0); } -TEST_P(evm, sha3) +TEST_P(evm, keccak256) { execute("6108006103ff2060005260206000f3"); EXPECT_EQ(result.status_code, EVMC_SUCCESS); @@ -608,7 +608,7 @@ TEST_P(evm, sha3) EXPECT_EQ(bytes(&result.output_data[0], 32), hash); } -TEST_P(evm, sha3_empty) +TEST_P(evm, keccak256_empty) { auto code = push(0) + OP_DUP1 + OP_KECCAK256 + ret_top(); execute(code); @@ -820,11 +820,11 @@ TEST_P(evm, mstore8_memory_cost) EXPECT_EQ(result.status_code, EVMC_OUT_OF_GAS); } -TEST_P(evm, sha3_memory_cost) +TEST_P(evm, keccak256_memory_cost) { - execute(45, sha3(0, 1)); + execute(45, keccak256(0, 1)); EXPECT_EQ(result.status_code, EVMC_SUCCESS); - execute(44, sha3(0, 1)); + execute(44, keccak256(0, 1)); EXPECT_EQ(result.status_code, EVMC_OUT_OF_GAS); } diff --git a/test/utils/bytecode.hpp b/test/utils/bytecode.hpp index 7f20cd8aef..d92528ee71 100644 --- a/test/utils/bytecode.hpp +++ b/test/utils/bytecode.hpp @@ -188,7 +188,7 @@ inline bytecode ret(bytecode c) return c + ret_top(); } -inline bytecode sha3(bytecode index, bytecode size) +inline bytecode keccak256(bytecode index, bytecode size) { return size + index + OP_KECCAK256; }