Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 12edb2b

Browse files
committed
Added is_kzg and is_lpc type_traits #309
1 parent 497f415 commit 12edb2b

File tree

3 files changed

+75
-7
lines changed

3 files changed

+75
-7
lines changed

include/nil/crypto3/zk/commitments/polynomial/kzg.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ namespace nil {
325325
static void update_transcript(const typename KZG::public_key_type &public_key,
326326
typename KZG::transcript_type &transcript) {
327327

328-
/* The procedure of updating the transcript is subject to review and change
328+
/* The procedure of updating the transcript is subject to review and change
329329
* #295 */
330330

331331
nil::marshalling::status_type status;
@@ -671,7 +671,7 @@ namespace nil {
671671
}
672672

673673
void update_transcript(std::size_t batch_ind, typename KZGScheme::transcript_type &transcript) {
674-
/* The procedure of updating the transcript is subject to review and change
674+
/* The procedure of updating the transcript is subject to review and change
675675
* #295 */
676676

677677
// Push commitments to transcript
@@ -849,7 +849,7 @@ namespace nil {
849849
typename KZGScheme::commitment_type,
850850
typename KZGScheme::poly_type> {
851851
public:
852-
constexpr static bool is_kzg_commitment_scheme_v2 = true;
852+
static constexpr bool is_kzg(){ return true; }
853853

854854
using curve_type = typename KZGScheme::curve_type;
855855
using field_type = typename KZGScheme::field_type;
@@ -912,7 +912,7 @@ namespace nil {
912912
}
913913

914914
void update_transcript(std::size_t batch_ind, typename KZGScheme::transcript_type &transcript) {
915-
/* The procedure of updating the transcript is subject to review and change
915+
/* The procedure of updating the transcript is subject to review and change
916916
* #295 */
917917

918918
// Push commitments to transcript

include/nil/crypto3/zk/commitments/polynomial/lpc.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ namespace nil {
5252
typename LPCScheme::commitment_type, PolynomialType>{
5353

5454
public:
55+
static constexpr bool is_lpc(){return true;}
56+
5557
using field_type = typename LPCScheme::field_type;
5658
using value_type = typename field_type::value_type;
5759
using params_type = typename LPCScheme::params_type;
@@ -67,8 +69,6 @@ namespace nil {
6769
using eval_storage_type = typename LPCScheme::eval_storage_type;
6870
using preprocessed_data_type = std::map<std::size_t, std::vector<value_type>>;
6971

70-
constexpr static bool is_lpc = true;
71-
7272
private:
7373
std::map<std::size_t, precommitment_type> _trees;
7474
typename fri_type::params_type _fri_params;

include/nil/crypto3/zk/commitments/type_traits.hpp

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,45 @@ namespace nil {
9898
constexpr static const bool value = !std::is_same<no, decltype(test<T>(nullptr))>::value;
9999
};
100100

101+
template<typename T>
102+
class has_available_static_member_function_is_kzg {
103+
struct no { };
104+
105+
protected:
106+
template<typename C>
107+
static void test(std::nullptr_t) {
108+
struct t {
109+
using C::is_kzg;
110+
};
111+
}
112+
113+
template<typename>
114+
static no test(...);
115+
116+
public:
117+
constexpr static const bool value = !std::is_same<no, decltype(test<T>(nullptr))>::value;
118+
};
119+
120+
template<typename T>
121+
class has_available_static_member_function_is_lpc {
122+
struct no { };
123+
124+
protected:
125+
template<typename C>
126+
127+
static void test(std::nullptr_t) {
128+
struct t {
129+
using C::is_lpc;
130+
};
131+
}
132+
133+
template<typename>
134+
static no test(...);
135+
136+
public:
137+
constexpr static const bool value = !std::is_same<no, decltype(test<T>(nullptr))>::value;
138+
};
139+
101140
template<typename T>
102141
struct is_commitment {
103142
using commitment_type = typename member_type_commitment_type<T>::type;
@@ -109,12 +148,41 @@ namespace nil {
109148
typedef T type;
110149
};
111150

151+
// An idea was copied from this example:
152+
// https://stackoverflow.com/questions/54920801/check-if-static-function-is-available-in-class-at-compile-time
153+
154+
template<typename T, typename Enable = void>
155+
struct is_kzg_struct: std::false_type{
156+
static const bool value = false;
157+
};
158+
159+
template<class T>
160+
struct is_kzg_struct<T, std::enable_if_t<std::is_invocable_r<bool, decltype(T::is_kzg)>::value>>
161+
: std::integral_constant<bool, T::is_kzg()>
162+
{};
163+
164+
template<class T>
165+
constexpr bool is_kzg = is_kzg_struct<T>::value;
166+
167+
168+
template<typename T, typename Enable = void>
169+
struct is_lpc_struct: std::false_type{
170+
static const bool value = false;
171+
};
172+
173+
template<class T>
174+
struct is_lpc_struct<T, std::enable_if_t<std::is_invocable_r<bool, decltype(T::is_lpc)>::value>>
175+
: std::integral_constant<bool, T::is_lpc()>
176+
{};
177+
178+
template<class T>
179+
constexpr bool is_lpc = is_lpc_struct<T>::value;
180+
112181
template<bool Condition, typename Type, std::size_t Size>
113182
struct select_container {
114183
using type = typename std::
115184
conditional<Condition, std::array<Type, Size>, std::vector<Type>>::type;
116185
};
117-
118186
} // namespace zk
119187
} // namespace crypto3
120188
} // namespace nil

0 commit comments

Comments
 (0)