Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Baseline default, select Advanced with "advanced" flag #500

Merged
merged 2 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ The codebase of _evmone_ is optimized to provide fast and efficient execution of
3. The [intx] library is used to provide 256-bit integer precision.
4. The [ethash] library is used to provide Keccak hash function implementation
needed for the special `KECCAK256` instruction.
5. Contains two interpreters: **Advanced** (default) and **Baseline** (experimental).

5. Contains two interpreters:
- **Baseline** (default)
- **Advanced** (select with the `advanced` option)

### Baseline Interpreter

1. Provides relatively straight-forward but efficient EVM implementation.
2. Performs only minimalistic `JUMPDEST` analysis.

### Advanced Interpreter

1. The _indirect call threading_ is the dispatch method used -
Expand All @@ -31,12 +38,6 @@ The codebase of _evmone_ is optimized to provide fast and efficient execution of
and applied once per block during execution.
3. Performs extensive and expensive bytecode analysis before execution.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specify we need the advanced flag in order to enable the Advanced interpreter (?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I forgot to add it in the second commit. Good now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.


### Baseline Interpreter

1. Provides relatively straight-forward EVM implementation.
2. Performs only minimalistic `JUMPDEST` analysis.
3. Experimental. Can be enabled with `O=0` option.


## Usage

Expand Down
4 changes: 2 additions & 2 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,12 @@ jobs:
name: "Silkworm-driven consensus tests (Advanced)"
working_directory: ~/build
no_output_timeout: 20m
command: ~/silkworm/consensus --evm lib/libevmone.so,O=2 --tests ~/tests --threads $CMAKE_BUILD_PARALLEL_LEVEL
command: ~/silkworm/consensus --evm lib/libevmone.so,advanced --tests ~/tests --threads $CMAKE_BUILD_PARALLEL_LEVEL
- run:
name: "Silkworm-driven consensus tests (Baseline)"
working_directory: ~/build
no_output_timeout: 20m
command: ~/silkworm/consensus --evm lib/libevmone.so,O=0 --tests ~/tests --threads $CMAKE_BUILD_PARALLEL_LEVEL
command: ~/silkworm/consensus --evm lib/libevmone.so --tests ~/tests --threads $CMAKE_BUILD_PARALLEL_LEVEL
- collect_coverage_gcc
- upload_coverage:
flags: consensus
Expand Down
17 changes: 4 additions & 13 deletions lib/evmone/vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,10 @@ evmc_set_option_result set_option(evmc_vm* c_vm, char const* c_name, char const*
const auto value = (c_value != nullptr) ? std::string_view{c_value} : std::string_view{};
auto& vm = *static_cast<VM*>(c_vm);

if (name == "O")
if (name == "advanced")
{
if (value == "0")
{
c_vm->execute = evmone::baseline::execute;
return EVMC_SET_OPTION_SUCCESS;
}
else if (value == "2")
{
c_vm->execute = evmone::advanced::execute;
return EVMC_SET_OPTION_SUCCESS;
}
return EVMC_SET_OPTION_INVALID_VALUE;
c_vm->execute = evmone::advanced::execute;
return EVMC_SET_OPTION_SUCCESS;
}
else if (name == "cgoto")
{
Expand Down Expand Up @@ -82,7 +73,7 @@ inline constexpr VM::VM() noexcept
"evmone",
PROJECT_VERSION,
evmone::destroy,
evmone::advanced::execute,
evmone::baseline::execute,
evmone::get_capabilities,
evmone::set_option,
}
Expand Down
6 changes: 3 additions & 3 deletions test/bench/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ int main(int argc, char** argv)
if (ec != 0)
return ec;

registered_vms["advanced"] = evmc::VM{evmc_create_evmone(), {{"O", "2"}}};
registered_vms["baseline"] = evmc::VM{evmc_create_evmone(), {{"O", "0"}}};
registered_vms["bnocgoto"] = evmc::VM{evmc_create_evmone(), {{"O", "0"}, {"cgoto", "no"}}};
registered_vms["advanced"] = evmc::VM{evmc_create_evmone(), {{"advanced", ""}}};
registered_vms["baseline"] = evmc::VM{evmc_create_evmone()};
registered_vms["bnocgoto"] = evmc::VM{evmc_create_evmone(), {{"cgoto", "no"}}};
register_benchmarks(benchmark_cases);
register_synthetic_benchmarks();
RunSpecifiedBenchmarks();
Expand Down
4 changes: 2 additions & 2 deletions test/fuzzer/fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ template <typename T1, typename T2>
static auto print_input = std::getenv("PRINT");

/// The reference VM: evmone Baseline
static auto ref_vm = evmc::VM{evmc_create_evmone(), {{"O", "0"}}};
static auto ref_vm = evmc::VM{evmc_create_evmone()};

static evmc::VM external_vms[] = {
evmc::VM{evmc_create_evmone(), {{"O", "2"}}},
evmc::VM{evmc_create_evmone(), {{"advanced", ""}}},
};


Expand Down
4 changes: 2 additions & 2 deletions test/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(PREFIX ${PROJECT_NAME}/integration)
get_target_property(EVMONE_LIB_TYPE evmone TYPE)
if(EVMONE_LIB_TYPE STREQUAL SHARED_LIBRARY)

add_test(NAME ${PREFIX}/histogram COMMAND $<TARGET_FILE:evmc::tool> --vm $<TARGET_FILE:evmone>,O=0,histogram run 6000808080800101010200)
add_test(NAME ${PREFIX}/histogram COMMAND $<TARGET_FILE:evmc::tool> --vm $<TARGET_FILE:evmone>,histogram run 6000808080800101010200)
set_tests_properties(
${PREFIX}/histogram PROPERTIES PASS_REGULAR_EXPRESSION
"--- # HISTOGRAM depth=0
Expand All @@ -19,7 +19,7 @@ PUSH1,1
DUP1,4
")

add_test(NAME ${PREFIX}/trace COMMAND $<TARGET_FILE:evmc::tool> --vm $<TARGET_FILE:evmone>,O=0,trace run 60006002800103)
add_test(NAME ${PREFIX}/trace COMMAND $<TARGET_FILE:evmc::tool> --vm $<TARGET_FILE:evmone>,trace run 60006002800103)
set_tests_properties(
${PREFIX}/trace PROPERTIES PASS_REGULAR_EXPRESSION
"{\"depth\":0,\"rev\":\"London\",\"static\":false}
Expand Down
6 changes: 3 additions & 3 deletions test/unittests/evm_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace evmone::test
{
namespace
{
evmc::VM advanced_vm{evmc_create_evmone(), {{"O", "2"}}};
evmc::VM baseline_vm{evmc_create_evmone(), {{"O", "0"}}};
evmc::VM bnocgoto_vm{evmc_create_evmone(), {{"O", "0"}, {"cgoto", "no"}}};
evmc::VM advanced_vm{evmc_create_evmone(), {{"advanced", ""}}};
evmc::VM baseline_vm{evmc_create_evmone()};
evmc::VM bnocgoto_vm{evmc_create_evmone(), {{"cgoto", "no"}}};

const char* print_vm_name(const testing::TestParamInfo<evmc::VM*>& info) noexcept
{
Expand Down
15 changes: 5 additions & 10 deletions test/unittests/evmone_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,13 @@ TEST(evmone, set_option_invalid)
vm->destroy(vm);
}

TEST(evmone, set_option_optimization_level)
TEST(evmone, set_option_advanced)
{
auto vm = evmc::VM{evmc_create_evmone()};
EXPECT_EQ(vm.set_option("O", ""), EVMC_SET_OPTION_INVALID_VALUE);
EXPECT_EQ(vm.set_option("O", "0"), EVMC_SET_OPTION_SUCCESS);
EXPECT_EQ(vm.set_option("O", "1"), EVMC_SET_OPTION_INVALID_VALUE);
EXPECT_EQ(vm.set_option("O", "2"), EVMC_SET_OPTION_SUCCESS);
EXPECT_EQ(vm.set_option("O", "3"), EVMC_SET_OPTION_INVALID_VALUE);

EXPECT_EQ(vm.set_option("O", "20"), EVMC_SET_OPTION_INVALID_VALUE);
EXPECT_EQ(vm.set_option("O", "21"), EVMC_SET_OPTION_INVALID_VALUE);
EXPECT_EQ(vm.set_option("O", "22"), EVMC_SET_OPTION_INVALID_VALUE);
EXPECT_EQ(vm.set_option("advanced", ""), EVMC_SET_OPTION_SUCCESS);

// This will also enable Advanced.
EXPECT_EQ(vm.set_option("advanced", "no"), EVMC_SET_OPTION_SUCCESS);
}

TEST(evmone, set_option_cgoto)
Expand Down
2 changes: 1 addition & 1 deletion test/unittests/tracing_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class tracing : public Test
std::ostringstream trace_stream;

tracing()
: m_baseline_vm{evmc_create_evmone(), {{"O", "0"}}},
: m_baseline_vm{evmc_create_evmone()},
vm{*static_cast<evmone::VM*>(m_baseline_vm.get_raw_pointer())}
{}

Expand Down