diff --git a/include/nil/blueprint/components/algebra/curves/edwards/plonk/non_native/bool_scalar_multiplication.hpp b/include/nil/blueprint/components/algebra/curves/edwards/plonk/non_native/bool_scalar_multiplication.hpp index 086017c37..4b6515654 100644 --- a/include/nil/blueprint/components/algebra/curves/edwards/plonk/non_native/bool_scalar_multiplication.hpp +++ b/include/nil/blueprint/components/algebra/curves/edwards/plonk/non_native/bool_scalar_multiplication.hpp @@ -57,6 +57,19 @@ namespace nil { using var = typename component_type::var; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return bool_scalar_multiplication::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = gate_manifest(gate_manifest_type()); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr( @@ -71,11 +84,6 @@ namespace nil { return 2; } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount; - } - const std::size_t rows_amount = get_rows_amount(this->witness_amount(), 0); constexpr static const std::size_t gates_amount = 1; diff --git a/include/nil/blueprint/components/algebra/curves/edwards/plonk/non_native/complete_addition.hpp b/include/nil/blueprint/components/algebra/curves/edwards/plonk/non_native/complete_addition.hpp index 7be9c7fa1..ac8010736 100644 --- a/include/nil/blueprint/components/algebra/curves/edwards/plonk/non_native/complete_addition.hpp +++ b/include/nil/blueprint/components/algebra/curves/edwards/plonk/non_native/complete_addition.hpp @@ -38,7 +38,7 @@ namespace nil { namespace components { template + typename NonNativePolicyType> class complete_addition; template, CurveType, Ed25519Type, - 9, basic_non_native_policy>: - public plonk_component { + public plonk_component { - constexpr static const std::uint32_t WitnessesAmount = 9; - constexpr static const std::uint32_t ConstantsAmount = 1; - - using component_type = plonk_component; + using component_type = plonk_component; + constexpr static std::size_t rows_amount_internal(std::size_t witness_amount) { + return + 2 * non_native_range_component::get_rows_amount(witness_amount, 0) + + 8 * multiplication_component::get_rows_amount(witness_amount, 0) + + 3 * addition_component::get_rows_amount(witness_amount, 0) + + subtraction_component::get_rows_amount(witness_amount, 0); + } public: using var = typename component_type::var; + using manifest_type = typename component_type::manifest_type; using non_native_policy_type = basic_non_native_policy; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return complete_addition::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = + gate_manifest(gate_manifest_type()) + .merge_with( + non_native_range_component::get_gate_manifest(witness_amount, lookup_column_amount)) + .merge_with(multiplication_component::get_gate_manifest(witness_amount, lookup_column_amount)) + .merge_with(addition_component::get_gate_manifest(witness_amount, lookup_column_amount)) + .merge_with(subtraction_component::get_gate_manifest(witness_amount, lookup_column_amount)); + + return manifest; + } + + static manifest_type get_manifest() { + static manifest_type manifest = manifest_type( + std::shared_ptr(new manifest_single_value_param(9)), + true + ).merge_with(multiplication_component::get_manifest()) + .merge_with(addition_component::get_manifest()) + .merge_with(subtraction_component::get_manifest()) + .merge_with(non_native_range_component::get_manifest()); + return manifest; + } + + constexpr static std::size_t get_rows_amount(std::size_t witness_amount, + std::size_t lookup_column_amount) { + return rows_amount_internal(witness_amount); + } + typedef crypto3::zk::snark::plonk_constraint_system ArithmetizationType; using non_native_range_component = components::range< - ArithmetizationType, typename Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, typename Ed25519Type::base_field_type, non_native_policy_type>; using multiplication_component = multiplication< - ArithmetizationType, typename Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, typename Ed25519Type::base_field_type, non_native_policy_type>; using addition_component = addition< - ArithmetizationType, typename Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, typename Ed25519Type::base_field_type, non_native_policy_type>; using subtraction_component = subtraction< - ArithmetizationType, typename Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, typename Ed25519Type::base_field_type, non_native_policy_type>; - constexpr static const std::size_t rows_amount = - 2 * non_native_range_component::rows_amount + 8 * multiplication_component::rows_amount + - 3 * addition_component::rows_amount + subtraction_component::rows_amount; + const std::size_t rows_amount = rows_amount_internal(this->witness_amount()); constexpr static const std::size_t gates_amount = 0; @@ -100,28 +138,28 @@ namespace nil { var(component.W(1), start_row_index, false), var(component.W(2), start_row_index, false), var(component.W(3), start_row_index, false)}; - output.y = {var(component.W(0), start_row_index + non_native_range_component::rows_amount, false), - var(component.W(1), start_row_index + non_native_range_component::rows_amount, false), - var(component.W(2), start_row_index + non_native_range_component::rows_amount, false), - var(component.W(3), start_row_index + non_native_range_component::rows_amount, false)}; + std::size_t non_native_range_component_rows_amount = + non_native_range_component::get_rows_amount(component.witness_amount(), 0); + output.y = { + var(component.W(0), start_row_index + non_native_range_component_rows_amount, false), + var(component.W(1), start_row_index + non_native_range_component_rows_amount, false), + var(component.W(2), start_row_index + non_native_range_component_rows_amount, false), + var(component.W(3), start_row_index + non_native_range_component_rows_amount, false)}; } }; - template - complete_addition(ContainerType witness) : component_type(witness, {}, {}) {}; - template complete_addition(WitnessContainerType witness, ConstantContainerType constant, PublicInputContainerType public_input) : - component_type(witness, constant, public_input) {}; + component_type(witness, constant, public_input, get_manifest()) {}; complete_addition(std::initializer_list witnesses, std::initializer_list constants, std::initializer_list public_inputs) : - component_type(witnesses, constants, public_inputs) {}; + component_type(witnesses, constants, public_inputs, get_manifest()) {}; }; template @@ -129,7 +167,6 @@ namespace nil { crypto3::zk::snark::plonk_constraint_system, CurveType, typename crypto3::algebra::curves::ed25519, - 9, basic_non_native_policy>; template @@ -150,13 +187,13 @@ namespace nil { using Ed25519Type = typename crypto3::algebra::curves::ed25519; using non_native_range_component = components::range< - ArithmetizationType, Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, Ed25519Type::base_field_type, non_native_policy_type>; using multiplication_component = multiplication< - ArithmetizationType, Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, Ed25519Type::base_field_type, non_native_policy_type>; using addition_component = addition< - ArithmetizationType, Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, Ed25519Type::base_field_type, non_native_policy_type>; using subtraction_component = subtraction< - ArithmetizationType, Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, Ed25519Type::base_field_type, non_native_policy_type>; non_native_range_component non_native_range_instance( {component.W(0), component.W(1), component.W(2), component.W(3), component.W(4), @@ -251,7 +288,7 @@ namespace nil { generate_assignments(non_native_range_instance, assignment, typename non_native_range_component::input_type({P_x}), row); - row += non_native_range_component::rows_amount; + row += non_native_range_instance.rows_amount; assignment.witness(component.W(1), row) = y3[1]; assignment.witness(component.W(0), row) = y3[0]; @@ -265,42 +302,42 @@ namespace nil { generate_assignments(non_native_range_instance, assignment, typename non_native_range_component::input_type({P_y}), row); - row += non_native_range_component::rows_amount; + row += non_native_range_instance.rows_amount; typename multiplication_component::result_type t0 = generate_assignments( multiplication_instance, assignment, typename multiplication_component::input_type({T_x, R_y}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; typename multiplication_component::result_type t1 = generate_assignments( multiplication_instance, assignment, typename multiplication_component::input_type({T_y, R_x}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; typename multiplication_component::result_type t2 = generate_assignments( multiplication_instance, assignment, typename multiplication_component::input_type({T_x, R_x}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; typename multiplication_component::result_type t3 = generate_assignments( multiplication_instance, assignment, typename multiplication_component::input_type({T_y, R_y}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; typename addition_component::result_type z0 = generate_assignments( addition_instance, assignment, typename addition_component::input_type({t0.output, t1.output}), row); - row += addition_component::rows_amount; + row += addition_instance.rows_amount; typename addition_component::result_type z1 = generate_assignments( addition_instance, assignment, typename addition_component::input_type({t2.output, t3.output}), row); - row += addition_component::rows_amount; + row += addition_instance.rows_amount; typename multiplication_component::result_type z2 = generate_assignments( multiplication_instance, assignment, typename multiplication_component::input_type({t0.output, t1.output}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; typename Ed25519Type::base_field_type::integral_type d = typename Ed25519Type::base_field_type::integral_type( @@ -313,27 +350,27 @@ namespace nil { typename multiplication_component::result_type k0 = generate_assignments( multiplication_instance, assignment, typename multiplication_component::input_type({d_var_array, z2.output}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; typename multiplication_component::result_type k1 = generate_assignments( multiplication_instance, assignment, typename multiplication_component::input_type({P_x, k0.output}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; typename multiplication_component::result_type k2 = generate_assignments( multiplication_instance, assignment, typename multiplication_component::input_type({P_y, k0.output}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; typename addition_component::result_type k3 = generate_assignments( addition_instance, assignment, typename addition_component::input_type({P_x, k1.output}), row); - row += addition_component::rows_amount; + row += addition_instance.rows_amount; typename subtraction_component::result_type k4 = generate_assignments( subtraction_instance, assignment, typename subtraction_component::input_type({P_y, k2.output}), row); - row += subtraction_component::rows_amount; + row += subtraction_instance.rows_amount; return typename plonk_ed25519_complete_addition::result_type(component, start_row_index); } @@ -357,13 +394,13 @@ namespace nil { using Ed25519Type = typename crypto3::algebra::curves::ed25519; using non_native_range_component = components::range< - ArithmetizationType, Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, Ed25519Type::base_field_type, non_native_policy_type>; using multiplication_component = multiplication< - ArithmetizationType, Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, Ed25519Type::base_field_type, non_native_policy_type>; using addition_component = addition< - ArithmetizationType, Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, Ed25519Type::base_field_type, non_native_policy_type>; using subtraction_component = subtraction< - ArithmetizationType, Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, Ed25519Type::base_field_type, non_native_policy_type>; non_native_range_component non_native_range_instance( {component.W(0), component.W(1), component.W(2), component.W(3), component.W(4), @@ -390,7 +427,7 @@ namespace nil { generate_circuit(non_native_range_instance, bp, assignment, typename non_native_range_component::input_type({P_x}), row); - row += non_native_range_component::rows_amount; + row += non_native_range_instance.rows_amount; std::array P_y = { var(component.W(0), row), @@ -400,7 +437,7 @@ namespace nil { generate_circuit(non_native_range_instance, bp, assignment, typename non_native_range_component::input_type({P_y}), row); - row += non_native_range_component::rows_amount; + row += non_native_range_instance.rows_amount; std::array R_x = instance_input.R.x; std::array R_y = instance_input.R.y; @@ -410,37 +447,37 @@ namespace nil { typename multiplication_component::result_type t0 = generate_circuit( multiplication_instance, bp, assignment, typename multiplication_component::input_type({T_x, R_y}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; typename multiplication_component::result_type t1 = generate_circuit( multiplication_instance, bp, assignment, typename multiplication_component::input_type({T_y, R_x}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; typename multiplication_component::result_type t2 = generate_circuit( multiplication_instance, bp, assignment, typename multiplication_component::input_type({T_x, R_x}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; typename multiplication_component::result_type t3 = generate_circuit( multiplication_instance, bp, assignment, typename multiplication_component::input_type({T_y, R_y}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; typename addition_component::result_type z0 = generate_circuit( addition_instance, bp, assignment, typename addition_component::input_type({t0.output, t1.output}), row); - row += addition_component::rows_amount; + row += addition_instance.rows_amount; typename addition_component::result_type z1 = generate_circuit( addition_instance, bp, assignment, typename addition_component::input_type({t2.output, t3.output}), row); - row += addition_component::rows_amount; + row += addition_instance.rows_amount; typename multiplication_component::result_type z2 = generate_circuit( multiplication_instance, bp, assignment, typename multiplication_component::input_type({t0.output, t1.output}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; std::array d_var_array = {var(component.C(0), row + 4, false, var::column_type::constant), var(component.C(0), row + 5, false, var::column_type::constant), @@ -450,27 +487,27 @@ namespace nil { typename multiplication_component::result_type k0 = generate_circuit( multiplication_instance, bp, assignment, typename multiplication_component::input_type({d_var_array, z2.output}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; typename multiplication_component::result_type k1 = generate_circuit( multiplication_instance, bp, assignment, typename multiplication_component::input_type({P_x, k0.output}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; typename multiplication_component::result_type k2 = generate_circuit( multiplication_instance, bp, assignment, typename multiplication_component::input_type({P_y, k0.output}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; typename addition_component::result_type k3 = generate_circuit( addition_instance, bp, assignment, typename addition_component::input_type({P_x, k1.output}), row); - row += addition_component::rows_amount; + row += addition_instance.rows_amount; typename subtraction_component::result_type k4 = generate_circuit( subtraction_instance, bp, assignment, typename subtraction_component::input_type({P_y, k2.output}), row); - row += subtraction_component::rows_amount; + row += subtraction_instance.rows_amount; generate_constants(component, bp, assignment, instance_input, start_row_index); generate_copy_constraints(component, bp, assignment, instance_input, start_row_index); @@ -491,22 +528,26 @@ namespace nil { using component_type = plonk_ed25519_complete_addition; - row += component_type::non_native_range_component::rows_amount; - row += component_type::non_native_range_component::rows_amount; - row += component_type::multiplication_component::rows_amount; - row += component_type::multiplication_component::rows_amount; - row += component_type::multiplication_component::rows_amount; - row += component_type::multiplication_component::rows_amount; + row += component_type::non_native_range_component::get_rows_amount(component.witness_amount(), 0); + row += component_type::non_native_range_component::get_rows_amount(component.witness_amount(), 0); + row += component_type::multiplication_component::get_rows_amount(component.witness_amount(), 0); + row += component_type::multiplication_component::get_rows_amount(component.witness_amount(), 0); + row += component_type::multiplication_component::get_rows_amount(component.witness_amount(), 0); + row += component_type::multiplication_component::get_rows_amount(component.witness_amount(), 0); for (std::size_t i = 0; i < 4; i++) { bp.add_copy_constraint({{component.W(i), (std::int32_t)(row + 2), false}, - {component.W(i), (std::int32_t)(start_row_index + component_type::rows_amount - 4 - 2), false}}); + {component.W(i), + (std::int32_t)(start_row_index + component.rows_amount - 4 - 2), + false}}); } - row += component_type::addition_component::rows_amount; + row += component_type::addition_component::get_rows_amount(component.witness_amount(), 0); for (std::size_t i = 0; i < 4; i++) { bp.add_copy_constraint({{component.W(i), (std::int32_t)(row + 2), false}, - {component.W(i), (std::int32_t)(start_row_index + component_type::rows_amount - 2), false}}); + {component.W(i), + (std::int32_t)(start_row_index + component.rows_amount - 2), + false}}); } } @@ -529,23 +570,23 @@ namespace nil { using Ed25519Type = typename crypto3::algebra::curves::ed25519; using non_native_range_component = components::range< - ArithmetizationType, Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, Ed25519Type::base_field_type, non_native_policy_type>; using multiplication_component = multiplication< - ArithmetizationType, Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, Ed25519Type::base_field_type, non_native_policy_type>; using addition_component = addition< - ArithmetizationType, Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, Ed25519Type::base_field_type, non_native_policy_type>; using subtraction_component = subtraction< - ArithmetizationType, Ed25519Type::base_field_type, 9, non_native_policy_type>; - - row += non_native_range_component::rows_amount; - row += non_native_range_component::rows_amount; - row += multiplication_component::rows_amount; - row += multiplication_component::rows_amount; - row += multiplication_component::rows_amount; - row += multiplication_component::rows_amount; - row += addition_component::rows_amount; - row += addition_component::rows_amount; - row += multiplication_component::rows_amount; + ArithmetizationType, Ed25519Type::base_field_type, non_native_policy_type>; + + row += non_native_range_component::get_rows_amount(component.witness_amount(), 0); + row += non_native_range_component::get_rows_amount(component.witness_amount(), 0); + row += multiplication_component::get_rows_amount(component.witness_amount(), 0); + row += multiplication_component::get_rows_amount(component.witness_amount(), 0); + row += multiplication_component::get_rows_amount(component.witness_amount(), 0); + row += multiplication_component::get_rows_amount(component.witness_amount(), 0); + row += addition_component::get_rows_amount(component.witness_amount(), 0); + row += addition_component::get_rows_amount(component.witness_amount(), 0); + row += multiplication_component::get_rows_amount(component.witness_amount(), 0); typename Ed25519Type::base_field_type::integral_type base = 1; typename Ed25519Type::base_field_type::integral_type mask = (base << 66) - 1; diff --git a/include/nil/blueprint/components/algebra/curves/edwards/plonk/non_native/doubling.hpp b/include/nil/blueprint/components/algebra/curves/edwards/plonk/non_native/doubling.hpp index a942e5c4d..b21a55826 100644 --- a/include/nil/blueprint/components/algebra/curves/edwards/plonk/non_native/doubling.hpp +++ b/include/nil/blueprint/components/algebra/curves/edwards/plonk/non_native/doubling.hpp @@ -38,7 +38,7 @@ namespace nil { namespace components { template + typename NonNativePolicyType> class doubling; template, CurveType, Ed25519Type, - 9, basic_non_native_policy>: - public plonk_component { + public plonk_component { typedef crypto3::zk::snark::plonk_constraint_system ArithmetizationType; - constexpr static const std::uint32_t WitnessesAmount = 9; - - using component_type = plonk_component; + using component_type = plonk_component; public: using var = typename component_type::var; + using manifest_type = typename component_type::manifest_type; using non_native_policy_type = basic_non_native_policy; using non_native_range_component = components::range< - ArithmetizationType, typename Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, typename Ed25519Type::base_field_type, non_native_policy_type>; using multiplication_component = multiplication< - ArithmetizationType, typename Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, typename Ed25519Type::base_field_type, non_native_policy_type>; using addition_component = addition< - ArithmetizationType, typename Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, typename Ed25519Type::base_field_type, non_native_policy_type>; using subtraction_component = subtraction< - ArithmetizationType, typename Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, typename Ed25519Type::base_field_type, non_native_policy_type>; - constexpr static const std::size_t rows_amount = - 2 * non_native_range_component::rows_amount + 5 * multiplication_component::rows_amount + - 4 * addition_component::rows_amount + 2 * subtraction_component::rows_amount; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return doubling::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = + gate_manifest(gate_manifest_type()) + .merge_with( + non_native_range_component::get_gate_manifest(witness_amount, lookup_column_amount)) + .merge_with(multiplication_component::get_gate_manifest(witness_amount, lookup_column_amount)) + .merge_with(addition_component::get_gate_manifest(witness_amount, lookup_column_amount)) + .merge_with(subtraction_component::get_gate_manifest(witness_amount, lookup_column_amount)); + return manifest; + } + + static manifest_type get_manifest() { + static manifest_type manifest = manifest_type( + std::shared_ptr(new manifest_single_value_param(9)), + false + ).merge_with(multiplication_component::get_manifest()) + .merge_with(addition_component::get_manifest()) + .merge_with(subtraction_component::get_manifest()) + .merge_with(non_native_range_component::get_manifest()); + return manifest; + } + + constexpr static std::size_t get_rows_amount(std::size_t witness_amount, + std::size_t lookup_column_amount) { + return + 2 * non_native_range_component::get_rows_amount(witness_amount, lookup_column_amount) + + 5 * multiplication_component::get_rows_amount(witness_amount, lookup_column_amount) + + 4 * addition_component::get_rows_amount(witness_amount, lookup_column_amount) + + 2 * subtraction_component::get_rows_amount(witness_amount, lookup_column_amount); + } + const std::size_t rows_amount = get_rows_amount(this->witness_amount(), 0); constexpr static const std::size_t gates_amount = 0; struct input_type { @@ -98,28 +132,31 @@ namespace nil { var(component.W(1), start_row_index, false), var(component.W(2), start_row_index, false), var(component.W(3), start_row_index, false)}; - output.y = {var(component.W(0), start_row_index + non_native_range_component::rows_amount, false), - var(component.W(1), start_row_index + non_native_range_component::rows_amount, false), - var(component.W(2), start_row_index + non_native_range_component::rows_amount, false), - var(component.W(3), start_row_index + non_native_range_component::rows_amount, false)}; + std::size_t non_native_rows_amount = non_native_range_component::get_rows_amount( + component.witness_amount(), 0); + output.y = { + var(component.W(0), start_row_index + non_native_rows_amount, false), + var(component.W(1), start_row_index + non_native_rows_amount, false), + var(component.W(2), start_row_index + non_native_rows_amount, false), + var(component.W(3), start_row_index + non_native_rows_amount, false)}; } }; template - doubling(ContainerType witness) : component_type(witness, {}, {}) {}; + doubling(ContainerType witness) : component_type(witness, {}, {}, get_manifest()) {}; template doubling(WitnessContainerType witness, ConstantContainerType constant, PublicInputContainerType public_input) : - component_type(witness, constant, public_input) {}; + component_type(witness, constant, public_input, get_manifest()) {}; doubling(std::initializer_list witnesses, std::initializer_list constants, std::initializer_list public_inputs) : - component_type(witnesses, constants, public_inputs) {}; + component_type(witnesses, constants, public_inputs, get_manifest()) {}; }; template @@ -127,7 +164,6 @@ namespace nil { crypto3::zk::snark::plonk_constraint_system, CurveType, typename crypto3::algebra::curves::ed25519, - 9, basic_non_native_policy>; @@ -139,7 +175,9 @@ namespace nil { const typename plonk_ed25519_doubling::input_type instance_input, const std::uint32_t start_row_index) { - using non_native_policy_type = basic_non_native_policy; + using non_native_policy_type = typename + plonk_ed25519_doubling::non_native_policy_type; typedef crypto3::zk::snark::plonk_constraint_system ArithmetizationType; @@ -149,13 +187,13 @@ namespace nil { using Ed25519Type = typename crypto3::algebra::curves::ed25519; using non_native_range_component = components::range< - ArithmetizationType, Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, Ed25519Type::base_field_type, non_native_policy_type>; using multiplication_component = multiplication< - ArithmetizationType, Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, Ed25519Type::base_field_type, non_native_policy_type>; using addition_component = addition< - ArithmetizationType, Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, Ed25519Type::base_field_type, non_native_policy_type>; using subtraction_component = subtraction< - ArithmetizationType, Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, Ed25519Type::base_field_type, non_native_policy_type>; non_native_range_component non_native_range_instance( {component.W(0), component.W(1), component.W(2), component.W(3), component.W(4), @@ -226,7 +264,7 @@ namespace nil { generate_assignments(non_native_range_instance, assignment, typename non_native_range_component::input_type({P_x}), row); - row += non_native_range_component::rows_amount; + row += non_native_range_instance.rows_amount; assignment.witness(component.W(0), row) = y3[0]; assignment.witness(component.W(1), row) = y3[1]; @@ -240,62 +278,62 @@ namespace nil { generate_assignments(non_native_range_instance, assignment, typename non_native_range_component::input_type({P_y}), row); - row += non_native_range_component::rows_amount; + row += non_native_range_instance.rows_amount; typename multiplication_component::result_type t0 = generate_assignments( multiplication_instance, assignment, typename multiplication_component::input_type({T_y, T_y}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; typename multiplication_component::result_type t1 = generate_assignments( multiplication_instance, assignment, typename multiplication_component::input_type({T_x, T_x}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; typename multiplication_component::result_type t2 = generate_assignments( multiplication_instance, assignment, typename multiplication_component::input_type({T_x, T_y}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; typename subtraction_component::result_type t3 = generate_assignments( subtraction_instance, assignment, typename subtraction_component::input_type({t0.output, t1.output}), row); - row += subtraction_component::rows_amount; + row += subtraction_instance.rows_amount; typename addition_component::result_type t4 = generate_assignments( addition_instance, assignment, typename addition_component::input_type({t2.output, t2.output}), row); - row += addition_component::rows_amount; + row += addition_instance.rows_amount; typename addition_component::result_type t5 = generate_assignments( addition_instance, assignment, typename addition_component::input_type({t1.output, t0.output}), row); - row += addition_component::rows_amount; + row += addition_instance.rows_amount; typename subtraction_component::result_type t6 = generate_assignments( subtraction_instance, assignment, typename subtraction_component::input_type({t1.output, t0.output}), row); - row += subtraction_component::rows_amount; + row += subtraction_instance.rows_amount; typename multiplication_component::result_type t7 = generate_assignments( multiplication_instance, assignment, typename multiplication_component::input_type({P_x, t3.output}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; typename addition_component::result_type t8 = generate_assignments( addition_instance, assignment, typename addition_component::input_type({P_y, P_y}), row); - row += addition_component::rows_amount; + row += addition_instance.rows_amount; typename multiplication_component::result_type t9 = generate_assignments( multiplication_instance, assignment, typename multiplication_component::input_type({P_y, t6.output}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; typename addition_component::result_type t10 = generate_assignments( addition_instance, assignment, typename addition_component::input_type({t8.output, t9.output}), row); - row += addition_component::rows_amount; + row += addition_instance.rows_amount; return typename plonk_ed25519_doubling::result_type(component, start_row_index); } @@ -311,7 +349,9 @@ namespace nil { const typename plonk_ed25519_doubling::input_type instance_input, const std::uint32_t start_row_index) { - using non_native_policy_type = basic_non_native_policy; + using non_native_policy_type = typename + plonk_ed25519_doubling::non_native_policy_type; typedef crypto3::zk::snark::plonk_constraint_system ArithmetizationType; @@ -321,13 +361,13 @@ namespace nil { using Ed25519Type = typename crypto3::algebra::curves::ed25519; using non_native_range_component = components::range< - ArithmetizationType, Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, Ed25519Type::base_field_type, non_native_policy_type>; using multiplication_component = multiplication< - ArithmetizationType, Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, Ed25519Type::base_field_type, non_native_policy_type>; using addition_component = addition< - ArithmetizationType, Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, Ed25519Type::base_field_type, non_native_policy_type>; using subtraction_component = subtraction< - ArithmetizationType, Ed25519Type::base_field_type, 9, non_native_policy_type>; + ArithmetizationType, Ed25519Type::base_field_type, non_native_policy_type>; non_native_range_component non_native_range_instance( {component.W(0), component.W(1), component.W(2), component.W(3), component.W(4), @@ -354,7 +394,7 @@ namespace nil { generate_circuit(non_native_range_instance, bp, assignment, typename non_native_range_component::input_type({P_x}), row); - row += non_native_range_component::rows_amount; + row += non_native_range_instance.rows_amount; std::array P_y = { var(component.W(0), row), @@ -363,7 +403,7 @@ namespace nil { var(component.W(3), row)}; generate_circuit(non_native_range_instance, bp, assignment, typename non_native_range_component::input_type({P_y}), row); - row += non_native_range_component::rows_amount; + row += non_native_range_instance.rows_amount; std::array T_x = instance_input.T.x; std::array T_y = instance_input.T.y; @@ -372,57 +412,57 @@ namespace nil { typename multiplication_component::result_type t0 = generate_circuit( multiplication_instance, bp, assignment, typename multiplication_component::input_type({T_y, T_y}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; typename multiplication_component::result_type t1 = generate_circuit( multiplication_instance, bp, assignment, typename multiplication_component::input_type({T_x, T_x}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; typename multiplication_component::result_type t2 = generate_circuit( multiplication_instance, bp, assignment, typename multiplication_component::input_type({T_x, T_y}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; typename subtraction_component::result_type t3 = generate_circuit( subtraction_instance, bp, assignment, typename subtraction_component::input_type({t0.output, t1.output}), row); - row += subtraction_component::rows_amount; + row += subtraction_instance.rows_amount; typename addition_component::result_type t4 = generate_circuit( addition_instance, bp, assignment, typename addition_component::input_type({t2.output, t2.output}), row); - row += addition_component::rows_amount; + row += addition_instance.rows_amount; typename addition_component::result_type t5 = generate_circuit( addition_instance, bp, assignment, typename addition_component::input_type({t1.output, t0.output}), row); - row += addition_component::rows_amount; + row += addition_instance.rows_amount; typename subtraction_component::result_type t6 = generate_circuit( subtraction_instance, bp, assignment, typename subtraction_component::input_type({t1.output, t0.output}), row); - row += subtraction_component::rows_amount; + row += subtraction_instance.rows_amount; typename multiplication_component::result_type t7 = generate_circuit( multiplication_instance, bp, assignment, typename multiplication_component::input_type({P_x, t3.output}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; typename addition_component::result_type t8 = generate_circuit( addition_instance, bp, assignment, typename addition_component::input_type({P_y, P_y}), row); - row += addition_component::rows_amount; + row += addition_instance.rows_amount; typename multiplication_component::result_type t9 = generate_circuit( multiplication_instance, bp, assignment, typename multiplication_component::input_type({P_y, t6.output}), row); - row += multiplication_component::rows_amount; + row += multiplication_instance.rows_amount; typename addition_component::result_type t10 = generate_circuit( addition_instance, bp, assignment, typename addition_component::input_type({t8.output, t9.output}), row); - row += addition_component::rows_amount; + row += addition_instance.rows_amount; generate_copy_constraints(component, bp, assignment, instance_input, start_row_index); @@ -440,23 +480,23 @@ namespace nil { std::size_t row = start_row_index; using component_type = plonk_ed25519_doubling; - row += component_type::non_native_range_component::rows_amount; - row += component_type::non_native_range_component::rows_amount; - row += component_type::multiplication_component::rows_amount; - row += component_type::multiplication_component::rows_amount; - row += component_type::multiplication_component::rows_amount; - row += component_type::subtraction_component::rows_amount; + row += component_type::non_native_range_component::get_rows_amount(component.witness_amount(), 0); + row += component_type::non_native_range_component::get_rows_amount(component.witness_amount(), 0); + row += component_type::multiplication_component::get_rows_amount(component.witness_amount(), 0); + row += component_type::multiplication_component::get_rows_amount(component.witness_amount(), 0); + row += component_type::multiplication_component::get_rows_amount(component.witness_amount(), 0); + row += component_type::subtraction_component::get_rows_amount(component.witness_amount(), 0); std::size_t t4_row = row; - row += component_type::addition_component::rows_amount; + row += component_type::addition_component::get_rows_amount(component.witness_amount(), 0); std::size_t t5_row = row; - row += component_type::addition_component::rows_amount; - row += component_type::subtraction_component::rows_amount; + row += component_type::addition_component::get_rows_amount(component.witness_amount(), 0); + row += component_type::subtraction_component::get_rows_amount(component.witness_amount(), 0); std::size_t t7_row = row; - row += component_type::multiplication_component::rows_amount; - row += component_type::addition_component::rows_amount; - row += component_type::multiplication_component::rows_amount; + row += component_type::multiplication_component::get_rows_amount(component.witness_amount(), 0); + row += component_type::addition_component::get_rows_amount(component.witness_amount(), 0); + row += component_type::multiplication_component::get_rows_amount(component.witness_amount(), 0); std::size_t t10_row = row; - row += component_type::addition_component::rows_amount; + row += component_type::addition_component::get_rows_amount(component.witness_amount(), 0); for (std::size_t i = 0; i < 4; i++) { bp.add_copy_constraint( diff --git a/include/nil/blueprint/components/algebra/curves/edwards/plonk/non_native/scalar_non_native_range.hpp b/include/nil/blueprint/components/algebra/curves/edwards/plonk/non_native/scalar_non_native_range.hpp index 00877412a..3f6c21cf5 100644 --- a/include/nil/blueprint/components/algebra/curves/edwards/plonk/non_native/scalar_non_native_range.hpp +++ b/include/nil/blueprint/components/algebra/curves/edwards/plonk/non_native/scalar_non_native_range.hpp @@ -53,6 +53,19 @@ namespace nil { using var = typename component_type::var; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return scalar_non_native_range::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = gate_manifest(gate_manifest_type()); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr( @@ -67,11 +80,6 @@ namespace nil { return 3; } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount; - } - const std::size_t rows_amount = get_rows_amount(this->witness_amount(), 0); constexpr static const std::size_t gates_amount = 1; diff --git a/include/nil/blueprint/components/algebra/curves/edwards/plonk/non_native/variable_base_multiplication.hpp b/include/nil/blueprint/components/algebra/curves/edwards/plonk/non_native/variable_base_multiplication.hpp index ac30a4765..752256194 100644 --- a/include/nil/blueprint/components/algebra/curves/edwards/plonk/non_native/variable_base_multiplication.hpp +++ b/include/nil/blueprint/components/algebra/curves/edwards/plonk/non_native/variable_base_multiplication.hpp @@ -32,21 +32,16 @@ #include #include #include +#include namespace nil { namespace blueprint { namespace components { - namespace detail { - enum bit_shift_mode { - LEFT, - RIGHT, - }; - } // namespace detail using detail::bit_shift_mode; template + typename NonNativePolicyType> class variable_base_multiplication; template, CurveType, Ed25519Type, - 9, basic_non_native_policy>: - public plonk_component { - - constexpr static const std::uint32_t WitnessesAmount = 9; - - using component_type = plonk_component; + public plonk_component { + + using component_type = plonk_component; + + constexpr static const std::size_t rows_amount_internal(std::size_t witness_amount, + std::size_t lookup_column_amount, + std::size_t bits_amount) { + return + decomposition_component_type::get_rows_amount(witness_amount, lookup_column_amount, + bits_amount) + + 252 * mul_per_bit_component::get_rows_amount(witness_amount, lookup_column_amount) + + bool_scalar_mul_component::get_rows_amount(witness_amount, lookup_column_amount); + } public: using var = typename component_type::var; + using manifest_type = typename component_type::manifest_type; using non_native_policy_type = basic_non_native_policy; typedef crypto3::zk::snark::plonk_constraint_system ArithmetizationType; using mul_per_bit_component = variable_base_multiplication_per_bit< - ArithmetizationType, CurveType, Ed25519Type, 9, non_native_policy_type>; + ArithmetizationType, CurveType, Ed25519Type, non_native_policy_type>; - using decomposition_component_type = bit_decomposition; + using decomposition_component_type = bit_decomposition; using bool_scalar_mul_component = bool_scalar_multiplication< - ArithmetizationType, Ed25519Type, 9, non_native_policy_type>; + ArithmetizationType, Ed25519Type, non_native_policy_type>; - const decomposition_component_type decomposition_subcomponent; - const mul_per_bit_component mul_per_bit_subcomponent; - const bool_scalar_mul_component bool_scalar_mul_subcomponent; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return variable_base_multiplication::gates_amount; + } + }; - const std::size_t rows_amount; + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount, + std::size_t bits_amount) { + static gate_manifest manifest = + gate_manifest(gate_manifest_type()) + .merge_with( + bool_scalar_mul_component::get_gate_manifest(witness_amount, lookup_column_amount)) + .merge_with(mul_per_bit_component::get_gate_manifest(witness_amount, lookup_column_amount)) + .merge_with( + decomposition_component_type::get_gate_manifest(witness_amount, lookup_column_amount, + bits_amount)); + + return manifest; + } + + static manifest_type get_manifest() { + static manifest_type manifest = manifest_type( + std::shared_ptr(new manifest_single_value_param(9)), + false + ).merge_with(mul_per_bit_component::get_manifest()) + .merge_with(decomposition_component_type::get_manifest()) + .merge_with(bool_scalar_mul_component::get_manifest()); + return manifest; + } - constexpr static const std::size_t rows( - const decomposition_component_type& decomposition_subcomponent, - const mul_per_bit_component& mul_per_bit_subcomponent, - const bool_scalar_mul_component& bool_scalar_mul_subcomponent - ) { - return decomposition_subcomponent.rows_amount - + mul_per_bit_subcomponent.rows_amount * 252 - + bool_scalar_mul_subcomponent.rows_amount; + constexpr static std::size_t get_rows_amount(std::size_t witness_amount, + std::size_t lookup_column_amount, + std::size_t bits_amount) { + return rows_amount_internal(witness_amount, lookup_column_amount, bits_amount); } + // We use bits_amount from decomposition subcomponent to initialize rows_amount + // CRITICAL: do not move decomposition_subcomponent below rows_amount + const decomposition_component_type decomposition_subcomponent; + // CRITICAL: do not move decomposition_subcomponent below rows_amount + const mul_per_bit_component mul_per_bit_subcomponent; + const bool_scalar_mul_component bool_scalar_mul_subcomponent; + + const std::size_t rows_amount = rows_amount_internal(this->witness_amount(), 0, decomposition_subcomponent.bits_amount); constexpr static const std::size_t gates_amount = 0; struct input_type { @@ -116,7 +149,7 @@ namespace nil { result_type(const variable_base_multiplication &component, std::uint32_t start_row_index) { using mul_per_bit_component = components::variable_base_multiplication_per_bit; + CurveType, Ed25519Type, non_native_policy_type>; mul_per_bit_component component_instance({0, 1, 2, 3, 4, 5, 6, 7, 8}, {0}, {}); auto final_mul_per_bit_res = typename plonk_ed25519_mul_per_bit::result_type( @@ -136,23 +169,21 @@ namespace nil { template variable_base_multiplication(ContainerType witness, std::uint32_t bits_amount, bit_shift_mode mode_) : - component_type(witness, {}, {}), + component_type(witness, {}, {}, get_manifest()), decomposition_subcomponent(witness, bits_amount, bit_composition_mode::MSB), mul_per_bit_subcomponent(witness), - bool_scalar_mul_subcomponent(witness), - rows_amount(rows(decomposition_subcomponent, mul_per_bit_subcomponent, bool_scalar_mul_subcomponent)) {}; + bool_scalar_mul_subcomponent(witness) {}; template variable_base_multiplication(WitnessContainerType witness, ConstantContainerType constant, PublicInputContainerType public_input, std::uint32_t bits_amount, bit_shift_mode mode_) : - component_type(witness, constant, public_input), + component_type(witness, constant, public_input, get_manifest()), decomposition_subcomponent(witness, constant, public_input, bits_amount, bit_composition_mode::MSB), mul_per_bit_subcomponent(witness, constant, public_input), - bool_scalar_mul_subcomponent(witness, constant, public_input), - rows_amount(rows(decomposition_subcomponent, mul_per_bit_subcomponent, bool_scalar_mul_subcomponent)) {}; + bool_scalar_mul_subcomponent(witness, constant, public_input) {}; variable_base_multiplication( std::initializer_list @@ -162,12 +193,11 @@ namespace nil { std::initializer_list public_inputs, std::uint32_t bits_amount = 253, bit_shift_mode mode_ = bit_shift_mode::RIGHT) : - component_type(witnesses, constants, public_inputs), + component_type(witnesses, constants, public_inputs, get_manifest()), decomposition_subcomponent(witnesses, constants, public_inputs, bits_amount, bit_composition_mode::MSB), mul_per_bit_subcomponent(witnesses, constants, public_inputs), - bool_scalar_mul_subcomponent(witnesses, constants, public_inputs), - rows_amount(rows(decomposition_subcomponent, mul_per_bit_subcomponent, bool_scalar_mul_subcomponent)) {}; + bool_scalar_mul_subcomponent(witnesses, constants, public_inputs) {}; }; template @@ -175,7 +205,6 @@ namespace nil { crypto3::zk::snark::plonk_constraint_system, CurveType, typename crypto3::algebra::curves::ed25519, - 9, basic_non_native_policy>; template @@ -186,13 +215,15 @@ namespace nil { const typename plonk_ed25519_var_base_mul::input_type instance_input, const std::uint32_t start_row_index) { - using non_native_policy_type = basic_non_native_policy; + using component_type = + plonk_ed25519_var_base_mul; + using non_native_policy_type = typename component_type::non_native_policy_type; using var = typename plonk_ed25519_mul_per_bit::var; using Ed25519Type = typename crypto3::algebra::curves::ed25519; typedef crypto3::zk::snark::plonk_constraint_system ArithmetizationType; - using component_type = plonk_ed25519_var_base_mul; + using mul_per_bit_component = typename component_type::mul_per_bit_component; using decomposition_component_type = typename component_type::decomposition_component_type; @@ -238,14 +269,14 @@ namespace nil { const typename plonk_ed25519_var_base_mul::input_type instance_input, const std::uint32_t start_row_index) { - using non_native_policy_type = basic_non_native_policy; + using component_type = + plonk_ed25519_var_base_mul; + using non_native_policy_type = typename component_type::non_native_policy_type; using var = typename plonk_ed25519_mul_per_bit::var; using Ed25519Type = typename crypto3::algebra::curves::ed25519; typedef crypto3::zk::snark::plonk_constraint_system ArithmetizationType; - using component_type = plonk_ed25519_var_base_mul; - using mul_per_bit_component = typename component_type::mul_per_bit_component; using decomposition_component_type = typename component_type::decomposition_component_type; using bool_scalar_mul_component = typename component_type::bool_scalar_mul_component; diff --git a/include/nil/blueprint/components/algebra/curves/edwards/plonk/non_native/variable_base_multiplication_per_bit.hpp b/include/nil/blueprint/components/algebra/curves/edwards/plonk/non_native/variable_base_multiplication_per_bit.hpp index 2829b345b..3608066aa 100644 --- a/include/nil/blueprint/components/algebra/curves/edwards/plonk/non_native/variable_base_multiplication_per_bit.hpp +++ b/include/nil/blueprint/components/algebra/curves/edwards/plonk/non_native/variable_base_multiplication_per_bit.hpp @@ -40,7 +40,7 @@ namespace nil { namespace components { template + typename NonNativePolicyType> class variable_base_multiplication_per_bit; template, CurveType, Ed25519Type, - 9, basic_non_native_policy>: - public plonk_component { + public plonk_component { - constexpr static const std::uint32_t WitnessesAmount = 9; + using component_type = plonk_component; - using component_type = plonk_component; + constexpr static const std::size_t rows_amount_internal(std::size_t witness_amount, + std::size_t lookup_column_amount) { + return + doubling_component::get_rows_amount(witness_amount, lookup_column_amount) + + complete_addition_component::get_rows_amount(witness_amount, lookup_column_amount) + + bool_scalar_multiplication_component::get_rows_amount(witness_amount, lookup_column_amount); + + } public: using var = typename component_type::var; + using manifest_type = typename component_type::manifest_type; using non_native_policy_type = basic_non_native_policy; typedef crypto3::zk::snark::plonk_constraint_system ArithmetizationType; using doubling_component = doubling< - ArithmetizationType, CurveType, Ed25519Type, 9, non_native_policy_type>; + ArithmetizationType, CurveType, Ed25519Type, non_native_policy_type>; using complete_addition_component = complete_addition< - ArithmetizationType, CurveType, Ed25519Type, 9, non_native_policy_type>; + ArithmetizationType, CurveType, Ed25519Type, non_native_policy_type>; using bool_scalar_multiplication_component = bool_scalar_multiplication< - ArithmetizationType, Ed25519Type, 9, non_native_policy_type>; + ArithmetizationType, Ed25519Type, non_native_policy_type>; + + using non_native_range_component = components::range< + ArithmetizationType, typename Ed25519Type::base_field_type, non_native_policy_type>; + + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return variable_base_multiplication_per_bit::gates_amount; + } + }; + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = + gate_manifest(gate_manifest_type()) + .merge_with( + non_native_range_component::get_gate_manifest(witness_amount, lookup_column_amount)) + .merge_with(doubling_component::get_gate_manifest(witness_amount, lookup_column_amount)) + .merge_with( + complete_addition_component::get_gate_manifest(witness_amount, lookup_column_amount)) + .merge_with( + bool_scalar_multiplication_component::get_gate_manifest(witness_amount, + lookup_column_amount)); + + return manifest; + } + static manifest_type get_manifest() { + static manifest_type manifest = manifest_type( + std::shared_ptr(new manifest_single_value_param(9)), + false + ).merge_with(non_native_range_component::get_manifest()) + .merge_with(doubling_component::get_manifest()) + .merge_with(complete_addition_component::get_manifest()) + .merge_with(bool_scalar_multiplication_component::get_manifest()); + return manifest; + } - constexpr static const std::size_t rows_amount = doubling_component::rows_amount + - complete_addition_component::rows_amount + - bool_scalar_multiplication_component::rows_amount; + constexpr static std::size_t get_rows_amount(std::size_t witness_amount, + std::size_t lookup_column_amount) { + return rows_amount_internal(witness_amount, lookup_column_amount); + } + const std::size_t rows_amount = rows_amount_internal(this->witness_amount(), 0); constexpr static const std::size_t gates_amount = 0; struct input_type { @@ -101,12 +145,12 @@ namespace nil { result_type(const variable_base_multiplication_per_bit &component, std::uint32_t start_row_index) { using complete_addition_component = - components::complete_addition>; + components::complete_addition>; complete_addition_component component_instance({0, 1, 2, 3, 4, 5, 6, 7, 8}, {0}, {}); auto final_addition_res = typename plonk_ed25519_complete_addition::result_type( - component_instance, start_row_index + rows_amount - complete_addition_component::rows_amount); + component_instance, start_row_index + component.rows_amount - complete_addition_component::get_rows_amount(component.witness_amount(), 0)); output.x = {final_addition_res.output.x[0], final_addition_res.output.x[1], @@ -120,20 +164,21 @@ namespace nil { }; template - variable_base_multiplication_per_bit(ContainerType witness) : component_type(witness, {}, {}) {}; + variable_base_multiplication_per_bit(ContainerType witness) : + component_type(witness, {}, {}, get_manifest()) {}; template variable_base_multiplication_per_bit(WitnessContainerType witness, ConstantContainerType constant, PublicInputContainerType public_input) : - component_type(witness, constant, public_input) {}; + component_type(witness, constant, public_input, get_manifest()) {}; variable_base_multiplication_per_bit(std::initializer_list witnesses, std::initializer_list constants, std::initializer_list public_inputs) : - component_type(witnesses, constants, public_inputs) {}; + component_type(witnesses, constants, public_inputs, get_manifest()) {}; }; template @@ -141,7 +186,6 @@ namespace nil { crypto3::zk::snark::plonk_constraint_system, CurveType, typename crypto3::algebra::curves::ed25519, - 9, basic_non_native_policy>; @@ -160,13 +204,13 @@ namespace nil { ArithmetizationType; using doubling_component = doubling< - ArithmetizationType, CurveType, Ed25519Type, 9, non_native_policy_type>; + ArithmetizationType, CurveType, Ed25519Type, non_native_policy_type>; using complete_addition_component = complete_addition< - ArithmetizationType, CurveType, Ed25519Type, 9, non_native_policy_type>; + ArithmetizationType, CurveType, Ed25519Type, non_native_policy_type>; using bool_scalar_multiplication_component = bool_scalar_multiplication< - ArithmetizationType, Ed25519Type, 9, non_native_policy_type>; + ArithmetizationType, Ed25519Type, non_native_policy_type>; doubling_component doubling_instance( {component.W(0), component.W(1), component.W(2), component.W(3), component.W(4), @@ -189,19 +233,19 @@ namespace nil { typename bool_scalar_multiplication_component::result_type bool_mul_res = generate_assignments(bool_scalar_multiplication_instance, assignment, typename bool_scalar_multiplication_component::input_type({{T_x, T_y}, instance_input.k}), row); - row += bool_scalar_multiplication_component::rows_amount; + row += bool_scalar_multiplication_instance.rows_amount; typename doubling_component::result_type doubling_res = generate_assignments(doubling_instance, assignment, typename doubling_component::input_type({R_x, R_y}), row); - row += doubling_component::rows_amount; + row += doubling_instance.rows_amount; typename complete_addition_component::result_type add_res = generate_assignments(complete_addition_instance, assignment, typename complete_addition_component::input_type( {{doubling_res.output.x, doubling_res.output.y}, {bool_mul_res.output.x, bool_mul_res.output.y}}), row); - row += complete_addition_component::rows_amount; + row += complete_addition_instance.rows_amount; return typename plonk_ed25519_mul_per_bit::result_type(component, start_row_index); @@ -223,13 +267,13 @@ namespace nil { ArithmetizationType; using doubling_component = doubling< - ArithmetizationType, CurveType, Ed25519Type, 9, non_native_policy_type>; + ArithmetizationType, CurveType, Ed25519Type, non_native_policy_type>; using complete_addition_component = complete_addition< - ArithmetizationType, CurveType, Ed25519Type, 9, non_native_policy_type>; + ArithmetizationType, CurveType, Ed25519Type, non_native_policy_type>; using bool_scalar_multiplication_component = bool_scalar_multiplication< - ArithmetizationType, Ed25519Type, 9, non_native_policy_type>; + ArithmetizationType, Ed25519Type, non_native_policy_type>; doubling_component doubling_instance( {component.W(0), component.W(1), component.W(2), component.W(3), component.W(4), @@ -252,22 +296,21 @@ namespace nil { typename bool_scalar_multiplication_component::result_type bool_mul_res = generate_circuit(bool_scalar_multiplication_instance, bp, assignment, typename bool_scalar_multiplication_component::input_type({{T_x, T_y}, instance_input.k}), row); - row += bool_scalar_multiplication_component::rows_amount; + row += bool_scalar_multiplication_instance.rows_amount; typename doubling_component::result_type doubling_res = generate_circuit(doubling_instance, bp, assignment, typename doubling_component::input_type({R_x, R_y}), row); - row += doubling_component::rows_amount; + row += doubling_instance.rows_amount; typename complete_addition_component::result_type add_res = generate_circuit(complete_addition_instance, bp, assignment, typename complete_addition_component::input_type( {{doubling_res.output.x, doubling_res.output.y}, {bool_mul_res.output.x, bool_mul_res.output.y}}), row); - row += complete_addition_component::rows_amount; + row += complete_addition_instance.rows_amount; return typename plonk_ed25519_mul_per_bit::result_type(component, start_row_index); - } } // namespace components diff --git a/include/nil/blueprint/components/algebra/curves/pasta/plonk/decomposed_variable_base_scalar_mul.hpp b/include/nil/blueprint/components/algebra/curves/pasta/plonk/decomposed_variable_base_scalar_mul.hpp index ba5652d91..634956240 100644 --- a/include/nil/blueprint/components/algebra/curves/pasta/plonk/decomposed_variable_base_scalar_mul.hpp +++ b/include/nil/blueprint/components/algebra/curves/pasta/plonk/decomposed_variable_base_scalar_mul.hpp @@ -69,6 +69,24 @@ namespace nil { using var = typename component_type::var; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return + curve_element_decomposed_variable_base_scalar_mul::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = + gate_manifest(gate_manifest_type()) + .merge_with(mul_component::get_gate_manifest(witness_amount, lookup_column_amount)); + .merge_with(mul_field_component::get_gate_manifest(witness_amount, lookup_column_amount)); + .merge_with(add_component::get_gate_manifest(witness_amount, lookup_column_amount)); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr(new manifest_single_value_param(15)), @@ -83,14 +101,6 @@ namespace nil { add_component::get_rows_amount(witness_amount, lookup_column_amount); } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount + - mul_component::get_total_gates_amount(witness_amount, lookup_column_amount) + - mul_field_component::get_total_gates_amount(witness_amount, lookup_column_amount) + - add_component::get_total_gates_amount(witness_amount, lookup_column_amount); - } - const std::size_t rows_amount_without_addition = rows_without_addition_internal(this->witness_amount(), 0); const std::size_t rows_amount = get_rows_amount(this->witness_amount(), 0); 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 0ac835b8b..46437639b 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 @@ -94,6 +94,19 @@ namespace nil { using var = typename component_type::var; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return endo_scalar::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = gate_manifest(gate_manifest_type()); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr(new manifest_single_value_param(15)), @@ -107,11 +120,6 @@ namespace nil { return 8; } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount; - } - const std::size_t scalar_size; const std::size_t rows_amount = get_rows_amount(this->witness_amount(), 0); 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 f52b395b1..ea72918b2 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 @@ -58,6 +58,19 @@ namespace nil { using var = typename component_type::var; using manifest_type = plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return unified_addition::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = gate_manifest(gate_manifest_type()); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr(new manifest_single_value_param(11)), @@ -71,11 +84,6 @@ namespace nil { return 1; } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount; - } - const std::size_t rows_amount = get_rows_amount(this->witness_amount(), 0); static constexpr const std::size_t gates_amount = 1; diff --git a/include/nil/blueprint/components/algebra/curves/pasta/plonk/variable_base_scalar_mul.hpp b/include/nil/blueprint/components/algebra/curves/pasta/plonk/variable_base_scalar_mul.hpp index c9a002dd6..d753a0127 100644 --- a/include/nil/blueprint/components/algebra/curves/pasta/plonk/variable_base_scalar_mul.hpp +++ b/include/nil/blueprint/components/algebra/curves/pasta/plonk/variable_base_scalar_mul.hpp @@ -117,6 +117,21 @@ namespace nil { using add_component = nil::blueprint::components::unified_addition, CurveType>; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return curve_element_variable_base_scalar_mul::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = + gate_manifest(gate_manifest_type()) + .merge_with(add_component::get_gate_manifest(witness_amount, lookup_column_amount)); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr(new manifest_single_value_param(15)), @@ -130,12 +145,6 @@ namespace nil { return rows_amount; } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount + - add_component::get_total_gates_amount(witness_amount, lookup_column_amount); - } - constexpr static const std::size_t mul_rows_amount = 102; constexpr static const std::size_t add_component_rows_amount = add_component::get_rows_amount(11, 0); diff --git a/include/nil/blueprint/components/algebra/fields/plonk/addition.hpp b/include/nil/blueprint/components/algebra/fields/plonk/addition.hpp index 15af1b565..7fb16ca46 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/addition.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/addition.hpp @@ -61,6 +61,19 @@ namespace nil { using var = typename component_type::var; using manifest_type = plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return addition::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = gate_manifest(gate_manifest_type()); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr(new manifest_single_value_param(3)), @@ -74,11 +87,6 @@ namespace nil { return 1; } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount; - } - constexpr static const std::size_t gates_amount = 1; const std::size_t rows_amount = get_rows_amount(this->witness_amount(), 0); diff --git a/include/nil/blueprint/components/algebra/fields/plonk/bit_shift_constant.hpp b/include/nil/blueprint/components/algebra/fields/plonk/bit_shift_constant.hpp index 758a6674b..89756bcc4 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/bit_shift_constant.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/bit_shift_constant.hpp @@ -87,6 +87,28 @@ namespace nil { ArithmetizationParams>>; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return 0; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount, + std::size_t bits_amount, + std::size_t shift, + bit_shift_mode mode) { + gate_manifest manifest = + gate_manifest(gate_manifest_type()) + .merge_with(decomposition_component_type::get_gate_manifest( + witness_amount, lookup_column_amount, bits_amount)) + .merge_with(composition_component_type::get_gate_manifest( + witness_amount, lookup_column_amount, + calculate_composition_bits_amount(bits_amount, shift, mode), false)); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = decomposition_component_type::get_manifest().merge_with( @@ -101,18 +123,6 @@ namespace nil { return rows_amount_internal(witness_amount, bits_amount, shift, mode); } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount, - std::size_t bits_amount, - std::size_t shift, bit_shift_mode mode) { - return gates_amount + - decomposition_component_type::get_total_gates_amount( - witness_amount, lookup_column_amount, bits_amount) + - composition_component_type::get_total_gates_amount(witness_amount, lookup_column_amount, - calculate_composition_bits_amount(bits_amount, shift, mode), false); - - } - constexpr static const std::size_t rows(const decomposition_component_type& decomposition_subcomponent, const composition_component_type& composition_subcomponent) { return decomposition_subcomponent.rows_amount + composition_subcomponent.rows_amount; diff --git a/include/nil/blueprint/components/algebra/fields/plonk/division.hpp b/include/nil/blueprint/components/algebra/fields/plonk/division.hpp index 6c16b60e8..49cd7f24c 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/division.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/division.hpp @@ -61,6 +61,19 @@ namespace nil { using var = typename component_type::var; using manifest_type = plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return division::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = gate_manifest(gate_manifest_type()); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr(new manifest_single_value_param(3)), @@ -73,11 +86,6 @@ namespace nil { return 1; } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount; - } - constexpr static const std::size_t gates_amount = 1; const std::size_t rows_amount = get_rows_amount(this->witness_amount(), 0); diff --git a/include/nil/blueprint/components/algebra/fields/plonk/division_or_zero.hpp b/include/nil/blueprint/components/algebra/fields/plonk/division_or_zero.hpp index 73af09c6c..7d8018a2e 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/division_or_zero.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/division_or_zero.hpp @@ -58,13 +58,22 @@ namespace nil { using component_type = plonk_component; public: - constexpr static std::size_t get_rows_amount(std::size_t witness_amount, std::size_t lookup_column_amount) { - return 1; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return division_or_zero::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = gate_manifest(gate_manifest_type()); + return manifest; } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount; + constexpr static std::size_t get_rows_amount(std::size_t witness_amount, + std::size_t lookup_column_amount) { + return 1; } constexpr static const std::size_t gates_amount = 1; diff --git a/include/nil/blueprint/components/algebra/fields/plonk/exponentiation.hpp b/include/nil/blueprint/components/algebra/fields/plonk/exponentiation.hpp index 580dae25d..9817ce26d 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/exponentiation.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/exponentiation.hpp @@ -98,6 +98,20 @@ namespace nil { using var = typename component_type::var; using manifest_type = plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return exponentiation::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = gate_manifest(gate_manifest_type()); + return manifest; + } + + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr(new manifest_single_value_param(15)), @@ -106,15 +120,11 @@ namespace nil { return manifest; } - constexpr static std::size_t get_rows_amount(std::size_t witness_amount, std::size_t lookup_column_amount) { + constexpr static std::size_t get_rows_amount(std::size_t witness_amount, + std::size_t lookup_column_amount) { return rows_amount_internal(witness_amount); } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount; - } - constexpr static const std::size_t intermediate_start = 0 + reserved_witnesses; constexpr static const std::size_t bits_per_intermediate_result = 2; // defines diff --git a/include/nil/blueprint/components/algebra/fields/plonk/logic_and_flag.hpp b/include/nil/blueprint/components/algebra/fields/plonk/logic_and_flag.hpp index 096e7e1e9..6256acbad 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/logic_and_flag.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/logic_and_flag.hpp @@ -66,6 +66,29 @@ namespace nil { using var = typename component_type::var; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::size_t witness_amount; + static const std::size_t clamp_val = 5; + + gate_manifest_type(std::size_t witness_amount_) + : witness_amount(std::min(witness_amount_, clamp_val)) {} + + std::uint32_t gates_amount() const override { + return logic_and_flag::gates_amount; + } + + bool operator<(const component_gate_manifest *other) const override { + return witness_amount < dynamic_cast(other)->witness_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + gate_manifest manifest = gate_manifest(gate_manifest_type(witness_amount)); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr(new manifest_range_param(2, 6)), @@ -79,11 +102,6 @@ namespace nil { return rows_amount_internal(witness_amount); } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount; - } - constexpr static const std::size_t gates_amount = 1; const std::size_t rows_amount = rows_amount_internal(component_type::witness_amount()); diff --git a/include/nil/blueprint/components/algebra/fields/plonk/logic_or_flag.hpp b/include/nil/blueprint/components/algebra/fields/plonk/logic_or_flag.hpp index 84132ac66..ec4b9cb33 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/logic_or_flag.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/logic_or_flag.hpp @@ -74,6 +74,29 @@ namespace nil { using var = typename component_type::var; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::size_t witness_amount; + static const std::size_t clamp_val = 6; + + gate_manifest_type(std::size_t witness_amount_) + : witness_amount(std::min(witness_amount_, clamp_val)) {} + + std::uint32_t gates_amount() const override { + return logic_or_flag::gates_amount_internal(witness_amount); + } + + bool operator<(const component_gate_manifest *other) const override { + return witness_amount < dynamic_cast(other)->witness_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + gate_manifest manifest = gate_manifest(gate_manifest_type(witness_amount)); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr(new manifest_range_param(2, 7)), @@ -87,11 +110,6 @@ namespace nil { return rows_amount_internal(witness_amount); } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount_internal(witness_amount); - } - const std::size_t gates_amount = gates_amount_internal(this->witness_amount()); const std::size_t rows_amount = get_rows_amount(this->witness_amount(), 0); diff --git a/include/nil/blueprint/components/algebra/fields/plonk/multiplication.hpp b/include/nil/blueprint/components/algebra/fields/plonk/multiplication.hpp index 0fef487a9..b7da52f26 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/multiplication.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/multiplication.hpp @@ -32,6 +32,7 @@ #define CRYPTO3_BLUEPRINT_COMPONENTS_PLONK_FIELD_MULTIPLICATION_HPP #include +#include #include @@ -61,6 +62,19 @@ namespace nil { using var = typename component_type::var; using manifest_type = plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return multiplication::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = gate_manifest(gate_manifest_type()); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr(new manifest_single_value_param(3)), @@ -74,11 +88,6 @@ namespace nil { return 1; } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount; - } - constexpr static const std::size_t gates_amount = 1; const std::size_t rows_amount = get_rows_amount(this->witness_amount(), 0); diff --git a/include/nil/blueprint/components/algebra/fields/plonk/multiplication_by_constant.hpp b/include/nil/blueprint/components/algebra/fields/plonk/multiplication_by_constant.hpp index c51c092dd..910a3ea49 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/multiplication_by_constant.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/multiplication_by_constant.hpp @@ -58,6 +58,19 @@ namespace nil { using component_type = plonk_component; public: + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return mul_by_constant::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = gate_manifest(gate_manifest_type()); + return manifest; + } + static constexpr const std::size_t gates_amount = 1; const std::size_t rows_amount = get_rows_amount(this->witness_amount(), 0); @@ -78,11 +91,6 @@ namespace nil { return 1; } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount; - } - value_type constant; struct input_type { diff --git a/include/nil/blueprint/components/algebra/fields/plonk/non_native/addition.hpp b/include/nil/blueprint/components/algebra/fields/plonk/non_native/addition.hpp index 00ddec908..f283e8842 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/non_native/addition.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/non_native/addition.hpp @@ -81,6 +81,21 @@ namespace nil { non_native_policy_type>; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return addition::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = + gate_manifest(gate_manifest_type()).merge_with( + range_type::get_gate_manifest(witness_amount, lookup_column_amount)); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr(new manifest_single_value_param(9)), @@ -94,11 +109,6 @@ namespace nil { return rows_amount_internal(witness_amount, lookup_column_amount); } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount + range_type::get_total_gates_amount(witness_amount, lookup_column_amount); - } - constexpr static const std::size_t T = 257; const std::size_t rows_amount = rows_amount_internal(this->witness_amount(), 0); diff --git a/include/nil/blueprint/components/algebra/fields/plonk/non_native/bit_composition.hpp b/include/nil/blueprint/components/algebra/fields/plonk/non_native/bit_composition.hpp index 7eee1955a..091d37cab 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/non_native/bit_composition.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/non_native/bit_composition.hpp @@ -74,6 +74,24 @@ namespace nil { using var = typename component_type::var; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return 0; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount, + std::size_t bits_amount, + bool check_input) { + gate_manifest manifest = + gate_manifest(gate_manifest_type()) + .merge_with(component_type::get_gate_manifest(witness_amount, lookup_column_amount, + bits_amount, check_input)); + return manifest; + } + static manifest_type get_manifest() { return component_type::get_manifest(); } @@ -85,13 +103,6 @@ namespace nil { bits_amount, check_input); } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount, - std::size_t bits_amount, bool check_input) { - return component_type::get_total_gates_amount(witness_amount, lookup_column_amount, - bits_amount, check_input); - } - const bit_composition_mode mode; struct input_type { diff --git a/include/nil/blueprint/components/algebra/fields/plonk/non_native/bit_decomposition.hpp b/include/nil/blueprint/components/algebra/fields/plonk/non_native/bit_decomposition.hpp index f6fe3ca7a..dffb725cc 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/non_native/bit_decomposition.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/non_native/bit_decomposition.hpp @@ -72,24 +72,34 @@ namespace nil { using var = typename component_type::var; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return 0; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount, + std::size_t bits_amount) { + gate_manifest manifest = + gate_manifest(gate_manifest_type()) + .merge_with(component_type::get_gate_manifest(witness_amount, lookup_column_amount, + bits_amount, true)); + return manifest; + } + static manifest_type get_manifest() { return component_type::get_manifest(); } constexpr static std::size_t get_rows_amount(std::size_t witness_amount, - std::size_t lookup_column_amount, - std::size_t bits_amount) { + std::size_t lookup_column_amount, + std::size_t bits_amount) { return component_type::get_rows_amount(witness_amount, lookup_column_amount, bits_amount, true); } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount, - std::size_t bits_amount) { - return component_type::get_total_gates_amount(witness_amount, lookup_column_amount, - bits_amount, true); - } - const bit_composition_mode mode; struct input_type { diff --git a/include/nil/blueprint/components/algebra/fields/plonk/non_native/comparison_checked.hpp b/include/nil/blueprint/components/algebra/fields/plonk/non_native/comparison_checked.hpp index 222bfc4ed..373b043e2 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/non_native/comparison_checked.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/non_native/comparison_checked.hpp @@ -135,6 +135,35 @@ namespace nil { using var = typename component_type::var; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::size_t witness_amount; + std::size_t bits_amount; + comparison_mode mode; + + gate_manifest_type(std::size_t witness_amount_, std::size_t bits_amount_, comparison_mode mode_) + : witness_amount(witness_amount_), bits_amount(bits_amount_), mode(mode_) {} + + std::uint32_t gates_amount() const override { + return comparison_checked::gates_amount_internal(bits_amount, mode); + } + + bool operator<(gate_manifest_type const& other) const { + return witness_amount < other.witness_amount || + (witness_amount == other.witness_amount && bits_amount < other.bits_amount) || + (witness_amount == other.witness_amount && + bits_amount == other.bits_amount && mode < other.mode); + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount, + std::size_t bits_amount, + comparison_mode mode) { + gate_manifest manifest = gate_manifest(gate_manifest_type(witness_amount, bits_amount, mode)); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr( @@ -152,14 +181,6 @@ namespace nil { return rows_amount_internal(witness_amount, bits_amount, mode); } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount, - std::size_t bits_amount, - comparison_mode mode) { - return gates_amount_internal(bits_amount, mode); - } - - /* It's CRITICAL that these three variables remain on top Otherwise initialization goes in wrong order, leading to arbitrary values. diff --git a/include/nil/blueprint/components/algebra/fields/plonk/non_native/comparison_flag.hpp b/include/nil/blueprint/components/algebra/fields/plonk/non_native/comparison_flag.hpp index 76c8387c7..4591c337c 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/non_native/comparison_flag.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/non_native/comparison_flag.hpp @@ -150,6 +150,40 @@ namespace nil { using var = typename component_type::var; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::size_t witness_amount; + std::size_t bits_amount; + comparison_mode mode; + + gate_manifest_type(std::size_t witness_amount_, std::size_t bits_amount_, + comparison_mode mode_) + : witness_amount(witness_amount_), bits_amount(bits_amount_), mode(mode_) {} + + std::uint32_t gates_amount() const override { + return comparison_flag::gates_amount_internal(bits_amount); + } + + bool operator<(const component_gate_manifest* other) const override{ + const gate_manifest_type* other_casted = dynamic_cast(other); + return witness_amount < other_casted->witness_amount || + (witness_amount == other_casted->witness_amount && + bits_amount < other_casted->bits_amount) || + (witness_amount == other_casted->witness_amount && + bits_amount == other_casted->bits_amount && + mode < other_casted->mode); + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount, + std::size_t bits_amount, + comparison_mode mode) { + gate_manifest manifest = + gate_manifest(gate_manifest_type(witness_amount, bits_amount, mode)); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr( @@ -166,13 +200,6 @@ namespace nil { return rows_amount_internal(witness_amount, bits_amount); } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount, - std::size_t bits_amount, - comparison_mode mode) { - return gates_amount_internal(bits_amount); - } - /* It's CRITICAL that these three variables remain on top Otherwise initialization goes in wrong order, leading to arbitrary values. diff --git a/include/nil/blueprint/components/algebra/fields/plonk/non_native/comparison_unchecked.hpp b/include/nil/blueprint/components/algebra/fields/plonk/non_native/comparison_unchecked.hpp index 7f02d87f7..d9360fa44 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/non_native/comparison_unchecked.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/non_native/comparison_unchecked.hpp @@ -92,6 +92,39 @@ namespace nil { ArithmetizationParams>>; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::size_t witness_amount; + comparison_mode mode; + static const std::size_t clamp = 4; + + gate_manifest_type(std::size_t witness_amount_, comparison_mode mode_) + : witness_amount(std::min(witness_amount_, clamp)), mode(mode_) {} + + std::uint32_t gates_amount() const override { + return comparison_unchecked::gates_amount; + } + + bool operator<(const component_gate_manifest* other) const override { + const gate_manifest_type* casted_other = + dynamic_cast(other); + return (witness_amount < casted_other->witness_amount) || + (witness_amount == casted_other->witness_amount && mode < casted_other->mode); + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount, + std::size_t bits_amount, + comparison_mode mode) { + gate_manifest manifest = + gate_manifest(gate_manifest_type(witness_amount, mode)) + .merge_with( + range_check_component_type::get_gate_manifest(witness_amount, lookup_column_amount, + bits_amount)); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr( @@ -108,14 +141,6 @@ namespace nil { return rows_amount_internal(witness_amount, bits_amount, mode); } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount, - std::size_t bits_amount, - comparison_mode mode) { - return gates_amount + range_check_component_type::get_total_gates_amount( - witness_amount, lookup_column_amount, bits_amount); - } - /* It's CRITICAL that these two variables remain on top Otherwise initialization goes in wrong order, leading to arbitrary values. diff --git a/include/nil/blueprint/components/algebra/fields/plonk/non_native/detail/bit_builder_component.hpp b/include/nil/blueprint/components/algebra/fields/plonk/non_native/detail/bit_builder_component.hpp index 17c6a791e..24febf904 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/non_native/detail/bit_builder_component.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/non_native/detail/bit_builder_component.hpp @@ -165,6 +165,33 @@ namespace nil { using var = typename component_type::var; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + private: + std::size_t bits_amount; + bool check_bits; + public: + gate_manifest_type(std::size_t bits_amount_, bool check_bits_) + : bits_amount(bits_amount_), check_bits(check_bits_) {} + + std::uint32_t gates_amount() const override { + return bit_builder_component::gates_amount; + } + + bool operator<(const component_gate_manifest *other) const override { + const gate_manifest_type* other_casted = dynamic_cast(other); + return bits_amount < other_casted->bits_amount || + (bits_amount == other_casted->bits_amount && check_bits < other_casted->check_bits); + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount, + std::size_t bits_amount, + bool check_bits) { + gate_manifest manifest = gate_manifest(gate_manifest_type(bits_amount, check_bits)); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr(new manifest_range_param( @@ -196,12 +223,6 @@ namespace nil { return rows_amount_internal(witness_amount, bits_amount, check_bits); } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount, - std::size_t bits_amount, bool check_bits) { - return gates_amount; - } - template bit_builder_component(ContainerType witness, manifest_type manifest, std::uint32_t bits_amount_, bool check_bits_) : diff --git a/include/nil/blueprint/components/algebra/fields/plonk/non_native/detail/boolean_op_component.hpp b/include/nil/blueprint/components/algebra/fields/plonk/non_native/detail/boolean_op_component.hpp index 4e642fce1..aa6b7af9d 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/non_native/detail/boolean_op_component.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/non_native/detail/boolean_op_component.hpp @@ -74,11 +74,6 @@ namespace nil { return 1; } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount; - } - const std::size_t rows_amount = get_rows_amount(this->witness_amount(), 0); constexpr static const std::size_t gates_amount = 1; diff --git a/include/nil/blueprint/components/algebra/fields/plonk/non_native/division_remainder.hpp b/include/nil/blueprint/components/algebra/fields/plonk/non_native/division_remainder.hpp index 680365e76..77db14861 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/non_native/division_remainder.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/non_native/division_remainder.hpp @@ -87,6 +87,37 @@ namespace nil { ArithmetizationParams>>; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t witness_amount; + static const std::size_t clamp = 5; + + gate_manifest_type(std::size_t witness_amount_) + : witness_amount(std::min(witness_amount_, clamp)) {} + + std::uint32_t gates_amount() const override { + return division_remainder::gates_amount; + } + + bool operator<(const component_gate_manifest *other) { + const gate_manifest_type *other_casted = + dynamic_cast(other); + return witness_amount < other_casted->witness_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount, + std::size_t bits_amount, + bool check_inputs) { + gate_manifest manifest = + gate_manifest(gate_manifest_type(witness_amount)) + .merge_with(range_check_component_type::get_gate_manifest(witness_amount, + lookup_column_amount, + bits_amount)); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr( @@ -103,14 +134,6 @@ namespace nil { return rows_amount_internal(witness_amount, bits_amount, check_inputs); } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount, - std::size_t bits_amount, - bool check_inputs) { - return gates_amount + range_check_component_type::get_total_gates_amount( - witness_amount, lookup_column_amount, bits_amount); - } - /* It's CRITICAL that these two variables remain on top Otherwise initialization goes in wrong order, leading to arbitrary values. diff --git a/include/nil/blueprint/components/algebra/fields/plonk/non_native/logic_ops.hpp b/include/nil/blueprint/components/algebra/fields/plonk/non_native/logic_ops.hpp index 77901ce11..1789c6047 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/non_native/logic_ops.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/non_native/logic_ops.hpp @@ -63,6 +63,19 @@ namespace nil { using var = typename component_type::var; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return logic_not::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = gate_manifest(gate_manifest_type()); + return manifest; + } + static manifest_type get_manifest() { return component_type::get_manifest(); } @@ -72,11 +85,6 @@ namespace nil { return component_type::get_rows_amount(witness_amount, lookup_column_amount); } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return component_type::get_total_gates_amount(witness_amount, lookup_column_amount); - } - virtual crypto3::zk::snark::plonk_constraint op_constraint(const std::array &witnesses) const { return 1 - witnesses[0] - witnesses[1]; @@ -124,6 +132,19 @@ namespace nil { using var = typename component_type::var; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return logic_and::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = gate_manifest(gate_manifest_type()); + return manifest; + } + static manifest_type get_manifest() { return component_type::get_manifest(); } @@ -133,11 +154,6 @@ namespace nil { return component_type::get_rows_amount(witness_amount, lookup_column_amount); } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return component_type::get_total_gates_amount(witness_amount, lookup_column_amount); - } - virtual crypto3::zk::snark::plonk_constraint op_constraint(const std::array &witnesses) const { return witnesses[2] - witnesses[0] * witnesses[1]; @@ -185,6 +201,19 @@ namespace nil { using var = typename component_type::var; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return logic_or::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = gate_manifest(gate_manifest_type()); + return manifest; + } + static manifest_type get_manifest() { return component_type::get_manifest(); } @@ -194,11 +223,6 @@ namespace nil { return component_type::get_rows_amount(witness_amount, lookup_column_amount); } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return component_type::get_total_gates_amount(witness_amount, lookup_column_amount); - } - virtual crypto3::zk::snark::plonk_constraint op_constraint(const std::array &witnesses) const { return witnesses[2] - (witnesses[0] + witnesses[1] - witnesses[0] * witnesses[1]); @@ -246,6 +270,19 @@ namespace nil { using var = typename component_type::var; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return logic_xor::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = gate_manifest(gate_manifest_type()); + return manifest; + } + static manifest_type get_manifest() { return component_type::get_manifest(); } @@ -255,11 +292,6 @@ namespace nil { return component_type::get_rows_amount(witness_amount, lookup_column_amount); } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return component_type::get_total_gates_amount(witness_amount, lookup_column_amount); - } - virtual crypto3::zk::snark::plonk_constraint op_constraint(const std::array &witnesses) const { return witnesses[2] - (witnesses[0] + witnesses[1] - 2 * witnesses[0] * witnesses[1]); @@ -309,6 +341,19 @@ namespace nil { using var = typename component_type::var; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return logic_nand::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = gate_manifest(gate_manifest_type()); + return manifest; + } + static manifest_type get_manifest() { return component_type::get_manifest(); } @@ -318,11 +363,6 @@ namespace nil { return component_type::get_rows_amount(witness_amount, lookup_column_amount); } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return component_type::get_total_gates_amount(witness_amount, lookup_column_amount); - } - virtual crypto3::zk::snark::plonk_constraint op_constraint(const std::array &witnesses) const { return witnesses[2] - (1 - witnesses[0] * witnesses[1]); @@ -369,6 +409,19 @@ namespace nil { using var = typename component_type::var; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return logic_nor::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = gate_manifest(gate_manifest_type()); + return manifest; + } + static manifest_type get_manifest() { return component_type::get_manifest(); } @@ -378,11 +431,6 @@ namespace nil { return component_type::get_rows_amount(witness_amount, lookup_column_amount); } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return component_type::get_total_gates_amount(witness_amount, lookup_column_amount); - } - virtual crypto3::zk::snark::plonk_constraint op_constraint(const std::array &witnesses) const { return witnesses[2] - (1 - (witnesses[0] + witnesses[1] - witnesses[0] * witnesses[1])); diff --git a/include/nil/blueprint/components/algebra/fields/plonk/non_native/multiplication.hpp b/include/nil/blueprint/components/algebra/fields/plonk/non_native/multiplication.hpp index 87e13deb3..b6d3ca8a7 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/non_native/multiplication.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/non_native/multiplication.hpp @@ -80,6 +80,21 @@ namespace nil { non_native_policy_type>; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return multiplication::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = + gate_manifest(gate_manifest_type()).merge_with( + range_type::get_gate_manifest(witness_amount, lookup_column_amount)); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr(new manifest_single_value_param(9)), @@ -93,11 +108,6 @@ namespace nil { return rows_amount_internal(witness_amount, lookup_column_amount); } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount + range_type::get_total_gates_amount(witness_amount, lookup_column_amount); - } - constexpr static const std::size_t T = 257; const std::size_t rows_amount = rows_amount_internal(this->witness_amount(), 0); 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 cd8f66014..a973ccf14 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 @@ -65,6 +65,19 @@ namespace nil { using var = typename component_type::var; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return range::gates_amount; + } + }; + + static gate_manifest& get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = gate_manifest(gate_manifest_type()); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr(new manifest_single_value_param(9)), @@ -77,12 +90,6 @@ namespace nil { std::size_t lookup_column_amount) { return 2; } - - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount; - } - const std::size_t rows_amount = get_rows_amount(this->witness_amount(), 0); constexpr static const std::size_t gates_amount = 1; diff --git a/include/nil/blueprint/components/algebra/fields/plonk/non_native/reduction.hpp b/include/nil/blueprint/components/algebra/fields/plonk/non_native/reduction.hpp index ecf1801c8..e6c5871b7 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/non_native/reduction.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/non_native/reduction.hpp @@ -60,6 +60,19 @@ namespace nil { public: using var = typename component_type::var;using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return reduction::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = gate_manifest(gate_manifest_type()); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr(new manifest_single_value_param(9)), @@ -73,13 +86,8 @@ namespace nil { return 4; } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return 2; - } - const std::size_t rows_amount = get_rows_amount(this->witness_amount(), 0); - const std::size_t gates_amount = get_total_gates_amount(this->witness_amount(), 0); + static const std::size_t gates_amount = 2; struct input_type { std::array k; diff --git a/include/nil/blueprint/components/algebra/fields/plonk/non_native/subtraction.hpp b/include/nil/blueprint/components/algebra/fields/plonk/non_native/subtraction.hpp index 7c21ecb9f..73876e14b 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/non_native/subtraction.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/non_native/subtraction.hpp @@ -79,6 +79,21 @@ namespace nil { non_native_policy_type>; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return subtraction::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = + gate_manifest(gate_manifest_type()) + .merge_with(range_type::get_gate_manifest(witness_amount, lookup_column_amount)); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr(new manifest_single_value_param(9)), @@ -92,11 +107,6 @@ namespace nil { return rows_amount_internal(witness_amount, lookup_column_amount); } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount + range_type::get_total_gates_amount(witness_amount, lookup_column_amount); - } - constexpr static const std::size_t T = 257; const std::size_t rows_amount = get_rows_amount(this->witness_amount(), 0); 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 631211a66..785641479 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/range_check.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/range_check.hpp @@ -108,6 +108,35 @@ namespace nil { using var = typename component_type::var; using manifest_type = plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::size_t bits_amount; + std::size_t witness_amount; + + gate_manifest_type(std::size_t witness_amount_, std::size_t bits_amount_) + : witness_amount(witness_amount_), bits_amount(bits_amount_) {} + + std::uint32_t gates_amount() const override { + return range_check::gates_amount_internal(bits_amount); + } + + bool operator<(const component_gate_manifest *other) const override { + std::size_t other_witness_amount = + dynamic_cast(other)->witness_amount; + return + (witness_amount < other_witness_amount) || + (witness_amount == other_witness_amount && + bits_amount < dynamic_cast(other)->bits_amount); + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount, + std::size_t bits_amount) { + gate_manifest manifest = gate_manifest(gate_manifest_type(witness_amount, bits_amount)); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr( @@ -123,12 +152,6 @@ namespace nil { return rows_amount_internal(witness_amount, bits_amount); } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount, - std::size_t bits_amount) { - return gates_amount_internal(bits_amount); - } - /* It's CRITICAL that these three variables remain on top Otherwise initialization goes in wrong order, leading to arbitrary values. @@ -168,7 +191,7 @@ namespace nil { PublicInputContainerType public_input, std::size_t bits_amount_): component_type(witness, constant, public_input, get_manifest()), - bits_amount(bits_amount_) {}; + bits_amount(bits_amount_) {} range_check( std::initializer_list witnesses, @@ -345,7 +368,6 @@ namespace nil { gate_type gate(first_selector_index, constraints); bp.add_gate(gate); - if (component.bits_amount % component.chunk_size == 0) return; // If bits_amount is not divisible by chunk size, the first chunk should be constrained to be // less than 2^{bits_amount % chunk_size} diff --git a/include/nil/blueprint/components/algebra/fields/plonk/subtraction.hpp b/include/nil/blueprint/components/algebra/fields/plonk/subtraction.hpp index b0e1e5f55..cba6b9ab9 100644 --- a/include/nil/blueprint/components/algebra/fields/plonk/subtraction.hpp +++ b/include/nil/blueprint/components/algebra/fields/plonk/subtraction.hpp @@ -58,16 +58,25 @@ namespace nil { using component_type = plonk_component; public: - constexpr static std::size_t get_rows_amount(std::size_t witness_amount, std::size_t lookup_column_amount) { - return 1; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return subtraction::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = gate_manifest(gate_manifest_type()); + return manifest; } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { + constexpr static std::size_t get_rows_amount(std::size_t witness_amount, + std::size_t lookup_column_amount) { return 1; } - const std::size_t gates_amount = get_total_gates_amount(this->witness_amount(), 0); + constexpr static const std::size_t gates_amount = 1; const std::size_t rows_amount = get_rows_amount(this->witness_amount(), 0); using var = typename component_type::var; diff --git a/include/nil/blueprint/components/hashes/poseidon/plonk/poseidon.hpp b/include/nil/blueprint/components/hashes/poseidon/plonk/poseidon.hpp index 31a65b41a..a8c54c66d 100644 --- a/include/nil/blueprint/components/hashes/poseidon/plonk/poseidon.hpp +++ b/include/nil/blueprint/components/hashes/poseidon/plonk/poseidon.hpp @@ -74,6 +74,20 @@ namespace nil { using var = typename component_type::var; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return poseidon::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = gate_manifest(gate_manifest_type()); + return manifest; + } + + static manifest_type get_manifest() { using manifest_param = nil::blueprint::manifest_param; using manifest_single_value_param = nil::blueprint::manifest_single_value_param; @@ -89,11 +103,6 @@ namespace nil { return rounds_amount / rounds_per_row + 1; } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount; - } - struct input_type { std::array input_state; }; diff --git a/include/nil/blueprint/components/hashes/sha2/plonk/decomposition.hpp b/include/nil/blueprint/components/hashes/sha2/plonk/decomposition.hpp index 8a83433cc..e125d9a52 100644 --- a/include/nil/blueprint/components/hashes/sha2/plonk/decomposition.hpp +++ b/include/nil/blueprint/components/hashes/sha2/plonk/decomposition.hpp @@ -56,6 +56,19 @@ namespace nil { using var = typename component_type::var; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return decomposition::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = gate_manifest(gate_manifest_type()); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr( @@ -70,11 +83,6 @@ namespace nil { return 3; } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount; - } - const std::size_t rows_amount = get_rows_amount(this->witness_amount(), 0); constexpr static const std::size_t gates_amount = 1; @@ -146,7 +154,7 @@ namespace nil { } assignment.witness(component.W(8), row) = data[0]; - assignment.witness(component.W(8), row + 2) = data[1]; + assignment.witness(component.W(8), row + 2) = data[1]; assignment.witness(component.W(3), row + 1) = range_chunks[1] * (65536) + range_chunks[0]; assignment.witness(component.W(2), row + 1) = range_chunks[3] * (65536) + range_chunks[2]; diff --git a/include/nil/blueprint/components/hashes/sha2/plonk/sha256.hpp b/include/nil/blueprint/components/hashes/sha2/plonk/sha256.hpp index 125b18e7d..d06d4b958 100644 --- a/include/nil/blueprint/components/hashes/sha2/plonk/sha256.hpp +++ b/include/nil/blueprint/components/hashes/sha2/plonk/sha256.hpp @@ -63,6 +63,22 @@ namespace nil { crypto3::zk::snark::plonk_constraint_system, BlueprintFieldType>; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return sha256::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = + gate_manifest(gate_manifest_type()) + .merge_with(sha256_process_type::get_gate_manifest(witness_amount, lookup_column_amount)) + .merge_with(decomposition_type::get_gate_manifest(witness_amount, lookup_column_amount)); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr( @@ -81,13 +97,6 @@ namespace nil { 2; } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount + - sha256_process_type::get_total_gates_amount(witness_amount, lookup_column_amount) + - decomposition_type::get_total_gates_amount(witness_amount, lookup_column_amount); - } - const std::size_t rows_amount = get_rows_amount(this->witness_amount(), 0); constexpr static const std::size_t gates_amount = 1; diff --git a/include/nil/blueprint/components/hashes/sha2/plonk/sha256_process.hpp b/include/nil/blueprint/components/hashes/sha2/plonk/sha256_process.hpp index e3628d680..e97fca954 100644 --- a/include/nil/blueprint/components/hashes/sha2/plonk/sha256_process.hpp +++ b/include/nil/blueprint/components/hashes/sha2/plonk/sha256_process.hpp @@ -59,6 +59,19 @@ namespace nil { using var = typename component_type::var; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return sha256_process::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = gate_manifest(gate_manifest_type()); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr( @@ -73,11 +86,6 @@ namespace nil { return 758; } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount; - } - constexpr static const std::size_t rounds_amount = 64; constexpr static const std::size_t base4 = 4; diff --git a/include/nil/blueprint/components/hashes/sha2/plonk/sha512.hpp b/include/nil/blueprint/components/hashes/sha2/plonk/sha512.hpp index b85fe5246..c2e3f067c 100644 --- a/include/nil/blueprint/components/hashes/sha2/plonk/sha512.hpp +++ b/include/nil/blueprint/components/hashes/sha2/plonk/sha512.hpp @@ -54,6 +54,21 @@ namespace nil { using var = typename component_type::var; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return sha512::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = + gate_manifest(gate_manifest_type()) + .merge_with(sha512_process_component::get_gate_manifest(witness_amount, lookup_column_amount)); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr( @@ -70,12 +85,6 @@ namespace nil { sha512_process_component::get_rows_amount(witness_amount, lookup_column_amount) * 2 /* + 2 */; } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount + - sha512_process_component::get_total_gates_amount(witness_amount, lookup_column_amount); - } - constexpr static const std::size_t gates_amount = 5; constexpr static const std::size_t rows_amount_creating_input_words_component = 15; // diff --git a/include/nil/blueprint/components/hashes/sha2/plonk/sha512_process.hpp b/include/nil/blueprint/components/hashes/sha2/plonk/sha512_process.hpp index 8c2283850..bd2005f9a 100644 --- a/include/nil/blueprint/components/hashes/sha2/plonk/sha512_process.hpp +++ b/include/nil/blueprint/components/hashes/sha2/plonk/sha512_process.hpp @@ -59,6 +59,19 @@ namespace nil { using var = typename component_type::var; using manifest_type = nil::blueprint::plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return sha512_process::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = gate_manifest(gate_manifest_type()); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr( @@ -73,11 +86,6 @@ namespace nil { return 6*64 + 2 + 9*80 + 4; } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount; - } - constexpr static const std::size_t rounds_amount = 80; constexpr static const std::size_t base4 = 4; 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 24c49ec98..ffd573319 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 @@ -66,6 +66,19 @@ namespace nil { using var = typename component_type::var; using manifest_type = plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return from_limbs::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = gate_manifest(gate_manifest_type()); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr(new manifest_single_value_param(3)), @@ -79,11 +92,6 @@ namespace nil { return 1; } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount; - } - const std::size_t rows_amount = get_rows_amount(this->witness_amount(), 0); static constexpr const std::size_t gates_amount = 1; @@ -225,6 +233,23 @@ namespace nil { using var = typename component_type::var; using manifest_type = plonk_component_manifest; + class gate_manifest_type : public component_gate_manifest { + public: + std::uint32_t gates_amount() const override { + return to_limbs::gates_amount; + } + }; + + static gate_manifest get_gate_manifest(std::size_t witness_amount, + std::size_t lookup_column_amount) { + static gate_manifest manifest = + gate_manifest(gate_manifest_type()) + .merge_with(range_check_component::get_gate_manifest(witness_amount, + lookup_column_amount, + chunk_size)); + return manifest; + } + static manifest_type get_manifest() { static manifest_type manifest = manifest_type( std::shared_ptr(new manifest_single_value_param(15)), @@ -240,13 +265,6 @@ namespace nil { chunk_size); } - constexpr static std::size_t get_total_gates_amount(std::size_t witness_amount, - std::size_t lookup_column_amount) { - return gates_amount + - range_check_component::get_total_gates_amount(witness_amount, lookup_column_amount, - chunk_size); - } - constexpr static const std::size_t chunk_size_public = chunk_size; constexpr static const std::size_t chunk_amount = 4; const std::size_t rows_amount = get_rows_amount(this->witness_amount(), 0); diff --git a/include/nil/blueprint/manifest.hpp b/include/nil/blueprint/manifest.hpp index d743bea28..6657c6bf4 100644 --- a/include/nil/blueprint/manifest.hpp +++ b/include/nil/blueprint/manifest.hpp @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -34,6 +35,7 @@ #include #include #include +#include #include #include @@ -1134,6 +1136,80 @@ namespace nil { ); } }; + + // Base class for all component gate manifests + class component_gate_manifest { + public: + virtual std::uint32_t gates_amount() const = 0; + // This is called in comparison function + // Derived classes should only support compariosn with instances of themselves + // The case of different classes is already handled in the comparator + // Default implementation is to return false, meaning equality of all instances in set terms. + virtual bool operator<(const component_gate_manifest *other) const { + return false; + } + }; + + class component_gate_manifest_comparison { + public: + bool operator()(const std::shared_ptr &a, + const std::shared_ptr &b) const { + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wpotentially-evaluated-expression" + if (typeid(*(a.get())) != typeid(*(b.get()))) { + #pragma clang diagnostic pop + return a.get() < b.get(); + } else { + return a->operator<(b.get()); + } + } + }; + + // We use this to avoid having "duplicate" gates counted in gates count. + // Done via references to allow constexpr access to gates amount. + struct gate_manifest { + private: + std::uint32_t gates_amount; + + void calc_gates_amount() { + std::uint32_t result = 0; + for (auto gate : component_gate_manifests) { + result += gate.get()->gates_amount(); + } + gates_amount = result; + } + + public: + std::set, component_gate_manifest_comparison> + component_gate_manifests = {}; + + gate_manifest() : gates_amount(0) {} + gate_manifest(const gate_manifest &other) : gates_amount(other.gates_amount) { + component_gate_manifests = other.component_gate_manifests; + } + template + gate_manifest(const GateManifestType &gate) : gates_amount(0) { + add(gate); + } + + template + gate_manifest& add(const GateManifestType &gate) { + component_gate_manifests.insert(std::make_shared(gate)); + calc_gates_amount(); + return *this; + } + + std::uint32_t get_gates_amount() const { + return gates_amount; + } + + gate_manifest& merge_with(const gate_manifest &other) { + component_gate_manifests.insert(other.component_gate_manifests.begin(), + other.component_gate_manifests.end()); + calc_gates_amount(); + return *this; + } + }; } // namespace blueprint } // namespace nil diff --git a/test/non_native/plonk/add_mul_zkllvm_compatible.cpp b/test/non_native/plonk/add_mul_zkllvm_compatible.cpp index e31a108d8..7802a053e 100644 --- a/test/non_native/plonk/add_mul_zkllvm_compatible.cpp +++ b/test/non_native/plonk/add_mul_zkllvm_compatible.cpp @@ -73,7 +73,6 @@ void test_mul(typename CurveType::base_field_type::value_type b_val, ArithmetizationType, CurveType, Ed25519Type, - WitnessColumns, nil::blueprint::basic_non_native_policy>; std::array input_var_Xa = { @@ -127,9 +126,9 @@ void test_mul(typename CurveType::base_field_type::value_type b_val, }; component_type component_instance({0, 1, 2, 3, 4, 5, 6, 7, 8}, {0}, {}); - + // 253 is the default bits_amount crypto3::test_component( - component_instance, public_input, result_check, instance_input); + component_instance, public_input, result_check, instance_input, 253); } template @@ -154,7 +153,6 @@ void test_mul_per_bit(){ ArithmetizationType, CurveType, ed25519_type, - WitnessColumns, nil::blueprint::basic_non_native_policy>; std::array input_var_Xa = { @@ -239,7 +237,7 @@ void test_doubling(){ using var = crypto3::zk::snark::plonk_variable; using component_type = blueprint::components::doubling>; std::array input_var_Xa = { @@ -301,7 +299,7 @@ void test_complete_addition(){ using var = crypto3::zk::snark::plonk_variable; using component_type = blueprint::components::complete_addition>; std::array input_var_Xa = { diff --git a/test/test_plonk_component.hpp b/test/test_plonk_component.hpp index 973a0bc9a..83a5c9809 100644 --- a/test/test_plonk_component.hpp +++ b/test/test_plonk_component.hpp @@ -207,8 +207,8 @@ namespace nil { component_static_info_args...), "Static component rows amount does not match actual rows amount."); BOOST_ASSERT_MSG(bp.num_gates() == - component_type::get_total_gates_amount(component_instance.witness_amount(), 0, - component_static_info_args...), + component_type::get_gate_manifest(component_instance.witness_amount(), 0, + component_static_info_args...).get_gates_amount(), "Component total gates amount does not match actual gates amount."); }