curves/params/multiexp/bn128.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2020-2021 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 2020-2021 Nikita Kaskov <nbering@nil.foundation>
4 //
5 // MIT License
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
8 // of this software and associated documentation files (the "Software"), to deal
9 // in the Software without restriction, including without limitation the rights
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 // copies of the Software, and to permit persons to whom the Software is
12 // furnished to do so, subject to the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be included in all
15 // copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 // SOFTWARE.
24 //---------------------------------------------------------------------------//
25 
26 #ifndef CRYPTO3_ALGEBRA_CURVES_BN128_MULTIEXP_PARAMS_HPP
27 #define CRYPTO3_ALGEBRA_CURVES_BN128_MULTIEXP_PARAMS_HPP
28 
30 
31 #include <nil/crypto3/algebra/curves/bn128.hpp>
32 
33 namespace nil {
34  namespace crypto3 {
35  namespace algebra {
36  namespace curves {
37 
38  template<typename GroupType>
39  struct multiexp_params;
40 
41  /************************* BN128-254 ***********************************/
42 
43  template<>
44  struct multiexp_params<typename bn128<254>::g1_type<>> {
45 
46  constexpr static const std::array<std::size_t, 22> fixed_base_exp_window_table = {
47  // window 1 is unbeaten in [-inf, 4.24]
48  1,
49  // window 2 is unbeaten in [4.24, 10.43]
50  4,
51  // window 3 is unbeaten in [10.43, 24.88]
52  10,
53  // window 4 is unbeaten in [24.88, 62.10]
54  25,
55  // window 5 is unbeaten in [62.10, 157.80]
56  62,
57  // window 6 is unbeaten in [157.80, 362.05]
58  158,
59  // window 7 is unbeaten in [362.05, 806.67]
60  362,
61  // window 8 is unbeaten in [806.67, 2090.34]
62  807,
63  // window 9 is unbeaten in [2090.34, 4459.58]
64  2090,
65  // window 10 is unbeaten in [4459.58, 9280.12]
66  4460,
67  // window 11 is unbeaten in [9280.12, 43302.64]
68  9280,
69  // window 12 is unbeaten in [43302.64, 210998.73]
70  43303,
71  // window 13 is never the best
72  0,
73  // window 14 is never the best
74  0,
75  // window 15 is unbeaten in [210998.73, 506869.47]
76  210999,
77  // window 16 is unbeaten in [506869.47, 930023.36]
78  506869,
79  // window 17 is unbeaten in [930023.36, 8350812.20]
80  930023,
81  // window 18 is never the best
82  0,
83  // window 19 is never the best
84  0,
85  // window 20 is unbeaten in [8350812.20, 21708138.87]
86  8350812,
87  // window 21 is unbeaten in [21708138.87, 29482995.52]
88  21708139,
89  // window 22 is unbeaten in [29482995.52, inf]
90  29482996};
91  };
92 
93  template<>
94  struct multiexp_params<typename bn128<254>::g2_type<>> {
95 
96  constexpr static const std::array<std::size_t, 22> fixed_base_exp_window_table = {
97  // window 1 is unbeaten in [-inf, 4.13]
98  1,
99  // window 2 is unbeaten in [4.13, 10.72]
100  4,
101  // window 3 is unbeaten in [10.72, 25.60]
102  11,
103  // window 4 is unbeaten in [25.60, 60.99]
104  26,
105  // window 5 is unbeaten in [60.99, 153.66]
106  61,
107  // window 6 is unbeaten in [153.66, 353.13]
108  154,
109  // window 7 is unbeaten in [353.13, 771.87]
110  353,
111  // window 8 is unbeaten in [771.87, 2025.85]
112  772,
113  // window 9 is unbeaten in [2025.85, 4398.65]
114  2026,
115  // window 10 is unbeaten in [4398.65, 10493.42]
116  4399,
117  // window 11 is unbeaten in [10493.42, 37054.73]
118  10493,
119  // window 12 is unbeaten in [37054.73, 49928.78]
120  37055,
121  // window 13 is unbeaten in [49928.78, 114502.82]
122  49929,
123  // window 14 is unbeaten in [114502.82, 161445.26]
124  114503,
125  // window 15 is unbeaten in [161445.26, 470648.01]
126  161445,
127  // window 16 is unbeaten in [470648.01, 1059821.87]
128  470648,
129  // window 17 is unbeaten in [1059821.87, 5450848.25]
130  1059822,
131  // window 18 is never the best
132  0,
133  // window 19 is unbeaten in [5450848.25, 5566795.57]
134  5450848,
135  // window 20 is unbeaten in [5566795.57, 33055217.52]
136  5566796,
137  // window 21 is never the best
138  0,
139  // window 22 is unbeaten in [33055217.52, inf]
140  33055218};
141  };
142 
143  /************************* BN128-254 definitions ***********************************/
144 
145  constexpr std::array<std::size_t, 22> const
146  multiexp_params<typename bn128<254>::g1_type<>>::fixed_base_exp_window_table;
147  constexpr std::array<std::size_t, 22> const
148  multiexp_params<typename bn128<254>::g2_type<>>::fixed_base_exp_window_table;
149 
150  } // namespace curves
151  } // namespace algebra
152  } // namespace crypto3
153 } // namespace nil
154 
155 #endif // CRYPTO3_ALGEBRA_CURVES_BN128_MULTIEXP_PARAMS_HPP
bn128_base_field< Version > bn128
Definition: bn128/base_field.hpp:86
Definition: pair.hpp:31
Definition: curves/params/multiexp/alt_bn128.hpp:39