Skip to content

Commit

Permalink
mnt6 mod #355
Browse files Browse the repository at this point in the history
  • Loading branch information
vo-nil committed Apr 19, 2024
1 parent 73d8f2b commit 9cb4177
Showing 1 changed file with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2023 Alexey Yashunsky <a.yashunsky@nil.foundation>
// Copyright (c) 2024 Vasiliy Olekhov <vasiliy.olkhov@nil.foundation>
//
// MIT License
//
Expand All @@ -26,8 +27,8 @@
// F_p^2 = F_p[u]/(u^2 - (-1)) and a a non-cubic residue.
//---------------------------------------------------------------------------//

#ifndef CRYPTO3_BLUEPRINT_COMPONENTS_PLONK_BLS12_G2_POINT_ADDITION_HPP
#define CRYPTO3_BLUEPRINT_COMPONENTS_PLONK_BLS12_G2_POINT_ADDITION_HPP
#ifndef CRYPTO3_BLUEPRINT_COMPONENTS_PLONK_MNT6_G2_POINT_ADDITION_HPP
#define CRYPTO3_BLUEPRINT_COMPONENTS_PLONK_MNT6_G2_POINT_ADDITION_HPP

#include <nil/crypto3/zk/snark/arithmetization/plonk/constraint_system.hpp>

