Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve rename copy constraints #456

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 48 additions & 46 deletions bin/assigner/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ using namespace nil::blueprint;
template<typename Endianness, typename ArithmetizationType, typename ConstraintSystemType>
void print_circuit(const circuit_proxy<ArithmetizationType> &circuit_proxy,
const assignment_proxy<ArithmetizationType> &table_proxy,
bool rename_required, std::ostream &out = std::cout) {
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 @@ -90,31 +90,28 @@ void print_circuit(const circuit_proxy<ArithmetizationType> &circuit_proxy,
const auto& copy_constraints = circuit_proxy.copy_constraints();
typename ConstraintSystemType::copy_constraints_container_type used_copy_constraints;
const auto& used_copy_constraints_idx = circuit_proxy.get_used_copy_constraints();
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);
}
if (circuit_proxy.get_id() > 0) {
const auto start_row = table_proxy.get_start_row();
for (const auto &it : used_copy_constraints_idx) {
auto first_var = copy_constraints[it].first;
auto second_var = copy_constraints[it].second;
if (first_var.type == variable_type::column_type::witness ||
first_var.type == variable_type::column_type::constant) {
ASSERT(first_var.rotation >= start_row);
first_var =
variable_type(first_var.index, first_var.rotation - start_row, first_var.relative, first_var.type);
}
if (second_var.type == variable_type::column_type::witness ||
second_var.type == variable_type::column_type::constant) {
ASSERT(second_var.rotation >= start_row);
second_var = variable_type(second_var.index, second_var.rotation - start_row, second_var.relative,
second_var.type);
}
local_row++;
used_copy_constraints.push_back({first_var, second_var});
}
} else {
for (const auto &it : used_copy_constraints_idx) {
used_copy_constraints.push_back(copy_constraints[it]);
}
}

