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

Commit c1f503c

Browse files
committed
LPC batching updated #65
1 parent 491e056 commit c1f503c

8 files changed

+519
-618
lines changed

include/nil/blueprint/transpiler/evm_verifier_gen.hpp

+13-8
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,6 @@ namespace nil {
618618
++gate_modules_count;
619619
}
620620
}
621-
std::cout << "Finished" << std::endl;
622621

623622
if (_term_powers.size() > 0) {
624623
std::stringstream power_functions;
@@ -818,9 +817,7 @@ namespace nil {
818817

819818
result << std::showbase << std::hex;
820819

821-
result << "\t\t\t// 1. 2*permutation_size" << std::endl;
822820
poly_points = 2;
823-
824821
while (j < 2*_permutation_size) {
825822
result << "\t\t\tpoints[" << i << "] = basic_marshalling.get_uint256_be(blob,";
826823
result << point_offset + (poly_points-1)*32 << ");" << std::endl;
@@ -831,7 +828,6 @@ namespace nil {
831828
++j;
832829
}
833830

834-
result << "\t\t\t// 2. special selectors " << std::endl;
835831
poly_points = 3;
836832

837833
j = 0;
@@ -845,7 +841,6 @@ namespace nil {
845841
++j;
846842
}
847843

848-
result << "\t\t\t// 3. constant columns " << std::endl;
849844
std::size_t column_rotation_offset = PlaceholderParams::witness_columns + PlaceholderParams::public_input_columns;
850845
j = 0;
851846
while (j < PlaceholderParams::arithmetization_params::constant_columns) {
@@ -859,7 +854,6 @@ namespace nil {
859854
++j;
860855
}
861856

862-
result << "\t\t\t// 4. selector columns " << std::endl;
863857
column_rotation_offset += PlaceholderParams::constant_columns;
864858
j = 0;
865859
while (j < PlaceholderParams::arithmetization_params::selector_columns) {
@@ -919,7 +913,18 @@ namespace nil {
919913
reps["$COMMITMENT_CODE$"] = commitment_code;
920914
reps["$ETA_VALUES_VERIFICATION$"] = eta_point_verification_code();
921915

922-
commitment_scheme_replaces<PlaceholderParams>(reps, _common_data, _lpc_scheme, _permutation_size, _use_lookups);
916+
std::size_t _lookup_degree = _constraint_system.lookup_poly_degree_bound();
917+
std::size_t _rows_amount = _common_data.rows_amount;
918+
std::size_t _quotient_degree = std::max(
919+
(_permutation_size + 2) * (_common_data.rows_amount -1 ),
920+
(_lookup_degree + 1) * (_common_data.rows_amount -1 )
921+
);
922+
923+
std::size_t _quotient_polys = (_quotient_degree % _rows_amount != 0)? (_quotient_degree / _rows_amount + 1): (_quotient_degree / _rows_amount);
924+
925+
commitment_scheme_replaces<PlaceholderParams>(
926+
reps, _common_data, _lpc_scheme, _permutation_size, _quotient_polys,
927+
_use_lookups?_constraint_system.sorted_lookup_columns_number():0, _use_lookups);
923928

924929
replace_and_print(modular_verifier_template, reps, _folder_name + "/modular_verifier.sol");
925930
replace_and_print(modular_permutation_argument_library_template, reps, _folder_name + "/permutation_argument.sol");
@@ -962,4 +967,4 @@ namespace nil {
962967
}
963968
}
964969

965-
#endif //__MODULAR_CONTRACTS_TEMPLATES_HPP__
970+
#endif //__MODULAR_CONTRACTS_TEMPLATES_HPP__

include/nil/blueprint/transpiler/lpc_scheme_gen.hpp

+25-97
Original file line numberDiff line numberDiff line change
@@ -44,115 +44,44 @@ namespace nil {
4444
PlaceholderParams
4545
>::preprocessed_data_type::common_data_type;
4646

47-
std::string rot_string (int j){
48-
if(j == 0) return "xi"; else
49-
if(j == 1 ) return "mulmod(xi, omega, modulus)"; else
50-
if(j == -1) return "mulmod(xi, inversed_omega, modulus)"; else
51-
if(j > 0) return "mulmod(xi, field.pow_small(omega, " + to_string(j) + ", modulus), modulus)"; else
52-
if(j < 0) return "mulmod(xi, field.pow_small(inversed_omega, " + to_string(-j) + ", modulus), modulus)";
53-
return "";
54-
}
55-
56-
5747
template<typename PlaceholderParams>
5848
void commitment_scheme_replaces(
5949
transpiler_replacements& replacements,
6050
const common_data_type<PlaceholderParams> &common_data,
6151
const typename PlaceholderParams::commitment_scheme_type& lpc_scheme,
6252
std::size_t permutation_size,
53+
std::size_t quotient_polys,
54+
std::size_t lookup_polys,
6355
bool use_lookups
6456
){
6557
std::set<std::string> unique_points;
6658
std::vector<std::string> points;
6759

68-
for(std::size_t i = 0; i < permutation_size*2; i++){
69-
points.push_back(rot_string(0) + "& _etha& ");
70-
}
71-
unique_points.insert(rot_string(0) + "& _etha& ");
72-
points.push_back(rot_string(0) + "& "+ rot_string(1) + "& _etha& ");
73-
points.push_back(rot_string(0) + "& "+ rot_string(1) + "& _etha& ");
74-
unique_points.insert(rot_string(0) + "& "+ rot_string(1) + "& _etha& ");
75-
76-
for(std::size_t i = 0; i < PlaceholderParams::constant_columns; i++){
77-
std::stringstream str;
78-
for(auto j:common_data.columns_rotations[i + PlaceholderParams::witness_columns + PlaceholderParams::public_input_columns]){
79-
str << rot_string(j) << "& ";
80-
}
81-
str << "_etha& ";
82-
unique_points.insert(str.str());
83-
points.push_back(str.str());
84-
}
85-
86-
for(std::size_t i = 0; i < PlaceholderParams::selector_columns; i++){
87-
std::stringstream str;
88-
for(auto j:common_data.columns_rotations[i + PlaceholderParams::witness_columns + PlaceholderParams::public_input_columns + PlaceholderParams::constant_columns]){
89-
str << rot_string(j) << "& ";
90-
}
91-
str << "_etha& ";
92-
unique_points.insert(str.str());
93-
points.push_back(str.str());
94-
}
60+
auto [z_points_indices, singles_strs, singles_map, poly_ids] = calculate_unique_points<PlaceholderParams, common_data_type<PlaceholderParams>>(
61+
common_data, permutation_size, use_lookups, quotient_polys, lookup_polys,
62+
"evm" // Generator mode
63+
);
9564

96-
for(std::size_t i = 0; i < PlaceholderParams::witness_columns; i++){
97-
std::stringstream str;
98-
for(auto j:common_data.columns_rotations[i]){
99-
str << rot_string(j) << "& ";
100-
}
101-
unique_points.insert(str.str());
102-
points.push_back(str.str());
103-
}
104-
105-
for(std::size_t i = 0; i < PlaceholderParams::public_input_columns; i++){
106-
std::stringstream str;
107-
for(auto j:common_data.columns_rotations[i + PlaceholderParams::witness_columns]){
108-
str << rot_string(j) << "& ";
109-
}
110-
unique_points.insert(str.str());
111-
points.push_back(str.str());
112-
}
113-
114-
unique_points.insert(rot_string(0) + "& " + rot_string(1) + "& ");//Permutation
115-
unique_points.insert(rot_string(0) + "& ");// Quotient
116-
if(use_lookups)
117-
unique_points.insert(rot_string(0) + "& " + rot_string(1) + "& " + rot_string(common_data.usable_rows_amount) + "& "); // Lookups
65+
std::stringstream points_initializer;
66+
std::size_t i = 0;
11867

119-
std::size_t permutation_point_id;
120-
std::size_t quotient_point_id;
121-
std::size_t lookup_point_id;
122-
std::size_t j = 0;
123-
for( const auto &unique_point:unique_points){
124-
if( unique_point == rot_string(0) + "& ") quotient_point_id = j;
125-
if( unique_point == rot_string(0) + "& " + rot_string(1) + "& " + rot_string(common_data.usable_rows_amount) + "& " ) lookup_point_id = j;
126-
if( unique_point == rot_string(0) + "& " + rot_string(1) + "& " ) permutation_point_id = j;
127-
j++;
68+
for(const auto& point: singles_strs){
69+
points_initializer << "\t\tresult[" << i << "] = " << point << ";" << std::endl;
70+
i++;
12871
}
12972

13073
std::stringstream points_ids;
131-
for(std::size_t i = 0; i < points.size(); i++){
132-
std::size_t j = 0;
133-
for(const auto &unique_point:unique_points){
134-
if(points[i] == unique_point){
135-
points_ids << std::hex << std::setw(2) << std::setfill('0') << j;
136-
break;
137-
}
138-
j++;
139-
}
74+
for( const auto& point_id: z_points_indices){
75+
points_ids << std::hex << std::setw(2) << std::setfill('0') << point_id;
14076
}
14177

142-
std::stringstream points_initializer;
143-
std::size_t i = 0;
144-
for(const auto& point: unique_points){
145-
points_initializer << "\t\t result[" << i << "] = new uint256[](" << std::count(point.begin(), point.end(), '&') << ");" << std::endl;
146-
std::size_t prev = 0;
147-
std::size_t found = point.find("& ");
148-
std::size_t j = 0;
149-
while (found!=std::string::npos){
150-
points_initializer << "\t\t result[" << i << "][" << j << "] = " << point.substr(prev, found-prev) << ";" << std::endl;
151-
prev = found + 2;
152-
found = point.find("& ",prev);
153-
j++;
78+
std::stringstream poly_ids_str;
79+
std::stringstream poly_points_num;
80+
for(i = 0; i < poly_ids.size(); i++){
81+
poly_points_num << std::hex << std::setw(4) << std::setfill('0') << poly_ids[i].size();
82+
for(std::size_t j = 0; j < poly_ids[i].size(); j++){
83+
poly_ids_str << std::hex << std::setw(4) << std::setfill('0') << poly_ids[i][j] * 0x40;
15484
}
155-
i++;
15685
}
15786

15887
std::vector<std::uint8_t> init_blob = {};
@@ -167,14 +96,13 @@ namespace nil {
16796
replacements["$D0_SIZE$"] = to_string(fri_params.D[0]->m);
16897
replacements["$D0_OMEGA$"] = to_string(fri_params.D[0]->get_domain_element(1));
16998
replacements["$MAX_DEGREE$"] = to_string(fri_params.max_degree);
170-
replacements["$UNIQUE_POINTS$"] = to_string(unique_points.size());
171-
replacements["$DIFFERENT_POINTS$"] = to_string(unique_points.size());
172-
replacements["$PERMUTATION_POINTS_ID$"] = to_string(permutation_point_id);
173-
replacements["$QUOTIENT_POINTS_ID$"] = to_string(quotient_point_id);
174-
replacements["$LOOKUP_POINTS_ID$"] = to_string(lookup_point_id);
99+
replacements["$UNIQUE_POINTS$"] = to_string(singles_strs.size());
100+
replacements["$DIFFERENT_POINTS$"] = to_string(singles_strs.size());
175101
replacements["$POINTS_IDS$"] = points_ids.str();
102+
replacements["$POLY_IDS$"] = poly_ids_str.str();
103+
replacements["$POLY_POINTS_NUM$"] = poly_points_num.str();
176104
replacements["$POINTS_INITIALIZATION$"] = points_initializer.str();
177-
replacements["$ETHA$"] = to_string(etha);
105+
replacements["$ETA$"] = to_string(etha);
178106
if( PlaceholderParams::commitment_scheme_type::fri_type::use_grinding){
179107
auto params = PlaceholderParams::commitment_scheme_type::fri_type::grinding_type::get_params();
180108
uint32_t mask_value = params.template get<uint32_t>("mask", 0);
@@ -204,4 +132,4 @@ namespace nil {
204132
}
205133
}
206134

207-
#endif //__MODULAR_CONTRACTS_TEMPLATES_HPP__
135+
#endif //__MODULAR_CONTRACTS_TEMPLATES_HPP__

0 commit comments

Comments
 (0)