Skip to content
This repository was archived by the owner on Nov 17, 2025. It is now read-only.
Closed
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
2 changes: 1 addition & 1 deletion tools/evmc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
hunter_add_package(CLI11)
find_package(CLI11 REQUIRED)

add_executable(evmc-tool main.cpp utils.cpp utils.hpp)
add_executable(evmc-tool check.cpp main.cpp utils.cpp utils.hpp)
add_executable(evmc::tool ALIAS evmc-tool)
set_target_properties(evmc-tool PROPERTIES
OUTPUT_NAME evmc
Expand Down
15 changes: 15 additions & 0 deletions tools/evmc/check.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// EVMC: Ethereum Client-VM Connector API.
// Copyright 2019 The EVMC Authors.
// Licensed under the Apache License, Version 2.0.

#include <evmc/evmc.hpp>
#include <iostream>

namespace evmc
{
int check_command(VM& vm)
{
std::cout << "Checking " << vm.name() << " " << vm.version() << "\n";
return 0;
}
} // namespace evmc
37 changes: 24 additions & 13 deletions tools/evmc/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

#include "utils.hpp"

namespace evmc
{
int check_command(VM& vm);
}

int main(int argc, const char** argv)
{
using namespace evmc;
Expand All @@ -16,18 +21,34 @@ int main(int argc, const char** argv)
const auto& version_flag = *app.add_flag("--version", "Print version information");

std::string vm_config;
evmc::VM vm;
std::function<void(const std::string&)> load_vm = [&vm, &vm_config](const std::string& config) {
evmc_loader_error_code ec;
vm = VM{evmc_load_and_configure(config.c_str(), &ec)};
if (ec != EVMC_LOADER_SUCCESS)
{
const auto error = evmc_last_error_msg();
throw std::invalid_argument{error != nullptr ? error : "Loading error"};
}
vm_config = config;
};

std::string code_hex;
evmc_message msg{};
msg.gas = 1000000;
auto rev = EVMC_ISTANBUL;

auto& run_cmd = *app.add_subcommand("run", "Execute EVM bytecode");
run_cmd.add_option_function("--vm", load_vm, "EVMC VM module")->required()->envname("EVMC_VM");

run_cmd.add_option("code", code_hex, "Hex-encoded bytecode")->required();
run_cmd.add_option("--vm", vm_config, "EVMC VM module")->required()->envname("EVMC_VM");
run_cmd.add_option("--gas", msg.gas, "Execution gas limit", true)
->check(CLI::Range(0, 1000000000));
run_cmd.add_option("--rev", rev, "EVM revision", true);

auto& check_cmd = *app.add_subcommand("check", "Check VM for compatibility with EVMC");
check_cmd.add_option_function("vm", load_vm, "EVMC VM module")->required();

try
{
app.parse(argc, argv);
Expand All @@ -43,18 +64,6 @@ int main(int argc, const char** argv)
{
const auto code = from_hex(code_hex);

evmc_loader_error_code ec;
auto vm = VM{evmc_load_and_configure(vm_config.c_str(), &ec)};
if (ec != EVMC_LOADER_SUCCESS)
{
const auto error = evmc_last_error_msg();
if (error != nullptr)
std::cerr << error << "\n";
else
std::cerr << "Loading error " << ec << "\n";
return static_cast<int>(ec);
}

MockedHost host;

std::cout << "Executing on " << rev << " with " << msg.gas << " gas limit\n"
Expand All @@ -70,6 +79,8 @@ int main(int argc, const char** argv)

return 0;
}
else if (check_cmd)
check_command(vm);

return 0;
}
Expand Down