Skip to content

Commit

Permalink
Remove assigner_interace
Browse files Browse the repository at this point in the history
  • Loading branch information
akokoshn committed Jun 14, 2024
1 parent 191395f commit aad7495
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 41 deletions.
33 changes: 33 additions & 0 deletions lib/assigner/include/nil/blueprint/assigner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include <nil/crypto3/algebra/curves/pallas.hpp>
#include <nil/blueprint/blueprint/plonk/assignment.hpp>

#include <vm.hpp>
#include <baseline.hpp>
#include <execution_state.hpp>

namespace nil {
namespace blueprint {

Expand All @@ -25,6 +29,35 @@ namespace nil {

std::vector<assignment<ArithmetizationType>> &m_assignments;
};

template<typename BlueprintFieldType>
static evmc::Result evaluate(evmc_vm* c_vm, 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) {
auto vm = static_cast<evmone::VM*>(c_vm);
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);
auto state = std::make_unique<evmone::ExecutionState<BlueprintFieldType>>(*msg, rev, *host, ctx, container, data, assigner);

state->analysis.baseline = &code_analysis; // Assign code analysis for instruction implementations.
const auto code = code_analysis.executable_code;

int64_t gas = msg->gas;

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

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

const auto gas_left = (state->status == EVMC_SUCCESS || state->status == EVMC_REVERT) ? gas : 0;
const auto gas_refund = (state->status == EVMC_SUCCESS) ? state->gas_refund : 0;

assert(state->output_size != 0 || state->output_offset == 0);
const auto evmc_result = evmc::make_result(state->status, gas_left, gas_refund,
state->output_size != 0 ? &state->memory[state->output_offset] : nullptr, state->output_size);
return evmc::Result{evmc_result};
}

} // namespace blueprint
} // namespace nil

Expand Down
35 changes: 0 additions & 35 deletions lib/assigner/include/nil/blueprint/assigner_interface.hpp

This file was deleted.

3 changes: 2 additions & 1 deletion lib/assigner/include/nil/blueprint/zkevm_word.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#include <intx/intx.hpp>
#include <ethash/keccak.hpp>

#include <nil/blueprint/assigner.hpp>
#include <nil/crypto3/algebra/curves/pallas.hpp>
#include <nil/blueprint/blueprint/plonk/assignment.hpp>
#include <nil/marshalling/field_type.hpp>
#include <nil/marshalling/endianness.hpp>
#include <nil/crypto3/marshalling/algebra/types/field_element.hpp>
Expand Down
2 changes: 1 addition & 1 deletion lib/assigner/include/vm_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <vector>
#include <memory>

#include <nil/blueprint/assigner_interface.hpp>
#include <nil/blueprint/assigner.hpp>
#include <nil/blueprint/zkevm_word.hpp>

using namespace evmc::literals;
Expand Down
2 changes: 1 addition & 1 deletion lib/assigner/test/assigner_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <map>

#include <nil/blueprint/assigner_interface.hpp>
#include <nil/blueprint/assigner.hpp>
#include <nil/blueprint/blueprint/plonk/assignment.hpp>

#include <evmc/evmc.hpp>
Expand Down
3 changes: 2 additions & 1 deletion lib/evmone/baseline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ int64_t dispatch(const CostTable& cost_table, ExecutionState<BlueprintFieldType>
}
//intx::unreachable();
}

/*
/// Executes in Baseline interpreter using EVMC-compatible parameters.
static evmc_result execute(evmc_vm* c_vm, const evmc_host_interface* host, evmc_host_context* ctx,
evmc_revision rev, const evmc_message* msg, const uint8_t* code, size_t code_size) noexcept {
Expand Down Expand Up @@ -280,6 +280,7 @@ static evmc_result execute(const VM&, int64_t gas, ExecutionState<BlueprintField
return result;
}
*/

} // namespace baseline
} // namespace evmone
9 changes: 7 additions & 2 deletions lib/evmone/execution_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@
#include <string>
#include <vector>

#include <nil/blueprint/assigner.hpp>
#include <nil/blueprint/zkevm_word.hpp>

namespace nil {
namespace blueprint {
template<typename BlueprintFieldType>
struct assigner;
}
}

namespace evmone
{
namespace baseline
Expand Down Expand Up @@ -113,7 +119,6 @@ class Memory
void clear() noexcept { m_size = 0; }
};


/// Generic execution state for generic instructions implementations.
// NOLINTNEXTLINE(clang-analyzer-optin.performance.Padding)
template<typename BlueprintFieldType>
Expand Down

0 comments on commit aad7495

Please sign in to comment.