From 99c59873cf6b12875cac3c09424fac1edd3d2832 Mon Sep 17 00:00:00 2001 From: cblpok Date: Fri, 13 Jan 2023 02:21:36 +0300 Subject: [PATCH] minor changes #98 --- .../algebra/curves/pasta/plonk/endo_scalar.hpp | 8 ++++---- .../curves/pasta/plonk/unified_addition.hpp | 4 ++-- .../algebra/fields/plonk/exponentiation.hpp | 11 +++++------ .../algebra/fields/plonk/range_check.hpp | 17 ++++++++--------- .../systems/snark/plonk/kimchi/detail/limbs.hpp | 6 +++--- test/algebra/curves/plonk/endo_scalar.cpp | 2 +- test/algebra/curves/plonk/unified_addition.cpp | 2 +- test/algebra/fields/plonk/exponentiation.cpp | 6 +++--- test/algebra/fields/plonk/range_check.cpp | 2 +- test/verifiers/kimchi/sponge/oracles.cpp | 2 +- 10 files changed, 29 insertions(+), 31 deletions(-) diff --git a/include/nil/blueprint/components/algebra/curves/pasta/plonk/endo_scalar.hpp b/include/nil/blueprint/components/algebra/curves/pasta/plonk/endo_scalar.hpp index eb51bf113..f34590611 100644 --- a/include/nil/blueprint/components/algebra/curves/pasta/plonk/endo_scalar.hpp +++ b/include/nil/blueprint/components/algebra/curves/pasta/plonk/endo_scalar.hpp @@ -80,16 +80,16 @@ namespace nil { template class endo_scalar, CurveType, ScalarSize, 15>: - public component, 15, 0, 0> { + public component, 15, 0, 1> { using component_type = component< crypto3::zk::snark::plonk_constraint_system, - 15, 0, 0>; + 15, 0, 1>; - using var = typename component_type::var; using endo_params = endo_scalar_params; public: + using var = typename component_type::var; constexpr static const std::size_t rows_amount = 8; constexpr static const std::size_t gates_amount = 2; @@ -247,7 +247,7 @@ namespace nil { const std::size_t first_selector_index) { using F = typename BlueprintFieldType::value_type; - using var = nil::crypto3::zk::snark::plonk_variable; + using var = typename plonk_endo_scalar::var; std::size_t selector_index_1 = first_selector_index; std::size_t selector_index_2 = first_selector_index + 1; diff --git a/include/nil/blueprint/components/algebra/curves/pasta/plonk/unified_addition.hpp b/include/nil/blueprint/components/algebra/curves/pasta/plonk/unified_addition.hpp index df5b4efda..19b0e7a68 100644 --- a/include/nil/blueprint/components/algebra/curves/pasta/plonk/unified_addition.hpp +++ b/include/nil/blueprint/components/algebra/curves/pasta/plonk/unified_addition.hpp @@ -47,7 +47,7 @@ namespace nil { class unified_addition, CurveType, 11>: public component, - 11,0,0> { + 11,0,1> { static_assert(std::is_same::value); @@ -55,7 +55,7 @@ namespace nil { using component_type = component< crypto3::zk::snark::plonk_constraint_system, - WitnessAmount,0,0>; + WitnessAmount,0,1>; public: diff --git a/include/nil/blueprint/components/algebra/fields/plonk/exponentiation.hpp b/include/nil/blueprint/components/algebra/fields/plonk/exponentiation.hpp index 3df8308e6..a2922d895 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/exponentiation.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/exponentiation.hpp @@ -67,16 +67,16 @@ namespace nil { 15 >: public component, - 15, 0, 0> { + 15, 1, 1> { using component_type = component< crypto3::zk::snark::plonk_constraint_system, - 15, 0, 0>; + 15, 1, 1>; - using var = typename component_type::var; constexpr static const std::size_t witness_amount = 15; constexpr static const std::size_t reserved_witnesses = 2; // base, accumulated_n public: + using var = typename component_type::var; constexpr static const std::size_t intermediate_start = 0 + reserved_witnesses; constexpr static const std::size_t bits_per_intermediate_result = 2; // defines @@ -246,8 +246,7 @@ namespace nil { const typename plonk_exponentiation::input_type instance_input, const std::size_t first_selector_index) { - using var = nil::crypto3::zk::snark::plonk_variable; - + using var = typename plonk_exponentiation::var; typename BlueprintFieldType::value_type exponent_shift = 2; exponent_shift = power(exponent_shift, component.bits_per_row); @@ -297,7 +296,7 @@ namespace nil { const typename plonk_exponentiation::input_type instance_input, const std::uint32_t start_row_index) { - using var = nil::crypto3::zk::snark::plonk_variable; + using var = typename plonk_exponentiation::var; var zero(component.W(0), start_row_index, false, var::column_type::constant); var one(component.W(0), start_row_index + 1, false, var::column_type::constant); diff --git a/include/nil/blueprint/components/algebra/fields/plonk/range_check.hpp b/include/nil/blueprint/components/algebra/fields/plonk/range_check.hpp index ab43ec9d8..b85e0f50f 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/range_check.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/range_check.hpp @@ -58,14 +58,13 @@ namespace nil { // The last sum = x template class range_check, R, 15>: - public component,15,0,0> { + public component,15,1,1> { - using component_type = component, 15, 0, 0>; - - using var = typename component_type::var; + using component_type = component, 15, 1, 1>; constexpr static const std::size_t witness_amount = 15; public: + using var = typename component_type::var; constexpr static const std::size_t chunk_size = 2; constexpr static const std::size_t reserved_columns = 1; constexpr static const std::size_t chunks_per_row = witness_amount - reserved_columns; @@ -205,9 +204,9 @@ namespace nil { const typename plonk_range_check::input_type &instance_input, const std::size_t first_selector_index) { - using var = nil::crypto3::zk::snark::plonk_variable; + using var = typename plonk_range_check::var; - typename BlueprintFieldType::value_type base_two = 2; //TODO + typename BlueprintFieldType::value_type base_two = 2; std::vector> constraints; @@ -248,7 +247,7 @@ namespace nil { const typename plonk_range_check::input_type &instance_input, const std::uint32_t start_row_index) { - using var = nil::crypto3::zk::snark::plonk_variable; + using var = typename plonk_range_check::var; var zero(0, start_row_index, false, var::column_type::constant); bp.add_copy_constraint({zero, var(component.W(0), start_row_index, false)}); @@ -267,10 +266,10 @@ namespace nil { const typename plonk_range_check::input_type &instance_input, const std::uint32_t start_row_index) { - using var = nil::crypto3::zk::snark::plonk_variable; + using var = typename plonk_range_check::var; std::size_t row = start_row_index; - assignment.constant(component.W(0), row) = 0; + assignment.constant(component.C(0), row) = 0; } } // namespace components diff --git a/include/nil/blueprint/components/systems/snark/plonk/kimchi/detail/limbs.hpp b/include/nil/blueprint/components/systems/snark/plonk/kimchi/detail/limbs.hpp index ad765738e..b6fe2a75a 100644 --- a/include/nil/blueprint/components/systems/snark/plonk/kimchi/detail/limbs.hpp +++ b/include/nil/blueprint/components/systems/snark/plonk/kimchi/detail/limbs.hpp @@ -58,9 +58,9 @@ namespace nil { template class from_limbs, 3>: public component, - 3, 0, 0> { + 3, 0, 1> { - using component_type = component, 3, 0, 0>; + using component_type = component, 3, 0, 1>; public: @@ -159,7 +159,7 @@ namespace nil { const typename plonk_from_limbs::input_type &instance_input, const std::size_t first_selector_index) { - using var = nil::crypto3::zk::snark::plonk_variable; + using var = typename plonk_from_limbs::var; typename BlueprintFieldType::value_type scalar = 2; auto constraint_1 = bp.add_constraint(var(component.W(0), 0) + var(component.W(1), 0) * scalar.pow(64) - var(component.W(2), 0)); diff --git a/test/algebra/curves/plonk/endo_scalar.cpp b/test/algebra/curves/plonk/endo_scalar.cpp index 499bb2aae..0640fb108 100644 --- a/test/algebra/curves/plonk/endo_scalar.cpp +++ b/test/algebra/curves/plonk/endo_scalar.cpp @@ -75,7 +75,7 @@ void test_endo_scalar(std::vector (component_instance, public_input, result_check, instance_input); } diff --git a/test/algebra/curves/plonk/unified_addition.cpp b/test/algebra/curves/plonk/unified_addition.cpp index acdcbbe66..bbc7ed280 100644 --- a/test/algebra/curves/plonk/unified_addition.cpp +++ b/test/algebra/curves/plonk/unified_addition.cpp @@ -76,7 +76,7 @@ void test_unified_addition(std::vector( component_instance, public_input, result_check, instance_input); diff --git a/test/algebra/fields/plonk/exponentiation.cpp b/test/algebra/fields/plonk/exponentiation.cpp index 82635537c..263d0fb81 100644 --- a/test/algebra/fields/plonk/exponentiation.cpp +++ b/test/algebra/fields/plonk/exponentiation.cpp @@ -72,7 +72,7 @@ void test_exponentiation(std::vector (component_instance, public_input, result_check, instance_input); @@ -99,7 +99,7 @@ BOOST_AUTO_TEST_CASE(blueprint_plonk_exponentiation) { test_exponentiation(public_input, expected_result); auto duration = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - start); - std::cout << "base_scalar_mul: " << duration.count() << "ms" << std::endl; + std::cout << "exponentiation_test: " << duration.count() << "ms" << std::endl; } BOOST_AUTO_TEST_CASE(blueprint_plonk_exponentiation_2) { @@ -118,7 +118,7 @@ BOOST_AUTO_TEST_CASE(blueprint_plonk_exponentiation_2) { test_exponentiation(public_input, expected_result); auto duration = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - start); - std::cout << "base_scalar_mul: " << duration.count() << "ms" << std::endl; + std::cout << "exponentiation_test: " << duration.count() << "ms" << std::endl; } BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test/algebra/fields/plonk/range_check.cpp b/test/algebra/fields/plonk/range_check.cpp index 8f3b33829..d632776c8 100644 --- a/test/algebra/fields/plonk/range_check.cpp +++ b/test/algebra/fields/plonk/range_check.cpp @@ -66,7 +66,7 @@ void test_range_check(std::vector publi typename component_type::result_type &real_res) { }; - component_type component_instance({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14},{},{}); + component_type component_instance({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14},{0},{0}); nil::crypto3::test_component (component_instance, public_input, result_check, instance_input); diff --git a/test/verifiers/kimchi/sponge/oracles.cpp b/test/verifiers/kimchi/sponge/oracles.cpp index 360a2916e..4cfd4b28b 100644 --- a/test/verifiers/kimchi/sponge/oracles.cpp +++ b/test/verifiers/kimchi/sponge/oracles.cpp @@ -72,7 +72,7 @@ void test_from_limbs(std::vector public assert(expected_res == var_value(assignment, real_res.result)); }; - component_type component_instance({0, 1, 2}, {}, {}); + component_type component_instance({0, 1, 2}, {}, {0}); nil::crypto3::test_component (component_instance, public_input, result_check, instance_input);