Skip to content

Commit

Permalink
Fixing everything
Browse files Browse the repository at this point in the history
  • Loading branch information
martun committed Dec 20, 2023
1 parent 79f9499 commit 5282505
Show file tree
Hide file tree
Showing 3 changed files with 404 additions and 305 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ namespace nil {
plonk_constraint_system(const gates_container_type &gates,
const copy_constraints_container_type &copy_constraints,
const lookup_gates_container_type &lookup_gates = {},
const lookup_tables_type &lookup_tables = {}) :
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 @@ -157,6 +158,74 @@ 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
24 changes: 22 additions & 2 deletions include/nil/actor/zk/snark/systems/plonk/placeholder/prover.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ namespace nil {
transcript(preprocessed_public_data.common_data.vk.constraint_system_hash);
transcript(preprocessed_public_data.common_data.vk.fixed_values_commitment);

// setup commitment scheme
nil::actor::zk::snark::detail::init_transcript<ParamsType, transcript_hash_type>(
transcript,
preprocessed_public_data.common_data.rows_amount,
Expand Down Expand Up @@ -237,7 +236,28 @@ 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);

// We need split_polynomial_size computation because proof size shouldn't depend on public input size.
// we set this size as maximum of
// F[2] (from permutation argument)
// F[5] (from lookup argument)
// F[7] (from gates argument)
// If some columns used in permutation or lookup argument are zero, real quotient polynomial degree
// may be less than split_polynomial_size.
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
Loading

0 comments on commit 5282505

Please sign in to comment.