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

Commit 97792e5

Browse files
committed
EVM verifier updated #65
1 parent 11a1088 commit 97792e5

File tree

5 files changed

+314
-496
lines changed

5 files changed

+314
-496
lines changed

include/nil/blueprint/transpiler/evm_verifier_gen.hpp

+12-6
Original file line numberDiff line numberDiff line change
@@ -819,9 +819,7 @@ namespace nil {
819819

820820
result << std::showbase << std::hex;
821821

822-
result << "\t\t\t// 1. 2*permutation_size" << std::endl;
823822
poly_points = 2;
824-
825823
while (j < 2*_permutation_size) {
826824
result << "\t\t\tpoints[" << i << "] = basic_marshalling.get_uint256_be(blob,";
827825
result << point_offset + (poly_points-1)*32 << ");" << std::endl;
@@ -832,7 +830,6 @@ namespace nil {
832830
++j;
833831
}
834832

835-
result << "\t\t\t// 2. special selectors " << std::endl;
836833
poly_points = 3;
837834

838835
j = 0;
@@ -846,7 +843,6 @@ namespace nil {
846843
++j;
847844
}
848845

849-
result << "\t\t\t// 3. constant columns " << std::endl;
850846
std::size_t column_rotation_offset = PlaceholderParams::witness_columns + PlaceholderParams::public_input_columns;
851847
j = 0;
852848
while (j < PlaceholderParams::arithmetization_params::constant_columns) {
@@ -860,7 +856,6 @@ namespace nil {
860856
++j;
861857
}
862858

863-
result << "\t\t\t// 4. selector columns " << std::endl;
864859
column_rotation_offset += PlaceholderParams::constant_columns;
865860
j = 0;
866861
while (j < PlaceholderParams::arithmetization_params::selector_columns) {
@@ -922,7 +917,18 @@ namespace nil {
922917
reps["$COMMITMENT_CODE$"] = commitment_code;
923918
reps["$ETA_VALUES_VERIFICATION$"] = eta_point_verification_code();
924919

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

927933
replace_and_print(modular_verifier_template, reps, _folder_name + "/modular_verifier.sol");
928934
replace_and_print(modular_permutation_argument_library_template, reps, _folder_name + "/permutation_argument.sol");

include/nil/blueprint/transpiler/lpc_scheme_gen.hpp

+30-80
Original file line numberDiff line numberDiff line change
@@ -60,74 +60,19 @@ namespace nil {
6060
const common_data_type<PlaceholderParams> &common_data,
6161
const typename PlaceholderParams::commitment_scheme_type& lpc_scheme,
6262
std::size_t permutation_size,
63+
std::size_t quotient_polys,
64+
std::size_t lookup_polys,
6365
bool use_lookups
6466
){
6567
std::set<std::string> unique_points;
6668
std::vector<std::string> points;
6769

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-
}
95-
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
118-
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++;
128-
}
70+
auto [z_points_indices, singles_strs, singles_map, poly_ids] = calculate_unique_points<PlaceholderParams, common_data_type<PlaceholderParams>>(
71+
common_data, permutation_size, use_lookups, quotient_polys, lookup_polys,
72+
"evm" // Generator mode
73+
);
12974

130-
std::stringstream points_ids;
75+
/* std::stringstream points_ids;
13176
for(std::size_t i = 0; i < points.size(); i++){
13277
std::size_t j = 0;
13378
for(const auto &unique_point:unique_points){
@@ -137,24 +82,30 @@ namespace nil {
13782
}
13883
j++;
13984
}
140-
}
85+
}*/
14186

14287
std::stringstream points_initializer;
14388
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++;
154-
}
89+
90+
for(const auto& point: singles_strs){
91+
points_initializer << "\t\tresult[" << i << "] = " << point << ";" << std::endl;
15592
i++;
15693
}
15794

95+
std::stringstream points_ids;
96+
for( const auto& point_id: z_points_indices){
97+
points_ids << std::hex << std::setw(2) << std::setfill('0') << point_id;
98+
}
99+
100+
std::stringstream poly_ids_str;
101+
std::stringstream poly_points_num;
102+
for(i = 0; i < poly_ids.size(); i++){
103+
poly_points_num << std::hex << std::setw(4) << std::setfill('0') << poly_ids[i].size();
104+
for(std::size_t j = 0; j < poly_ids[i].size(); j++){
105+
poly_ids_str << std::hex << std::setw(4) << std::setfill('0') << poly_ids[i][j] * 0x40;
106+
}
107+
}
108+
158109
std::vector<std::uint8_t> init_blob = {};
159110
nil::crypto3::zk::transcript::fiat_shamir_heuristic_sequential<typename PlaceholderParams::transcript_hash_type> transcript(init_blob);
160111
transcript(common_data.vk.constraint_system_with_params_hash);
@@ -167,14 +118,13 @@ namespace nil {
167118
replacements["$D0_SIZE$"] = to_string(fri_params.D[0]->m);
168119
replacements["$D0_OMEGA$"] = to_string(fri_params.D[0]->get_domain_element(1));
169120
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);
121+
replacements["$UNIQUE_POINTS$"] = to_string(singles_strs.size());
122+
replacements["$DIFFERENT_POINTS$"] = to_string(singles_strs.size());
175123
replacements["$POINTS_IDS$"] = points_ids.str();
124+
replacements["$POLY_IDS$"] = poly_ids_str.str();
125+
replacements["$POLY_POINTS_NUM$"] = poly_points_num.str();
176126
replacements["$POINTS_INITIALIZATION$"] = points_initializer.str();
177-
replacements["$ETHA$"] = to_string(etha);
127+
replacements["$ETA$"] = to_string(etha);
178128
if( PlaceholderParams::commitment_scheme_type::fri_type::use_grinding){
179129
auto params = PlaceholderParams::commitment_scheme_type::fri_type::grinding_type::get_params();
180130
uint32_t mask_value = params.template get<uint32_t>("mask", 0);

0 commit comments

Comments
 (0)