Skip to content

Commit

Permalink
zkevm_circuit and zkevm_table are different structures now#325
Browse files Browse the repository at this point in the history
  • Loading branch information
ETatuzova committed Sep 15, 2024
1 parent 76b93f2 commit d3d1949
Show file tree
Hide file tree
Showing 37 changed files with 755 additions and 381 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ namespace nil {
const std::set<std::uint32_t> &used_lookup_gates,
const std::set<std::uint32_t> &used_copy_constraints,
const std::set<std::uint32_t> &selector_rows){
std::cout << "Satisfiability check" << std::endl;

const auto &gates = bp.gates();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

namespace nil {
namespace blueprint {
template<typename BlueprintFieldType>
class zkevm_operation;

template<typename BlueprintFieldType>
class zkevm_add_sub_operation : public zkevm_operation<BlueprintFieldType> {
Expand All @@ -42,6 +44,7 @@ namespace nil {
using constraint_type = typename op_type::constraint_type;
using lookup_constraint_type = crypto3::zk::snark::plonk_lookup_constraint<BlueprintFieldType>;
using zkevm_circuit_type = typename op_type::zkevm_circuit_type;
using zkevm_table_type = typename op_type::zkevm_table_type;
using assignment_type = typename op_type::assignment_type;
using value_type = typename BlueprintFieldType::value_type;
using var = typename op_type::var;
Expand Down Expand Up @@ -123,7 +126,7 @@ namespace nil {
return {{gate_class::MIDDLE_OP, {constraints, {}}}};
}

void generate_assignments(zkevm_circuit_type &zkevm_circuit, zkevm_machine_interface &machine) override {
void generate_assignments(zkevm_table_type &zkevm_table, zkevm_machine_interface &machine) override {
zkevm_stack &stack = machine.stack;
using word_type = typename zkevm_stack::word_type;
word_type a = stack.pop();
Expand All @@ -136,9 +139,9 @@ namespace nil {
const std::vector<value_type> a_chunks = zkevm_word_to_field_element<BlueprintFieldType>(a);
const std::vector<value_type> b_chunks = zkevm_word_to_field_element<BlueprintFieldType>(b);
const std::vector<value_type> r_chunks = zkevm_word_to_field_element<BlueprintFieldType>(result);
const std::vector<std::size_t> &witness_cols = zkevm_circuit.get_opcode_cols();
assignment_type &assignment = zkevm_circuit.get_assignment();
const std::size_t curr_row = zkevm_circuit.get_current_row();
const std::vector<std::size_t> &witness_cols = zkevm_table.get_opcode_cols();
assignment_type &assignment = zkevm_table.get_assignment();
const std::size_t curr_row = zkevm_table.get_current_row();
// TODO: replace with memory access, which would also do range checks!
for (std::size_t i = 0; i < a_chunks.size(); i++) {
assignment.witness(witness_cols[i], curr_row) = a_chunks[i];
Expand Down
11 changes: 7 additions & 4 deletions libs/blueprint/include/nil/blueprint/zkevm/operations/addmod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

namespace nil {
namespace blueprint {
template<typename BlueprintFieldType>
class zkevm_operation;

template<typename BlueprintFieldType>
class zkevm_addmod_operation : public zkevm_operation<BlueprintFieldType> {
Expand All @@ -41,6 +43,7 @@ namespace nil {
using constraint_type = typename op_type::constraint_type;
using lookup_constraint_type = crypto3::zk::snark::plonk_lookup_constraint<BlueprintFieldType>;
using zkevm_circuit_type = typename op_type::zkevm_circuit_type;
using zkevm_table_type = typename op_type::zkevm_table_type;
using assignment_type = typename op_type::assignment_type;
using value_type = typename BlueprintFieldType::value_type;
using var = typename op_type::var;
Expand Down Expand Up @@ -315,7 +318,7 @@ namespace nil {
return { {gate_class::MIDDLE_OP, {constraints, {} }} };
}

void generate_assignments(zkevm_circuit_type &zkevm_circuit, zkevm_machine_interface &machine) override {
void generate_assignments(zkevm_table_type &zkevm_table, zkevm_machine_interface &machine) override {
using word_type = typename zkevm_stack::word_type;
using integral_type = boost::multiprecision::number<
boost::multiprecision::backends::cpp_int_modular_backend<257>>;
Expand Down Expand Up @@ -362,9 +365,9 @@ namespace nil {
r_64_chunks.push_back(chunk_sum_64<value_type>(r_chunks, i));
q_64_chunks.push_back(chunk_sum_64<value_type>(q_chunks, i));
}
const std::vector<std::size_t> &witness_cols = zkevm_circuit.get_opcode_cols();
assignment_type &assignment = zkevm_circuit.get_assignment();
const std::size_t curr_row = zkevm_circuit.get_current_row();
const std::vector<std::size_t> &witness_cols = zkevm_table.get_opcode_cols();
assignment_type &assignment = zkevm_table.get_assignment();
const std::size_t curr_row = zkevm_table.get_current_row();
// caluclate first row carries
auto first_row_carries =
first_carryless_construct(s_64_chunks, N_64_chunks, r_64_chunks, q_64_chunks).data >> 128;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

namespace nil {
namespace blueprint {
template<typename BlueprintFieldType>
class zkevm_operation;

enum bitwise_type { B_AND, B_OR, B_XOR };

Expand All @@ -43,6 +45,7 @@ namespace nil {
using constraint_type = typename op_type::constraint_type;
using lookup_constraint_type = crypto3::zk::snark::plonk_lookup_constraint<BlueprintFieldType>;
using zkevm_circuit_type = typename op_type::zkevm_circuit_type;
using zkevm_table_type = typename op_type::zkevm_table_type;
using assignment_type = typename op_type::assignment_type;
using value_type = typename BlueprintFieldType::value_type;
using var = typename op_type::var;
Expand Down Expand Up @@ -97,7 +100,7 @@ namespace nil {
return { {gate_class::MIDDLE_OP, {constraints, lookup_constraints}} };
}

void generate_assignments(zkevm_circuit_type &zkevm_circuit, zkevm_machine_interface &machine) override {
void generate_assignments(zkevm_table_type &zkevm_table, zkevm_machine_interface &machine) override {
zkevm_stack &stack = machine.stack;
using word_type = typename zkevm_stack::word_type;
using integral_type = typename BlueprintFieldType::integral_type;
Expand All @@ -115,9 +118,9 @@ namespace nil {
const std::vector<value_type> a_chunks = zkevm_word_to_field_element<BlueprintFieldType>(a);
const std::vector<value_type> b_chunks = zkevm_word_to_field_element<BlueprintFieldType>(b);
const std::vector<value_type> r_chunks = zkevm_word_to_field_element<BlueprintFieldType>(result);
const std::vector<std::size_t> &witness_cols = zkevm_circuit.get_opcode_cols();
assignment_type &assignment = zkevm_circuit.get_assignment();
const std::size_t curr_row = zkevm_circuit.get_current_row();
const std::vector<std::size_t> &witness_cols = zkevm_table.get_opcode_cols();
assignment_type &assignment = zkevm_table.get_assignment();
const std::size_t curr_row = zkevm_table.get_current_row();

size_t chunk_amount = a_chunks.size();

Expand Down
11 changes: 7 additions & 4 deletions libs/blueprint/include/nil/blueprint/zkevm/operations/byte.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

namespace nil {
namespace blueprint {
template<typename BlueprintFieldType>
class zkevm_operation;

template<typename BlueprintFieldType>
class zkevm_byte_operation : public zkevm_operation<BlueprintFieldType> {
Expand All @@ -41,6 +43,7 @@ namespace nil {
using constraint_type = typename op_type::constraint_type;
using lookup_constraint_type = crypto3::zk::snark::plonk_lookup_constraint<BlueprintFieldType>;
using zkevm_circuit_type = typename op_type::zkevm_circuit_type;
using zkevm_table_type = typename op_type::zkevm_table_type;
using assignment_type = typename op_type::assignment_type;
using value_type = typename BlueprintFieldType::value_type;
using var = typename op_type::var;
Expand Down Expand Up @@ -121,7 +124,7 @@ namespace nil {
return {{gate_class::MIDDLE_OP, {constraints, lookup_constraints}}};
}

void generate_assignments(zkevm_circuit_type &zkevm_circuit, zkevm_machine_interface &machine) override {
void generate_assignments(zkevm_table_type &zkevm_table, zkevm_machine_interface &machine) override {
zkevm_stack &stack = machine.stack;
using word_type = typename zkevm_stack::word_type;
using integral_type = boost::multiprecision::number<
Expand All @@ -146,9 +149,9 @@ namespace nil {
const std::vector<value_type> x_chunks = zkevm_word_to_field_element<BlueprintFieldType>(x);

size_t chunk_amount = i_chunks.size();
const std::vector<std::size_t> &witness_cols = zkevm_circuit.get_opcode_cols();
assignment_type &assignment = zkevm_circuit.get_assignment();
const std::size_t curr_row = zkevm_circuit.get_current_row();
const std::vector<std::size_t> &witness_cols = zkevm_table.get_opcode_cols();
assignment_type &assignment = zkevm_table.get_assignment();
const std::size_t curr_row = zkevm_table.get_current_row();

// TODO: replace with memory access, which would also do range checks!
for(std::size_t j = 0; j < chunk_amount; j++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

namespace nil {
namespace blueprint {
template<typename BlueprintFieldType>
class zkevm_operation;

template<typename BlueprintFieldType>
class zkevm_calldataload_operation : public zkevm_operation<BlueprintFieldType> {
Expand All @@ -41,6 +43,7 @@ namespace nil {
using constraint_type = typename op_type::constraint_type;
using lookup_constraint_type = crypto3::zk::snark::plonk_lookup_constraint<BlueprintFieldType>;
using zkevm_circuit_type = typename op_type::zkevm_circuit_type;
using zkevm_table_type = typename op_type::zkevm_table_type;
using assignment_type = typename op_type::assignment_type;
using value_type = typename BlueprintFieldType::value_type;
using var = typename op_type::var;
Expand All @@ -63,7 +66,7 @@ namespace nil {
return {{gate_class::MIDDLE_OP, {{}, {}}}};
}

void generate_assignments(zkevm_circuit_type &zkevm_circuit, zkevm_machine_interface &machine) override {
void generate_assignments(zkevm_table_type &zkevm_table, zkevm_machine_interface &machine) override {
zkevm_stack &stack = machine.stack;
std::cout << "Generate assignments and gates for CALLDATALOAD" << std::endl;
stack.push(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

namespace nil {
namespace blueprint {
template<typename BlueprintFieldType>
class zkevm_operation;

template<typename BlueprintFieldType>
class zkevm_calldatasize_operation : public zkevm_operation<BlueprintFieldType> {
Expand All @@ -41,6 +43,7 @@ namespace nil {
using constraint_type = typename op_type::constraint_type;
using lookup_constraint_type = crypto3::zk::snark::plonk_lookup_constraint<BlueprintFieldType>;
using zkevm_circuit_type = typename op_type::zkevm_circuit_type;
using zkevm_table_type = typename op_type::zkevm_table_type;
using assignment_type = typename op_type::assignment_type;
using value_type = typename BlueprintFieldType::value_type;
using var = typename op_type::var;
Expand All @@ -63,7 +66,7 @@ namespace nil {
return {{gate_class::MIDDLE_OP, {{}, {}}}};
}

void generate_assignments(zkevm_circuit_type &zkevm_circuit, zkevm_machine_interface &machine) override {
void generate_assignments(zkevm_table_type &zkevm_table, zkevm_machine_interface &machine) override {
zkevm_stack &stack = machine.stack;
std::cout << "Generate assignments and gates for CALLDATASIZE" << std::endl;
stack.push(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

namespace nil {
namespace blueprint {
template<typename BlueprintFieldType>
class zkevm_operation;

template<typename BlueprintFieldType>
class zkevm_callvalue_operation : public zkevm_operation<BlueprintFieldType> {
Expand All @@ -41,6 +43,7 @@ namespace nil {
using constraint_type = typename op_type::constraint_type;
using lookup_constraint_type = crypto3::zk::snark::plonk_lookup_constraint<BlueprintFieldType>;
using zkevm_circuit_type = typename op_type::zkevm_circuit_type;
using zkevm_table_type = typename op_type::zkevm_table_type;
using assignment_type = typename op_type::assignment_type;
using value_type = typename BlueprintFieldType::value_type;
using var = typename op_type::var;
Expand All @@ -63,7 +66,7 @@ namespace nil {
return {{gate_class::MIDDLE_OP, {{}, {}}}};
}

void generate_assignments(zkevm_circuit_type &zkevm_circuit, zkevm_machine_interface &machine) override {
void generate_assignments(zkevm_table_type &zkevm_table, zkevm_machine_interface &machine) override {
zkevm_stack &stack = machine.stack;
std::cout << "Generate assignments and gates for CALLVALUE" << std::endl;
stack.push(0);
Expand Down
11 changes: 7 additions & 4 deletions libs/blueprint/include/nil/blueprint/zkevm/operations/cmp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

namespace nil {
namespace blueprint {
template<typename BlueprintFieldType>
class zkevm_operation;

enum cmp_type { C_LT, C_EQ, C_GT, C_SLT, C_SGT };

Expand All @@ -43,6 +45,7 @@ namespace nil {
using constraint_type = typename op_type::constraint_type;
using lookup_constraint_type = crypto3::zk::snark::plonk_lookup_constraint<BlueprintFieldType>;
using zkevm_circuit_type = typename op_type::zkevm_circuit_type;
using zkevm_table_type = typename op_type::zkevm_table_type;
using assignment_type = typename op_type::assignment_type;
using value_type = typename BlueprintFieldType::value_type;
using var = typename op_type::var;
Expand Down Expand Up @@ -167,7 +170,7 @@ namespace nil {
return {{gate_class::MIDDLE_OP, {constraints, {}}}};
}

void generate_assignments(zkevm_circuit_type &zkevm_circuit, zkevm_machine_interface &machine) override {
void generate_assignments(zkevm_table_type &zkevm_table, zkevm_machine_interface &machine) override {
zkevm_stack &stack = machine.stack;
using word_type = typename zkevm_stack::word_type;
using integral_type = boost::multiprecision::number<
Expand Down Expand Up @@ -213,9 +216,9 @@ namespace nil {
const std::vector<value_type> a_chunks = zkevm_word_to_field_element<BlueprintFieldType>(a);
const std::vector<value_type> b_chunks = zkevm_word_to_field_element<BlueprintFieldType>(b);
const std::vector<value_type> r_chunks = zkevm_word_to_field_element<BlueprintFieldType>(c);
const std::vector<std::size_t> &witness_cols = zkevm_circuit.get_opcode_cols();
assignment_type &assignment = zkevm_circuit.get_assignment();
const std::size_t curr_row = zkevm_circuit.get_current_row();
const std::vector<std::size_t> &witness_cols = zkevm_table.get_opcode_cols();
assignment_type &assignment = zkevm_table.get_assignment();
const std::size_t curr_row = zkevm_table.get_current_row();
std:size_t chunk_amount = 16;

// TODO: replace with memory access, which would also do range checks!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

namespace nil {
namespace blueprint {
template<typename BlueprintFieldType>
class zkevm_operation;

template<typename BlueprintFieldType>
class zkevm_div_mod_operation : public zkevm_operation<BlueprintFieldType> {
Expand All @@ -43,6 +45,7 @@ namespace nil {
using lookup_constraint_type = crypto3::zk::snark::plonk_lookup_constraint<BlueprintFieldType>;
using zkevm_circuit_type = typename op_type::zkevm_circuit_type;
using assignment_type = typename op_type::assignment_type;
using zkevm_table_type = typename op_type::zkevm_table_type;
using value_type = typename BlueprintFieldType::value_type;
using var = typename op_type::var;

Expand Down Expand Up @@ -284,7 +287,7 @@ namespace nil {
return {{gate_class::MIDDLE_OP, {constraints, {}}}};
}

void generate_assignments(zkevm_circuit_type &zkevm_circuit, zkevm_machine_interface &machine) override {
void generate_assignments(zkevm_table_type &zkevm_table, zkevm_machine_interface &machine) override {
using word_type = typename zkevm_stack::word_type;
zkevm_stack &stack = machine.stack;
word_type a = stack.pop();
Expand Down Expand Up @@ -318,9 +321,9 @@ namespace nil {
r_64_chunks.push_back(chunk_sum_64<value_type>(r_chunks, i));
q_64_chunks.push_back(chunk_sum_64<value_type>(q_chunks, i));
}
const std::vector<std::size_t> &witness_cols = zkevm_circuit.get_opcode_cols();
assignment_type &assignment = zkevm_circuit.get_assignment();
const std::size_t curr_row = zkevm_circuit.get_current_row();
const std::vector<std::size_t> &witness_cols = zkevm_table.get_opcode_cols();
assignment_type &assignment = zkevm_table.get_assignment();
const std::size_t curr_row = zkevm_table.get_current_row();
// caluclate first row carries
auto first_row_carries =
first_carryless_construct(a_64_chunks, b_64_chunks, r_64_chunks, q_64_chunks).data >> 128;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

namespace nil {
namespace blueprint {
template<typename BlueprintFieldType>
class zkevm_operation;

template<typename BlueprintFieldType>
class zkevm_dupx_operation : public zkevm_operation<BlueprintFieldType> {
Expand All @@ -41,6 +43,7 @@ namespace nil {
using constraint_type = typename op_type::constraint_type;
using lookup_constraint_type = crypto3::zk::snark::plonk_lookup_constraint<BlueprintFieldType>;
using zkevm_circuit_type = typename op_type::zkevm_circuit_type;
using zkevm_table_type = typename op_type::zkevm_table_type;
using assignment_type = typename op_type::assignment_type;
using value_type = typename BlueprintFieldType::value_type;
using var = typename op_type::var;
Expand All @@ -60,7 +63,7 @@ namespace nil {
return {{gate_class::MIDDLE_OP, {{}, {}}}};
}

void generate_assignments(zkevm_circuit_type &zkevm_circuit, zkevm_machine_interface &machine) override{
void generate_assignments(zkevm_table_type &zkevm_table, zkevm_machine_interface &machine) override{
zkevm_stack &stack = machine.stack;
std::cout << "Generate assignments for DUPx opcodes" << std::endl;
stack.push(0);
Expand Down
Loading

0 comments on commit d3d1949

Please sign in to comment.