Expand Down Expand Up @@ -203,8 +200,9 @@ void print_assignment_table(const assignment_proxy<ArithmetizationType> &table_p
for (const auto &i : lookup_selector_cols) {
max_selector_size = std::max(max_selector_size, table_proxy.selector_column_size(i));
}
usable_rows_amount = table_proxy.get_used_rows().size();
usable_rows_amount = std::max({usable_rows_amount, max_shared_size, max_public_inputs_size, max_constant_size, max_selector_size});
max_selector_size = std::max(max_selector_size, (std::uint32_t)table_proxy.get_used_selector_rows().size());
usable_rows_amount = std::max({table_proxy.get_num_private_rows(),
max_shared_size, max_public_inputs_size, max_constant_size, max_selector_size});
} else { // FULL
total_columns = AssignmentTableType::arithmetization_params::total_columns;
std::uint32_t max_witness_size = 0;
Expand Down Expand Up @@ -269,19 +267,17 @@ void print_assignment_table(const assignment_proxy<ArithmetizationType> &table_p
it += padded_rows_amount;
}
} else {
const auto& rows = table_proxy.get_used_rows();
const auto& selector_rows = table_proxy.get_used_selector_rows();
const std::uint32_t padding = padded_rows_amount - rows.size();
std::uint32_t idx = 0;
auto it = table_values.begin();
std::uint32_t start_row = table_proxy.get_start_row();
std::uint32_t num_private_rows = table_proxy.get_num_private_rows();
// witness
for( std::size_t i = 0; i < AssignmentTableType::arithmetization_params::witness_columns; i++ ){
const auto column_size = table_proxy.witness_column_size(i);
std::uint32_t offset = 0;
for(const auto& j : rows){
if (j < column_size) {
table_values[idx + offset] = table_proxy.witness(i, j);
offset++;
for(std::size_t j = 0; j < num_private_rows; j++){
if ((j + start_row) < column_size) {
table_values[idx + j] = table_proxy.witness(i, j + start_row);
}
}
idx += padded_rows_amount;
Expand All @@ -303,11 +299,9 @@ void print_assignment_table(const assignment_proxy<ArithmetizationType> &table_p
// constant
for (std::uint32_t i = 0; i < ComponentConstantColumns; i++) {
const auto column_size = table_proxy.constant_column_size(i);
std::uint32_t offset = 0;
for(const auto& j : rows){
if (j < column_size) {
table_values[idx + offset] = table_proxy.constant(i, j);
offset++;
for(std::size_t j = 0; j < num_private_rows; j++){
if ((j + start_row) < column_size) {
table_values[idx + j] = table_proxy.constant(i, j + start_row);
}
}
idx += padded_rows_amount;
Expand All @@ -323,12 +317,10 @@ void print_assignment_table(const assignment_proxy<ArithmetizationType> &table_p
for (std::uint32_t i = 0; i < ComponentSelectorColumns; i++) {
const auto column_size = table_proxy.selector_column_size(i);
std::uint32_t offset = 0;
for(const auto& j : rows){
for(const auto& j : selector_rows){
if (j < column_size) {
if (selector_rows.find(j) != selector_rows.end()) {
table_values[idx + offset] = table_proxy.selector(i, j);
}
offset++;
offset = j - start_row;
table_values[idx + offset] = table_proxy.selector(i, j);
}
}
idx += padded_rows_amount;
Expand Down Expand Up @@ -448,9 +440,14 @@ int curve_dependent_main(std::string bytecode_file_name,
return 1;
}

auto start = std::chrono::system_clock::now();
if (!parser_instance.evaluate(*module, public_input_json_value.as_array(), private_input_json_value.as_array())) {
return 1;
}
auto end = std::chrono::system_clock::now();
auto elapsed =
std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
//std::cout << "evaluate: " << elapsed.count() << "\n";

ASSERT_MSG(!parser_instance.assignments.empty() && !parser_instance.circuits.empty(), "Not found any proxy for prover" );

Expand Down Expand Up @@ -502,7 +499,7 @@ int curve_dependent_main(std::string bytecode_file_name,
}

print_circuit<nil::marshalling::option::big_endian, ArithmetizationType, ConstraintSystemType>(
parser_instance.circuits[0], parser_instance.assignments[0], false, ocircuit);
parser_instance.circuits[0], parser_instance.assignments[0], ocircuit);
ocircuit.close();
} else if (parser_instance.assignments.size() > 1) {
for (std::uint32_t idx = 0; idx < parser_instance.assignments.size(); idx++) {
Expand Down Expand Up @@ -530,8 +527,13 @@ int curve_dependent_main(std::string bytecode_file_name,
}

ASSERT_MSG(idx < parser_instance.circuits.size(), "Not found circuit");
start = std::chrono::system_clock::now();
print_circuit<nil::marshalling::option::big_endian, ArithmetizationType, ConstraintSystemType>(
parser_instance.circuits[idx], parser_instance.assignments[idx], (idx > 0), ocircuit);
parser_instance.circuits[idx], parser_instance.assignments[idx], ocircuit);
end = std::chrono::system_clock::now();
elapsed =
std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
//std::cout << "print: " << elapsed.count() << "\n";

ocircuit.close();
}
Expand Down
2 changes: 1 addition & 1 deletion libs/blueprint
Submodule blueprint updated 35 files
+27 −20 include/nil/blueprint/blueprint/plonk/assignment_proxy.hpp
+26 −0 include/nil/blueprint/components/algebra/fields/plonk/addition.hpp
+26 −0 include/nil/blueprint/components/algebra/fields/plonk/division.hpp
+25 −0 include/nil/blueprint/components/algebra/fields/plonk/division_or_zero.hpp
+43 −0 include/nil/blueprint/components/algebra/fields/plonk/logic_and_flag.hpp
+45 −0 include/nil/blueprint/components/algebra/fields/plonk/logic_or_flag.hpp
+27 −0 include/nil/blueprint/components/algebra/fields/plonk/multiplication.hpp
+24 −0 include/nil/blueprint/components/algebra/fields/plonk/multiplication_by_constant.hpp
+105 −0 include/nil/blueprint/components/algebra/fields/plonk/non_native/addition.hpp
+52 −0 include/nil/blueprint/components/algebra/fields/plonk/non_native/bit_composition.hpp
+58 −0 include/nil/blueprint/components/algebra/fields/plonk/non_native/bit_decomposition.hpp
+148 −4 include/nil/blueprint/components/algebra/fields/plonk/non_native/comparison_flag.hpp
+1 −1 include/nil/blueprint/components/algebra/fields/plonk/non_native/detail/bit_builder_component.hpp
+50 −0 include/nil/blueprint/components/algebra/fields/plonk/non_native/division_remainder.hpp
+130 −0 include/nil/blueprint/components/algebra/fields/plonk/non_native/multiplication.hpp
+104 −0 include/nil/blueprint/components/algebra/fields/plonk/non_native/subtraction.hpp
+26 −0 include/nil/blueprint/components/algebra/fields/plonk/subtraction.hpp
+66 −0 include/nil/blueprint/components/hashes/sha2/plonk/decomposition.hpp
+81 −5 include/nil/blueprint/components/hashes/sha2/plonk/sha256.hpp
+319 −0 include/nil/blueprint/components/hashes/sha2/plonk/sha256_process.hpp
+6 −0 test/algebra/fields/plonk/field_operations.cpp
+2 −0 test/algebra/fields/plonk/logic_and_flag.cpp
+2 −0 test/algebra/fields/plonk/logic_or_flag.cpp
+2 −0 test/algebra/fields/plonk/non_native/addition.cpp
+3 −0 test/algebra/fields/plonk/non_native/bit_composition.cpp
+3 −0 test/algebra/fields/plonk/non_native/bit_decomposition.cpp
+3 −0 test/algebra/fields/plonk/non_native/comparison_flag.cpp
+3 −0 test/algebra/fields/plonk/non_native/division_remainder.cpp
+2 −0 test/algebra/fields/plonk/non_native/multiplication.cpp
+2 −0 test/algebra/fields/plonk/non_native/subtraction.cpp
+16 −8 test/hashes/plonk/decomposition.cpp
+8 −1 test/hashes/plonk/sha256.cpp
+13 −0 test/hashes/plonk/sha256_process.cpp
+24 −38 test/proxy.cpp
+90 −0 test/test_plonk_component.hpp
Loading