diff --git a/include/nil/crypto3/zk/commitments/detail/polynomial/basic_fri.hpp b/include/nil/crypto3/zk/commitments/detail/polynomial/basic_fri.hpp index 5d2fde902..c70c04412 100644 --- a/include/nil/crypto3/zk/commitments/detail/polynomial/basic_fri.hpp +++ b/include/nil/crypto3/zk/commitments/detail/polynomial/basic_fri.hpp @@ -69,7 +69,8 @@ namespace nil { * */ template> + std::size_t Lambda, std::size_t M, bool UseGrinding = false, + typename GrindingType = nil::crypto3::zk::commitments::proof_of_work> struct basic_batched_fri { BOOST_STATIC_ASSERT_MSG(M == 2, "unsupported m value!"); diff --git a/include/nil/crypto3/zk/commitments/detail/polynomial/proof_of_work.hpp b/include/nil/crypto3/zk/commitments/detail/polynomial/proof_of_work.hpp index 5dd42f91c..b63bc0c4c 100644 --- a/include/nil/crypto3/zk/commitments/detail/polynomial/proof_of_work.hpp +++ b/include/nil/crypto3/zk/commitments/detail/polynomial/proof_of_work.hpp @@ -22,8 +22,8 @@ // SOFTWARE. //---------------------------------------------------------------------------// -#ifndef PROOF_OF_WORK_HPP -#define PROOF_OF_WORK_HPP +#ifndef CRYPTO3_PROOF_OF_WORK_HPP +#define CRYPTO3_PROOF_OF_WORK_HPP #include @@ -88,4 +88,4 @@ namespace nil { } } -#endif +#endif // CRYPTO3_PROOF_OF_WORK_HPP diff --git a/include/nil/crypto3/zk/snark/systems/plonk/placeholder/detail/transcript_initialization_context.hpp b/include/nil/crypto3/zk/snark/systems/plonk/placeholder/detail/transcript_initialization_context.hpp index d7cf467ff..c6fa7f79b 100644 --- a/include/nil/crypto3/zk/snark/systems/plonk/placeholder/detail/transcript_initialization_context.hpp +++ b/include/nil/crypto3/zk/snark/systems/plonk/placeholder/detail/transcript_initialization_context.hpp @@ -30,6 +30,8 @@ #include #include +#include + #include #include @@ -64,7 +66,6 @@ namespace nil { // All fields below this line must be included in the transcript initilization, including // static const fields. - constexpr static const std::size_t witness_columns = PlaceholderParamsType::witness_columns; constexpr static const std::size_t public_input_columns = PlaceholderParamsType::public_input_columns; constexpr static const std::size_t constant_columns = PlaceholderParamsType::constant_columns; @@ -86,8 +87,9 @@ namespace nil { }; template - void init_transcript( - transcript::fiat_shamir_heuristic_sequential& transcript, + typename transcript_hash_type::digest_type compute_constraint_system_with_params_hash( + const plonk_constraint_system &constraint_system, std::size_t rows_amount, std::size_t usable_rows_amount, const typename PlaceholderParamsType::commitment_scheme_type::params_type& commitment_params, @@ -104,15 +106,29 @@ namespace nil { using TTypeBase = nil::marshalling::field_type; using value_marshalling_type = nil::crypto3::marshalling::types::transcript_initialization_context< TTypeBase, nil::crypto3::zk::snark::detail::transcript_initialization_context>; - auto filled_val = nil::crypto3::marshalling::types::fill_transcript_initialization_context< + auto filled_context = nil::crypto3::marshalling::types::fill_transcript_initialization_context< Endianness, nil::crypto3::zk::snark::detail::transcript_initialization_context>(context); - std::vector cv(filled_val.length(), 0x00); + std::vector cv(filled_context.length(), 0x00); auto write_iter = cv.begin(); - nil::marshalling::status_type status = filled_val.write(write_iter, cv.size()); + nil::marshalling::status_type status = filled_context.write(write_iter, cv.size()); + BOOST_CHECK(status == nil::marshalling::status_type::success); + + // Append constraint_system to the buffer "cv". + using FieldType = typename PlaceholderParamsType::field_type; + using ConstraintSystem = plonk_constraint_system; + using constraint_system_marshalling_type = nil::crypto3::marshalling::types::plonk_constraint_system; + + auto filled_constraint_system = nil::crypto3::marshalling::types::fill_plonk_constraint_system(constraint_system); + cv.resize(filled_context.length() + filled_constraint_system.length(), 0x00); + + // Function write wants an lvalue as 1st parameter. + write_iter = cv.begin() + filled_context.length(); + status = filled_constraint_system.write(write_iter, filled_constraint_system.length()); + BOOST_CHECK(status == nil::marshalling::status_type::success); - // TODO(martun): uncomment this after fix. - // transcript(cv); + // Return hash of "cv", which contains concatenated constraint system and other initialization parameters. + return hash(cv); } } // namespace detail } // namespace snark diff --git a/include/nil/crypto3/zk/snark/systems/plonk/placeholder/preprocessor.hpp b/include/nil/crypto3/zk/snark/systems/plonk/placeholder/preprocessor.hpp index bfdaffa50..b937a9383 100644 --- a/include/nil/crypto3/zk/snark/systems/plonk/placeholder/preprocessor.hpp +++ b/include/nil/crypto3/zk/snark/systems/plonk/placeholder/preprocessor.hpp @@ -83,11 +83,11 @@ namespace nil { }; struct verification_key { - typename transcript_hash_type::digest_type constraint_system_hash; + typename transcript_hash_type::digest_type constraint_system_with_params_hash; commitment_type fixed_values_commitment; bool operator==(const verification_key &rhs) const { - return constraint_system_hash == rhs.constraint_system_hash && + return constraint_system_with_params_hash == rhs.constraint_system_with_params_hash && fixed_values_commitment == rhs.fixed_values_commitment; } @@ -98,7 +98,7 @@ namespace nil { std::string to_string() const{ std::stringstream ss; - ss << constraint_system_hash <<" " <, ParamsType::arithmetization_params::total_columns> c_rotations = columns_rotations(constraint_system, table_description); - // Push fixed values and marshalled circuit to transcript. - using Endianness = nil::marshalling::option::big_endian; - using TTypeBase = nil::marshalling::field_type; - using ConstraintSystem = plonk_constraint_system; - using value_marshalling_type = nil::crypto3::marshalling::types::plonk_constraint_system; + typename transcript_hash_type::digest_type constraint_system_with_params_hash = + nil::crypto3::zk::snark::detail::compute_constraint_system_with_params_hash( + constraint_system, + N_rows, + table_description.usable_rows_amount, + commitment_scheme.get_commitment_params(), + "Default application dependent transcript initialization string"); - auto filled_val = nil::crypto3::marshalling::types::fill_plonk_constraint_system(constraint_system); - std::vector cv(filled_val.length(), 0x00); - - // Function write wants an lvalue as 1st parameter. - auto write_iter = cv.begin(); - nil::marshalling::status_type status = filled_val.write(write_iter, cv.size()); - typename transcript_hash_type::digest_type circuit_hash = hash(cv); - - typename preprocessed_data_type::verification_key vk = {circuit_hash, public_commitments.fixed_values}; + typename preprocessed_data_type::verification_key vk = {constraint_system_with_params_hash, public_commitments.fixed_values}; typename preprocessed_data_type::common_data_type common_data ( std::move(public_commitments), std::move(c_rotations), N_rows, table_description.usable_rows_amount, max_gates_degree, vk ); transcript_type transcript(std::vector({})); - transcript(vk.constraint_system_hash); + transcript(vk.constraint_system_with_params_hash); transcript(vk.fixed_values_commitment); - nil::crypto3::zk::snark::detail::init_transcript( - transcript, - common_data.rows_amount, - common_data.usable_rows_amount, - commitment_scheme.get_commitment_params(), - "Default application dependent transcript initialization string" - ); - common_data.commitment_scheme_data = commitment_scheme.preprocess(transcript); + // Push circuit description to transcript preprocessed_data_type preprocessed_data({ std::move(public_polynomial_table), diff --git a/include/nil/crypto3/zk/snark/systems/plonk/placeholder/prover.hpp b/include/nil/crypto3/zk/snark/systems/plonk/placeholder/prover.hpp index ba90cb09f..0d88baa2b 100644 --- a/include/nil/crypto3/zk/snark/systems/plonk/placeholder/prover.hpp +++ b/include/nil/crypto3/zk/snark/systems/plonk/placeholder/prover.hpp @@ -131,21 +131,10 @@ namespace nil { , _is_lookup_enabled(constraint_system.lookup_gates().size() > 0) , transcript(std::vector({})) { - // 1. Add circuit definition to transcript - // transcript(short_description); - // Initialize transcript. - transcript(preprocessed_public_data.common_data.vk.constraint_system_hash); + transcript(preprocessed_public_data.common_data.vk.constraint_system_with_params_hash); transcript(preprocessed_public_data.common_data.vk.fixed_values_commitment); - nil::crypto3::zk::snark::detail::init_transcript( - transcript, - preprocessed_public_data.common_data.rows_amount, - preprocessed_public_data.common_data.usable_rows_amount, - _commitment_scheme.get_commitment_params(), - "Default application dependent transcript initialization string" - ); - // Setup commitment scheme. LPC adds an additional point here. _commitment_scheme.setup(transcript, preprocessed_public_data.common_data.commitment_scheme_data); } diff --git a/include/nil/crypto3/zk/snark/systems/plonk/placeholder/verifier.hpp b/include/nil/crypto3/zk/snark/systems/plonk/placeholder/verifier.hpp index 72cfd7092..acd227ef3 100644 --- a/include/nil/crypto3/zk/snark/systems/plonk/placeholder/verifier.hpp +++ b/include/nil/crypto3/zk/snark/systems/plonk/placeholder/verifier.hpp @@ -34,8 +34,11 @@ #include #include #include +#include +#include #include #include +#include namespace nil { namespace crypto3 { @@ -166,19 +169,10 @@ namespace nil { const plonk_constraint_system &constraint_system, commitment_scheme_type commitment_scheme ) { - // 1. Add circuit definition to transcript - // transcript(short_description); transcript::fiat_shamir_heuristic_sequential transcript(std::vector({})); - transcript(preprocessed_public_data.common_data.vk.constraint_system_hash); - transcript(preprocessed_public_data.common_data.vk.fixed_values_commitment); - nil::crypto3::zk::snark::detail::init_transcript( - transcript, - preprocessed_public_data.common_data.rows_amount, - preprocessed_public_data.common_data.usable_rows_amount, - commitment_scheme.get_commitment_params(), - "Default application dependent transcript initialization string" - ); + transcript(preprocessed_public_data.common_data.vk.constraint_system_with_params_hash); + transcript(preprocessed_public_data.common_data.vk.fixed_values_commitment); // Setup commitment scheme. LPC adds an additional point here. commitment_scheme.setup(transcript, preprocessed_public_data.common_data.commitment_scheme_data);