-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor precompiles detection (#732)
Extract a precompile address recognition into new is_precompile() function and use it in all places where this information is needed. Improve maintenance of "precompile ids" by adding aliases to the enum. Add unit tests for is_precompile().
- Loading branch information
Showing
5 changed files
with
77 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// evmone: Fast Ethereum Virtual Machine implementation | ||
// Copyright 2023 The evmone Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include <gtest/gtest.h> | ||
#include <test/state/precompiles.hpp> | ||
|
||
using namespace evmc; | ||
using namespace evmone::state; | ||
|
||
TEST(state_precompiles, is_precompile) | ||
{ | ||
for (int r = 0; r <= EVMC_MAX_REVISION; ++r) | ||
{ | ||
const auto rev = static_cast<evmc_revision>(r); | ||
|
||
EXPECT_FALSE(is_precompile(rev, 0x00_address)); | ||
|
||
// Frontier: | ||
EXPECT_TRUE(is_precompile(rev, 0x01_address)); | ||
EXPECT_TRUE(is_precompile(rev, 0x02_address)); | ||
EXPECT_TRUE(is_precompile(rev, 0x03_address)); | ||
EXPECT_TRUE(is_precompile(rev, 0x04_address)); | ||
|
||
// Byzantium: | ||
EXPECT_EQ(is_precompile(rev, 0x05_address), rev >= EVMC_BYZANTIUM); | ||
EXPECT_EQ(is_precompile(rev, 0x06_address), rev >= EVMC_BYZANTIUM); | ||
EXPECT_EQ(is_precompile(rev, 0x07_address), rev >= EVMC_BYZANTIUM); | ||
EXPECT_EQ(is_precompile(rev, 0x08_address), rev >= EVMC_BYZANTIUM); | ||
|
||
// Istanbul: | ||
EXPECT_EQ(is_precompile(rev, 0x09_address), rev >= EVMC_ISTANBUL); | ||
|
||
// Future? | ||
EXPECT_FALSE(is_precompile(rev, 0x0a_address)); | ||
EXPECT_FALSE(is_precompile(rev, 0x0b_address)); | ||
EXPECT_FALSE(is_precompile(rev, 0x0c_address)); | ||
EXPECT_FALSE(is_precompile(rev, 0x0d_address)); | ||
EXPECT_FALSE(is_precompile(rev, 0x0e_address)); | ||
EXPECT_FALSE(is_precompile(rev, 0x0f_address)); | ||
} | ||
} |