Skip to content

Commit

Permalink
Rename copy constraints witness/constant variables for local rows
Browse files Browse the repository at this point in the history
  • Loading branch information
akokoshn authored and akokoshn committed Nov 16, 2023
1 parent ea39658 commit 31f6d27
Showing 1 changed file with 36 additions and 5 deletions.
41 changes: 36 additions & 5 deletions bin/assigner/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ void print_hex_byteblob(std::ostream &os, TIter iter_begin, TIter iter_end, bool
}

template<typename Endianness, typename ArithmetizationType, typename ConstraintSystemType>
void print_circuit(const circuit_proxy<ArithmetizationType> &circuit_proxy, std::ostream &out = std::cout) {
void print_circuit(const circuit_proxy<ArithmetizationType> &circuit_proxy,
const assignment_proxy<ArithmetizationType> &table_proxy,
bool rename_required, std::ostream &out = std::cout) {
using TTypeBase = nil::marshalling::field_type<Endianness>;
using plonk_constraint_system = nil::marshalling::types::bundle<
TTypeBase, std::tuple<
Expand All @@ -83,6 +85,8 @@ void print_circuit(const circuit_proxy<ArithmetizationType> &circuit_proxy, std:
nil::crypto3::marshalling::types::plonk_lookup_tables< TTypeBase, typename ConstraintSystemType::lookup_tables_type::value_type > // lookup tables
>
>;
using AssignmentTableType = assignment_proxy<ArithmetizationType>;
using variable_type = crypto3::zk::snark::plonk_variable<typename AssignmentTableType::field_type::value_type>;

const auto gates = circuit_proxy.gates();
const std::set<std::uint32_t>& used_gates_idx = circuit_proxy.get_used_gates();
Expand All @@ -97,6 +101,29 @@ void print_circuit(const circuit_proxy<ArithmetizationType> &circuit_proxy, std:
for (const auto &it : used_copy_constraints_idx) {
used_copy_constraints.push_back(copy_constraints[it]);
}
if (rename_required) {
const auto used_rows = table_proxy.get_used_rows();
std::uint32_t local_row = 0;
for (const auto &row : used_rows) {
for (auto &constraint : used_copy_constraints) {
const auto first_var = constraint.first;
const auto second_var = constraint.second;
if ((first_var.type == variable_type::column_type::witness ||
first_var.type == variable_type::column_type::constant) &&
first_var.rotation == row) {
constraint.first = variable_type(first_var.index, local_row, first_var.relative,
first_var.type);
}
if ((second_var.type == variable_type::column_type::witness ||
second_var.type == variable_type::column_type::constant) &&
second_var.rotation == row) {
constraint.second = variable_type(second_var.index, local_row,
second_var.relative, second_var.type);
}
}
local_row++;
}
}

const auto lookup_gates = circuit_proxy.lookup_gates();
typename ConstraintSystemType::lookup_gates_container_type used_lookup_gates;
Expand Down Expand Up @@ -279,10 +306,10 @@ void print_assignment_table(const assignment_proxy<ArithmetizationType> &table_p
fill_vector_value<typename AssignmentTableType::field_type::value_type, ArithmetizationType>
(table_values, table_proxy, print_column_kind::SELECTOR, selector_size, usable_rows_amount, padding);
} else if (print_kind == print_table_kind::SHARED) {
fill_vector_value<typename AssignmentTableType::field_type::value_type, ArithmetizationType>
(table_values, table_proxy, print_column_kind::SHARED, shared_size, usable_rows_amount, padding);
fill_vector_value<typename AssignmentTableType::field_type::value_type, ArithmetizationType>
(table_values, table_proxy, print_column_kind::PUBLIC_INPUT, public_input_size, usable_rows_amount, padding);
fill_vector_value<typename AssignmentTableType::field_type::value_type, ArithmetizationType>
(table_values, table_proxy, print_column_kind::SHARED, shared_size, usable_rows_amount, padding);
} else {
const auto rows = table_proxy.get_used_rows();
for( std::size_t i = 0; i < AssignmentTableType::arithmetization_params::witness_columns; i++ ){
Expand Down Expand Up @@ -442,7 +469,8 @@ int curve_dependent_main(std::string bytecode_file_name,
}
}

for (const auto& it : parser_instance.circuits) {
auto assignment_it = parser_instance.assignments.begin();
for (auto& it : parser_instance.circuits) {
std::ofstream ocircuit;
std::string file_name = parser_instance.circuits.size() > 1 ?
circuit_file_name + std::to_string(it.get_id()) : circuit_file_name;
Expand All @@ -451,8 +479,11 @@ int curve_dependent_main(std::string bytecode_file_name,
std::cout << "Something wrong with output " << file_name << std::endl;
return 1;
}
print_circuit<nil::marshalling::option::big_endian, ArithmetizationType, ConstraintSystemType>(it, ocircuit);
ASSERT_MSG(assignment_it != parser_instance.assignments.end(), "Not found assignment for circuit");
print_circuit<nil::marshalling::option::big_endian, ArithmetizationType, ConstraintSystemType>
(it, *assignment_it, (parser_instance.assignments.size() > 1), ocircuit);
ocircuit.close();
assignment_it++;
}

if (check_validity){
Expand Down

0 comments on commit 31f6d27

Please sign in to comment.