Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 03a25b1

Browse files
committed
Recursive tests updated #65
1 parent 7ffffb1 commit 03a25b1

File tree

6 files changed

+73
-156
lines changed

6 files changed

+73
-156
lines changed

include/nil/blueprint/transpiler/evm_verifier_gen.hpp

-4
Original file line numberDiff line numberDiff line change
@@ -596,10 +596,8 @@ namespace nil {
596596
gate_argument_str << "\t\tuint256 gate;" << std::endl;
597597
gate_argument_str << print_constraint_series(it, constraints.end());
598598
} else {
599-
std::cout << "I am here!" << std::endl;
600599
auto it = constraints.begin();
601600
while (it != constraints.end()) {
602-
std::cout << "Gates modules count" << gate_modules_count << std::endl;
603601
std::string code = print_constraint_series(it, constraints.end());
604602

605603
std::string result = modular_external_gate_library_template;
@@ -619,7 +617,6 @@ namespace nil {
619617
++gate_modules_count;
620618
}
621619
}
622-
std::cout << "Finished" << std::endl;
623620

624621
if (_term_powers.size() > 0) {
625622
std::stringstream power_functions;
@@ -881,7 +878,6 @@ namespace nil {
881878

882879
void print(){
883880
std::filesystem::create_directory(_folder_name);
884-
std::cout << "Generating verifier " << _test_name << std::endl;
885881

886882
std::string gate_argument = print_gate_argument();
887883
std::string lookup_argument = print_lookup_argument();

include/nil/blueprint/transpiler/lpc_scheme_gen.hpp

-9
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,6 @@ namespace nil {
6262
"evm" // Generator mode
6363
);
6464

65-
for( std::size_t i = 0; i < z_points_indices.size(); i ++){
66-
std::cout << "[" << i <<"]" << "=>" << z_points_indices[i] << " ";
67-
}
68-
std::cout << std::endl;
69-
70-
for( std::size_t i = 0; i < poly_ids.size(); i++ ){
71-
std::cout << "point " << i << " has " << poly_ids[i].size() <<" polys." << std::endl;
72-
}
73-
7465
std::stringstream points_initializer;
7566
std::size_t i = 0;
7667

include/nil/blueprint/transpiler/recursive_verifier_generator.hpp

+29-80
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ namespace nil {
220220
for(std::size_t j = 0; j < eval_proof.z.get_poly_points_number(k, i); j++){
221221
if( sum != 0 ) out << "," << std::endl;
222222
out << "\t\t\t{\"field\":\"" << eval_proof.z.get(k, i, j) << "\"}";
223-
//std::cout << "batch " << k << " poly " << i << " value " << eval_proof.z.get(k, i, j) << std::endl;
224223
sum++;
225224
}
226225
}
@@ -349,29 +348,30 @@ namespace nil {
349348
std::stringstream out;
350349
out << "[" << std::endl;
351350

352-
out << "\t{\"array\":[" << std::endl;
353-
std::size_t cur = 0;
354-
for(std::size_t i = 0; i < arithmetization_params::public_input_columns; i++){
355-
std::size_t max_non_zero = 0;
356-
for(std::size_t j = 0; j < public_inputs[i].size(); j++){
357-
if( public_inputs[i][j] != 0 ) max_non_zero = j;
358-
}
359-
if( max_non_zero + 1 > public_input_sizes[i] ) {
360-
std::cout << "Public input size is larger than reserved. Real size = " << max_non_zero + 1 << " reserved = " << public_input_sizes[i] << std::endl;
361-
exit(1);
362-
}
363-
BOOST_ASSERT(max_non_zero <= public_input_sizes[i]);
364-
for(std::size_t j = 0; j < public_input_sizes[i]; j++){
365-
if(cur != 0) out << "," << std::endl;
366-
if( j >= public_inputs[i].size() )
367-
out << "\t\t{\"field\": \"" << typename field_type::value_type(0) << "\"}";
368-
else
369-
out << "\t\t{\"field\": \"" << public_inputs[i][j] << "\"}";
370-
cur++;
351+
if(arithmetization_params::public_input_columns != 0){
352+
out << "\t{\"array\":[" << std::endl;
353+
std::size_t cur = 0;
354+
for(std::size_t i = 0; i < arithmetization_params::public_input_columns; i++){
355+
std::size_t max_non_zero = 0;
356+
for(std::size_t j = 0; j < public_inputs[i].size(); j++){
357+
if( public_inputs[i][j] != 0 ) max_non_zero = j;
358+
}
359+
if( max_non_zero + 1 > public_input_sizes[i] ) {
360+
std::cout << "Public input size is larger than reserved. Real size = " << max_non_zero + 1 << " reserved = " << public_input_sizes[i] << std::endl;
361+
exit(1);
362+
}
363+
BOOST_ASSERT(max_non_zero <= public_input_sizes[i]);
364+
for(std::size_t j = 0; j < public_input_sizes[i]; j++){
365+
if(cur != 0) out << "," << std::endl;
366+
if( j >= public_inputs[i].size() )
367+
out << "\t\t{\"field\": \"" << typename field_type::value_type(0) << "\"}";
368+
else
369+
out << "\t\t{\"field\": \"" << public_inputs[i][j] << "\"}";
370+
cur++;
371+
}
371372
}
373+
out << std::endl << "\t]}," << std::endl;
372374
}
373-
out << std::endl << "\t]}," << std::endl;
374-
std::cout << "Public input: " << out.str() << std::endl;
375375

376376
out << "\t{\"array\":[" << std::endl;
377377
out << "\t\t" << generate_hash<typename PlaceholderParams::transcript_hash_type>(
@@ -743,7 +743,6 @@ namespace nil {
743743
}
744744
}
745745
}
746-
std::cout << "Printing" << std::endl;
747746

748747
std::stringstream lookup_shifted_options_list;
749748
cur = 0;
@@ -770,40 +769,6 @@ namespace nil {
770769
use_lookups?constraint_system.sorted_lookup_columns_number():0,
771770
"recursive" // Generator mode
772771
);
773-
std::cout << "Singles" << std::endl;
774-
for( const auto &single: singles_strs){
775-
std::cout << single << std::endl;
776-
}
777-
std::cout << "Singles_map" << std::endl;
778-
for( const auto &[single, ind]: singles_map){
779-
std::cout << single << " => " << ind << std::endl;
780-
}
781-
std::cout << "Poly ids" << std::endl;
782-
for( std::size_t i = 0; i < poly_ids.size(); i++){
783-
std::cout << "Poly " << i << std::endl;
784-
for( std::size_t j = 0; j < poly_ids[i].size(); j++){
785-
std::cout << poly_ids[i][j] << " ";
786-
}
787-
std::cout << std::endl;
788-
}
789-
std::cout << "Z points indices" << std::endl;
790-
for( std::size_t i = 0; i < z_points_indices.size(); i++){
791-
std::cout << "[" << i << "]=>" << z_points_indices[i] << " ";
792-
}
793-
std::cout << std::endl;
794-
795-
std::vector<std::vector<std::string>> unique_points;
796-
std::vector<std::size_t> point_ids;
797-
std::map<std::string, std::size_t> singles;
798-
std::tie(unique_points, point_ids, singles) = calculate_unique_point_sets(
799-
common_data, permutation_size, use_lookups, quotient_polys, use_lookups?constraint_system.sorted_lookup_columns_number():0
800-
);
801-
802-
std::string point_inds_str = "";
803-
for(std::size_t i = 0; i < point_ids.size(); i++){
804-
if( i != 0) point_inds_str += ", ";
805-
point_inds_str += to_string(point_ids[i]);
806-
}
807772

808773
std::string singles_str = "";
809774
for(const auto &[k, v]: singles_map){
@@ -822,29 +787,14 @@ namespace nil {
822787

823788
std::stringstream prepare_U_V_str;
824789
prepare_U_V_str << "\tpallas::base_field_type::value_type theta_acc = pallas::base_field_type::value_type(1);\n\n";
825-
for(std::size_t i = 0; i < unique_points.size();i++){
790+
for(std::size_t i = 0; i < singles_strs.size();i++){
826791
for(std::size_t j = 0; j <z_points_indices.size(); j++){
827792
if( z_points_indices[j] == i)
828793
prepare_U_V_str << "\tU[" + to_string(i) << "] += theta_acc * proof.z[" << j << "]; theta_acc *= challenges.lpc_theta;\n";
829794
}
830795
prepare_U_V_str << "\n";
831796
}
832797

833-
std::stringstream compute_combined_y;
834-
for(std::size_t i = 0; i < point_ids.size(); i++){
835-
/*y[0] = y[0] * challenges.lpc_theta;
836-
y[0] = y[0] + proof.initial_proof_values[initial_proof_ind] * V_evals[point_ids[k]][0];
837-
y[1] = y[1] * challenges.lpc_theta;
838-
y[1] = y[1] + proof.initial_proof_values[initial_proof_ind+1] * V_evals[point_ids[k]][1];*/
839-
840-
// compute_combined_y << "\t\ty[0] = y[0]*challenges.lpc_theta;" << std::endl;
841-
// compute_combined_y << "\t\ty[0] = y[0] + proof.initial_proof_values[initial_proof_ind] * V_evals[" << point_ids[i]<< "][0];" << std::endl;
842-
// compute_combined_y << "\t\tinitial_proof_ind++;" << std::endl;
843-
// compute_combined_y << "\t\ty[1] = y[1]*challenges.lpc_theta;" << std::endl;
844-
// compute_combined_y << "\t\ty[1] = y[1] + proof.initial_proof_values[initial_proof_ind] * V_evals[" << point_ids[i]<< "][1];" << std::endl;
845-
// compute_combined_y << "\t\tinitial_proof_ind++;" << std::endl;
846-
}
847-
848798
std::string public_input_sizes_str = "";
849799
std::size_t full_public_input_size = 0;
850800
for(std::size_t i = 0; i < public_input_sizes.size(); i++){
@@ -864,9 +814,8 @@ namespace nil {
864814
}
865815
lpc_y_computation << "\t\tQ0 -= U["<< i << "];" << std::endl;
866816
lpc_y_computation << "\t\tQ1 -= U["<< i << "];" << std::endl;
867-
lpc_y_computation << "\t\tQ0 /= (res[0][0] - challenges." << singles_strs[i] <<");" << std::endl;
868-
lpc_y_computation << "\t\tQ1 /= (res[0][1] - challenges." << singles_strs[i] <<");" << std::endl;
869-
std::cout << "single " << singles_strs[i] << std::endl;
817+
lpc_y_computation << "\t\tQ0 /= (res[0][0] - singles[" << i << "]);" << std::endl;
818+
lpc_y_computation << "\t\tQ1 /= (res[0][1] - singles[" << i << "]);" << std::endl;
870819
lpc_y_computation << "\t\ty[0] += Q0;" << std::endl;
871820
lpc_y_computation << "\t\ty[1] += Q1;" << std::endl;
872821
}
@@ -920,12 +869,10 @@ namespace nil {
920869
reps["$D0_OMEGA$"] = "pallas::base_field_type::value_type(0x" + to_hex_string(fri_params.D[0]->get_domain_element(1)) + "_cppui255)";
921870
reps["$OMEGA$"] = "pallas::base_field_type::value_type(0x" + to_hex_string(common_data.basic_domain->get_domain_element(1)) + "_cppui255)";
922871
reps["$FRI_ROUNDS$"] = to_string(fri_params.r);
923-
reps["$UNIQUE_POINTS$"] = to_string(unique_points.size());
924-
reps["$POINTS_IDS$"] = point_inds_str;
925-
reps["$SINGLES_AMOUNT$"] = to_string(singles.size());
872+
reps["$UNIQUE_POINTS$"] = to_string(singles_strs.size());
873+
reps["$SINGLES_AMOUNT$"] = to_string(singles_strs.size());
926874
reps["$SINGLES_COMPUTATION$"] = singles_str;
927875
reps["$PREPARE_U_AND_V$"] = prepare_U_V_str.str();
928-
reps["$COMPUTE_COMBINED_Y$"] = compute_combined_y.str();
929876
reps["$SORTED_COLUMNS$"] = to_string(constraint_system.sorted_lookup_columns_number());
930877
reps["$SORTED_ALPHAS$"] = to_string(use_lookups? constraint_system.sorted_lookup_columns_number() - 1: 1);
931878
reps["$LOOKUP_TABLE_AMOUNT$"] = to_string(constraint_system.lookup_tables().size());
@@ -951,6 +898,8 @@ namespace nil {
951898
reps["$FULL_PUBLIC_INPUT_SIZE$"] = to_string(full_public_input_size);
952899
reps["$LPC_POLY_IDS_CONSTANT_ARRAYS$"] = lpc_poly_ids_const_arrays;
953900
reps["$LPC_Y_COMPUTATION$"] = lpc_y_computation.str();
901+
reps["$PUBLIC_INPUT_CHECK$"] = arithmetization_params::public_input_columns == 0 ? "" :public_input_check_str;
902+
reps["$PUBLIC_INPUT_INPUT$"] = arithmetization_params::public_input_columns == 0 ? "" : public_input_input_str;
954903

955904
result = replace_all(result, reps);
956905
return result;

include/nil/blueprint/transpiler/templates/recursive_verifier.hpp

+23-31
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace nil {
77
namespace blueprint {
88
std::string lookup_vars = R"(
9-
#ifdef __USE_LOOKUPS__
109
const size_t lookup_table_amount = $LOOKUP_TABLE_AMOUNT$;
1110
const size_t lookup_gate_amount = $LOOKUP_GATE_AMOUNT$;
1211
constexpr std::array<std::size_t, lookup_table_amount> lookup_options_amount_list = {$LOOKUP_OPTIONS_AMOUNT_LIST$};
@@ -35,22 +34,18 @@ constexpr std::size_t input_size_shifted_lookup_table_lookup_options = lookup_ta
3534
3635
constexpr std::size_t input_size_sorted = m_parameter * 3 - 1;
3736
$LPC_POLY_IDS_CONSTANT_ARRAYS$
38-
#endif
3937
)";
4038

4139
std::string lookup_expressions = R"(
42-
#ifdef __USE_LOOKUPS__
4340
std::array<pallas::base_field_type::value_type, lookup_expressions_amount> calculate_lookup_expressions(std::array<pallas::base_field_type::value_type, points_num> z){
4441
std::array<pallas::base_field_type::value_type, lookup_expressions_amount> expressions;
4542
$LOOKUP_EXPRESSIONS_BODY$
4643
4744
return expressions;
4845
}
49-
#endif
5046
)";
5147

5248
std::string lookup_code = R"(
53-
#ifdef __USE_LOOKUPS__
5449
{
5550
std::array<typename pallas::base_field_type::value_type, input_size_alphas> alphas = challenges.lookup_alphas;
5651
std::array<typename pallas::base_field_type::value_type, input_size_lookup_gate_selectors> lookup_gate_selectors;
@@ -149,9 +144,24 @@ std::array<pallas::base_field_type::value_type, lookup_expressions_amount> calcu
149144
F[5] = lookup_argument[2];
150145
F[6] = lookup_argument[3];
151146
}
152-
#endif
153147
)";
154148

149+
std::string public_input_check_str = R"(
150+
//Check public input
151+
std::size_t cur = 0;
152+
for( std::size_t i = 0; i < public_input_amount; i++){
153+
pallas::base_field_type::value_type Omega(1);
154+
pallas::base_field_type::value_type result(0);
155+
for( std::size_t j = 0; j < public_input_sizes[i]; j++){
156+
result += public_input[cur] * Omega / (challenges.xi - Omega);
157+
Omega *= omega;
158+
cur++;
159+
}
160+
__builtin_assigner_exit_check(rows_amount * proof.z[zero_indices[witness_amount + i]] == precomputed_values.Z_at_xi * result);
161+
}
162+
)";
163+
std::string public_input_input_str = "\tstd::array<pallas::base_field_type::value_type, full_public_input_size> public_input,\n";
164+
155165
std::string recursive_verifier_template = R"(
156166
#include <nil/crypto3/hash/algorithm/hash.hpp>
157167
#include <nil/crypto3/hash/poseidon.hpp>
@@ -204,7 +214,6 @@ const pallas::base_field_type::value_type omega = $OMEGA$;
204214
const size_t fri_rounds = $FRI_ROUNDS$;
205215
const std::array<int, gates_amount> gates_sizes = {$GATES_SIZES$};
206216
const size_t unique_points = $UNIQUE_POINTS$;
207-
const std::array<int, poly_num> point_ids = {$POINTS_IDS$};
208217
const size_t singles_amount = $SINGLES_AMOUNT$;
209218
const std::array<std::size_t, batches_num> batches_amount_list = {$BATCHES_AMOUNT_LIST$};
210219
@@ -331,17 +340,11 @@ pallas::base_field_type::value_type pow9(pallas::base_field_type::value_type x){
331340
}
332341
333342
pallas::base_field_type::value_type pow(pallas::base_field_type::value_type x, size_t p){
334-
pallas::base_field_type::value_type result = 1;
335-
std::size_t mask = 1;
336-
while(mask < p){mask = mask * 2;} // 8
337-
while(mask > 1){
338-
result = result * result;
339-
mask = mask / 2;
340-
if( p >= mask ){
341-
result = result * x;
342-
p = p - mask;
343-
}
344-
}
343+
if( p == 0 ) return pallas::base_field_type::value_type(1);
344+
if( p == 1 ) return x;
345+
pallas::base_field_type::value_type result = pow(x, p/2);
346+
result = result * result;
347+
if( p%2 == 1 ) result = result * x;
345348
return result;
346349
}
347350
@@ -610,7 +613,7 @@ typedef __attribute__((ext_vector_type(2)))
610613
611614
612615
[[circuit]] bool placeholder_verifier(
613-
std::array<pallas::base_field_type::value_type, full_public_input_size> public_input,
616+
$PUBLIC_INPUT_INPUT$
614617
std::array<pallas::base_field_type::value_type, 2> vk,
615618
placeholder_proof_type proof
616619
) {
@@ -620,18 +623,7 @@ typedef __attribute__((ext_vector_type(2)))
620623
precomputed_values_type precomputed_values;
621624
std::tie(precomputed_values.l0, precomputed_values.Z_at_xi) = xi_polys(challenges.xi);
622625
623-
//Check public input
624-
std::size_t cur = 0;
625-
for( std::size_t i = 0; i < public_input_amount; i++){
626-
pallas::base_field_type::value_type Omega(1);
627-
pallas::base_field_type::value_type result(0);
628-
for( std::size_t j = 0; j < public_input_sizes[i]; j++){
629-
result += public_input[cur] * Omega / (challenges.xi - Omega);
630-
Omega *= omega;
631-
cur++;
632-
}
633-
__builtin_assigner_exit_check(rows_amount * proof.z[zero_indices[witness_amount + i]] == precomputed_values.Z_at_xi * result);
634-
}
626+
$PUBLIC_INPUT_CHECK$
635627
636628
std::array<pallas::base_field_type::value_type, 8> F;// = {0,0,0,0,0,0,0,0};
637629

0 commit comments

Comments
 (0)