Skip to content

Commit

Permalink
Use zkevm_circuit enum as key of the map assignment tables
Browse files Browse the repository at this point in the history
  • Loading branch information
akokoshn authored and akokoshn committed Aug 16, 2024
1 parent 9d755e5 commit d992095
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
11 changes: 4 additions & 7 deletions lib/assigner/include/assigner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,11 @@ namespace nil {

using ArithmetizationType = crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>;

constexpr static size_t BYTECODE_TABLE_INDEX = 0;
constexpr static size_t RW_TABLE_INDEX = 1;

assigner(std::unordered_map<uint8_t, nil::blueprint::assignment<ArithmetizationType>> &assignments): m_assignments(assignments) {}
assigner(std::unordered_map<zkevm_circuit, nil::blueprint::assignment<ArithmetizationType>> &assignments): m_assignments(assignments) {}

// TODO error handling
void handle_bytecode(size_t original_code_size, const uint8_t* code) {
auto it = m_assignments.find(BYTECODE_TABLE_INDEX);
auto it = m_assignments.find(zkevm_circuit::BYTECODE);
if (it == m_assignments.end()) {
return;
}
Expand All @@ -61,15 +58,15 @@ namespace nil {

// TODO error handling
void handle_rw(std::vector<rw_operation<BlueprintFieldType>>& rw_trace) {
auto it = m_assignments.find(RW_TABLE_INDEX);
auto it = m_assignments.find(zkevm_circuit::RW);
if (it == m_assignments.end()) {
return;
}
return process_rw_operations<BlueprintFieldType>(
rw_trace, it->second);
}

std::unordered_map<uint8_t, nil::blueprint::assignment<ArithmetizationType>> &m_assignments;
std::unordered_map<zkevm_circuit, nil::blueprint::assignment<ArithmetizationType>> &m_assignments;
};

template<typename BlueprintFieldType>
Expand Down
13 changes: 6 additions & 7 deletions lib/assigner/test/assigner_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ class AssignerTest : public testing::Test
nil::crypto3::zk::snark::plonk_table_description<BlueprintFieldType> desc(
WitnessColumns, PublicInputColumns, ConstantColumns, SelectorColumns);

assignments.insert(std::pair<uint8_t, nil::blueprint::assignment<ArithmetizationType>>(0, nil::blueprint::assignment<ArithmetizationType>(desc)));
// for check create, call op codes, where message depth = 1
assignments.insert(std::pair<uint8_t, nil::blueprint::assignment<ArithmetizationType>>(1, nil::blueprint::assignment<ArithmetizationType>(desc)));
assignments.insert(std::pair<nil::evm_assigner::zkevm_circuit, nil::blueprint::assignment<ArithmetizationType>>(nil::evm_assigner::zkevm_circuit::BYTECODE, nil::blueprint::assignment<ArithmetizationType>(desc)));
assignments.insert(std::pair<nil::evm_assigner::zkevm_circuit, nil::blueprint::assignment<ArithmetizationType>>(nil::evm_assigner::zkevm_circuit::RW, nil::blueprint::assignment<ArithmetizationType>(desc)));

assigner_ptr =
std::make_shared<nil::evm_assigner::assigner<BlueprintFieldType>>(assignments);
Expand Down Expand Up @@ -70,7 +69,7 @@ class AssignerTest : public testing::Test
}

static std::shared_ptr<nil::evm_assigner::assigner<BlueprintFieldType>> assigner_ptr;
static std::unordered_map<uint8_t, nil::blueprint::assignment<ArithmetizationType>> assignments;
static std::unordered_map<nil::evm_assigner::zkevm_circuit, nil::blueprint::assignment<ArithmetizationType>> assignments;
static const struct evmc_host_interface* host_interface;
static struct evmc_host_context* ctx;
static evmc_revision rev;
Expand All @@ -79,7 +78,7 @@ class AssignerTest : public testing::Test

std::shared_ptr<nil::evm_assigner::assigner<AssignerTest::BlueprintFieldType>>
AssignerTest::assigner_ptr;
std::unordered_map<uint8_t, nil::blueprint::assignment<AssignerTest::ArithmetizationType>>
std::unordered_map<nil::evm_assigner::zkevm_circuit, nil::blueprint::assignment<AssignerTest::ArithmetizationType>>
AssignerTest::assignments;
const struct evmc_host_interface* AssignerTest::host_interface;
struct evmc_host_context* AssignerTest::ctx;
Expand All @@ -92,7 +91,7 @@ inline void check_eq(const uint8_t* l, const uint8_t* r, size_t len) {
}
}

inline void rw_circuit_check(const std::unordered_map<uint8_t, nil::blueprint::assignment<AssignerTest::ArithmetizationType>> &assignments,
inline void rw_circuit_check(const std::unordered_map<nil::evm_assigner::zkevm_circuit, nil::blueprint::assignment<AssignerTest::ArithmetizationType>> &assignments,
uint32_t start_row_index,
uint8_t operation_type,
uint32_t call_id,
Expand All @@ -103,7 +102,7 @@ inline void rw_circuit_check(const std::unordered_map<uint8_t, nil::blueprint::a
bool is_write,
const typename AssignerTest::BlueprintFieldType::value_type& value_hi,
const typename AssignerTest::BlueprintFieldType::value_type& value_lo) {
auto it = assignments.find(nil::evm_assigner::assigner<AssignerTest::BlueprintFieldType>::RW_TABLE_INDEX);
auto it = assignments.find(nil::evm_assigner::zkevm_circuit::RW);
if (it == assignments.end()) {
return;
}
Expand Down

0 comments on commit d992095

Please sign in to comment.