Skip to content

Commit

Permalink
Make number of quotient polynomials fixed #243
Browse files Browse the repository at this point in the history
  • Loading branch information
ETatuzova committed Dec 7, 2023
1 parent 5086354 commit 969e231
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ namespace nil {
typedef plonk_lookup_table<FieldType> lookup_table_type;
typedef std::vector<lookup_table_type> lookup_tables_type;
typedef std::vector<plonk_variable<typename FieldType::value_type>> public_input_gate_type;
typedef math::expression_max_degree_visitor<variable_type> degree_visitor_type;
typedef math::expression<variable_type> expression_type;
typedef math::term<variable_type> term_type;
typedef math::binary_arithmetic_operation<variable_type> binary_operation_type;
typedef math::pow_operation<variable_type> pow_operation_type;

protected:
gates_container_type _gates;
Expand All @@ -79,7 +84,7 @@ namespace nil {
const lookup_tables_type &lookup_tables = {}
) :
_gates(gates),
_copy_constraints(copy_constraints),
_copy_constraints(copy_constraints),
_lookup_gates(lookup_gates),
_lookup_tables(lookup_tables)
{
Expand Down Expand Up @@ -133,7 +138,7 @@ namespace nil {
std::size_t sorted_lookup_columns_number() const {
if(_lookup_gates.size() == 0){
return 0;
}
}
return lookup_options_num() + lookup_constraints_num();
}

Expand All @@ -152,7 +157,75 @@ namespace nil {
}
return result;
}


std::size_t lookup_expressions_num() const{
std::size_t result = 0;
for(std::size_t i = 0; i < _lookup_gates.size(); ++i) {
for(std::size_t j = 0; j < _lookup_gates[i].constraints.size(); ++j) {
result += _lookup_gates[i].constraints[j].lookup_input.size();
}
}
return result;
}

std::size_t lookup_tables_columns_num() const{
std::size_t result = 0;
for(std::size_t i = 0; i < _lookup_tables.size(); ++i) {
result += _lookup_tables[i].lookup_options[0].size() * _lookup_tables[i].lookup_options.size();
}
return result;
}

std::size_t max_gates_degree() const {
std::size_t max_gates_degree = 0;
math::expression_max_degree_visitor<variable_type> gates_visitor;
for (const auto& gate : _gates) {
for (const auto& constr : gate.constraints) {
std::size_t deg = gates_visitor.compute_max_degree(constr);
max_gates_degree = std::max(max_gates_degree, deg);
}
}
return max_gates_degree;
}

std::size_t max_lookup_gates_degree() const {
std::size_t max_lookup_gates_degree = 0;
math::expression_max_degree_visitor<variable_type> lookup_visitor;
for (const auto& gate :_lookup_gates) {
for (const auto& constr : gate.constraints) {
for (const auto& li : constr.lookup_input) {
std::size_t deg = lookup_visitor.compute_max_degree(li);
max_lookup_gates_degree = std::max(
max_lookup_gates_degree,
deg
);
}
}
}
return max_lookup_gates_degree;
}

std::size_t lookup_poly_degree_bound() const{
std::uint32_t lookup_degree = 0;
if(_lookup_gates.size() > 0){
degree_visitor_type degree_visitor;
for(std::size_t i = 0; i < _lookup_gates.size(); i++){
for(std::size_t j = 0; j < _lookup_gates[i].constraints.size(); j++){
std::size_t degree = 0;
for(std::size_t k = 0; k < _lookup_gates[i].constraints[j].lookup_input.size(); k++){
degree = std::max(degree, std::size_t(degree_visitor.compute_max_degree(_lookup_gates[i].constraints[j].lookup_input[k])));
}
lookup_degree += (degree + 1);
}
}
for(std::size_t i = 0; i < _lookup_tables.size(); i++){
lookup_degree += 3 * _lookup_tables[i].lookup_options.size();
}
}
return lookup_degree;
}


bool operator==(const plonk_constraint_system<FieldType, ArithmetizationParams> &other) const {
return (this->_gates == other._gates) && (this->_copy_constraints == other._copy_constraints) &&
(this->_lookup_gates == other._lookup_gates) && (this->_lookup_tables == other._lookup_tables);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,22 +442,10 @@ namespace nil {
std::size_t N_rows = table_description.rows_amount;
std::size_t usable_rows = table_description.usable_rows_amount;

std::uint32_t max_gates_degree = 0;
math::expression_max_degree_visitor<variable_type> gates_visitor;
for (const auto& gate : constraint_system.gates()) {
for (const auto& constr : gate.constraints) {
max_gates_degree = std::max(max_gates_degree, gates_visitor.compute_max_degree(constr));
}
}
math::expression_max_degree_visitor<variable_type> lookup_visitor;
for (const auto& gate : constraint_system.lookup_gates()) {
for (const auto& constr : gate.constraints) {
for (const auto& li : constr.lookup_input) {
max_gates_degree = std::max(max_gates_degree,
lookup_visitor.compute_max_degree(li));
}
}
}
std::uint32_t max_gates_degree = std::max(
constraint_system.max_gates_degree(),
constraint_system.max_lookup_gates_degree()
);
assert(max_gates_degree > 0);

std::shared_ptr<math::evaluation_domain<FieldType>> basic_domain =
Expand Down
18 changes: 16 additions & 2 deletions include/nil/crypto3/zk/snark/systems/plonk/placeholder/prover.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace nil {
// 1. Add circuit definition to transcript
// transcript(short_description);

// Initialize transcript.
// Initialize transcript.
transcript(preprocessed_public_data.common_data.vk.constraint_system_hash);
transcript(preprocessed_public_data.common_data.vk.fixed_values_commitment);

Expand Down Expand Up @@ -236,7 +236,21 @@ namespace nil {

PROFILE_PLACEHOLDER_SCOPE("split_polynomial_dfs_conversion_time");

std::vector<polynomial_dfs_type> T_splitted_dfs(T_splitted.size());
std::size_t split_polynomial_size = std::max(
(preprocessed_public_data.identity_polynomials.size() + 1) * (preprocessed_public_data.common_data.rows_amount -1 ),
(constraint_system.lookup_poly_degree_bound() + 1) * (preprocessed_public_data.common_data.rows_amount -1 )//,
);
split_polynomial_size = std::max(
split_polynomial_size,
(preprocessed_public_data.common_data.max_gates_degree + 1) * (preprocessed_public_data.common_data.rows_amount -1)
);
split_polynomial_size = (split_polynomial_size % preprocessed_public_data.common_data.rows_amount != 0)?
(split_polynomial_size / preprocessed_public_data.common_data.rows_amount + 1):
(split_polynomial_size / preprocessed_public_data.common_data.rows_amount);

std::vector<polynomial_dfs_type> T_splitted_dfs(split_polynomial_size,
polynomial_dfs_type(0, _F_dfs[0].size(), FieldType::value_type::zero()));

for (std::size_t k = 0; k < T_splitted.size(); k++) {
T_splitted_dfs[k].from_coefficients(T_splitted[k]);
}
Expand Down

0 comments on commit 969e231

Please sign in to comment.