From f2501e1893aebc537328a06093bc6f2f3ff20fcb Mon Sep 17 00:00:00 2001 From: "e.tatuzova" Date: Mon, 29 Apr 2024 06:49:00 +0400 Subject: [PATCH] Crypto3, transpiler and other submodules updated #597 --- .github/workflows/build_linux.yml | 2 +- bin/assigner/src/main.cpp | 2 +- bin/recursive_gen/src/main.cpp | 43 +++++++++++++---------------- bin/transpiler/src/main.cpp | 45 ++++++++++++------------------- libs/assigner | 2 +- libs/blueprint | 2 +- libs/crypto3 | 2 +- libs/transpiler | 2 +- 8 files changed, 41 insertions(+), 59 deletions(-) diff --git a/.github/workflows/build_linux.yml b/.github/workflows/build_linux.yml index e0528b6a..82258a07 100644 --- a/.github/workflows/build_linux.yml +++ b/.github/workflows/build_linux.yml @@ -331,7 +331,7 @@ jobs: with: artifact-name: ${{ needs.build-and-test-linux.outputs.examples-artifact-name }} # Update next line if you need new version of proof producer - proof-producer-ref: 938426d309e586d87cd2b7895a0dea05ff88c0c5 + proof-producer-ref: f26b14984135ba613e240c485e05999afa1c9efd refs: ${{ needs.handle-syncwith.outputs.prs-refs }} targets: ${{ needs.build-and-test-linux.outputs.prover-targets }} diff --git a/bin/assigner/src/main.cpp b/bin/assigner/src/main.cpp index cc9c394e..07e42360 100644 --- a/bin/assigner/src/main.cpp +++ b/bin/assigner/src/main.cpp @@ -147,7 +147,7 @@ void print_circuit(const circuit_proxy &circuit_proxy, auto filled_val = value_marshalling_type(std::make_tuple( nil::crypto3::marshalling::types::fill_plonk_gates(used_gates), - nil::crypto3::marshalling::types::fill_plonk_copy_constraints(used_copy_constraints), + nil::crypto3::marshalling::types::fill_plonk_copy_constraints(used_copy_constraints), nil::crypto3::marshalling::types::fill_plonk_lookup_gates(used_lookup_gates), nil::crypto3::marshalling::types::fill_plonk_lookup_tables(used_lookup_tables), public_input_sizes diff --git a/bin/recursive_gen/src/main.cpp b/bin/recursive_gen/src/main.cpp index c86cf2ee..645f0066 100644 --- a/bin/recursive_gen/src/main.cpp +++ b/bin/recursive_gen/src/main.cpp @@ -43,7 +43,7 @@ #include #include #include -#include +#include #include #include @@ -166,18 +166,6 @@ inline std::vector generate_random_step_list(const std::size_t r, c return step_list; } -template -typename FRIScheme::params_type create_fri_params(std::size_t degree_log, const int max_step = 1, const int expand_factor = 2) { - std::size_t r = degree_log - 1; - - return typename FRIScheme::params_type( - (1 << degree_log) - 1, // max_degree - math::calculate_domain_set(degree_log + expand_factor, r), - generate_random_step_list(r, max_step), - expand_factor - ); -} - template void print_hex_byteblob(std::ostream &os, TIter iter_begin, TIter iter_end, bool endl) { os << "0x" << std::hex; @@ -231,6 +219,9 @@ int main(int argc, char *argv[]) { It'll be better to create an empty folder for output") ("skip-verification", "Used with gen-test-proof, if set - skips verifiyng the generated proof") ("multi-prover", "Pass this flag if input circuit is a part of larger circuit, divided for faster paralel proving") + ("lambda,l", boost::program_options::value(), "Number of FRI rounds") + ("expand-factor", boost::program_options::value(), "FRI blow-up factor") + ("max-quotient-chunks", boost::program_options::value(), "Maximal parts of quotient polynomial") ("elliptic-curve-type,e", boost::program_options::value(), "Native elliptic curve type (pallas, vesta, ed25519, bls12381)"); // clang-format on @@ -376,7 +367,10 @@ int curve_dependent_main( using AssignmentTableType = nil::crypto3::zk::snark::plonk_table; - const std::size_t Lambda = parameters_policy::lambda; + const std::size_t Lambda = vm.count("lambda")? vm["lambda"].as() : parameters_policy::lambda; + const std::size_t max_quotient_chunks = vm.count("max-quotient-chunks")? vm["max-quotient-chunks"].as() : 0; + const std::size_t expand_factor = vm.count("expand-factor")? vm["expand-factor"].as() : 2; + using Hash = typename parameters_policy::hash; using circuit_params = nil::crypto3::zk::snark::placeholder_circuit_params< BlueprintFieldType @@ -385,7 +379,6 @@ int curve_dependent_main( using lpc_params_type = nil::crypto3::zk::commitments::list_polynomial_commitment_params< Hash, Hash, - Lambda, 2 >; using lpc_type = nil::crypto3::zk::commitments::list_polynomial_commitment; @@ -437,10 +430,10 @@ int curve_dependent_main( if (!marshalled_value) { return false; } - auto [c_data, description] = nil::crypto3::marshalling::types::make_placeholder_common_data( + auto c_data = nil::crypto3::marshalling::types::make_placeholder_common_data( *marshalled_value ); - desc.emplace(description); + desc.emplace(c_data.desc); common_data.emplace(c_data); } @@ -459,14 +452,14 @@ int curve_dependent_main( using lpc_params_type = nil::crypto3::zk::commitments::list_polynomial_commitment_params< Hash, Hash, - Lambda, 2 >; - auto fri_params = create_fri_params(table_rows_log); - std::size_t permutation_size = - desc->witness_columns + desc->public_input_columns + desc->constant_columns; - lpc_scheme_type lpc_scheme(fri_params); + // TODO: grinding bits + typename lpc_type::fri_type::params_type fri_params( + 1, table_rows_log, Lambda, expand_factor + ); + lpc_scheme_type lpc_scheme(fri_params); if( mode == "gen-verifier" && !assignment_table && !common_data ){ std::cerr << "Invalid command line argument - assignment table file name or common data file name should be specified" << std::endl; @@ -489,7 +482,7 @@ int curve_dependent_main( typename nil::crypto3::zk::snark::placeholder_public_preprocessor< BlueprintFieldType, placeholder_params>::preprocessed_data_type public_preprocessed_data = nil::crypto3::zk::snark::placeholder_public_preprocessor::process( - *constraint_system, assignment_table->public_table(), *desc, lpc_scheme, permutation_size); + *constraint_system, assignment_table->public_table(), *desc, lpc_scheme, max_quotient_chunks); common_data.emplace(public_preprocessed_data.common_data); if (mode == "gen-input") { @@ -510,7 +503,7 @@ int curve_dependent_main( std::cout << "Verifying proof..." << std::endl; bool verification_result = nil::crypto3::zk::snark::placeholder_verifier::process( - public_preprocessed_data, proof, *desc, *constraint_system, lpc_scheme + public_preprocessed_data.common_data, proof, *desc, *constraint_system, lpc_scheme ); ASSERT_MSG(verification_result, "Proof is not verified" ); @@ -539,7 +532,7 @@ int curve_dependent_main( nil::crypto3::zk::snark::placeholder_proof, typename nil::crypto3::zk::snark::placeholder_public_preprocessor::preprocessed_data_type::common_data_type >(*desc).generate_recursive_verifier( - *constraint_system, *common_data, lpc_scheme, permutation_size, public_input_sizes + *constraint_system, *common_data, public_input_sizes ); output_file.close(); return 0; diff --git a/bin/transpiler/src/main.cpp b/bin/transpiler/src/main.cpp index f8f11b7e..41380f2c 100644 --- a/bin/transpiler/src/main.cpp +++ b/bin/transpiler/src/main.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -34,7 +35,7 @@ #include #include #include -#include +#include #include #include @@ -85,19 +86,6 @@ inline std::vector generate_random_step_list(const std::size_t r, c return step_list; } -template -typename FRIScheme::params_type create_fri_params( - std::size_t degree_log, const int max_step = 1, std::size_t expand_factor = 2) { - std::size_t r = degree_log - 1; - - return typename FRIScheme::params_type( - (1 << degree_log) - 1, // max_degree - nil::crypto3::math::calculate_domain_set(degree_log + expand_factor, r), - generate_random_step_list(r, max_step), - expand_factor - ); -} - template void print_hex_byteblob(std::ostream &os, TIter iter_begin, TIter iter_end, bool endl) { os << "0x" << std::hex; @@ -174,6 +162,9 @@ int main(int argc, char *argv[]) { ("deduce-horner", "Detect polynomials over one variable and deduce to Horner's formula") ("optimize-powers", "Optimize terms that are powers of single variable") ("multi-prover", "Pass this flag if input circuit is a part of larger circuit, divided for faster paralel proving") + ("lambda,l", boost::program_options::value(), "Number of FRI rounds") + ("expand-factor", boost::program_options::value(), "FRI blow-up factor") + ("max-quotient-chunks", boost::program_options::value(), "Maximal quotient polynomial parts amount") ("elliptic-curve-type,e", boost::program_options::value(), "Native elliptic curve type (pallas, vesta, ed25519, bls12381)") ; // clang-format on @@ -394,13 +385,14 @@ int curve_dependent_main( nil::crypto3::marshalling::types::make_assignment_table( marshalled_table_data ); - desc.rows_amount = assignment_table.rows_amount(); } std::vector> columns_rotations; - const std::size_t Lambda = 9;//ParametersPolicy::lambda; + std::size_t Lambda = vm.count("lambda") > 0 ? vm["lambda"].as() : 9;//ParametersPolicy::lambda; + std::size_t expand_factor = vm.count("expand-factor") > 0 ? vm["expand-factor"].as() : 2;//ParametersPolicy::lambda; + std::size_t max_quotient_chunks = vm.count("max-quotient-chunks") > 0 ? vm["max-quotient-chunks"].as() : 0; using Hash = nil::crypto3::hashes::keccak_1600<256>; using circuit_params = nil::crypto3::zk::snark::placeholder_circuit_params; @@ -409,19 +401,18 @@ int curve_dependent_main( using lpc_params_type = nil::crypto3::zk::commitments::list_polynomial_commitment_params< Hash, Hash, - Lambda, - 2, - ParametersPolicy::UseGrinding, - nil::crypto3::zk::commitments::proof_of_work + 2 >; + using lpc_type = nil::crypto3::zk::commitments::list_polynomial_commitment; using lpc_scheme_type = typename nil::crypto3::zk::commitments::lpc_commitment_scheme; using placeholder_params = nil::crypto3::zk::snark::placeholder_params; using policy_type = nil::crypto3::zk::snark::detail::placeholder_policy; - auto fri_params = create_fri_params(table_rows_log); - std::size_t permutation_size = - desc.witness_columns + desc.public_input_columns + ParametersPolicy::ComponentConstantColumns; + // TODO: grinding bits + typename lpc_type::fri_type::params_type fri_params( + 1, table_rows_log, Lambda, expand_factor + ); lpc_scheme_type lpc_scheme(fri_params); @@ -442,7 +433,8 @@ int curve_dependent_main( typename nil::crypto3::zk::snark::placeholder_public_preprocessor< BlueprintFieldType, placeholder_params>::preprocessed_data_type public_preprocessed_data = nil::crypto3::zk::snark::placeholder_public_preprocessor::process( - constraint_system, assignment_table.public_table(), desc, lpc_scheme, permutation_size); + constraint_system, assignment_table.public_table(), desc, lpc_scheme, max_quotient_chunks + ); if (mode == "gen-evm-verifier") { std::size_t gates_contract_size_threshold = 800; @@ -474,11 +466,8 @@ int curve_dependent_main( optimize_powers = true; } nil::blueprint::evm_verifier_printer( - desc, constraint_system, public_preprocessed_data.common_data, - lpc_scheme, - permutation_size, output_folder_path, gates_contract_size_threshold, lookups_library_threshold, @@ -531,7 +520,7 @@ int curve_dependent_main( std::cout << "Verifying proof..." << std::endl; bool verification_result = nil::crypto3::zk::snark::placeholder_verifier::process( - public_preprocessed_data, + public_preprocessed_data.common_data, proof, desc, constraint_system, diff --git a/libs/assigner b/libs/assigner index 94800db7..ec3930d0 160000 --- a/libs/assigner +++ b/libs/assigner @@ -1 +1 @@ -Subproject commit 94800db769328037b117722ee0b7d6892ac52524 +Subproject commit ec3930d05f0704f900341f186f19b8c3a6b690dc diff --git a/libs/blueprint b/libs/blueprint index fde02cb0..5a2209e0 160000 --- a/libs/blueprint +++ b/libs/blueprint @@ -1 +1 @@ -Subproject commit fde02cb041a0d4603dd80b9318a66179d98acd65 +Subproject commit 5a2209e09c1e19ad41b1d3ff308185ea03a3c114 diff --git a/libs/crypto3 b/libs/crypto3 index d9f4661d..7f3f8e98 160000 --- a/libs/crypto3 +++ b/libs/crypto3 @@ -1 +1 @@ -Subproject commit d9f4661d01510f5221ecc179c4253c7798719a99 +Subproject commit 7f3f8e9857b1dbb1f00cf567bbbb38795a8d586e diff --git a/libs/transpiler b/libs/transpiler index 695180ef..6e91f1f1 160000 --- a/libs/transpiler +++ b/libs/transpiler @@ -1 +1 @@ -Subproject commit 695180efdff2f8f0c8c9c11a6391a825d3a3351a +Subproject commit 6e91f1f1ba612892c508ad63f95028145ef504b6