diff --git a/bin/proof-generator/include/nil/proof-generator/arg_parser.hpp b/bin/proof-generator/include/nil/proof-generator/arg_parser.hpp index c95903a5..68da68f6 100644 --- a/bin/proof-generator/include/nil/proof-generator/arg_parser.hpp +++ b/bin/proof-generator/include/nil/proof-generator/arg_parser.hpp @@ -43,9 +43,9 @@ namespace nil { bool verification_only = false; CurvesVariant elliptic_curve_type = type_identity{}; HashesVariant hash_type = type_identity>{}; - ColumnsParams columns = all_columns_params[0]; LambdaParam lambda = all_lambda_params[0]; GrindParam grind = all_grind_params[0]; + std::size_t component_constant_columns = 5; std::size_t expand_factor = 2; }; diff --git a/bin/proof-generator/include/nil/proof-generator/arithmetization_params.hpp b/bin/proof-generator/include/nil/proof-generator/arithmetization_params.hpp index 93f48536..9c9ec76a 100644 --- a/bin/proof-generator/include/nil/proof-generator/arithmetization_params.hpp +++ b/bin/proof-generator/include/nil/proof-generator/arithmetization_params.hpp @@ -28,17 +28,6 @@ namespace nil { namespace proof_generator { - // Available in runtime columns params. Order is: - // witness | public_input | component_constant | component_selector | - // lookup_constant | lookup_selector - constexpr std::array all_columns_params = {{ - {15, 1, 5, 50, 30, 6}, - {15, 1, 5, 60, 0, 0}, - {15, 1, 2, 50, 14, 6}, - {15, 1, 5, 30, 30, 6} - // Add more params as needed. - }}; - constexpr std::array all_lambda_params = { 9 // Add more params as needed. diff --git a/bin/proof-generator/include/nil/proof-generator/non_type_arithmetization_params.hpp b/bin/proof-generator/include/nil/proof-generator/non_type_arithmetization_params.hpp index a0c938e6..b3e11062 100644 --- a/bin/proof-generator/include/nil/proof-generator/non_type_arithmetization_params.hpp +++ b/bin/proof-generator/include/nil/proof-generator/non_type_arithmetization_params.hpp @@ -22,23 +22,6 @@ namespace nil { namespace proof_generator { - struct ColumnsParams { - std::size_t witness_columns; - std::size_t public_input_columns; - std::size_t component_constant_columns; - std::size_t component_selector_columns; - std::size_t lookup_constant_columns; - std::size_t lookup_selector_columns; - - bool operator==(const ColumnsParams& other) const { - return witness_columns == other.witness_columns && public_input_columns == other.public_input_columns - && component_constant_columns == other.component_constant_columns - && component_selector_columns == other.component_selector_columns - && lookup_constant_columns == other.lookup_constant_columns - && lookup_selector_columns == other.lookup_selector_columns; - } - }; - // Need this class to be derived into actual params, so we could overload // read/write operators for parsing. class SizeTParam { diff --git a/bin/proof-generator/include/nil/proof-generator/prover.hpp b/bin/proof-generator/include/nil/proof-generator/prover.hpp index bda66940..eb923d27 100644 --- a/bin/proof-generator/include/nil/proof-generator/prover.hpp +++ b/bin/proof-generator/include/nil/proof-generator/prover.hpp @@ -130,12 +130,7 @@ namespace nil { } } // namespace detail - template< - typename CurveType, - typename HashType, - std::size_t ColumnsParamsIdx, - std::size_t LambdaParamIdx, - std::size_t GrindParamIdx> + template class Prover { public: Prover( @@ -143,12 +138,15 @@ namespace nil { boost::filesystem::path preprocessed_common_data_file_name, boost::filesystem::path assignment_table_file_name, boost::filesystem::path proof_file, + std::size_t component_constant_columns, // We need it to calculate permutation size, and it couldn't be + // established form assignment table yet std::size_t expand_factor ) : circuit_file_(circuit_file_name) , preprocessed_common_data_file_(preprocessed_common_data_file_name) , assignment_table_file_(assignment_table_file_name) , proof_file_(proof_file) + , component_constant_columns_(component_constant_columns) , expand_factor_(expand_factor) { } @@ -238,39 +236,20 @@ namespace nil { } private: - // C++20 allows passing non-type template param by value, so we could make the - // current function use - // columns_policy type directly instead of index after standard upgrade. - // clang-format off - static constexpr std::size_t WitnessColumns = all_columns_params[ColumnsParamsIdx].witness_columns; - static constexpr std::size_t PublicInputColumns = all_columns_params[ColumnsParamsIdx].public_input_columns; - static constexpr std::size_t ComponentConstantColumns = all_columns_params[ColumnsParamsIdx].component_constant_columns; - static constexpr std::size_t LookupConstantColumns = all_columns_params[ColumnsParamsIdx].lookup_constant_columns; - static constexpr std::size_t ConstantColumns = ComponentConstantColumns + LookupConstantColumns; - static constexpr std::size_t ComponentSelectorColumns = all_columns_params[ColumnsParamsIdx].component_selector_columns; - static constexpr std::size_t LookupSelectorColumns = all_columns_params[ColumnsParamsIdx].lookup_selector_columns; - static constexpr std::size_t SelectorColumns = ComponentSelectorColumns + LookupSelectorColumns; - // clang-format on - - using ArithmetizationParams = nil::crypto3::zk::snark:: - plonk_arithmetization_params; using BlueprintField = typename CurveType::base_field_type; using LpcParams = nil::crypto3::zk::commitments:: list_polynomial_commitment_params; using Lpc = nil::crypto3::zk::commitments::list_polynomial_commitment; using LpcScheme = typename nil::crypto3::zk::commitments::lpc_commitment_scheme; - using CircuitParams = - nil::crypto3::zk::snark::placeholder_circuit_params; + using CircuitParams = nil::crypto3::zk::snark::placeholder_circuit_params; using PlaceholderParams = nil::crypto3::zk::snark::placeholder_params; using Proof = nil::crypto3::zk::snark::placeholder_proof; using PublicPreprocessedData = typename nil::crypto3::zk::snark:: placeholder_public_preprocessor::preprocessed_data_type; using PrivatePreprocessedData = typename nil::crypto3::zk::snark:: placeholder_private_preprocessor::preprocessed_data_type; - using ConstraintSystem = - nil::crypto3::zk::snark::plonk_constraint_system; - using TableDescription = - nil::crypto3::zk::snark::plonk_table_description; + using ConstraintSystem = nil::crypto3::zk::snark::plonk_constraint_system; + using TableDescription = nil::crypto3::zk::snark::plonk_table_description; using Endianness = nil::marshalling::option::big_endian; using FriParams = typename Lpc::fri_type::params_type; @@ -280,6 +259,7 @@ namespace nil { nil::crypto3::zk::snark::placeholder_verifier::process( *public_preprocessed_data_, proof, + *table_description_, *constraint_system_, *lpc_scheme_ ); @@ -300,8 +280,7 @@ namespace nil { nil::crypto3::marshalling::types::plonk_constraint_system; using Column = nil::crypto3::zk::snark::plonk_column; - using AssignmentTable = - nil::crypto3::zk::snark::plonk_table; + using AssignmentTable = nil::crypto3::zk::snark::plonk_table; { auto marshalled_value = detail::decode_marshalling_from_file(circuit_file_); @@ -317,21 +296,16 @@ namespace nil { using TableValueMarshalling = nil::crypto3::marshalling::types::plonk_assignment_table; - AssignmentTable assignment_table; - { - TableDescription table_description; - auto marshalled_table = - detail::decode_marshalling_from_file(assignment_table_file_); - if (!marshalled_table) { - return false; - } - std::tie(table_description.usable_rows_amount, assignment_table) = - nil::crypto3::marshalling::types::make_assignment_table( - *marshalled_table - ); - table_description.rows_amount = assignment_table.rows_amount(); - table_description_.emplace(table_description); + auto marshalled_table = + detail::decode_marshalling_from_file(assignment_table_file_); + if (!marshalled_table) { + return false; } + auto [table_description, assignment_table] = + nil::crypto3::marshalling::types::make_assignment_table( + *marshalled_table + ); + table_description_.emplace(table_description); // Lambdas and grinding bits should be passed threw preprocessor directives std::size_t table_rows_log = std::ceil(std::log2(table_description_->rows_amount)); @@ -341,7 +315,7 @@ namespace nil { ); std::size_t permutation_size = table_description_->witness_columns - + table_description_->public_input_columns + ComponentConstantColumns; + + table_description_->public_input_columns + component_constant_columns_; lpc_scheme_.emplace(*fri_params_); BOOST_LOG_TRIVIAL(info) << "Preprocessing public data"; @@ -369,6 +343,7 @@ namespace nil { const boost::filesystem::path assignment_table_file_; const boost::filesystem::path proof_file_; const std::size_t expand_factor_; + const std::size_t component_constant_columns_; // All set on prepare_for_operation() std::optional public_preprocessed_data_; diff --git a/bin/proof-generator/src/arg_parser.cpp b/bin/proof-generator/src/arg_parser.cpp index 270b933e..072d83e2 100644 --- a/bin/proof-generator/src/arg_parser.cpp +++ b/bin/proof-generator/src/arg_parser.cpp @@ -29,20 +29,6 @@ namespace nil { namespace proof_generator { namespace po = boost::program_options; - void print_all_columns_params() { - std::cout << "Available Policies:\n"; - std::cout << "Index: witness, public input, component constant, component " - "selector, lookup constant, " - "lookup selector\n"; - - for (std::size_t i = 0; i < all_columns_params.size(); ++i) { - const auto& params = all_columns_params[i]; - std::cout << std::setw(5) << i << ":\t" << params.witness_columns << "," << params.public_input_columns - << "," << params.component_constant_columns << "," << params.component_selector_columns << "," - << params.lookup_constant_columns << "," << params.lookup_selector_columns << "\n"; - } - } - void check_exclusive_options(const po::variables_map& vm, const std::vector& opts) { std::vector found_opts; for (const auto& opt : opts) { @@ -55,6 +41,11 @@ namespace nil { } } + template + po::typed_value* make_defaulted_option(T& variable) { + return po::value(&variable)->default_value(variable); + } + std::optional parse_args(int argc, char* argv[]) { po::options_description options("Nil; Proof Generator Options"); // Declare a group of options that will be @@ -64,8 +55,7 @@ namespace nil { generic.add_options() ("help,h", "Produce help message") ("version,v", "Print version string") - ("config,c", po::value(), "Config file path") - ("list-columns-params", "Print available columns params"); + ("config,c", po::value(), "Config file path"); // clang-format on ProverOptions prover_options; @@ -80,17 +70,17 @@ namespace nil { ); // clang-format off auto options_appender = config.add_options() - ("proof,p", po::value(&prover_options.proof_file_path)->default_value(prover_options.proof_file_path), "Output proof file") - ("common-data", po::value(&prover_options.preprocessed_common_data_path)->default_value(prover_options.preprocessed_common_data_path), "Output preprocessed common data file") + ("proof,p", make_defaulted_option(prover_options.proof_file_path), "Output proof file") + ("common-data", make_defaulted_option(prover_options.preprocessed_common_data_path), "Output preprocessed common data file") ("circuit,c", po::value(&prover_options.circuit_file_path)->required(), "Circuit input file") ("assignment-table,t", po::value(&prover_options.assignment_table_file_path)->required(), "Assignment table input file") - ("log-level,l", po::value(&prover_options.log_level)->default_value(prover_options.log_level), "Log level (trace, debug, info, warning, error, fatal)") - ("elliptic-curve-type,e", po::value(&prover_options.elliptic_curve_type)->default_value(prover_options.elliptic_curve_type), "Elliptic curve type (pallas)") - ("hash-type", po::value(&prover_options.hash_type)->default_value(prover_options.hash_type), "Hash type (keccak)") - ("columns-params", po::value(&prover_options.columns)->default_value(prover_options.columns), "Columns params, use --list-columns-params to list") - ("lambda-param", po::value(&prover_options.lambda)->default_value(prover_options.lambda), "Lambda param (9)") - ("grind-param", po::value(&prover_options.lambda)->default_value(prover_options.lambda), "Grind param (69)") - ("expand-factor", po::value(&prover_options.expand_factor)->default_value(prover_options.expand_factor), "Expand factor") + ("log-level,l", make_defaulted_option(prover_options.log_level), "Log level (trace, debug, info, warning, error, fatal)") + ("elliptic-curve-type,e", make_defaulted_option(prover_options.elliptic_curve_type), "Elliptic curve type (pallas)") + ("hash-type", make_defaulted_option(prover_options.hash_type), "Hash type (keccak)") + ("lambda-param", make_defaulted_option(prover_options.lambda), "Lambda param (9)") + ("grind-param", make_defaulted_option(prover_options.grind), "Grind param (69)") + ("expand-factor", make_defaulted_option(prover_options.expand_factor), "Expand factor") + ("component-constant-columns", make_defaulted_option(prover_options.component_constant_columns), "Component constant columns") ("skip-verification", po::bool_switch(&prover_options.skip_verification), "Skip generated proof verifying step") ("verification-only", po::bool_switch(&prover_options.verification_only), "Read proof for verification instead of writing to it"); // clang-format on @@ -134,11 +124,6 @@ namespace nil { } } - if (vm.count("list-columns-params")) { - print_all_columns_params(); - return std::nullopt; - } - // Calling notify(vm) after handling no-op cases prevent parser from alarming // about absence of required args try { @@ -163,25 +148,6 @@ namespace nil { // >> and << operators are needed for Boost porgram_options to read values and // to print default values to help message: The rest of the file contains them: - std::ostream& operator<<(std::ostream& strm, const ColumnsParams& columns) { - auto it = std::find(all_columns_params.cbegin(), all_columns_params.cend(), columns); - strm << std::distance(all_columns_params.cbegin(), it); - return strm; - } - - std::istream& operator>>(std::istream& strm, ColumnsParams& columns) { - std::string str; - strm >> str; - std::size_t pos; - int idx = std::stoi(str, &pos); - if (pos < str.size() || idx < 0 || static_cast(idx) >= all_columns_params.size()) { - strm.setstate(std::ios_base::failbit); - } else { - columns = all_columns_params[idx]; - } - return strm; - } - std::ostream& operator<<(std::ostream& strm, const LambdaParam& lambda) { strm << static_cast(lambda); return strm; diff --git a/bin/proof-generator/src/main.cpp b/bin/proof-generator/src/main.cpp index 1a9515b3..407e39c4 100644 --- a/bin/proof-generator/src/main.cpp +++ b/bin/proof-generator/src/main.cpp @@ -23,26 +23,21 @@ #include #include -// #include #include #undef B0 using namespace nil::proof_generator; -template< - typename CurveType, - std::size_t ColumnsParamsIdx, - std::size_t LambdaParamIdx, - typename HashType, - std::size_t GridParamIdx> +template int run_prover(const nil::proof_generator::ProverOptions& prover_options) { auto prover_task = [&] { - auto prover = nil::proof_generator::Prover( + auto prover = nil::proof_generator::Prover( prover_options.circuit_file_path, prover_options.preprocessed_common_data_path, prover_options.assignment_table_file_path, prover_options.proof_file_path, + prover_options.component_constant_columns, prover_options.expand_factor ); bool prover_result; @@ -62,55 +57,42 @@ int run_prover(const nil::proof_generator::ProverOptions& prover_options) { // We could either make lambdas for generating Cartesian products of templates, // but this would lead to callback hell. Instead, we declare extra function for // each factor. Last declared function starts the chain. -template +template int grind_param_wrapper(const ProverOptions& prover_options) { int ret; auto run_prover_void = [&prover_options, &ret]() { - ret = run_prover(prover_options); + ret = run_prover(prover_options); }; generate_templates_from_array_for_runtime_check(prover_options.grind, run_prover_void); return ret; } -template +template int hash_wrapper(const ProverOptions& prover_options) { int ret; - auto run_prover_wrapper = [&prover_options, &ret]() { + auto run_prover_wrapper_void = [&prover_options, &ret]() { using HashType = typename HashTypeIdentity::type; - ret = grind_param_wrapper(prover_options); + ret = grind_param_wrapper(prover_options); }; - pass_variant_type_to_template_func(prover_options.hash_type, run_prover_wrapper); + pass_variant_type_to_template_func(prover_options.hash_type, run_prover_wrapper_void); return ret; } -template +template int lambda_param_wrapper(const ProverOptions& prover_options) { int ret; auto hash_wrapper_void = [&prover_options, &ret]() { - ret = hash_wrapper(prover_options); + ret = hash_wrapper(prover_options); }; generate_templates_from_array_for_runtime_check(prover_options.lambda, hash_wrapper_void); return ret; } -template -int columns_params_wrapper(const ProverOptions& prover_options) { - int ret; - auto columns_params_wrapper_void = [&prover_options, &ret]() { - ret = lambda_param_wrapper(prover_options); - }; - generate_templates_from_array_for_runtime_check( - prover_options.columns, - columns_params_wrapper_void - ); - return ret; -} - int curve_wrapper(const ProverOptions& prover_options) { int ret; auto curves_wrapper_void = [&prover_options, &ret]() { using CurveType = typename CurveTypeIdentity::type; - ret = columns_params_wrapper(prover_options); + ret = lambda_param_wrapper(prover_options); }; pass_variant_type_to_template_func(prover_options.elliptic_curve_type, curves_wrapper_void); return ret; diff --git a/cmake/modules b/cmake/modules index 5e742531..a016a421 160000 --- a/cmake/modules +++ b/cmake/modules @@ -1 +1 @@ -Subproject commit 5e7425312d9873958db838491883b9e218bb33c9 +Subproject commit a016a42163a58ef68bbde48082d0ddafe68b8e56 diff --git a/libs/actor/container b/libs/actor/container index e366de42..6106726b 160000 --- a/libs/actor/container +++ b/libs/actor/container @@ -1 +1 @@ -Subproject commit e366de4260bbdd39d237eacd6e63227f28461f3e +Subproject commit 6106726bfccad08a74c55b030bcce9a56d842e9b diff --git a/libs/actor/zk b/libs/actor/zk index 3afc1535..f12be386 160000 --- a/libs/actor/zk +++ b/libs/actor/zk @@ -1 +1 @@ -Subproject commit 3afc15359b3628ed1463b28ea6d298e6928a73df +Subproject commit f12be386c9ee8468f4d0e2673ef240c22d430d6f diff --git a/libs/crypto3 b/libs/crypto3 index f5332a79..97767b15 160000 --- a/libs/crypto3 +++ b/libs/crypto3 @@ -1 +1 @@ -Subproject commit f5332a7929ba9a645b911a4739ee6b86280f5d2f +Subproject commit 97767b1553b8304304390c2df520863a2666ee3f