Skip to content

Commit

Permalink
fold genFlag into component_creation_parameters_struct
Browse files Browse the repository at this point in the history
  • Loading branch information
CblPOK-git committed Feb 2, 2024
1 parent ce1cf62 commit 4031373
Show file tree
Hide file tree
Showing 28 changed files with 314 additions and 266 deletions.
4 changes: 2 additions & 2 deletions include/nil/blueprint/boolean/logic_ops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace nil {
circuit_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp,
assignment_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
&assignment,
std::uint32_t start_row, std::uint32_t target_prover_idx, generate_flag gen_flag) {
std::uint32_t start_row, std::uint32_t target_prover_idx, component_creation_parameters_struct comp_gen_params) {

using arithmetization_type = crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>;
using component_type = components::logic_and<arithmetization_type>;
Expand All @@ -52,7 +52,7 @@ namespace nil {
instance_input.input[1] = y;

return get_component_result<BlueprintFieldType, ArithmetizationParams>
(bp, assignment, start_row, target_prover_idx, gen_flag, instance_input).output;
(bp, assignment, start_row, target_prover_idx, comp_gen_params, instance_input).output;
}

} // namespace blueprint
Expand Down
6 changes: 3 additions & 3 deletions include/nil/blueprint/comparison/comparison.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace nil {
circuit_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp,
assignment_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
&assignment,
std::uint32_t start_row, std::uint32_t target_prover_idx, generate_flag gen_flag) {
std::uint32_t start_row, std::uint32_t target_prover_idx, component_creation_parameters_struct comp_gen_params) {

using eq_component_type = components::equality_flag<
crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>, BlueprintFieldType>;
Expand All @@ -54,12 +54,12 @@ namespace nil {
switch (p) {
case llvm::CmpInst::ICMP_EQ: {
return get_component_result<BlueprintFieldType, ArithmetizationParams, eq_component_type>
(bp, assignment, start_row, target_prover_idx, instance_input, gen_flag, false);
(bp, assignment, start_row, target_prover_idx, instance_input, comp_gen_params, false);
break;
}
case llvm::CmpInst::ICMP_NE:{
return get_component_result<BlueprintFieldType, ArithmetizationParams, eq_component_type>
(bp, assignment, start_row, target_prover_idx, instance_input, gen_flag, true);
(bp, assignment, start_row, target_prover_idx, instance_input, comp_gen_params, true);
break;
}
default:
Expand Down
62 changes: 62 additions & 0 deletions include/nil/blueprint/component_creation_parameters.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2022 Mikhail Komarov <[email protected]>
// Copyright (c) 2022 Nikita Kaskov <[email protected]>
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//---------------------------------------------------------------------------//

#ifndef CRYPTO3_BLUEPRINT_COMPONENT_CREATION_PARAMETERS_HPP
#define CRYPTO3_BLUEPRINT_COMPONENT_CREATION_PARAMETERS_HPP

namespace nil {
namespace blueprint {

enum class generate_flag : uint8_t {
NONE = 0,
CIRCUIT = 1 << 0,
ASSIGNMENTS = 1 << 1,
FALSE_ASSIGNMENTS = 1 << 2
};

constexpr enum generate_flag operator |( const enum generate_flag self, const enum generate_flag val )
{
return (enum generate_flag)(uint8_t(self) | uint8_t(val));
}
constexpr enum generate_flag operator &( const enum generate_flag self, const enum generate_flag val )
{
return (enum generate_flag)(uint8_t(self) & uint8_t(val));
}


struct component_creation_parameters_struct {
generate_flag genFlag;
component_creation_parameters_struct(generate_flag input) {
genFlag = input;
}
component_creation_parameters_struct() {
genFlag = ((generate_flag)((uint8_t)generate_flag::ASSIGNMENTS | (uint8_t)generate_flag::CIRCUIT));
}
};

} // namespace blueprint
} // namespace nil

#endif // CRYPTO3_BLUEPRINT_COMPONENT_CREATION_PARAMETERS_HPP
18 changes: 9 additions & 9 deletions include/nil/blueprint/curves/addition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace nil {
circuit_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp,
assignment_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
&assignment,
std::uint32_t start_row, std::uint32_t target_prover_idx, generate_flag gen_flag) {
std::uint32_t start_row, std::uint32_t target_prover_idx, component_creation_parameters_struct comp_gen_params) {

using var = crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>;

Expand All @@ -70,7 +70,7 @@ namespace nil {
typename component_type::input_type addition_input = {{P.X, P.Y}, {Q.X, Q.Y}};

return get_component_result<BlueprintFieldType, ArithmetizationParams, component_type>
(bp, assignment, start_row, target_prover_idx, addition_input, gen_flag);
(bp, assignment, start_row, target_prover_idx, addition_input, comp_gen_params);
}

template<typename BlueprintFieldType, typename ArithmetizationParams, typename CurveType, typename Ed25519Type>
Expand All @@ -85,7 +85,7 @@ namespace nil {
circuit_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp,
assignment_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
&assignment,
std::uint32_t start_row, std::uint32_t target_prover_idx, generate_flag gen_flag) {
std::uint32_t start_row, std::uint32_t target_prover_idx, component_creation_parameters_struct comp_gen_params) {

using var = crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>;

Expand Down Expand Up @@ -127,7 +127,7 @@ namespace nil {
typename component_type::input_type addition_input = {{P.X, P.Y}, {Q.X, Q.Y}};

return get_component_result<BlueprintFieldType, ArithmetizationParams, component_type>
(bp, assignment, start_row, target_prover_idx, addition_input, gen_flag);
(bp, assignment, start_row, target_prover_idx, addition_input, comp_gen_params);
}
} // namespace detail

Expand All @@ -138,7 +138,7 @@ namespace nil {
circuit_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp,
assignment_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
&assignment,
std::uint32_t start_row, std::uint32_t target_prover_idx, generate_flag gen_flag) {
std::uint32_t start_row, std::uint32_t target_prover_idx, component_creation_parameters_struct comp_gen_params) {

using non_native_policy_type = basic_non_native_policy<BlueprintFieldType>;

Expand Down Expand Up @@ -168,9 +168,9 @@ namespace nil {
using component_type = components::unified_addition<ArithmetizationType, operating_curve_type>;
typename component_type::result_type res =
detail::handle_native_curve_unified_addition_component<BlueprintFieldType, ArithmetizationParams, operating_curve_type>(
operand0, operand1, frame.vectors, bp, assignment, start_row, target_prover_idx, gen_flag);
operand0, operand1, frame.vectors, bp, assignment, start_row, target_prover_idx, comp_gen_params);
std::vector<crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>> res_vector = {res.X, res.Y};
handle_component_result<BlueprintFieldType, ArithmetizationParams, component_type>(assignment, inst, frame, res, gen_flag);
handle_component_result<BlueprintFieldType, ArithmetizationParams, component_type>(assignment, inst, frame, res, comp_gen_params);
} else {
UNREACHABLE("non-native pallas is undefined");
}
Expand Down Expand Up @@ -209,8 +209,8 @@ namespace nil {
operating_curve_type, basic_non_native_policy<BlueprintFieldType>>;
typename component_type::result_type res =
detail::handle_non_native_curve_addition_component<BlueprintFieldType, ArithmetizationParams, pallas_curve_type, operating_curve_type>(
operand0, operand1, frame.vectors, bp, assignment, start_row, target_prover_idx, gen_flag);
handle_component_result<BlueprintFieldType, ArithmetizationParams, component_type>(assignment, inst, frame, res, gen_flag);
operand0, operand1, frame.vectors, bp, assignment, start_row, target_prover_idx, comp_gen_params);
handle_component_result<BlueprintFieldType, ArithmetizationParams, component_type>(assignment, inst, frame, res, comp_gen_params);
}
}

Expand Down
18 changes: 9 additions & 9 deletions include/nil/blueprint/curves/multiplication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace nil {
circuit_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp,
assignment_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
&assignment,
std::uint32_t start_row, std::uint32_t target_prover_idx, generate_flag gen_flag) {
std::uint32_t start_row, std::uint32_t target_prover_idx, component_creation_parameters_struct comp_gen_params) {

using var = crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>;

Expand All @@ -71,7 +71,7 @@ namespace nil {
typename component_type::input_type addition_input = {{T.X, T.Y}, b[0], b[1]};

return get_component_result<BlueprintFieldType, ArithmetizationParams, component_type>
(bp, assignment, start_row, target_prover_idx, addition_input, gen_flag);
(bp, assignment, start_row, target_prover_idx, addition_input, comp_gen_params);
}

template<typename BlueprintFieldType, typename ArithmetizationParams, typename CurveType, typename Ed25519Type>
Expand All @@ -88,7 +88,7 @@ namespace nil {
circuit_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp,
assignment_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
&assignment,
std::uint32_t start_row, std::uint32_t target_prover_idx, generate_flag gen_flag) {
std::uint32_t start_row, std::uint32_t target_prover_idx, component_creation_parameters_struct comp_gen_params) {

using var = crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>;

Expand Down Expand Up @@ -119,7 +119,7 @@ namespace nil {
typename component_type::input_type addition_input = {{T.X, T.Y}, b};

return get_component_result<BlueprintFieldType, ArithmetizationParams, component_type>
(bp, assignment, start_row, target_prover_idx, addition_input, gen_flag,
(bp, assignment, start_row, target_prover_idx, addition_input, comp_gen_params,
253, nil::blueprint::components::bit_shift_mode::RIGHT);
}

Expand All @@ -132,7 +132,7 @@ namespace nil {
circuit_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp,
assignment_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
&assignment,
std::uint32_t start_row, std::uint32_t target_prover_idx, generate_flag gen_flag) {
std::uint32_t start_row, std::uint32_t target_prover_idx, component_creation_parameters_struct comp_gen_params) {

using non_native_policy_type = basic_non_native_policy<BlueprintFieldType>;

Expand Down Expand Up @@ -185,9 +185,9 @@ namespace nil {
ArithmetizationType, operating_curve_type>;
typename component_type::result_type res =
detail::handle_native_curve_non_native_scalar_multiplication_component<BlueprintFieldType, ArithmetizationParams, operating_curve_type>(
operand_curve, operand_field, frame.vectors, bp, assignment, start_row, target_prover_idx, gen_flag);
operand_curve, operand_field, frame.vectors, bp, assignment, start_row, target_prover_idx, comp_gen_params);
std::vector<crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>> res_vector = {res.X, res.Y};
handle_component_result<BlueprintFieldType, ArithmetizationParams, component_type>(assignment, inst, frame, res, gen_flag);
handle_component_result<BlueprintFieldType, ArithmetizationParams, component_type>(assignment, inst, frame, res, comp_gen_params);
} else {
UNREACHABLE("non-native pallas multiplication is not implemented");
}
Expand Down Expand Up @@ -227,9 +227,9 @@ namespace nil {
assignment,
start_row,
target_prover_idx,
gen_flag);
comp_gen_params);

handle_component_result<BlueprintFieldType, ArithmetizationParams, component_type>(assignment, inst, frame, res, gen_flag);
handle_component_result<BlueprintFieldType, ArithmetizationParams, component_type>(assignment, inst, frame, res, comp_gen_params);
}
}

Expand Down
2 changes: 1 addition & 1 deletion include/nil/blueprint/curves/subtraction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace nil {
circuit_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp,
assignment_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
&assignment,
std::uint32_t start_row, std::uint32_t target_prover_idx, generate_flag gen_flag) {
std::uint32_t start_row, std::uint32_t target_prover_idx, component_creation_parameters_struct comp_gen_params) {

using non_native_policy_type = basic_non_native_policy<BlueprintFieldType>;

Expand Down
4 changes: 2 additions & 2 deletions include/nil/blueprint/extract_constructor_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ namespace nil {
typename std::map<const llvm::Value *, crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>> &variables,
program_memory<crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>> &memory,
assignment_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
&assignment, generate_flag gen_flag
&assignment, component_creation_parameters_struct comp_gen_params
) {
std::vector<var> res = {};
if (std::uint8_t(gen_flag & generate_flag::ASSIGNMENTS)) {
if (std::uint8_t(comp_gen_params.genFlag & generate_flag::ASSIGNMENTS)) {
ptr_type input_ptr = static_cast<ptr_type>(
typename BlueprintFieldType::integral_type(var_value(assignment, variables[input_value]).data));
for (std::size_t i = 0; i < input_length; i++) {
Expand Down
Loading

0 comments on commit 4031373

Please sign in to comment.