From f9b34c9c10a1df323768841d9674cf022adf296f Mon Sep 17 00:00:00 2001 From: "e.tatuzova" Date: Wed, 10 Apr 2024 19:32:43 +0400 Subject: [PATCH] Tests issues fixed #335 --- .../algebra/fields/plonk/non_native/range.hpp | 8 +- .../hashes/poseidon/plonk/poseidon.hpp | 2 +- .../systems/snark/plonk/flexible/poseidon.hpp | 2 +- .../systems/snark/plonk/flexible/swap.hpp | 228 ++++++------------ .../snark/plonk/verifier/proof_input_type.hpp | 55 +++-- .../systems/snark/plonk/verifier/verifier.hpp | 49 ++-- .../curves/plonk/variable_base_scalar_mul.cpp | 2 - test/component_batch.cpp | 73 +++--- test/verifiers/flexible/swap.cpp | 69 ++---- .../data/merkle_tree_poseidon/circuit.crct | Bin 88785 -> 88793 bytes .../data/merkle_tree_poseidon/common.dat | Bin 1432 -> 4264 bytes .../data/merkle_tree_poseidon/proof.bin | 2 +- test/verifiers/placeholder/verifier.cpp | 45 ++-- 13 files changed, 209 insertions(+), 326 deletions(-) diff --git a/include/nil/blueprint/components/algebra/fields/plonk/non_native/range.hpp b/include/nil/blueprint/components/algebra/fields/plonk/non_native/range.hpp index 329642a5a..45e01127c 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/non_native/range.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/non_native/range.hpp @@ -263,10 +263,10 @@ namespace nil { using var = typename plonk_ed25519_range::var; std::size_t row = start_row_index; - bp.add_copy_constraint({var(component.W(0), static_cast(row), false), instance_input.input[0]}); - bp.add_copy_constraint({var(component.W(1), static_cast(row), false), instance_input.input[1]}); - bp.add_copy_constraint({var(component.W(2), static_cast(row), false), instance_input.input[2]}); - bp.add_copy_constraint({var(component.W(3), static_cast(row), false), instance_input.input[3]}); + if(var(component.W(0), static_cast(row), false) != instance_input.input[0]) bp.add_copy_constraint({var(component.W(0), static_cast(row), false), instance_input.input[0]}); + if(var(component.W(1), static_cast(row), false) != instance_input.input[1]) bp.add_copy_constraint({var(component.W(1), static_cast(row), false), instance_input.input[1]}); + if(var(component.W(2), static_cast(row), false) != instance_input.input[2]) bp.add_copy_constraint({var(component.W(2), static_cast(row), false), instance_input.input[2]}); + if(var(component.W(3), static_cast(row), false) != instance_input.input[3]) bp.add_copy_constraint({var(component.W(3), static_cast(row), false), instance_input.input[3]}); } template diff --git a/include/nil/blueprint/components/hashes/poseidon/plonk/poseidon.hpp b/include/nil/blueprint/components/hashes/poseidon/plonk/poseidon.hpp index fa9129889..0cc70c12e 100644 --- a/include/nil/blueprint/components/hashes/poseidon/plonk/poseidon.hpp +++ b/include/nil/blueprint/components/hashes/poseidon/plonk/poseidon.hpp @@ -378,7 +378,7 @@ namespace nil { // Proceed with care using var = typename plonk_poseidon::var; for (std::size_t i = 0; i < 3; i++) { - bp.add_copy_constraint({var(component.W(i), start_row_index), instance_input.input_state[i]}); + bp.add_copy_constraint({var(component.W(i), start_row_index, false), instance_input.input_state[i]}); } } diff --git a/include/nil/blueprint/components/systems/snark/plonk/flexible/poseidon.hpp b/include/nil/blueprint/components/systems/snark/plonk/flexible/poseidon.hpp index 57d339df7..ea05f3a7f 100644 --- a/include/nil/blueprint/components/systems/snark/plonk/flexible/poseidon.hpp +++ b/include/nil/blueprint/components/systems/snark/plonk/flexible/poseidon.hpp @@ -311,7 +311,7 @@ namespace nil { // Proceed with care using var = typename plonk_flexible_poseidon::var; for (std::size_t i = 0; i < 3; i++) { - bp.add_copy_constraint({var(component.W(i), start_row_index), instance_input.input_state[i]}); + bp.add_copy_constraint({var(component.W(i), start_row_index, false), instance_input.input_state[i]}); } } diff --git a/include/nil/blueprint/components/systems/snark/plonk/flexible/swap.hpp b/include/nil/blueprint/components/systems/snark/plonk/flexible/swap.hpp index c44a25cd3..6df5bba59 100644 --- a/include/nil/blueprint/components/systems/snark/plonk/flexible/swap.hpp +++ b/include/nil/blueprint/components/systems/snark/plonk/flexible/swap.hpp @@ -37,7 +37,7 @@ namespace nil { namespace blueprint { namespace components { - // Input: array of triples <, , ..., >, where bi -- is 0 or 1 + // Input: array of triples < // Output: array of pairs where if b_i == 0 => , else // b1, c1, d1, output1_0, output1_1, b2, c2, d2, output2_0, output2_1, ... template @@ -53,8 +53,6 @@ namespace nil { using var = typename component_type::var; using manifest_type = plonk_component_manifest; - std::size_t n; - class gate_manifest_type : public component_gate_manifest { public: std::uint32_t gates_amount() const override { @@ -63,101 +61,75 @@ namespace nil { }; static gate_manifest get_gate_manifest( - std::size_t witness_amount, - std::size_t n + std::size_t witness_amount ) { gate_manifest manifest = gate_manifest(gate_manifest_type()); return manifest; } - static manifest_type get_manifest(std::size_t n) { + static manifest_type get_manifest() { manifest_type manifest = manifest_type( - std::shared_ptr(new manifest_range_param(5, 5 * n + 1, 5)), + std::shared_ptr(new manifest_single_value_param(5)), false ); return manifest; } - constexpr static std::size_t get_rows_amount(std::size_t witness_amount, - std::size_t n) { - std::size_t cells = 5 * n; - std::size_t one_row_cells = (witness_amount / 5)*5; - return cells%one_row_cells == 0? cells/one_row_cells: cells/one_row_cells + 1; + constexpr static std::size_t get_rows_amount( + std::size_t witness_amount + ) { + return 1; } constexpr static const std::size_t gates_amount = 1; - const std::size_t rows_amount = get_rows_amount(this->witness_amount(), n); + const std::size_t rows_amount = get_rows_amount(this->witness_amount()); struct input_type { - std::vector> arr; // the array of pairs of elements + std::array inp; // the array of pairs of elements std::vector> all_vars() { std::vector> result; - for( std::size_t i = 0; i < arr.size(); i++ ){ - result.push_back(std::get<0>(arr[i])); - result.push_back(std::get<1>(arr[i])); - result.push_back(std::get<2>(arr[i])); - } + result.push_back(inp[0]); + result.push_back(inp[1]); + result.push_back(inp[2]); return result; } }; struct result_type { - std::vector> output; // the array with possibly swapped elements - std::size_t n; + std::array output; // the array with possibly swapped elements result_type(const flexible_swap &component, std::size_t start_row_index) { - const std::size_t witness_amount = component.witness_amount(); - const std::size_t rows_amount = component.rows_amount; - n = component.n; - - output.reserve(n); - std::size_t cur = 0; - for (std::size_t row = 0; row < rows_amount; row++) { - if( cur >= n ) break; - for(std::size_t block = 0; block < witness_amount / 5; block++, cur++ ){ - if( cur >= n ) break; - output.emplace_back( - std::make_pair( - var(component.W(block * 5 + 3), start_row_index + row, false), - var(component.W(block * 5 + 4), start_row_index + row, false) - ) - ); - } - } + output[0] = var(component.W(3), start_row_index, false); + output[1] = var(component.W(4), start_row_index, false); } std::vector> all_vars() { std::vector> result; - for( std::size_t i = 0; i < output.size(); i++ ){ - result.push_back(output[i].first); - result.push_back(output[i].second); - } + result.push_back(output[0]); + result.push_back(output[1]); return result; } }; template explicit flexible_swap(ContainerType witness, std::size_t _n) : - component_type(witness, {}, {}, get_manifest(_n)), - n(_n) {}; + component_type(witness, {}, {}, get_manifest()) {}; template flexible_swap(WitnessContainerType witness, ConstantContainerType constant, - PublicInputContainerType public_input, std::size_t _n) : - component_type(witness, constant, public_input, get_manifest(_n)), - n(_n) {}; + PublicInputContainerType public_input) : + component_type(witness, constant, public_input, get_manifest()){}; flexible_swap( std::initializer_list witnesses, std::initializer_list constants, std::initializer_list - public_inputs, - std::size_t _n) : - component_type(witnesses, constants, public_inputs, get_manifest(_n)), - n(_n) {}; + public_inputs) : + component_type(witnesses, constants, public_inputs, get_manifest()) + {}; }; template @@ -176,38 +148,38 @@ namespace nil { using component_type = plonk_flexible_swap; using value_type = typename BlueprintFieldType::value_type; + auto b = var_value(assignment, instance_input.inp[0]); + auto c = var_value(assignment, instance_input.inp[1]); + auto d = var_value(assignment, instance_input.inp[2]); + + assignment.witness(component.W(0), start_row_index) = b; + assignment.witness(component.W(1), start_row_index) = c; + assignment.witness(component.W(2), start_row_index) = d; + assignment.witness(component.W(3), start_row_index) = b == 0? c: d; + assignment.witness(component.W(4), start_row_index) = b == 0? d: c; + return typename component_type::result_type(component, start_row_index); + } - const std::size_t n = instance_input.arr.size(); - BOOST_ASSERT(component.n == instance_input.arr.size()); - const std::size_t witness_amount = component.witness_amount(); - const std::size_t rows_amount = component.rows_amount; - - std::size_t cur = 0; - for (std::size_t row = 0; row < rows_amount; row++) { - for (std::size_t block = 0; block < witness_amount/5; block++, cur++) { - if (cur < n) { - value_type b = var_value(assignment, std::get<0>(instance_input.arr[cur])); - value_type c = var_value(assignment, std::get<1>(instance_input.arr[cur])); - value_type d = var_value(assignment, std::get<2>(instance_input.arr[cur])); - BOOST_ASSERT(b == 0 || b == 1); - assignment.witness(component.W(block*5), start_row_index + row) = b; - assignment.witness(component.W(block*5 + 1), start_row_index + row) = c; - assignment.witness(component.W(block*5 + 2), start_row_index + row) = d; - assignment.witness(component.W(block*5 + 3), start_row_index + row) = b == 0? c: d; - assignment.witness(component.W(block*5 + 4), start_row_index + row) = b == 0? d: c; - } else { - assignment.witness(component.W(block*5), start_row_index + row) = 0; - assignment.witness(component.W(block*5 + 1), start_row_index + row) = 0; - assignment.witness(component.W(block*5 + 2), start_row_index + row) = 0; - assignment.witness(component.W(block*5 + 3), start_row_index + row) = 0; - assignment.witness(component.W(block*5 + 4), start_row_index + row) = 0; - } - } - for( std::size_t i = (witness_amount/5)*5; i + typename plonk_flexible_swap::result_type generate_empty_assignments( + const plonk_flexible_swap &component, + assignment> + &assignment, + const typename plonk_flexible_swap::input_type + &instance_input, + const std::uint32_t start_row_index) { + using component_type = plonk_flexible_swap; + using value_type = typename BlueprintFieldType::value_type; + auto b = var_value(assignment, instance_input.inp[0]); + auto c = var_value(assignment, instance_input.inp[1]); + auto d = var_value(assignment, instance_input.inp[2]); + + assignment.witness(component.W(0), start_row_index) = b; + assignment.witness(component.W(1), start_row_index) = c; + assignment.witness(component.W(2), start_row_index) = d; + assignment.witness(component.W(3), start_row_index) = b == 0? c: d; + assignment.witness(component.W(4), start_row_index) = b == 0? d: c; return typename component_type::result_type(component, start_row_index); } @@ -218,29 +190,23 @@ namespace nil { assignment> &assignment, const typename plonk_flexible_swap::input_type - &instance_input) { - + &instance_input + ) { using component_type = plonk_flexible_swap; using var = typename component_type::var; using constraint_type = crypto3::zk::snark::plonk_constraint; - BOOST_ASSERT(component.n == instance_input.arr.size()); - std::vector constraints; - constraints.reserve(component.n); - var t = var(component.W(0), 0, true); - const std::size_t witness_amount = component.witness_amount(); - for( std::size_t block = 0; block < witness_amount/5; block++ ) { - var input_b_var = var(component.W(block * 5), 0, true), - input_c_var = var(component.W(block * 5 + 1), 0, true), - input_d_var = var(component.W(block * 5 + 2), 0, true), - output0_var = var(component.W(block * 5 + 3), 0, true), - output1_var = var(component.W(block * 5 + 4), 0, true); - - constraints.emplace_back(input_b_var * (input_b_var - 1)); - constraints.emplace_back(output0_var - ((1-input_b_var) * input_c_var + input_b_var * input_d_var)); - constraints.emplace_back(output1_var - ((1-input_b_var) * input_d_var + input_b_var * input_c_var)); - } + + var input_b_var = var(component.W(0), 0, true), + input_c_var = var(component.W(1), 0, true), + input_d_var = var(component.W(2), 0, true), + output0_var = var(component.W(3), 0, true), + output1_var = var(component.W(4), 0, true); + + constraints.emplace_back(input_b_var * (input_b_var - 1)); + constraints.emplace_back(output0_var - ((1-input_b_var) * input_c_var + input_b_var * input_d_var)); + constraints.emplace_back(output1_var - ((1-input_b_var) * input_d_var + input_b_var * input_c_var)); return bp.add_gate(constraints); } @@ -258,24 +224,12 @@ namespace nil { using component_type = plonk_flexible_swap; using var = typename component_type::var; - BOOST_ASSERT(component.n == instance_input.arr.size()); - std::size_t n = instance_input.arr.size(); - const std::size_t witness_amount = component.witness_amount(); - const std::size_t rows_amount = component.rows_amount; - - std::size_t cur = 0; - for (std::size_t row = 0; row < rows_amount; row++) { - if(cur >= n) break; - for (std::size_t block = 0; block < witness_amount/5; block++, cur++) { - if(cur >= n) break; - bp.add_copy_constraint( - {std::get<0>(instance_input.arr[cur]), var(component.W(5*block), start_row_index + row, false)}); - bp.add_copy_constraint( - {std::get<1>(instance_input.arr[cur]), var(component.W(5*block+1), start_row_index + row, false)}); - bp.add_copy_constraint( - {std::get<2>(instance_input.arr[cur]), var(component.W(5*block+2), start_row_index + row, false)}); - } - } + bp.add_copy_constraint( + {std::get<0>(instance_input.inp), var(component.W(0), start_row_index, false)}); + bp.add_copy_constraint( + {std::get<1>(instance_input.inp), var(component.W(1), start_row_index, false)}); + bp.add_copy_constraint( + {std::get<2>(instance_input.inp), var(component.W(2), start_row_index, false)}); } template @@ -286,8 +240,8 @@ namespace nil { &assignment, const typename plonk_flexible_swap::input_type &instance_input, - const std::size_t start_row_index) { - + const std::size_t start_row_index + ) { using component_type = plonk_flexible_swap; std::size_t selector_index = generate_gates(component, bp, assignment, instance_input); @@ -297,40 +251,6 @@ namespace nil { return typename component_type::result_type(component, start_row_index); } - - template - typename plonk_flexible_swap::result_type - generate_empty_assignments( - const plonk_flexible_swap &component, - assignment> - &assignment, - const typename plonk_flexible_swap::input_type - instance_input, - const std::uint32_t start_row_index) { - - using value_type = typename BlueprintFieldType::value_type; - - const std::size_t n = instance_input.arr.size(); - BOOST_ASSERT(component.n == instance_input.arr.size()); - const std::size_t witness_amount = component.witness_amount(); - const std::size_t rows_amount = component.rows_amount; - - std::size_t cur = 0; - for (std::size_t row = 0; row < rows_amount; row++) { - for (std::size_t block = 0; block < witness_amount/5; block++, cur++) { - if (cur < n) { - value_type b = var_value(assignment, std::get<0>(instance_input.arr[cur])); - value_type c = var_value(assignment, std::get<1>(instance_input.arr[cur])); - value_type d = var_value(assignment, std::get<2>(instance_input.arr[cur])); - assignment.witness(component.W(block*5 + 3), start_row_index + row) = b == 0 ? c: d; - assignment.witness(component.W(block*5 + 4), start_row_index + row) = b == 0 ? d: c; - } - } - } - - return typename plonk_flexible_swap::result_type( - component, start_row_index); - } } // namespace components } // namespace blueprint } // namespace nil diff --git a/include/nil/blueprint/components/systems/snark/plonk/verifier/proof_input_type.hpp b/include/nil/blueprint/components/systems/snark/plonk/verifier/proof_input_type.hpp index ee11d8804..bb39663eb 100644 --- a/include/nil/blueprint/components/systems/snark/plonk/verifier/proof_input_type.hpp +++ b/include/nil/blueprint/components/systems/snark/plonk/verifier/proof_input_type.hpp @@ -61,7 +61,7 @@ namespace nil { placeholder_info = nil::crypto3::zk::snark::prepare_placeholder_info( constraint_system, common_data, fri_params, - PlaceholderParams::WitnessColumns + PlaceholderParams::PublicInputColumns + PlaceholderParams::ComponentConstantColumns + constraint_system.permuted_columns().size() ); fill_vector(); @@ -105,6 +105,8 @@ namespace nil { std::vector> _round_proof_hashes; void fill_vector() { + auto &desc = common_data.desc; + std::size_t cur = 0; _commitments.push_back(var(0, cur++, false, var::column_type::public_input)); var_vector.push_back(_commitments[0]); @@ -126,43 +128,52 @@ namespace nil { // Z-s // Fixed values batch. // Permutation polynomials - for(std::size_t i = 0; i < placeholder_info.permutation_size * 4; i++){ + std::cout << "placeholder_info.permutation_size = " << constraint_system.permuted_columns().size() << std::endl; + for(auto &column: constraint_system.permuted_columns()){ + std::cout << "Permuted column " << column << std::endl; + } + std::size_t permutation_size = constraint_system.permuted_columns().size(); + std::size_t points_num = 0; + for(std::size_t i = 0; i < permutation_size * 2; i++){ var_vector.push_back(var(0, cur++, false, var::column_type::public_input)); + points_num++; } // Special selectors var_vector.push_back(var(0, cur++, false, var::column_type::public_input)); var_vector.push_back(var(0, cur++, false, var::column_type::public_input)); var_vector.push_back(var(0, cur++, false, var::column_type::public_input)); var_vector.push_back(var(0, cur++, false, var::column_type::public_input)); - var_vector.push_back(var(0, cur++, false, var::column_type::public_input)); - var_vector.push_back(var(0, cur++, false, var::column_type::public_input)); + points_num += 4; //Constant columns - for( std::size_t i = 0; i < PlaceholderParams::ConstantColumns; i++){ - for( std::size_t j = 0; j < common_data.columns_rotations[PlaceholderParams::WitnessColumns + PlaceholderParams::PublicInputColumns + i].size(); j++){ + for( std::size_t i = 0; i < desc.constant_columns; i++){ + for( std::size_t j = 0; j < common_data.columns_rotations[desc.witness_columns + desc.public_input_columns + i].size(); j++){ var_vector.push_back(var(0, cur++, false, var::column_type::public_input)); + points_num++; } - var_vector.push_back(var(0, cur++, false, var::column_type::public_input)); } //Selector columns - for( std::size_t i = 0; i < PlaceholderParams::SelectorColumns; i++){ - for( std::size_t j = 0; j < common_data.columns_rotations[PlaceholderParams::WitnessColumns + PlaceholderParams::PublicInputColumns + PlaceholderParams::ConstantColumns + i].size(); j++){ + for( std::size_t i = 0; i < desc.selector_columns; i++){ + for( std::size_t j = 0; j < common_data.columns_rotations[desc.witness_columns + desc.public_input_columns + desc.public_input_columns + i].size(); j++){ var_vector.push_back(var(0, cur++, false, var::column_type::public_input)); + points_num++; } - var_vector.push_back(var(0, cur++, false, var::column_type::public_input)); } //Variable values //Witness columns - for( std::size_t i = 0; i < PlaceholderParams::WitnessColumns; i++){ + for( std::size_t i = 0; i < desc.witness_columns; i++){ for( std::size_t j = 0; j < common_data.columns_rotations[i].size(); j++){ var_vector.push_back(var(0, cur++, false, var::column_type::public_input)); + points_num++; } } //Public input columns - for( std::size_t i = 0; i < PlaceholderParams::PublicInputColumns; i++){ - for( std::size_t j = 0; j < common_data.columns_rotations[i + PlaceholderParams::WitnessColumns].size(); j++){ + for( std::size_t i = 0; i < desc.public_input_columns; i++){ + for( std::size_t j = 0; j < common_data.columns_rotations[i + desc.witness_columns].size(); j++){ var_vector.push_back(var(0, cur++, false, var::column_type::public_input)); + points_num++; } } + std::cout << "Proof input points num = " << points_num << std::endl; //Permutation Polynomials var_vector.push_back(var(0, cur++, false, var::column_type::public_input)); var_vector.push_back(var(0, cur++, false, var::column_type::public_input)); @@ -190,13 +201,13 @@ namespace nil { } // Query proofs - _merkle_tree_positions.resize(PlaceholderParams::Lambda); - _initial_proof_values.resize(PlaceholderParams::Lambda); - _initial_proof_hashes.resize(PlaceholderParams::Lambda); - _round_proof_values.resize(PlaceholderParams::Lambda); - _round_proof_hashes.resize(PlaceholderParams::Lambda); + _merkle_tree_positions.resize(fri_params.lambda); + _initial_proof_values.resize(fri_params.lambda); + _initial_proof_hashes.resize(fri_params.lambda); + _round_proof_values.resize(fri_params.lambda); + _round_proof_hashes.resize(fri_params.lambda); std::cout << "Poly input num = " << placeholder_info.poly_num << std::endl; - for( std::size_t i = 0; i < PlaceholderParams::Lambda; i++){ + for( std::size_t i = 0; i < fri_params.lambda; i++){ // Initial proof values _initial_proof_values[i] = {}; for( std::size_t j = 0; j < placeholder_info.poly_num; j++ ){ @@ -243,10 +254,10 @@ namespace nil { } } private: - common_data_type common_data; - constraint_system_type constraint_system; + const common_data_type &common_data; + const constraint_system_type &constraint_system; std::vector var_vector; - typename PlaceholderParams::fri_params_type fri_params; + const typename PlaceholderParams::fri_params_type &fri_params; placeholder_info_type placeholder_info; }; } diff --git a/include/nil/blueprint/components/systems/snark/plonk/verifier/verifier.hpp b/include/nil/blueprint/components/systems/snark/plonk/verifier/verifier.hpp index fee48a98d..95aefa9ad 100644 --- a/include/nil/blueprint/components/systems/snark/plonk/verifier/verifier.hpp +++ b/include/nil/blueprint/components/systems/snark/plonk/verifier/verifier.hpp @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include @@ -211,16 +211,17 @@ namespace nil { const typename SrcParams::fri_params_type &fri_params ): component_type(witnesses, constants, public_inputs, get_manifest()) { + auto &desc = common_data.desc; placeholder_info = nil::crypto3::zk::snark::prepare_placeholder_info( constraint_system, common_data, fri_params, - SrcParams::WitnessColumns + SrcParams::PublicInputColumns + SrcParams::ComponentConstantColumns + constraint_system.permuted_columns().size() ); rows_amount = 100000; // TODO: count rows carefully vk0 = common_data.vk.constraint_system_with_params_hash; vk1 = common_data.vk.fixed_values_commitment; fri_params_r = fri_params.r; - fri_params_lambda = SrcParams::Lambda; + fri_params_lambda = fri_params.lambda; fri_omega = fri_params.D[0]->get_domain_element(1); fri_domain_size = fri_params.D[0]->size(); fri_initial_merkle_proof_size = log2(fri_params.D[0]->m) - 1; @@ -380,7 +381,7 @@ namespace nil { for( std::size_t j = 0; j < component.fri_initial_merkle_proof_size; j++){ x_index_input.b.push_back(instance_input.merkle_tree_positions[i][j]); } - generate_assignments( + typename x_index_component_type::result_type x_index_output = generate_assignments( x_index_instance, assignment, x_index_input, row ); row += x_index_instance.rows_amount; @@ -403,7 +404,7 @@ namespace nil { colinear_checks_input.alphas.push_back(challenges.fri_alphas[j]); colinear_checks_input.bs.push_back(instance_input.merkle_tree_positions[i][instance_input.merkle_tree_positions[i].size() - j - 1]); } - generate_assignments( + typename colinear_checks_component_type::result_type colinear_checks_output = generate_assignments( colinear_checks_instance, assignment, colinear_checks_input, row ); row += colinear_checks_instance.rows_amount; @@ -431,16 +432,14 @@ namespace nil { poseidon_rows += poseidon_instance.rows_amount; merkle_leaf_rows += poseidon_instance.rows_amount; } -// std::cout << "Merkle leaf " << var_value(assignment, poseidon_output.output_state[2]) << std::endl; var hash_var = poseidon_output.output_state[2]; // std::cout << "First hash i = " << i << "; cur_hash = " << cur_hash << " = " << instance_input.initial_proof_hashes[i][cur_hash] << " = " << var_value(assignment, instance_input.initial_proof_hashes[i][cur_hash]) << std::endl; for( std::size_t k = 0; k < component.fri_initial_merkle_proof_size; k++){ swap_input_type swap_input; - swap_input.arr.push_back({instance_input.merkle_tree_positions[i][k], - instance_input.initial_proof_hashes[i][cur_hash], hash_var}); - auto swap_result = assignment.template add_input_to_batch_assignment( - swap_input, 1); - poseidon_input = {zero_var, swap_result.output[0].first, swap_result.output[0].second}; + swap_input.inp = {instance_input.merkle_tree_positions[i][k], instance_input.initial_proof_hashes[i][cur_hash], hash_var}; + auto swap_result = assignment.template add_input_to_batch( + swap_input, 0); + poseidon_input = {zero_var, swap_result.output[0], swap_result.output[1]}; poseidon_output = generate_assignments(poseidon_instance, assignment, poseidon_input, row); // std::cout << "\t(" // << var_value(assignment, poseidon_input.input_state[1]) << ", " @@ -469,11 +468,10 @@ namespace nil { merkle_proof_rows += poseidon_instance.rows_amount; for( std::size_t k = 0; k < component.fri_initial_merkle_proof_size - j; k++){ swap_input_type swap_input; - swap_input.arr.push_back({instance_input.merkle_tree_positions[i][k], - instance_input.round_proof_hashes[i][cur_hash], hash_var}); - auto swap_result = assignment.template add_input_to_batch_assignment( - swap_input, 1); - poseidon_input = {zero_var, swap_result.output[0].first, swap_result.output[0].second}; + swap_input.inp = {instance_input.merkle_tree_positions[i][k], instance_input.round_proof_hashes[i][cur_hash], hash_var}; + auto swap_result = assignment.template add_input_to_batch( + swap_input, 0); + poseidon_input = {zero_var, swap_result.output[0], swap_result.output[1]}; poseidon_output = generate_assignments(poseidon_instance, assignment, poseidon_input, row); row += poseidon_instance.rows_amount; poseidon_rows += poseidon_instance.rows_amount; @@ -621,7 +619,7 @@ namespace nil { for( std::size_t j = 0; j < component.fri_initial_merkle_proof_size; j++ ){ x_index_input.b.push_back(instance_input.merkle_tree_positions[i][j]); } - generate_circuit( + typename x_index_component_type::result_type x_index_output = generate_circuit( x_index_instance, bp, assignment, x_index_input, row ); row += x_index_instance.rows_amount; @@ -643,7 +641,7 @@ namespace nil { colinear_checks_input.alphas.push_back(challenges.fri_alphas[j]); colinear_checks_input.bs.push_back(instance_input.merkle_tree_positions[i][instance_input.merkle_tree_positions[i].size() - j - 1]); } - generate_circuit( + typename colinear_checks_component_type::result_type colinear_checks_output = generate_circuit( colinear_checks_instance, bp, assignment, colinear_checks_input, row ); row += colinear_checks_instance.rows_amount; @@ -667,11 +665,10 @@ namespace nil { var hash_var = poseidon_output.output_state[2]; for( std::size_t k = 0; k < component.fri_initial_merkle_proof_size; k++){ swap_input_type swap_input; - swap_input.arr.push_back({instance_input.merkle_tree_positions[i][k], - instance_input.initial_proof_hashes[i][cur_hash], hash_var}); - auto swap_result = assignment.template add_input_to_batch_circuit( + swap_input.inp = {instance_input.merkle_tree_positions[i][k], instance_input.initial_proof_hashes[i][cur_hash], hash_var}; + auto swap_result = assignment.template add_input_to_batch( swap_input, 1); - poseidon_input = {zero_var, swap_result.output[0].first, swap_result.output[0].second}; + poseidon_input = {zero_var, swap_result.output[0], swap_result.output[1]}; poseidon_output = generate_circuit(poseidon_instance, bp, assignment, poseidon_input, row); hash_var = poseidon_output.output_state[2]; cur_hash++; @@ -683,6 +680,7 @@ namespace nil { bp.add_copy_constraint({poseidon_output.output_state[2], instance_input.commitments[j-1]}); } // Compute y-s for first round + std::size_t round_merkle_proof_size = component.fri_initial_merkle_proof_size; // Round proofs cur = 0; cur_hash = 0; @@ -698,11 +696,10 @@ namespace nil { row += poseidon_instance.rows_amount; for( std::size_t k = 0; k < component.fri_initial_merkle_proof_size - j; k++){ swap_input_type swap_input; - swap_input.arr.push_back({instance_input.merkle_tree_positions[i][k], - instance_input.round_proof_hashes[i][cur_hash], hash_var}); - auto swap_result = assignment.template add_input_to_batch_circuit( + swap_input.inp = {instance_input.merkle_tree_positions[i][k], instance_input.round_proof_hashes[i][cur_hash], hash_var}; + auto swap_result = assignment.template add_input_to_batch( swap_input, 1); - poseidon_input = {zero_var, swap_result.output[0].first, swap_result.output[0].second}; + poseidon_input = {zero_var, swap_result.output[0], swap_result.output[1]}; poseidon_output = generate_circuit(poseidon_instance, bp, assignment, poseidon_input, row); row += poseidon_instance.rows_amount; hash_var = poseidon_output.output_state[2]; diff --git a/test/algebra/curves/plonk/variable_base_scalar_mul.cpp b/test/algebra/curves/plonk/variable_base_scalar_mul.cpp index e1fa05f4f..683630933 100644 --- a/test/algebra/curves/plonk/variable_base_scalar_mul.cpp +++ b/test/algebra/curves/plonk/variable_base_scalar_mul.cpp @@ -46,8 +46,6 @@ #include #include "../../../test_plonk_component.hpp" -#include "../../zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/profiling.hpp" - template void test_variable_base_scalar_mul ( const std::vector &public_input, diff --git a/test/component_batch.cpp b/test/component_batch.cpp index 28f357f00..129ae6839 100644 --- a/test/component_batch.cpp +++ b/test/component_batch.cpp @@ -54,10 +54,10 @@ struct compare_copy_constraints { bool operator()(const crypto3::zk::snark::plonk_copy_constraint &lhs, const crypto3::zk::snark::plonk_copy_constraint &rhs) const { crypto3::zk::snark::plonk_copy_constraint norm_lhs = - lhs.first < lhs.second ? lhs : std::make_pair(lhs.second, lhs.first); + lhs.first < lhs.second ? lhs : crypto3::zk::snark::plonk_copy_constraint(lhs.second, lhs.first); crypto3::zk::snark::plonk_copy_constraint norm_rhs = - rhs.first < rhs.second ? rhs : std::make_pair(rhs.second, rhs.first); - return norm_lhs < norm_rhs; + rhs.first < rhs.second ? rhs : crypto3::zk::snark::plonk_copy_constraint(rhs.second, rhs.first); + return norm_lhs.fist < norm_rhs.first || (norm_lhs.first == norm_rhs.first && norm_lhs.second < norm_rhs.second); } }; @@ -65,8 +65,16 @@ template bool compare_copy_constraint_vectors(const std::vector> &lhs, const std::vector> &rhs) { std::set, compare_copy_constraints> - lhs_set(lhs.begin(), lhs.end()), rhs_set(rhs.begin(), rhs.end()); - if (lhs_set.size() != lhs.size() || rhs_set.size() != rhs.size()) { + lhs_set, rhs_set; + + for( const auto &c: lhs ) { + lhs_set.insert(c); + } + for( const auto &c: rhs ) { + rhs_set.insert(c); + } + + if (lhs_set.size() != rhs_set.size() ) { return false; } return lhs_set == rhs_set; @@ -427,21 +435,18 @@ BOOST_AUTO_TEST_CASE(component_batch_params_test) { constexpr std::size_t size_small = 1; constexpr std::size_t size_big = 2; input_type input; - input.arr.push_back(std::make_tuple( - public_input_var_maker.binary_var(), public_input_var_maker(), public_input_var_maker())); - auto res_1 = assignment.add_input_to_batch_assignment(input, size_small); - input.arr = {}; - input.arr.push_back(std::make_tuple( - public_input_var_maker.binary_var(), public_input_var_maker(), public_input_var_maker())); - input.arr.push_back(std::make_tuple( - public_input_var_maker.binary_var(), public_input_var_maker(), public_input_var_maker())); - auto res_2 = assignment.add_input_to_batch_assignment(input, size_big); - input.arr = {}; - input.arr.push_back({public_input_var_maker.binary_var(), res_1.output[0].first, res_2.output[0].second}); - auto res_3 = assignment.add_input_to_batch_assignment(input, size_small); + + input.inp = {public_input_var_maker.binary_var(), public_input_var_maker(), public_input_var_maker()}; + auto res_1 = assignment.add_input_to_batch_assignment(input); + + input.inp = {public_input_var_maker.binary_var(), public_input_var_maker(), public_input_var_maker()}; + auto res_2 = assignment.add_input_to_batch_assignment(input); + + input.inp = {public_input_var_maker.binary_var(), res_1.output[0], res_2.output[1]}; + auto res_3 = assignment.add_input_to_batch_assignment(input); assignment.finalize_component_batches(circuit, 0); - BOOST_CHECK_EQUAL(circuit.gates().size(), 2); + BOOST_CHECK_EQUAL(circuit.gates().size(), 1); const auto &gate_1 = circuit.gates()[0]; BOOST_CHECK_EQUAL(gate_1.constraints.size(), 9); std::array expected_constraints = { @@ -460,34 +465,18 @@ BOOST_AUTO_TEST_CASE(component_batch_params_test) { BOOST_CHECK_EQUAL(gate_1.constraints[i], expected_constraints[i]); } - const auto &gate_2 = circuit.gates()[1]; - BOOST_CHECK_EQUAL(gate_2.constraints.size(), 6); - std::array expected_constraints_2 = { - var(0, 0) * (var(0, 0) - 1), - var(3, 0) - (((0 - (var(0, 0) - 1)) * var(1, 0)) + var(0, 0) * var(2, 0)), - var(4, 0) - (((0 - (var(0, 0) - 1)) * var(2, 0)) + var(0, 0) * var(1, 0)), - var(5, 0) * (var(5, 0) - 1), - var(8, 0) - (((0 - (var(5, 0) - 1)) * var(6, 0)) + var(5, 0) * var(7, 0)), - var(9, 0) - (((0 - (var(5, 0) - 1)) * var(7, 0)) + var(5, 0) * var(6, 0)), - }; - - for (std::size_t i = 0; i < gate_2.constraints.size(); ++i) { - BOOST_CHECK_EQUAL(gate_2.constraints[i], expected_constraints[i]); - } - const std::vector expected_copy_constraints = { {var(0, 0, false, var::column_type::public_input), var(0, 0, false, var::column_type::witness)}, {var(0, 1, false, var::column_type::public_input), var(1, 0, false, var::column_type::witness)}, {var(0, 2, false, var::column_type::public_input), var(2, 0, false, var::column_type::witness)}, - {var(0, 9, false, var::column_type::public_input), var(5, 0, false, var::column_type::witness)}, - {var(3, 0, false, var::column_type::witness), var(6, 0, false, var::column_type::witness)}, - {var(4, 1, false, var::column_type::witness), var(7, 0, false, var::column_type::witness)}, - {var(0, 3, false, var::column_type::public_input), var(0, 1, false, var::column_type::witness)}, - {var(0, 4, false, var::column_type::public_input), var(1, 1, false, var::column_type::witness)}, - {var(0, 5, false, var::column_type::public_input), var(2, 1, false, var::column_type::witness)}, - {var(0, 6, false, var::column_type::public_input), var(5, 1, false, var::column_type::witness)}, - {var(0, 7, false, var::column_type::public_input), var(6, 1, false, var::column_type::witness)}, - {var(0, 8, false, var::column_type::public_input), var(7, 1, false, var::column_type::witness)}, + + {var(0, 3, false, var::column_type::public_input), var(5, 0, false, var::column_type::witness)}, + {var(0, 4, false, var::column_type::public_input), var(6, 0, false, var::column_type::witness)}, + {var(0, 5, false, var::column_type::public_input), var(7, 0, false, var::column_type::witness)}, + + {var(0, 6, false, var::column_type::public_input), var(10, 0, false, var::column_type::witness)}, + {var(3, 0, false, var::column_type::witness), var(11, 0, false, var::column_type::witness)}, + {var(9, 0, false, var::column_type::witness), var(12, 0, false, var::column_type::witness)} }; BOOST_ASSERT(compare_copy_constraint_vectors(circuit.copy_constraints(), expected_copy_constraints)); diff --git a/test/verifiers/flexible/swap.cpp b/test/verifiers/flexible/swap.cpp index bb9a7ac7b..4bfb64cbe 100644 --- a/test/verifiers/flexible/swap.cpp +++ b/test/verifiers/flexible/swap.cpp @@ -45,9 +45,9 @@ using namespace nil; -template +template void test_flexible_swap( - const std::vector> &array + const std::array &input ){ constexpr std::size_t PublicInputColumns = 1; constexpr std::size_t ConstantColumns = 0; @@ -65,33 +65,24 @@ void test_flexible_swap( using component_type = blueprint::components::flexible_swap; typename component_type::input_type instance_input; - instance_input.arr.reserve(ArraySize); - for (std::size_t i = 0; i < ArraySize; i++) { - instance_input.arr.emplace_back(std::make_tuple( - var(0, 3*i, false, var::column_type::public_input), - var(0, 3*i+1, false, var::column_type::public_input), - var(0, 3*i+2, false, var::column_type::public_input) - )); - } + instance_input.inp[0] = var(0, 0, false, var::column_type::public_input); + instance_input.inp[1] = var(0, 1, false, var::column_type::public_input); + instance_input.inp[2] = var(0, 2, false, var::column_type::public_input); std::vector public_input; - for (std::size_t i = 0; i < ArraySize; i++) { - public_input.push_back(std::get<0>(array[i])); - public_input.push_back(std::get<1>(array[i])); - public_input.push_back(std::get<2>(array[i])); - } - - auto result_check = [&array](AssignmentType &assignment, - typename component_type::result_type &real_res) { - BOOST_ASSERT(real_res.output.size() == ArraySize); - for (std::size_t i = 0; i < ArraySize; i++) { - if( std::get<0>(array[i]) == 0){ - BOOST_ASSERT(var_value(assignment, real_res.output[i].first) == std::get<1>(array[i])); - BOOST_ASSERT(var_value(assignment, real_res.output[i].second) == std::get<2>(array[i])); - } else { - BOOST_ASSERT(var_value(assignment, real_res.output[i].first) == std::get<2>(array[i])); - BOOST_ASSERT(var_value(assignment, real_res.output[i].second) == std::get<1>(array[i])); - } + public_input.push_back(input[0]); + public_input.push_back(input[1]); + public_input.push_back(input[2]); + + auto result_check = [&public_input](AssignmentType &assignment, + typename component_type::result_type &real_res + ) { + if( public_input[0] == 0){ + BOOST_ASSERT(var_value(assignment, real_res.output[0]) == public_input[1]); + BOOST_ASSERT(var_value(assignment, real_res.output[1]) == public_input[2]); + } else { + BOOST_ASSERT(var_value(assignment, real_res.output[0]) == public_input[2]); + BOOST_ASSERT(var_value(assignment, real_res.output[1]) == public_input[1]); } }; @@ -101,10 +92,10 @@ void test_flexible_swap( } component_type component_instance = component_type(witnesses, std::array{0}, - std::array{0}, ArraySize); + std::array{0}); nil::crypto3::test_component (component_instance, desc, public_input, result_check, instance_input, - nil::blueprint::connectedness_check_type::type::STRONG, ArraySize); + nil::blueprint::connectedness_check_type::type::STRONG); } template @@ -114,25 +105,7 @@ void flexible_swap_tests() { boost::random::uniform_int_distribution<> t_dist(0, 1); for (std::size_t i = 0; i < RandomTestsAmount; i++) { - test_flexible_swap( - { - {t_dist(seed_seq), generate_random(), generate_random()}, - {t_dist(seed_seq), generate_random(), generate_random()}, - {t_dist(seed_seq), generate_random(), generate_random()} - } - ); - test_flexible_swap( - { - {t_dist(seed_seq), generate_random(), generate_random()}, - {t_dist(seed_seq), generate_random(), generate_random()}, - {t_dist(seed_seq), generate_random(), generate_random()}, - {t_dist(seed_seq), generate_random(), generate_random()}, - {t_dist(seed_seq), generate_random(), generate_random()}, - {t_dist(seed_seq), generate_random(), generate_random()}, - {t_dist(seed_seq), generate_random(), generate_random()}, - {t_dist(seed_seq), generate_random(), generate_random()} - } - ); + test_flexible_swap({t_dist(seed_seq), generate_random(), generate_random()}); } } diff --git a/test/verifiers/placeholder/data/merkle_tree_poseidon/circuit.crct b/test/verifiers/placeholder/data/merkle_tree_poseidon/circuit.crct index ac90a4d0b2045c4e72634381ed2b9e8aad49c8c0..851964834b70b64cce5d73da734a9c284bce0bee 100644 GIT binary patch delta 2592 zcmY+Ey>E_D9EP9M=zzo^@l`{Klu(;W)J79@(pN<-z6K0P3@V|+BSF++P*sb8vKdNs z5^1|iC}Riw19Ua`h;u!CpZoXTZ<_X;-*w;DIZyKT`7+bKIMaUXZF(|LZZ7Ii%8PYH zTfNPHH)#!vB;yV-8qT`K=yjQMr?Ku*TNb;tLmC>!`^AvFj!*G|xwR z)uh){gb|I;u$D-j-4&x(n)9}?DjCmzM-XXf7(Wt2`oN?QjYX32m>5oHlNGDZNBY#H z&s2mhN9)n^dQml;y%D4L%A8Zin#ub4Ukh^6&@i4CL;B97v&JIHcuowbv(HVI&qw;f zq@PrT)zRhQf*4X~-^J)Hn)9nMCAU@MZ-Ph#tLaiP@ozA#&lfF-Y>h@Z)1^U{70;f^9`oef?1kYv`W)TW0B0`v`Q>rw8a9mH*Q+n;w+1_K}8OX zD8-FpNS*Bvqu1FYEmD`UNaEZsmYrpCxK|MAZj7j-82 zC!$C%tBBOuh}d#3C+bhSQLidzB=b1k6vLTW%k!uEf=EZ~ruU3R66vTIQfCulI7iJn zo>}vJU__BVRuQSQmtyqBO*&~Tk~m+8;jEbchtqU1v1TZBl<~?&KCKFZc!48uHm@YT pDZA9Hu}I>a6T>-wTw7qgmXW?U=|?4Dk)#)|dZY_ujn1uU%YX8rY>NN@ delta 2583 zcmZYBQHV@Y0LJlqZf#0=5z~ZBl&G!M7PZ9#wJ%FVVcQfnr9>$riS~*lwIxL}Pvng@ zFBmUsACwZMHV;UO@}S6rXrIXW-!t>w`NpL7p7Xose-7Kd<9%mnzB6?3acJ);)`qP6 z;i8e{eIvJJGVXD!%UC{U&CN2V-G&PxQOAukqPr}*L&mh*HW^K~aT(2KDEPsL%wZv; zrfs-iM$~Oe7AZSx>rTs2TeqHb?x-2Jd0@86&r^$=IK$<998L6c+bK!y;LncFX?AV$&@I8O=twS&P^4 z&nh9KMre&32(^Mp@5XdrP4^Mm)Quz?mCx{&CsMeoUoy4{fxoeiy*Q(;9hXX~Hp9@e`(l(F8eBjZf- z)_g6a>Gs^-jssY|SBQSG=x2+%y_0cJw+}L!3-)~zehE40f^GOsM%3+xEJkyCJ>>R! za0`F!`^GW1_d~wA|1kMVZ5XEqY^f|BbikI&IOu3xoZk1mbMg@(BQSj!t&bo_|IO`TH}f{vSfrt!dHe YGTK{rUPi_3RI)lp`47)z`HeO8f8t|o4*&oF diff --git a/test/verifiers/placeholder/data/merkle_tree_poseidon/common.dat b/test/verifiers/placeholder/data/merkle_tree_poseidon/common.dat index b077d8c48730e3dc8f67c458677efae9d0b63e6e..76ebeac130c81566cfa78655ddd743c1cce4a319 100644 GIT binary patch literal 4264 zcmY#nN-6hCb(!uw{p6afJ+t*08h)$TaOtXW@XmdqKSk&z0|bOaX(lMmNF*Po4y1gP z4GFZ-a2O4T;hF~cAyEs@>&j5R3N*@ZLugnr!oZHE9ywe+|=-szPG4qP&v#r%w=(XleYgfvfsd~HrGEBa9y3E?^UfQ<2RO_1+IbGH63Estz z1mD@-xL<0tf2;EoPF7F0$8A}koK=_oc+M0k_lf0L$^NC&mY&@H)Fg50o`)t$o8E-B zEoXY^SbfV}uitCJqL)RF?U=HdemV#^A7ta>p5WWUk}>mnNr6i7&(|F@gI}I%(K>u* z$M41aR6nnK&zn;^OD))ATmJ)|3hdpyrZ|Pm_(FB#@rCOuq~;hzFg!P^*}Yauav#@8zQxmzG{rfr zUwTn0?A_;&rvH?UKJH*?w8>wU*wnDi^sT4iw`<+ko!K+J`llVfk?fQ&YrbQKSd;x8 zmFHaT6Zbxy`9h(^X0QCec?J?ClQI|ndd}g#&iMO7hDjPR@9PR``vSiHe{{O;sg`VP z@aFXsmzBHRo3wII?_1?p5k^TasEAv#Y}k?Mmkmr&u}_= zTKeA?*J`})=7gJ>2skU4=g%3|FgB2ZIN)P$CU+#lLg}oTB`Xj-nX>L zublkx?63FNSH+&yxWM?sNA1nsi;S*fxz}I5`F_3UNn+}vKyU986*Gn9nqUEoi?%kj z|MtTE$=31~i6uWh|E$(K!M%RD)1%1AkE%_ApPJa=(l;tT8UmvsFd72lzxI2*Fh27_ zCjaP#BHJC>XRG%c^!+JG?KCl5qIAoAvf-4y#p`sJZVpZqotPfJRQ2laA%Hss0BLgqKmY&$ literal 1432 zcmdO!eEXR18{_;}cF&%4A1PIMZW$Z& +#include +#include #include #include @@ -46,6 +48,8 @@ #include #include #include +#include +#include #include #include #include @@ -82,15 +86,6 @@ bool read_buffer_from_file(std::ifstream &ifile, std::vector &v) { struct default_zkllvm_params{ using field_type = typename crypto3::algebra::curves::pallas::base_field_type; - static constexpr std::size_t WitnessColumns = 15; - static constexpr std::size_t PublicInputColumns = 1; - static constexpr std::size_t ComponentConstantColumns = 5; - static constexpr std::size_t LookupConstantColumns = 30; - static constexpr std::size_t ConstantColumns = ComponentConstantColumns + LookupConstantColumns; - static constexpr std::size_t ComponentSelectorColumns = 50; - static constexpr std::size_t LookupSelectorColumns = 6; - static constexpr std::size_t SelectorColumns = ComponentSelectorColumns + LookupSelectorColumns; - using constraint_system_type = nil::crypto3::zk::snark::plonk_constraint_system; using table_description_type = @@ -103,7 +98,6 @@ struct default_zkllvm_params{ nil::crypto3::zk::snark::plonk_table; using ColumnsRotationsType = std::vector>; - static const std::size_t Lambda = 20;//ParametersPolicy::lambda; using poseidon_policy = nil::crypto3::hashes::detail::mina_poseidon_policy; using Hash = nil::crypto3::hashes::poseidon; using circuit_params = nil::crypto3::zk::snark::placeholder_circuit_params; @@ -111,7 +105,6 @@ struct default_zkllvm_params{ 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; @@ -147,7 +140,6 @@ struct default_zkllvm_params{ table_marshalling_type marshalled_table_data; auto read_iter = v.begin(); auto status = marshalled_table_data.read(read_iter, v.size()); - BOOST_ASSERT(status == nil::marshalling::status_type::success); auto [table_description, assignment_table] = nil::crypto3::marshalling::types::make_assignment_table( marshalled_table_data @@ -175,7 +167,6 @@ struct default_zkllvm_params{ circuit_marshalling_type marshalled_data; auto read_iter = v.begin(); auto status = marshalled_data.read(read_iter, v.size()); - BOOST_ASSERT(status == nil::marshalling::status_type::success); constraint_system = nil::crypto3::marshalling::types::make_plonk_constraint_system( marshalled_data ); @@ -183,7 +174,7 @@ struct default_zkllvm_params{ return constraint_system; } - static std::tuple load_common_data(std::string filename){ + static common_data_type load_common_data(std::string filename){ std::ifstream ifile; ifile.open(filename, std::ios_base::binary | std::ios_base::in); BOOST_ASSERT(ifile.is_open()); @@ -200,7 +191,6 @@ struct default_zkllvm_params{ common_data_marshalling_type marshalled_data; auto read_iter = v.begin(); auto status = marshalled_data.read(read_iter, v.size()); - BOOST_ASSERT(status == nil::marshalling::status_type::success); return nil::crypto3::marshalling::types::make_placeholder_common_data( marshalled_data ); @@ -217,8 +207,7 @@ struct default_zkllvm_params{ proof_marshalling_type marshalled_proof_data; auto read_iter = v.begin(); auto status = marshalled_proof_data.read(read_iter, v.size()); - BOOST_ASSERT(status == nil::marshalling::status_type::success); - return nil::crypto3::marshalling::types::make_placeholder_proof( + return nil::crypto3::marshalling::types::make_placeholder_proof( marshalled_proof_data ); } @@ -284,15 +273,13 @@ gen_test_proof( using field_type = typename SrcParams::field_type; auto fri_params = create_fri_params(std::ceil(std::log2(table_description.rows_amount)), 0); - std::size_t permutation_size = - table_description.witness_columns + table_description.public_input_columns + SrcParams::ComponentConstantColumns; typename SrcParams::lpc_scheme_type lpc_scheme(fri_params); std::cout <<"Preprocess public data" << std::endl; typename nil::crypto3::zk::snark::placeholder_public_preprocessor< field_type, src_placeholder_params>::preprocessed_data_type public_preprocessed_data = nil::crypto3::zk::snark::placeholder_public_preprocessor::process( - constraint_system, assignment_table.move_public_table(), table_description, lpc_scheme, permutation_size + constraint_system, assignment_table.move_public_table(), table_description, lpc_scheme ); std::cout <<"Preprocess private data" << std::endl; @@ -326,23 +313,27 @@ void test_flexible_verifier( const typename SrcParams::fri_params_type &fri_params ){ std::cout << "****************** Test flexible verifier with " << DstParams::WitnessColumns <<" witness rows ******************" << std::endl; + using src_placeholder_params = typename SrcParams::placeholder_params; using field_type = typename SrcParams::field_type; + using value_type = typename field_type::value_type; std::array witnesses; for (std::uint32_t i = 0; i < DstParams::WitnessColumns; i++) { witnesses[i] = i; } using component_type = nil::blueprint::components::plonk_flexible_verifier; + using var = crypto3::zk::snark::plonk_variable; - auto result_check = []( + bool expected_res = true; + auto result_check = [&expected_res]( typename DstParams::assignment_table_type &assignment, typename component_type::result_type &real_res) { return true; }; - nil::blueprint::components::detail::placeholder_proof_input_typefull_instance_input(common_data, constraint_system, fri_params); nil::blueprint::components::detail::placeholder_proof_wrapperproof_ext(common_data, proof); + std::size_t value_vector_size = proof_ext.vector().size(); std::cout << "value vector size = " << value_vector_size << std::endl; std::cout << "var vector size = " << full_instance_input.vector().size() << std::endl; @@ -379,10 +370,13 @@ void test_flexible_verifier( template void test_multiple_arithmetizations(std::string folder_name){ // auto table_description = SrcParams::load_table_description(folder_name + "/assignment.tbl"); + std::cout << "Start loading" << std::endl; auto constraint_system = SrcParams::load_circuit(folder_name + "/circuit.crct"); - auto [common_data, table_description] = SrcParams::load_common_data(folder_name + "/common.dat"); + std::cout << "Load constraint system" << std::endl; + auto common_data = SrcParams::load_common_data(folder_name + "/common.dat"); auto proof = SrcParams::load_proof(folder_name + "/proof.bin"); - auto fri_params = create_fri_params(std::ceil(std::log2(table_description.rows_amount)), 2); + auto table_description = common_data.desc; + auto fri_params = common_data.commitment_params; std::cout << "Usable rows = " << table_description.usable_rows_amount << std::endl; std::cout << "Rows amount = " << table_description.rows_amount << std::endl; @@ -390,6 +384,7 @@ void test_multiple_arithmetizations(std::string folder_name){ std::cout << "Public input amount = " << table_description.public_input_columns << std::endl; std::cout << "Constant amount = " << table_description.constant_columns << std::endl; std::cout << "Selector amount = " << table_description.selector_columns << std::endl; + std::cout << "Lambda = " << fri_params.lambda << std::endl; // auto [common_data, fri_params, proof] = gen_test_proof(constraint_system, table_description, assignment_table); @@ -402,7 +397,7 @@ void test_multiple_arithmetizations(std::string folder_name){ BOOST_AUTO_TEST_SUITE(blueprint_pallas_test_suite) BOOST_AUTO_TEST_CASE(basic_test) { - test_multiple_arithmetizations("../libs/crypto3/libs/blueprint/test/verifiers/placeholder/data/merkle_tree_poseidon"); + test_multiple_arithmetizations("../libs/blueprint/test/verifiers/placeholder/data/merkle_tree_poseidon"); } // TODO: add vesta tests