Skip to content

Commit

Permalink
EVM verifier update #78
Browse files Browse the repository at this point in the history
  • Loading branch information
ETatuzova authored and martun committed May 7, 2024
1 parent 1c60445 commit 1d498c2
Show file tree
Hide file tree
Showing 12 changed files with 1,346 additions and 679 deletions.
216 changes: 97 additions & 119 deletions include/nil/blueprint/transpiler/evm_verifier_gen.hpp

Large diffs are not rendered by default.

29 changes: 22 additions & 7 deletions include/nil/blueprint/transpiler/lpc_scheme_gen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <nil/blueprint/transpiler/util.hpp>
#include <nil/blueprint/transpiler/templates/commitment_scheme.hpp>
#include <nil/crypto3/zk/snark/systems/plonk/placeholder/preprocessor.hpp>
#include <nil/crypto3/zk/snark/systems/plonk/placeholder/detail/profiling.hpp>

namespace nil {
namespace blueprint {
Expand All @@ -46,6 +47,7 @@ namespace nil {

template<typename PlaceholderParams>
void commitment_scheme_replaces(
const zk::snark::placeholder_info<PlaceholderParams> &placeholder_info,
zk::snark::plonk_table_description<typename PlaceholderParams::field_type> desc,
transpiler_replacements& replacements,
const common_data_type<PlaceholderParams> &common_data,
Expand All @@ -59,8 +61,9 @@ namespace nil {
std::vector<std::string> points;

auto [z_points_indices, singles_strs, singles_map, poly_ids] = calculate_unique_points<PlaceholderParams, common_data_type<PlaceholderParams>>(
placeholder_info,
desc,
common_data, permutation_size, use_lookups, quotient_polys, lookup_polys,
common_data, permutation_size, quotient_polys, lookup_polys,
"evm" // Generator mode
);

Expand All @@ -86,6 +89,16 @@ namespace nil {
}
}

std::string eta_point_U;
std::vector<typename PlaceholderParams::field_type::value_type> eta_points;
for( const auto &it:common_data.commitment_scheme_data){
for( std::size_t i = 0; i < it.second.size(); i++ )
eta_points.push_back(it.second[i]);
}
for( std::size_t i = 0; i < eta_points.size(); i++){
eta_point_U += "\t\tresult = addmod(0x" +to_hex_string(eta_points[eta_points.size() - i - 1]) + ", mulmod(result, theta, modulus), modulus);\n";
}

std::vector<std::uint8_t> init_blob = {};
nil::crypto3::zk::transcript::fiat_shamir_heuristic_sequential<typename PlaceholderParams::transcript_hash_type> transcript(init_blob);
transcript(common_data.vk.constraint_system_with_params_hash);
Expand All @@ -94,8 +107,9 @@ namespace nil {

auto fri_params = lpc_scheme.get_commitment_params();
replacements["$R$"] = to_string(fri_params.r);
replacements["$LAMBDA$"] = to_string(PlaceholderParams::commitment_scheme_type::fri_type::lambda);
replacements["$LAMBDA$"] = to_string(fri_params.lambda);
replacements["$D0_SIZE$"] = to_string(fri_params.D[0]->m);
replacements["$D0_LOG$"] = to_string(log2(fri_params.D[0]->m));
replacements["$D0_OMEGA$"] = to_string(fri_params.D[0]->get_domain_element(1));
replacements["$MAX_DEGREE$"] = to_string(fri_params.max_degree);
replacements["$UNIQUE_POINTS$"] = to_string(singles_strs.size());
Expand All @@ -105,24 +119,25 @@ namespace nil {
replacements["$POLY_POINTS_NUM$"] = poly_points_num.str();
replacements["$POINTS_INITIALIZATION$"] = points_initializer.str();
replacements["$ETA$"] = to_string(etha);
if( PlaceholderParams::commitment_scheme_type::fri_type::use_grinding){
replacements["$ETA_POINT_U$"] = eta_point_U;
replacements["$FIXED_BATCH_SIZE$"] = to_string(placeholder_info.batches_sizes[0]);
/* if( fri_params.use_grinding){
auto params = PlaceholderParams::commitment_scheme_type::fri_type::grinding_type::get_params();
uint32_t mask_value = params.template get<uint32_t>("mask", 0);
std::stringstream mask_value_hex;
mask_value_hex << std::hex << std::showbase << std::setw(8) << std::setfill('0') << mask_value;
replacements["$GRINDING_CHECK$"] = modular_commitment_grinding_check_template;
replacements["$GRINDING_MASK$"] = mask_value_hex.str();
} else {
} else {*/
replacements["$GRINDING_CHECK$"] = "";
}
// }
}

template<typename PlaceholderParams>
std::string generate_commitment_scheme_code(
const common_data_type<PlaceholderParams> &common_data,
const typename PlaceholderParams::commitment_scheme_type& lpc_scheme
const typename PlaceholderParams::commitment_scheme_type::params_type& fri_params
){
auto fri_params = lpc_scheme.get_commitment_params();
BOOST_ASSERT(fri_params.step_list.size() == fri_params.r);
for(std::size_t i = 0; i < fri_params.step_list.size(); i++){
BOOST_ASSERT(fri_params.step_list[i] == 1);
Expand Down
26 changes: 17 additions & 9 deletions include/nil/blueprint/transpiler/recursive_verifier_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
#include <nil/crypto3/zk/math/expression_visitors.hpp>
#include <nil/crypto3/zk/math/expression_evaluator.hpp>

#include<nil/blueprint/transpiler/templates/recursive_verifier.hpp>
#include<nil/blueprint/transpiler/util.hpp>
#include <nil/blueprint/transpiler/templates/recursive_verifier.hpp>
#include <nil/blueprint/transpiler/util.hpp>

#include <nil/crypto3/zk/snark/systems/plonk/placeholder/detail/profiling.hpp>

namespace nil {
namespace blueprint {
Expand Down Expand Up @@ -672,17 +674,22 @@ namespace nil {
std::string generate_recursive_verifier(
const constraint_system_type &constraint_system,
const common_data_type &common_data,
const commitment_scheme_type &commitment_scheme,
std::size_t permutation_size,
const std::vector<std::size_t> public_input_sizes
){
auto placeholder_info = nil::crypto3::zk::snark::prepare_placeholder_info<PlaceholderParams>(
constraint_system,
common_data
);

std::size_t permutation_size = common_data.permuted_columns.size();
const auto &desc = common_data.desc;
BOOST_ASSERT(desc.public_input_columns == public_input_sizes.size());
std::string result = nil::blueprint::recursive_verifier_template;
bool use_lookups = constraint_system.lookup_gates().size() > 0;
transpiler_replacements lookup_reps;
transpiler_replacements reps;

auto fri_params = commitment_scheme.get_commitment_params();
auto fri_params = common_data.commitment_params;
std::size_t batches_num = use_lookups?5:4;
auto lambda = fri_params.lambda;

Expand All @@ -693,10 +700,10 @@ namespace nil {

std::size_t lookup_degree = constraint_system.lookup_poly_degree_bound();

std::size_t rows_amount = common_data.rows_amount;
std::size_t rows_amount = desc.rows_amount;
std::size_t quotient_degree = std::max(
(permutation_size + 2) * (common_data.rows_amount -1 ),
(lookup_degree + 1) * (common_data.rows_amount -1 )
(permutation_size + 2) * (desc.rows_amount -1 ),
(lookup_degree + 1) * (desc.rows_amount -1 )
);

std::size_t quotient_polys = (quotient_degree % rows_amount != 0)? (quotient_degree / rows_amount + 1): (quotient_degree / rows_amount);
Expand Down Expand Up @@ -807,8 +814,9 @@ namespace nil {
}

auto [z_points_indices, singles_strs, singles_map, poly_ids] = calculate_unique_points<PlaceholderParams, common_data_type>(
placeholder_info,
desc,
common_data, permutation_size, use_lookups, quotient_polys,
common_data, permutation_size, quotient_polys,
use_lookups?constraint_system.sorted_lookup_columns_number():0,
"recursive" // Generator mode
);
Expand Down
Loading

0 comments on commit 1d498c2

Please sign in to comment.