-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working MNT4 pairing components: Miller loop and Final exponentiation #…
- Loading branch information
Showing
26 changed files
with
7,436 additions
and
11 deletions.
There are no files selected for viewing
Submodule modules
updated
6 files
385 changes: 385 additions & 0 deletions
385
include/nil/blueprint/components/algebra/curves/detail/plonk/mnt4_g2_point_addition.hpp
Large diffs are not rendered by default.
Oops, something went wrong.
399 changes: 399 additions & 0 deletions
399
include/nil/blueprint/components/algebra/curves/detail/plonk/mnt6_g2_point_addition.hpp
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
include/nil/blueprint/components/algebra/fields/plonk/non_native/detail/abstract_fp3.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
//---------------------------------------------------------------------------// | ||
// Copyright (c) 2024 Vasiliy Olekhov <[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. | ||
//---------------------------------------------------------------------------// | ||
// @file Declaration of F_p^3 elements over an abstract entity (to be used with constraints) | ||
// with F_p^3 = F_p[u]/(u^3 + non_residue). | ||
//---------------------------------------------------------------------------// | ||
|
||
#ifndef CRYPTO3_BLUEPRINT_COMPONENTS_PLONK_ABSTRACT_FP3_HPP | ||
#define CRYPTO3_BLUEPRINT_COMPONENTS_PLONK_ABSTRACT_FP3_HPP | ||
|
||
#include <array> | ||
|
||
namespace nil { | ||
namespace blueprint { | ||
namespace components { | ||
namespace detail { | ||
template<typename T, typename UnderlyingFieldType> | ||
class abstract_fp3_element { | ||
public: | ||
std::array<T,3> data; | ||
|
||
T& operator[](std::size_t idx) { | ||
return data[idx]; | ||
} | ||
const T& operator[](std::size_t idx) const { | ||
return data[idx]; | ||
} | ||
|
||
constexpr abstract_fp3_element operator*(abstract_fp3_element const& other) { | ||
auto s = UnderlyingFieldType::non_residue; | ||
return { | ||
data[0]*other[0] + s*(data[1]*other[2] + data[2]*other[1]), | ||
data[0]*other[1] + data[1]*other[0] + s*data[2]*other[2], | ||
data[0]*other[2] + data[1]*other[1] + data[2]*other[0] | ||
}; | ||
} | ||
|
||
constexpr abstract_fp3_element operator*(const int x) { | ||
return { data[0]*x, data[1]*x, data[2]*x }; | ||
} | ||
friend abstract_fp3_element operator*(const int x, abstract_fp3_element const& e) { | ||
return { e[0]*x, e[1]*x, e[2]*x }; | ||
} | ||
constexpr abstract_fp3_element operator+(abstract_fp3_element const& other) { | ||
return { data[0] + other[0], data[1] + other[1], data[2] + other[2] }; | ||
} | ||
constexpr abstract_fp3_element operator-(abstract_fp3_element const& other) { | ||
return { data[0] - other[0], data[1] - other[1], data[2] - other[2] }; | ||
} | ||
}; | ||
|
||
} // namespace detail | ||
} // namespace components | ||
} // namespace blueprint | ||
} // namespace nil | ||
|
||
#endif // CRYPTO3_BLUEPRINT_COMPONENTS_PLONK_ABSTRACT_FP3_HPP |
87 changes: 87 additions & 0 deletions
87
include/nil/blueprint/components/algebra/fields/plonk/non_native/detail/abstract_fp4.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
//---------------------------------------------------------------------------// | ||
// Copyright (c) 2024 Vasiliy Olekhov <[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. | ||
//---------------------------------------------------------------------------// | ||
// @file Declaration of F_p^4 elements over an abstract entity (to be used with constraints) | ||
// with F_p^4 = Fp^2 over Fp^2: | ||
// Fp^4 = Fp^2[x]/(x^2 - u), u = (0,1) | ||
// Fp^2 = Fp[y]/(y^2 - v), v = 17 (0x11), u^2 = v | ||
//---------------------------------------------------------------------------// | ||
|
||
#ifndef CRYPTO3_BLUEPRINT_COMPONENTS_PLONK_ABSTRACT_FP4_HPP | ||
#define CRYPTO3_BLUEPRINT_COMPONENTS_PLONK_ABSTRACT_FP4_HPP | ||
|
||
#include <array> | ||
#include <cstddef> | ||
|
||
#include <nil/crypto3/algebra/fields/fp4.hpp> | ||
|
||
namespace nil { | ||
namespace blueprint { | ||
namespace components { | ||
namespace detail { | ||
|
||
template<typename T, typename UnderlyingFieldType> | ||
class abstract_fp4_element{ | ||
public: | ||
using policy_type_fp4 = crypto3::algebra::fields::fp4<UnderlyingFieldType>; | ||
std::array<T,4> x; | ||
|
||
T& operator[](std::size_t idx) { | ||
return x[idx]; | ||
} | ||
const T& operator[](std::size_t idx) const { | ||
return x[idx]; | ||
} | ||
|
||
constexpr abstract_fp4_element operator*(abstract_fp4_element const& y) { | ||
// Devegili et al - Multiplication and squaring in pairing-friendly fields | ||
// https://eprint.iacr.org/2006/471.pdf | ||
constexpr auto s = policy_type_fp4::extension_policy::non_residue; | ||
auto d00 = x[0b00]*y[0b00] + s*(x[0b01]*y[0b01] + x[0b10]*y[0b11] + x[0b11]*y[0b10]); | ||
auto d01 = x[0b00]*y[0b01] + x[0b10]*y[0b10] + x[0b01]*y[0b00] + s*x[0b11]*y[0b11]; | ||
auto d10 = x[0b00]*y[0b10] + x[0b10]*y[0b00] + s*(x[0b01]*y[0b11] + x[0b11]*y[0b01]); | ||
auto d11 = x[0b00]*y[0b11] + x[0b01]*y[0b10] + x[0b10]*y[0b01] + x[0b11]*y[0b00]; | ||
|
||
return { d00, d01, d10, d11}; | ||
} | ||
|
||
constexpr abstract_fp4_element operator*(const int a) { | ||
return { x[0]*a, x[1]*a, x[2]*a, x[3]*a }; | ||
} | ||
friend abstract_fp4_element operator*(const int a, abstract_fp4_element const& x) { | ||
return { x[0]*a, x[1]*a, x[2]*a, x[3]*a }; | ||
} | ||
constexpr abstract_fp4_element operator+(abstract_fp4_element const& y) { | ||
return { x[0] + y[0], x[1] + y[1], x[2] + y[2], x[3] + y[3] }; | ||
} | ||
constexpr abstract_fp4_element operator-(abstract_fp4_element const& y) { | ||
return { x[0] - y[0], x[1] - y[1], x[2] - y[2], x[3] - y[3] }; | ||
} | ||
}; | ||
|
||
} // namespace detail | ||
} // namespace components | ||
} // namespace blueprint | ||
} // namespace nil | ||
|
||
#endif // CRYPTO3_BLUEPRINT_COMPONENTS_PLONK_abstract_FP4_HPP |
86 changes: 86 additions & 0 deletions
86
include/nil/blueprint/components/algebra/fields/plonk/non_native/detail/mnt4_fp4.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
//---------------------------------------------------------------------------// | ||
// Copyright (c) 2024 Vasiliy Olekhov <[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. | ||
//---------------------------------------------------------------------------// | ||
// @file Declaration of F_p^4 elements over an mnt4 entity (to be used with constraints) | ||
// with F_p^4 = Fp^2 over Fp^2: | ||
// Fp^4 = Fp^2[x]/(x^2 - u), u = (0,1) | ||
// Fp^2 = Fp[y]/(y^2 - v), v = 17 (0x11), u^2 = v | ||
//---------------------------------------------------------------------------// | ||
|
||
#ifndef CRYPTO3_BLUEPRINT_COMPONENTS_PLONK_MNT4_FP4_HPP | ||
#define CRYPTO3_BLUEPRINT_COMPONENTS_PLONK_MNT4_FP4_HPP | ||
|
||
#include <array> | ||
#include <cstddef> | ||
|
||
namespace nil { | ||
namespace blueprint { | ||
namespace components { | ||
namespace detail { | ||
|
||
template<typename T> | ||
class mnt4_fp4_element { | ||
public: | ||
std::array<T,4> x; | ||
|
||
T& operator[](std::size_t idx) { | ||
return x[idx]; | ||
} | ||
const T& operator[](std::size_t idx) const { | ||
return x[idx]; | ||
} | ||
|
||
constexpr mnt4_fp4_element operator*(mnt4_fp4_element const& y) { | ||
|
||
// Devegili et al - Multiplication and squaring in pairing-friendly fields | ||
// https://eprint.iacr.org/2006/471.pdf | ||
//crypto3::algebra::curves::mnt4<298>::..?..::non_residue; | ||
constexpr auto s = 0x11; | ||
auto d00 = x[0b00]*y[0b00] + s*(x[0b01]*y[0b01] + x[0b10]*y[0b11] + x[0b11]*y[0b10]); | ||
auto d01 = x[0b00]*y[0b01] + x[0b10]*y[0b10] + x[0b01]*y[0b00] + s*x[0b11]*y[0b11]; | ||
auto d10 = x[0b00]*y[0b10] + x[0b10]*y[0b00] + s*(x[0b01]*y[0b11] + x[0b11]*y[0b01]); | ||
auto d11 = x[0b00]*y[0b11] + x[0b01]*y[0b10] + x[0b10]*y[0b01] + x[0b11]*y[0b00]; | ||
|
||
return { d00, d01, d10, d11}; | ||
} | ||
|
||
constexpr mnt4_fp4_element operator*(const int a) { | ||
return { x[0]*a, x[1]*a, x[2]*a, x[3]*a }; | ||
} | ||
friend mnt4_fp4_element operator*(const int a, mnt4_fp4_element const& x) { | ||
return { x[0]*a, x[1]*a, x[2]*a, x[3]*a }; | ||
} | ||
constexpr mnt4_fp4_element operator+(mnt4_fp4_element const& y) { | ||
return { x[0] + y[0], x[1] + y[1], x[2] + y[2], x[3] + y[3] }; | ||
} | ||
constexpr mnt4_fp4_element operator-(mnt4_fp4_element const& y) { | ||
return { x[0] - y[0], x[1] - y[1], x[2] - y[2], x[3] - y[3] }; | ||
} | ||
}; | ||
|
||
} // namespace detail | ||
} // namespace components | ||
} // namespace blueprint | ||
} // namespace nil | ||
|
||
#endif // CRYPTO3_BLUEPRINT_COMPONENTS_PLONK_MNT4_FP4_HPP |
100 changes: 100 additions & 0 deletions
100
include/nil/blueprint/components/algebra/fields/plonk/non_native/detail/mnt6_fp6.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
//---------------------------------------------------------------------------// | ||
// Copyright (c) 2024 Vasiliy Olekhov <[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. | ||
//---------------------------------------------------------------------------// | ||
// @file Declaration of F_p^6 elements over an mnt6 entity (to be used with constraints) | ||
// with F_p^6 = Fp^2 over Fp^3: | ||
// Fp^6 = Fp^2[x]/(x^2 - u), u^2 = v = (0, 1, 0) | ||
// Fp^3 = Fp[y]/(y^3 - v), v^3 = 5 | ||
//---------------------------------------------------------------------------// | ||
|
||
#ifndef CRYPTO3_BLUEPRINT_COMPONENTS_PLONK_MNT6_FP6_HPP | ||
#define CRYPTO3_BLUEPRINT_COMPONENTS_PLONK_MNT6_FP6_HPP | ||
|
||
#include <array> | ||
#include <cstddef> | ||
|
||
namespace nil { | ||
namespace blueprint { | ||
namespace components { | ||
namespace detail { | ||
|
||
template<typename T> | ||
class mnt6_fp6_element { | ||
public: | ||
std::array<T, 6> x; | ||
|
||
T& operator[](std::size_t idx) { | ||
return x[idx]; | ||
} | ||
const T& operator[](std::size_t idx) const { | ||
return x[idx]; | ||
} | ||
|
||
constexpr mnt6_fp6_element operator*(mnt6_fp6_element const& y) { | ||
|
||
//crypto3::algebra::curves::mnt4<298>::..?..::non_residue; | ||
constexpr int | ||
_00 = 0, _01 = 1, _02 = 2, | ||
_10 = 3, _11 = 4, _12 = 5; | ||
|
||
constexpr auto s = 0x5; | ||
auto d00 = x[0b00]*y[0b00] + s*(x[0b01]*y[0b01] + x[0b10]*y[0b11] + x[0b11]*y[0b10]); | ||
auto d01 = x[0b01]*y[0b10] + x[0b00]*y[0b11] + x[0b10]*y[0b10] + s*x[0b11]*y[0b11]; | ||
auto d10 = x[0b00]*y[0b10] + x[0b10]*y[0b00] + s*(x[0b01]*y[0b11] + x[0b11]*y[0b01]); | ||
auto d11 = x[0b00]*y[0b11] + x[0b01]*y[0b10] + x[0b10]*y[0b01] + x[0b11]*y[0b00]; | ||
|
||
return { d00, d01, d10, d11}; | ||
} | ||
|
||
constexpr mnt6_fp6_element operator*(const int a) { | ||
return { | ||
x[0]*a, x[1]*a, x[2]*a, | ||
x[3]*a, x[4]*a, x[5]*a, | ||
}; | ||
} | ||
friend mnt6_fp6_element operator*(const int a, mnt6_fp6_element const& x) { | ||
return { | ||
x[0]*a, x[1]*a, x[2]*a, | ||
x[3]*a, x[4]*a, x[5]*a, | ||
}; | ||
} | ||
constexpr mnt6_fp6_element operator+(mnt6_fp6_element const& y) { | ||
return { | ||
x[0] + y[0], x[1] + y[1], x[2] + y[2], | ||
x[3] + y[3], x[4] + y[4], x[5] + y[5], | ||
}; | ||
} | ||
constexpr mnt6_fp6_element operator-(mnt6_fp6_element const& y) { | ||
return { | ||
x[0] - y[0], x[1] - y[1], x[2] - y[2], | ||
x[3] - y[3], x[4] - y[4], x[5] - y[5], | ||
}; | ||
} | ||
}; | ||
|
||
} // namespace detail | ||
} // namespace components | ||
} // namespace blueprint | ||
} // namespace nil | ||
|
||
#endif // CRYPTO3_BLUEPRINT_COMPONENTS_PLONK_MNT6_FP6_HPP |
Oops, something went wrong.