Skip to content

Commit

Permalink
Add boost log and target circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
akokoshn committed Jul 4, 2024
1 parent 3021b99 commit 71cde3a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 26 deletions.
2 changes: 1 addition & 1 deletion cmake/Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

include(CMakeFindDependencyMacro)
find_dependency(crypto3 REQUIRED)
find_dependency(blueprint_crypto3 REQUIRED)
find_dependency(crypto3_blueprint REQUIRED)
find_dependency(evmc REQUIRED)
find_dependency(intx REQUIRED)
find_dependency(ethash REQUIRED)
Expand Down
30 changes: 15 additions & 15 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@
flake-utils.follows = "flake-utils";
};
};
nil_crypto3 = {
nil-crypto3 = {
url = "https://github.com/NilFoundation/crypto3";
type = "git";
submodules = true;
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
nil_zkllvm_blueprint = {
nil-zkllvm-blueprint = {
url = "https://github.com/NilFoundation/zkllvm-blueprint";
type = "git";
submodules = true;
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
nil_crypto3.follows = "nil_crypto3";
nil-crypto3.follows = "nil-crypto3";
};
};
};
Expand All @@ -50,12 +50,12 @@
# Add more complicated logic here if you need to have debug packages
resolveInput = input: input.packages.${system}.default;

nil_inputs = with inputs; [
nil_crypto3
nil_zkllvm_blueprint
nil-inputs = with inputs; [
nil-crypto3
nil-zkllvm-blueprint
];

nil_packages = map resolveInput nil_inputs;
nil-packages = map resolveInput nil-inputs;

defaultNativeBuildInputs = with pkgs; [
cmake
Expand All @@ -77,7 +77,7 @@
ethash
];
in
deps ++ nil_packages;
deps ++ nil-packages;

devInputs = [ pkgs.clang_17 ];

Expand Down
1 change: 0 additions & 1 deletion lib/assigner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ add_library(${PROJECT_NAME} STATIC ${evmone_sources})

target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20)

find_package(Boost REQUIRED COMPONENTS container random filesystem log log_setup program_options thread system)
find_package(crypto3 REQUIRED)
find_package(crypto3_blueprint REQUIRED)

Expand Down
24 changes: 23 additions & 1 deletion lib/assigner/include/assigner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

#include <evmc/evmc.hpp>

#include <boost/log/core.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/trivial.hpp>

#include <nil/crypto3/algebra/curves/pallas.hpp>
#include <nil/blueprint/blueprint/plonk/assignment.hpp>

Expand All @@ -20,6 +24,18 @@
namespace nil {
namespace blueprint {

enum zkevm_circuit : uint8_t {
ALL = 0,
BYTECODE = 1,
RW = 2
};

static const std::map<std::string, zkevm_circuit> zkevm_circuits_map = {
{"", zkevm_circuit::ALL},
{"bytecode", zkevm_circuit::BYTECODE},
{"rw", zkevm_circuit::RW}
};

template<typename BlueprintFieldType>
struct assigner {

Expand All @@ -43,7 +59,11 @@ namespace nil {
template<typename BlueprintFieldType>
static evmc::Result evaluate(const evmc_host_interface* host, evmc_host_context* ctx,
evmc_revision rev, const evmc_message* msg, const uint8_t* code_ptr, size_t code_size,
std::shared_ptr<nil::blueprint::assigner<BlueprintFieldType>> assigner) {
std::shared_ptr<nil::blueprint::assigner<BlueprintFieldType>> assigner, const std::string& target_circuit = "") {
if(zkevm_circuits_map.find(target_circuit) == zkevm_circuits_map.end()) {
std::cerr << "Unknown target circuit " << target_circuit << "\n";
return evmc::Result{EVMC_FAILURE, msg->gas};
}
const evmone::bytes_view container{code_ptr, code_size};
const auto code_analysis = evmone::baseline::analyze(rev, container);
const auto data = code_analysis.eof_header.get_data(container);
Expand All @@ -59,6 +79,8 @@ namespace nil {

const auto& cost_table = evmone::baseline::get_baseline_cost_table(state.rev, code_analysis.eof_header.version);

BOOST_LOG_TRIVIAL(debug) << "Run evaluate\n";

gas = evmone::baseline::dispatch<false>(cost_table, state, msg->gas, code.data());

// fill assignments for read/write circuit
Expand Down

0 comments on commit 71cde3a

Please sign in to comment.