Skip to content

Commit

Permalink
Merge marks removed #65
Browse files Browse the repository at this point in the history
  • Loading branch information
ETatuzova committed Feb 5, 2024
1 parent 69eea67 commit 7793afc
Showing 1 changed file with 0 additions and 293 deletions.
293 changes: 0 additions & 293 deletions include/nil/blueprint/transpiler/recursive_verifier_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,8 @@
#include <nil/crypto3/zk/math/expression_evaluator.hpp>

#include<nil/blueprint/transpiler/templates/recursive_verifier.hpp>
<<<<<<< HEAD
#include<nil/blueprint/transpiler/util.hpp>
=======
<<<<<<< HEAD
=======
>>>>>>> 236a5cb579a4f58209be97a2794836b525d10198

>>>>>>> f206e94a0635f5ba293f7decb9e08ffe08503bc1
namespace nil {
namespace blueprint {
template<typename PlaceholderParams, typename ProofType, typename CommonDataType>
Expand Down Expand Up @@ -909,296 +903,9 @@ namespace nil {

result = replace_all(result, reps);
return result;
=======
=======
>>>>>>> f206e94a0635f5ba293f7decb9e08ffe08503bc1
std::size_t permutation_size
>>>>>>> 236a5cb579a4f58209be97a2794836b525d10198
){
std::string result = nil::blueprint::recursive_verifier_template;
bool use_lookups = constraint_system.lookup_gates().size() > 0;
transpiler_replacements lookup_reps;
transpiler_replacements reps;

auto fri_params = commitment_scheme.get_commitment_params();
std::size_t batches_num = use_lookups?5:4;
auto lambda = PlaceholderParams::commitment_scheme_type::fri_type::lambda;

std::size_t round_proof_layers_num = 0;
for(std::size_t i = 0; i < fri_params.r; i++ ){
round_proof_layers_num += log2(fri_params.D[i]->m) -1;
}

std::size_t lookup_degree = constraint_system.lookup_poly_degree_bound();

std::size_t rows_amount = common_data.rows_amount;
std::size_t quotient_degree = std::max(
(permutation_size + 2) * (common_data.rows_amount -1 ),
(lookup_degree + 1) * (common_data.rows_amount -1 )
);

std::size_t quotient_polys = (quotient_degree % rows_amount != 0)? (quotient_degree / rows_amount + 1): (quotient_degree / rows_amount);

std::size_t poly_num = 2 * permutation_size + 2 + (use_lookups?2:1)
+ arithmetization_params::total_columns
+ constraint_system.sorted_lookup_columns_number() + quotient_polys;

std::size_t points_num = 4 * permutation_size + 6;
std::size_t table_values_num = 0;
for(std::size_t i = 0; i < arithmetization_params::constant_columns + arithmetization_params::selector_columns; i++){
points_num += common_data.columns_rotations[i + arithmetization_params::witness_columns + arithmetization_params::public_input_columns].size() + 1;
table_values_num += common_data.columns_rotations[i + arithmetization_params::witness_columns + arithmetization_params::public_input_columns].size() + 1;
}
for(std::size_t i = 0; i < arithmetization_params::witness_columns + arithmetization_params::public_input_columns; i++){
points_num += common_data.columns_rotations[i].size();
table_values_num += common_data.columns_rotations[i].size();
}
points_num += use_lookups? 4 : 2;
points_num += quotient_polys;

if( use_lookups ) {
points_num += constraint_system.sorted_lookup_columns_number() * 3;
}


std::size_t constraints_amount = 0;
std::string gates_sizes = "";
std::stringstream constraints_body;
std::size_t cur = 0;
auto verifier_indices = get_plonk_variable_indices(common_data.columns_rotations, 4*permutation_size + 6);

expression_gen_code_visitor<variable_type> visitor(verifier_indices);
for(std::size_t i = 0; i < constraint_system.gates().size(); i++){
constraints_amount += constraint_system.gates()[i].constraints.size();
if( i != 0) gates_sizes += ", ";
gates_sizes += to_string(constraint_system.gates()[i].constraints.size());
for(std::size_t j = 0; j < constraint_system.gates()[i].constraints.size(); j++, cur++){
constraints_body << "\tconstraints[" << cur << "] = " << visitor.generate_expression(constraint_system.gates()[i].constraints[j]) << ";" << std::endl;
}
}

std::stringstream lookup_expressions_body;
cur = 0;
for(const auto &lookup_gate: constraint_system.lookup_gates()){
for(const auto &lookup_constraint: lookup_gate.constraints){
for( const auto &expr: lookup_constraint.lookup_input){
lookup_expressions_body << "\texpressions[" << cur << "] = " << visitor.generate_expression(expr) << ";" << std::endl;
cur++;
}
}
}
<<<<<<< HEAD

std::stringstream lookup_gate_selectors_list;
cur = 0;
for(const auto &lookup_gate: constraint_system.lookup_gates()){
variable_type var(lookup_gate.tag_index, 0, true, variable_type::column_type::selector);
lookup_gate_selectors_list << "\t\tlookup_gate_selectors[" << cur << "] = proof.z[" << verifier_indices[var] <<"];" << std::endl;
cur++;
}

std::stringstream lookup_table_selectors_list;
cur = 0;
for(const auto &lookup_table: constraint_system.lookup_tables()){
variable_type var(lookup_table.tag_index, 0, true, variable_type::column_type::selector);
lookup_table_selectors_list << "\t\tlookup_table_selectors[" << cur << "] = proof.z[" << verifier_indices[var] <<"];" << std::endl;
cur++;
}

std::stringstream lookup_shifted_table_selectors_list;
cur = 0;
for(const auto &lookup_table: constraint_system.lookup_tables()){
variable_type var(lookup_table.tag_index, 1, true, variable_type::column_type::selector);
lookup_shifted_table_selectors_list << "\t\tshifted_lookup_table_selectors[" << cur << "] = proof.z[" << verifier_indices[var] <<"];" << std::endl;
cur++;
}

std::stringstream lookup_options_list;
cur = 0;
for(const auto &lookup_table: constraint_system.lookup_tables()){
for(const auto &lookup_option: lookup_table.lookup_options){
for( const auto &column: lookup_option){
variable_type var(column.index, 0, true, variable_type::column_type::constant);
lookup_options_list << "\t\tlookup_table_lookup_options[" << cur << "] = proof.z[" << verifier_indices[var] <<"];" << std::endl;
cur++;
}
}
}

std::stringstream lookup_shifted_options_list;
cur = 0;
for(const auto &lookup_table: constraint_system.lookup_tables()){
for(const auto &lookup_option: lookup_table.lookup_options){
for( const auto &column: lookup_option){
variable_type var(column.index, 1, true, variable_type::column_type::constant);
lookup_shifted_options_list << "\t\tshifted_lookup_table_lookup_options[" << cur << "] = proof.z[" << verifier_indices[var] <<"];" << std::endl;
cur++;
}
}
}

std::stringstream gates_selectors_indices;
cur = 0;
for(const auto &gate: constraint_system.gates()){
if(cur != 0) gates_selectors_indices << ", ";
gates_selectors_indices << gate.selector_index;
cur++;
}

auto [z_points_indices, singles_strs, singles_map, poly_ids] = calculate_unique_points<PlaceholderParams, common_data_type>(
common_data, permutation_size, use_lookups, quotient_polys,
use_lookups?constraint_system.sorted_lookup_columns_number():0,
"recursive" // Generator mode
);

std::string singles_str = "";
for(const auto &[k, v]: singles_map){
singles_str+= "\tsingles[" + to_string(v) + "] = " + k + ";\n";
}

std::string lpc_poly_ids_const_arrays = "";
for(std::size_t i = 0; i < poly_ids.size(); i++){
lpc_poly_ids_const_arrays += "\tconstexpr std::array<std::size_t, " + to_string(poly_ids[i].size()) + "> lpc_poly_ids" + to_string(i) + " = {";
for(std::size_t j = 0; j < poly_ids[i].size(); j++){
if(j != 0) lpc_poly_ids_const_arrays += ", ";
lpc_poly_ids_const_arrays += to_string(poly_ids[i][j]);
}
lpc_poly_ids_const_arrays += "};\n";
}

std::stringstream prepare_U_V_str;
prepare_U_V_str << "\tpallas::base_field_type::value_type theta_acc = pallas::base_field_type::value_type(1);\n\n";
for(std::size_t i = 0; i < singles_strs.size();i++){
for(std::size_t j = 0; j <z_points_indices.size(); j++){
if( z_points_indices[j] == i)
prepare_U_V_str << "\tU[" + to_string(i) << "] += theta_acc * proof.z[" << j << "]; theta_acc *= challenges.lpc_theta;\n";
}
prepare_U_V_str << "\n";
}

std::string public_input_sizes_str = "";
std::size_t full_public_input_size = 0;
for(std::size_t i = 0; i < public_input_sizes.size(); i++){
if(i != 0) public_input_sizes_str += ", ";
public_input_sizes_str += to_string(public_input_sizes[i]);
full_public_input_size += public_input_sizes[i];
}

std::stringstream lpc_y_computation;
for( std::size_t i = 0; i < singles_strs.size(); i++){
lpc_y_computation << "\t\tQ0 = pallas::base_field_type::value_type(0);" << std::endl;
lpc_y_computation << "\t\tQ1 = pallas::base_field_type::value_type(0);" << std::endl;
for( std::size_t j = 0; j < poly_ids[i].size(); j++){
lpc_y_computation << "\t\tQ0 += proof.initial_proof_values[i]["<< poly_ids[i][j]*2 <<"] * theta_acc;" << std::endl;
lpc_y_computation << "\t\tQ1 += proof.initial_proof_values[i]["<< poly_ids[i][j]*2 + 1 <<"] * theta_acc;" << std::endl;
lpc_y_computation << "\t\ttheta_acc *= challenges.lpc_theta;\n";
}
lpc_y_computation << "\t\tQ0 -= U["<< i << "];" << std::endl;
lpc_y_computation << "\t\tQ1 -= U["<< i << "];" << std::endl;
lpc_y_computation << "\t\tQ0 /= (res[0][0] - singles[" << i << "]);" << std::endl;
lpc_y_computation << "\t\tQ1 /= (res[0][1] - singles[" << i << "]);" << std::endl;
lpc_y_computation << "\t\ty[0] += Q0;" << std::endl;
lpc_y_computation << "\t\ty[1] += Q1;" << std::endl;
}

std::size_t fixed_values_size = permutation_size * 2 + 2 + arithmetization_params::constant_columns + arithmetization_params::selector_columns;
std::size_t variable_values_size = arithmetization_params::witness_columns + arithmetization_params::public_input_columns;
std::string batches_size_list = to_string(fixed_values_size) + ", " + to_string(variable_values_size) + ", " +
to_string(use_lookups?2:1) + ", " + to_string(quotient_polys);
if(use_lookups) batches_size_list += ", " + to_string(constraint_system.sorted_lookup_columns_number());

lookup_reps["$LOOKUP_VARS$"] = use_lookups?lookup_vars:"";
lookup_reps["$LOOKUP_EXPRESSIONS$"] = use_lookups?lookup_expressions:"";
lookup_reps["$LOOKUP_CODE$"] = use_lookups?lookup_code:"";
result = replace_all(result, lookup_reps);

reps["$USE_LOOKUPS_DEFINE$"] = use_lookups?"#define __USE_LOOKUPS__ 1\n":"";
reps["$USE_LOOKUPS$"] = use_lookups? "true" : "false";
reps["$BATCHES_NUM$"] = to_string(batches_num);
reps["$COMMITMENTS_NUM$"] = to_string(batches_num - 1);
reps["$POINTS_NUM$"] = to_string(points_num);
reps["$POLY_NUM$"] = to_string(poly_num);
reps["$INITIAL_PROOF_POINTS_NUM$"] = to_string(poly_num * 2);
reps["$ROUND_PROOF_POINTS_NUM$"] = to_string(fri_params.r * 2 * lambda);
reps["$FRI_ROOTS_NUM$"] = to_string(fri_params.r);
reps["$INITIAL_MERKLE_PROOFS_NUM$"] = to_string(batches_num * lambda);
reps["$INITIAL_MERKLE_PROOFS_POSITION_NUM$"] = to_string(lambda * (log2(fri_params.D[0]->m) - 1));
reps["$INITIAL_MERKLE_PROOFS_HASH_NUM$"] = to_string(lambda * (log2(fri_params.D[0]->m) - 1) * batches_num);
reps["$ROUND_MERKLE_PROOFS_POSITION_NUM$"] = to_string(lambda * round_proof_layers_num);
reps["$ROUND_MERKLE_PROOFS_HASH_NUM$"] = to_string(lambda * round_proof_layers_num);
reps["$FINAL_POLYNOMIAL_SIZE$"] = to_string(std::pow(2, std::log2(fri_params.max_degree + 1) - fri_params.r + 1) - 2);
reps["$LAMBDA$"] = to_string(lambda);
reps["$PERMUTATION_SIZE$"] = to_string(permutation_size);
reps["$ZERO_INDICES$"] = zero_indices(common_data.columns_rotations, permutation_size);
reps["$TOTAL_COLUMNS$"] = to_string(arithmetization_params::total_columns);
reps["$ROWS_LOG$"] = to_string(log2(rows_amount));
reps["$ROWS_AMOUNT$"] = to_string(rows_amount);
reps["$TABLE_VALUES_NUM$"] = to_string(table_values_num);
reps["$GATES_AMOUNT$"] = to_string(constraint_system.gates().size());
reps["$CONSTRAINTS_AMOUNT$"] = to_string(constraints_amount);
reps["$GATES_SIZES$"] = gates_sizes;
reps["$GATES_SELECTOR_INDICES$"] = gates_selectors_indices.str();
reps["$CONSTRAINTS_BODY$"] = constraints_body.str();
reps["$WITNESS_COLUMNS_AMOUNT$"] = to_string(arithmetization_params::witness_columns);
reps["$PUBLIC_INPUT_COLUMNS_AMOUNT$"] = to_string(arithmetization_params::public_input_columns);
reps["$CONSTANT_COLUMNS_AMOUNT$"] = to_string(arithmetization_params::constant_columns);
reps["$SELECTOR_COLUMNS_AMOUNT$"] = to_string(arithmetization_params::selector_columns);
reps["$QUOTIENT_POLYS_START$"] = to_string(4*permutation_size + 6 + table_values_num + (use_lookups?4:2));
reps["$QUOTIENT_POLYS_AMOUNT$"] = to_string(quotient_polys);
reps["$D0_SIZE$"] = to_string(fri_params.D[0]->m);
reps["$D0_LOG$"] = to_string(log2(fri_params.D[0]->m));
reps["$D0_OMEGA$"] = "pallas::base_field_type::value_type(0x" + to_hex_string(fri_params.D[0]->get_domain_element(1)) + "_cppui255)";
reps["$OMEGA$"] = "pallas::base_field_type::value_type(0x" + to_hex_string(common_data.basic_domain->get_domain_element(1)) + "_cppui255)";
reps["$FRI_ROUNDS$"] = to_string(fri_params.r);
reps["$UNIQUE_POINTS$"] = to_string(singles_strs.size());
reps["$SINGLES_AMOUNT$"] = to_string(singles_strs.size());
reps["$SINGLES_COMPUTATION$"] = singles_str;
reps["$PREPARE_U_AND_V$"] = prepare_U_V_str.str();
reps["$SORTED_COLUMNS$"] = to_string(constraint_system.sorted_lookup_columns_number());
reps["$SORTED_ALPHAS$"] = to_string(use_lookups? constraint_system.sorted_lookup_columns_number() - 1: 1);
reps["$LOOKUP_TABLE_AMOUNT$"] = to_string(constraint_system.lookup_tables().size());
reps["$LOOKUP_GATE_AMOUNT$"] = to_string(constraint_system.lookup_gates().size());
reps["$LOOKUP_OPTIONS_AMOUNT$"] = to_string(constraint_system.lookup_options_num());
reps["$LOOKUP_OPTIONS_AMOUNT_LIST$"] = generate_lookup_options_amount_list(constraint_system);
reps["$LOOKUP_CONSTRAINTS_AMOUNT$"] = to_string(constraint_system.lookup_constraints_num());
reps["$LOOKUP_CONSTRAINTS_AMOUNT_LIST$"] = generate_lookup_constraints_amount_list(constraint_system);
reps["$LOOKUP_EXPRESSIONS_AMOUNT$"] = to_string(constraint_system.lookup_expressions_num());
reps["$LOOKUP_EXPRESSIONS_AMOUNT_LIST$"] = generate_lookup_expressions_amount_list(constraint_system);
reps["$LOOKUP_TABLES_COLUMNS_AMOUNT$"] = to_string(constraint_system.lookup_tables_columns_num());
reps["$LOOKUP_TABLES_COLUMNS_AMOUNT_LIST$"] = generate_lookup_columns_amount_list(constraint_system);
reps["$LOOKUP_EXPRESSIONS_BODY$"] = lookup_expressions_body.str();
reps["$LOOKUP_CONSTRAINT_TABLE_IDS_LIST$"] = generate_lookup_constraint_table_ids_list(constraint_system);
reps["$LOOKUP_GATE_SELECTORS_LIST$"] = lookup_gate_selectors_list.str();
reps["$LOOKUP_TABLE_SELECTORS_LIST$"] = lookup_table_selectors_list.str();
reps["$LOOKUP_SHIFTED_TABLE_SELECTORS_LIST$"] = lookup_shifted_table_selectors_list.str();
reps["$LOOKUP_OPTIONS_LIST$"] = lookup_options_list.str();
reps["$LOOKUP_SHIFTED_OPTIONS_LIST$"] = lookup_shifted_options_list.str();
reps["$LOOKUP_SORTED_START$"] = to_string(4*permutation_size + 6 + table_values_num + (use_lookups?4:2) + quotient_polys);
reps["$BATCHES_AMOUNT_LIST$"] = batches_size_list;
reps["$PUBLIC_INPUT_SIZES$"] = public_input_sizes_str;
reps["$FULL_PUBLIC_INPUT_SIZE$"] = to_string(full_public_input_size);
reps["$LPC_POLY_IDS_CONSTANT_ARRAYS$"] = lpc_poly_ids_const_arrays;
reps["$LPC_Y_COMPUTATION$"] = lpc_y_computation.str();
reps["$PUBLIC_INPUT_CHECK$"] = arithmetization_params::public_input_columns == 0 ? "" :public_input_check_str;
reps["$PUBLIC_INPUT_INPUT$"] = arithmetization_params::public_input_columns == 0 ? "" : public_input_input_str;

result = replace_all(result, reps);
return result;
=======
BOOST_ASSERT_MSG(false, "unsupported commitment scheme type");
return "unsupported commitment scheme type";
<<<<<<< HEAD
>>>>>>> f302960... Add recursive generator, update EVM verifier #39
=======
>>>>>>> f206e94a0635f5ba293f7decb9e08ffe08503bc1
>>>>>>> 236a5cb579a4f58209be97a2794836b525d10198
}
};
}
}

<<<<<<< HEAD
#endif // CRYPTO3_RECURSIVE_VERIFIER_GENERATOR_HPP
=======
#endif // CRYPTO3_RECURSIVE_VERIFIER_GENERATOR_HPP
>>>>>>> f206e94a0635f5ba293f7decb9e08ffe08503bc1

0 comments on commit 7793afc

Please sign in to comment.