Skip to content

Commit

Permalink
Public input processing enabled #65
Browse files Browse the repository at this point in the history
  • Loading branch information
ETatuzova committed Jan 24, 2024
1 parent 13531d8 commit 6b4a6f3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 46 deletions.
44 changes: 8 additions & 36 deletions include/nil/blueprint/transpiler/recursive_verifier_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace nil {
using assignment_table_type = typename PlaceholderParams::assignment_table_type;

// TODO: Move logic to utils.hpp. It's similar to EVM verifier generator
static std::string zero_indices(columns_rotations_type col_rotations){
static std::string zero_indices(columns_rotations_type col_rotations, std::size_t permutation_size){
std::vector<std::size_t> zero_indices;
std::uint16_t fixed_values_points = 0;
std::stringstream result;
Expand All @@ -90,16 +90,17 @@ namespace nil {
for(; i < PlaceholderParams::witness_columns + PlaceholderParams::public_input_columns; i++){
zero_indices[i] = sum + zero_indices[i];
sum += col_rotations[i].size();
if( i != 0) result << ", ";
result << zero_indices[i];
}

sum = 0;
for(; i < PlaceholderParams::total_columns; i++){
zero_indices[i] = sum + zero_indices[i];
sum += col_rotations[i].size() + 1;
if( i != 0) result << ", ";
result << zero_indices[i];
}

for( i = 0; i < PlaceholderParams::total_columns; i++){
if( i != 0 ) result << ", ";
result << zero_indices[i] + 4 * permutation_size + 6;
}
return result.str();
}
Expand Down Expand Up @@ -995,36 +996,7 @@ namespace nil {
}
prepare_U_V_str << "\n";
}
/* for(std::size_t i = 0; i < unique_points.size(); i++){
prepare_U_V_str << "\tV[" << i << "] = getV"<< unique_points[i].size() << "(";
for(std::size_t j = 0; j < unique_points[i].size(); j++ ){
if(j != 0) prepare_U_V_str << ", ";
prepare_U_V_str << "singles[" << singles[unique_points[i][j]] << "]";
}
prepare_U_V_str << ");" << std::endl << std::endl;
}
for(std::size_t ind = 0; ind < point_ids.size(); ind++){
std::size_t i = point_ids.size() - 1 - ind;
prepare_U_V_str << "\ttmp = getU"<< unique_points[point_ids[i]].size() << "(";
for(std::size_t j = 0; j < unique_points[point_ids[i]].size(); j++ ){
if(j != 0) prepare_U_V_str << ", ";
prepare_U_V_str << "singles[" << singles[unique_points[point_ids[i]][j]] << "]";
}
for(std::size_t j = 0; j < unique_points[point_ids[i]].size(); j++ ){
prepare_U_V_str << ", ";
if( j == unique_points[point_ids[i]].size() - 1 )
prepare_U_V_str << "proof.z[z_ind]";
else
prepare_U_V_str << "proof.z[z_ind - "<< unique_points[point_ids[i]].size() - j - 1 <<" ]";
}
prepare_U_V_str << ");" << std::endl;
prepare_U_V_str << "\tz_ind = z_ind - " << unique_points[point_ids[i]].size() << ";" << std::endl;
for(std::size_t j = 0; j < unique_points[point_ids[i]].size(); j++ ){
prepare_U_V_str << "\tcombined_U[" << point_ids[i] << "][" << j << "] = combined_U[" << point_ids[i] << "][" << j << "] + tmp[" << j << "] * theta_acc;" << std::endl;
}
prepare_U_V_str << "\ttheta_acc = theta_acc * challenges.lpc_theta;" << std::endl;
}
*/

std::stringstream compute_combined_y;
for(std::size_t i = 0; i < point_ids.size(); i++){
/*y[0] = y[0] * challenges.lpc_theta;
Expand Down Expand Up @@ -1094,7 +1066,7 @@ namespace nil {
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);
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);
Expand Down
25 changes: 15 additions & 10 deletions include/nil/blueprint/transpiler/templates/recursive_verifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,23 +620,28 @@ typedef __attribute__((ext_vector_type(2)))
precomputed_values_type precomputed_values;
std::tie(precomputed_values.l0, precomputed_values.Z_at_xi) = xi_polys(challenges.xi);
//Check public input
std::size_t cur = 0;
for( std::size_t i = 0; i < public_input_amount; i++){
pallas::base_field_type::value_type Omega(1);
pallas::base_field_type::value_type result(0);
for( std::size_t j = 0; j < public_input_sizes[i]; j++){
result += public_input[cur] * Omega / (challenges.xi - Omega);
Omega *= omega;
cur++;
}
__builtin_assigner_exit_check(rows_amount * proof.z[zero_indices[witness_amount + i]] == precomputed_values.Z_at_xi * result);
}
std::array<pallas::base_field_type::value_type, 8> F;// = {0,0,0,0,0,0,0,0};
F[0] = pallas::base_field_type::value_type(0);
F[1] = pallas::base_field_type::value_type(0);
F[2] = pallas::base_field_type::value_type(0);
F[3] = pallas::base_field_type::value_type(0);
F[4] = pallas::base_field_type::value_type(0);
F[5] = pallas::base_field_type::value_type(0);
F[6] = pallas::base_field_type::value_type(0);
F[7] = pallas::base_field_type::value_type(0);
// Call permutation argument
placeholder_permutation_argument_input_type perm_arg_input;
perm_arg_input.thetas[0] = challenges.perm_beta;
perm_arg_input.thetas[1] = challenges.perm_gamma;
for( std::size_t i = 0; i < permutation_size; i++ ){
perm_arg_input.xi_values[i] = proof.z[4*permutation_size + 6 + zero_indices[i]];
perm_arg_input.xi_values[i] = proof.z[zero_indices[i]];
perm_arg_input.id_perm[i] = proof.z[2*i];
perm_arg_input.sigma_perm[i] = proof.z[2*permutation_size + 2*i];
}
Expand Down Expand Up @@ -666,7 +671,7 @@ typedef __attribute__((ext_vector_type(2)))
constraints = calculate_constraints(proof.z);
for( std::size_t i = 0; i < gates_amount; i++ ){
selectors[i] = proof.z[4 * permutation_size + 6 + zero_indices[witness_amount + public_input_amount + constant_amount + gates_selector_indices[i]]];
selectors[i] = proof.z[zero_indices[witness_amount + public_input_amount + constant_amount + gates_selector_indices[i]]];
}
F[7] = gate_argument_verifier(
Expand Down

0 comments on commit 6b4a6f3

Please sign in to comment.