Expand Down Expand Up @@ -59,10 +60,10 @@ namespace nil {
//

template<typename ArithmetizationType>
class bls12_g2_point_addition;
class mnt6_g2_point_addition;

template<typename BlueprintFieldType>
class bls12_g2_point_addition<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>>
class mnt6_g2_point_addition<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>>
: public plonk_component<BlueprintFieldType> {

public:
Expand All @@ -74,7 +75,7 @@ namespace nil {
class gate_manifest_type : public component_gate_manifest {
public:
std::uint32_t gates_amount() const override {
return bls12_g2_point_addition::gates_amount;
return mnt6_g2_point_addition::gates_amount;
}
};

Expand Down Expand Up @@ -115,7 +116,7 @@ namespace nil {
struct result_type {
std::array<var,4> R;

result_type(const bls12_g2_point_addition &component, std::uint32_t start_row_index) {
result_type(const mnt6_g2_point_addition &component, std::uint32_t start_row_index) {
const std::size_t WA = component.witness_amount();

for(std::size_t i = 0; i < 4; i++) {
Expand All @@ -132,15 +133,15 @@ namespace nil {
};

template<typename ContainerType>
explicit bls12_g2_point_addition(ContainerType witness) : component_type(witness, {}, {}, get_manifest()) {};
explicit mnt6_g2_point_addition(ContainerType witness) : component_type(witness, {}, {}, get_manifest()) {};

template<typename WitnessContainerType, typename ConstantContainerType,
typename PublicInputContainerType>
bls12_g2_point_addition(WitnessContainerType witness, ConstantContainerType constant,
mnt6_g2_point_addition(WitnessContainerType witness, ConstantContainerType constant,
PublicInputContainerType public_input) :
component_type(witness, constant, public_input, get_manifest()) {};

bls12_g2_point_addition(
mnt6_g2_point_addition(
std::initializer_list<typename component_type::witness_container_type::value_type>
witnesses,
std::initializer_list<typename component_type::constant_container_type::value_type>
Expand All @@ -151,16 +152,16 @@ namespace nil {
};

template<typename BlueprintFieldType>
using plonk_bls12_g2_point_addition =
bls12_g2_point_addition<
using plonk_mnt6_g2_point_addition =
mnt6_g2_point_addition<
crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>>;

template<typename BlueprintFieldType>
typename plonk_bls12_g2_point_addition<BlueprintFieldType>::result_type generate_assignments(
const plonk_bls12_g2_point_addition<BlueprintFieldType> &component,
typename plonk_mnt6_g2_point_addition<BlueprintFieldType>::result_type generate_assignments(
const plonk_mnt6_g2_point_addition<BlueprintFieldType> &component,
assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>>
&assignment,
const typename plonk_bls12_g2_point_addition<BlueprintFieldType>::input_type
const typename plonk_mnt6_g2_point_addition<BlueprintFieldType>::input_type
&instance_input,
const std::uint32_t start_row_index) {

Expand Down Expand Up @@ -221,22 +222,22 @@ namespace nil {
assignment.witness(component.W((22 + i) % WA),start_row_index + (WA < 24)) = yR.data[i];
}

return typename plonk_bls12_g2_point_addition<BlueprintFieldType>::result_type(
return typename plonk_mnt6_g2_point_addition<BlueprintFieldType>::result_type(
component, start_row_index);
}

template<typename BlueprintFieldType>
std::size_t generate_gates(
const plonk_bls12_g2_point_addition<BlueprintFieldType> &component,
const plonk_mnt6_g2_point_addition<BlueprintFieldType> &component,
circuit<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>> &bp,
assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>>
&assignment,
const typename plonk_bls12_g2_point_addition<BlueprintFieldType>::input_type
const typename plonk_mnt6_g2_point_addition<BlueprintFieldType>::input_type
&instance_input) {

const std::size_t WA = component.witness_amount();

using var = typename plonk_bls12_g2_point_addition<BlueprintFieldType>::var;
using var = typename plonk_mnt6_g2_point_addition<BlueprintFieldType>::var;
using constraint_type = crypto3::zk::snark::plonk_constraint<BlueprintFieldType>;

// Fp2 field over constraints:
Expand Down Expand Up @@ -326,14 +327,14 @@ namespace nil {

template<typename BlueprintFieldType>
void generate_copy_constraints(
const plonk_bls12_g2_point_addition<BlueprintFieldType> &component,
const plonk_mnt6_g2_point_addition<BlueprintFieldType> &component,
circuit<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>> &bp,
assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>>
&assignment,
const typename plonk_bls12_g2_point_addition<BlueprintFieldType>::input_type &instance_input,
const typename plonk_mnt6_g2_point_addition<BlueprintFieldType>::input_type &instance_input,
const std::size_t start_row_index) {

using var = typename plonk_bls12_g2_point_addition<BlueprintFieldType>::var;
using var = typename plonk_mnt6_g2_point_addition<BlueprintFieldType>::var;

const std::size_t WA = component.witness_amount();

Expand All @@ -343,12 +344,12 @@ namespace nil {
}

template<typename BlueprintFieldType>
typename plonk_bls12_g2_point_addition<BlueprintFieldType>::result_type generate_circuit(
const plonk_bls12_g2_point_addition<BlueprintFieldType> &component,
typename plonk_mnt6_g2_point_addition<BlueprintFieldType>::result_type generate_circuit(
const plonk_mnt6_g2_point_addition<BlueprintFieldType> &component,
circuit<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>> &bp,
assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>>
&assignment,
const typename plonk_bls12_g2_point_addition<BlueprintFieldType>::input_type &instance_input,
const typename plonk_mnt6_g2_point_addition<BlueprintFieldType>::input_type &instance_input,
const std::size_t start_row_index) {

std::size_t selector_index = generate_gates(component, bp, assignment, instance_input);
Expand All @@ -357,12 +358,12 @@ namespace nil {

generate_copy_constraints(component, bp, assignment, instance_input, start_row_index);

return typename plonk_bls12_g2_point_addition<BlueprintFieldType>::result_type(
return typename plonk_mnt6_g2_point_addition<BlueprintFieldType>::result_type(
component, start_row_index);
}

} // namespace components
} // namespace blueprint
} // namespace nil

#endif // CRYPTO3_BLUEPRINT_COMPONENTS_PLONK_BLS12_G2_POINT_ADDITION_HPP
#endif // CRYPTO3_BLUEPRINT_COMPONENTS_PLONK_MNT6_G2_POINT_ADDITION_HPP

0 comments on commit 9cb4177

Please sign in to comment.