@@ -44,115 +44,44 @@ namespace nil {
44
44
PlaceholderParams
45
45
>::preprocessed_data_type::common_data_type;
46
46
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
-
57
47
template <typename PlaceholderParams>
58
48
void commitment_scheme_replaces (
59
49
transpiler_replacements& replacements,
60
50
const common_data_type<PlaceholderParams> &common_data,
61
51
const typename PlaceholderParams::commitment_scheme_type& lpc_scheme,
62
52
std::size_t permutation_size,
53
+ std::size_t quotient_polys,
54
+ std::size_t lookup_polys,
63
55
bool use_lookups
64
56
){
65
57
std::set<std::string> unique_points;
66
58
std::vector<std::string> points;
67
59
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
+ );
95
64
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 ;
118
67
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\t result[" << i << " ] = " << point << " ;" << std::endl;
70
+ i++;
128
71
}
129
72
130
73
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;
140
76
}
141
77
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 ;
154
84
}
155
- i++;
156
85
}
157
86
158
87
std::vector<std::uint8_t > init_blob = {};
@@ -167,14 +96,13 @@ namespace nil {
167
96
replacements[" $D0_SIZE$" ] = to_string (fri_params.D [0 ]->m );
168
97
replacements[" $D0_OMEGA$" ] = to_string (fri_params.D [0 ]->get_domain_element (1 ));
169
98
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 ());
175
101
replacements[" $POINTS_IDS$" ] = points_ids.str ();
102
+ replacements[" $POLY_IDS$" ] = poly_ids_str.str ();
103
+ replacements[" $POLY_POINTS_NUM$" ] = poly_points_num.str ();
176
104
replacements[" $POINTS_INITIALIZATION$" ] = points_initializer.str ();
177
- replacements[" $ETHA $" ] = to_string (etha);
105
+ replacements[" $ETA $" ] = to_string (etha);
178
106
if ( PlaceholderParams::commitment_scheme_type::fri_type::use_grinding){
179
107
auto params = PlaceholderParams::commitment_scheme_type::fri_type::grinding_type::get_params ();
180
108
uint32_t mask_value = params.template get <uint32_t >(" mask" , 0 );
@@ -204,4 +132,4 @@ namespace nil {
204
132
}
205
133
}
206
134
207
- #endif // __MODULAR_CONTRACTS_TEMPLATES_HPP__
135
+ #endif // __MODULAR_CONTRACTS_TEMPLATES_HPP__
0 commit comments