Skip to content

Commit

Permalink
Commitments type_traits added. #20 #25
Browse files Browse the repository at this point in the history
  • Loading branch information
nkaskov committed Mar 10, 2022
1 parent 9f7f84a commit 5409a70
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
65 changes: 60 additions & 5 deletions include/nil/crypto3/zk/commitments/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,71 @@ namespace nil {
// BOOST_TTI_HAS_TYPE(proving_key)
// BOOST_TTI_HAS_TYPE(verification_key)

BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION(commit)
BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION(proof_eval)
BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION(verify_eval)

template<typename T>
class has_available_static_member_function_commit {
struct no { };

protected:
template<typename C>
static void test(std::nullptr_t) {
struct t{
using C::commit;
};
}

template<typename>
static no test(...);

public:
constexpr static const bool value = !std::is_same<no, decltype(test<T>(nullptr))>::value;
};

template<typename T>
class has_available_static_member_function_proof_eval {
struct no { };

protected:
template<typename C>
static void test(std::nullptr_t) {
struct t{
using C::proof_eval;
};
}

template<typename>
static no test(...);

public:
constexpr static const bool value = !std::is_same<no, decltype(test<T>(nullptr))>::value;
};

template<typename T>
class has_available_static_member_function_verify_eval {
struct no { };

protected:
template<typename C>
static void test(std::nullptr_t) {
struct t{
using C::verify_eval;
};
}

template<typename>
static no test(...);

public:
constexpr static const bool value = !std::is_same<no, decltype(test<T>(nullptr))>::value;
};

template<typename T>
struct is_commitment {
using commitment_type = typename member_type_commitment_type<T>::type;

static const bool value = has_type_commitment_type<T>::value && has_type_proof_type<T>::value &&
has_static_member_function_commit<T, commitment_type>::value;
has_available_static_member_function_commit<T>::value &&
has_available_static_member_function_proof_eval<T>::value &&
has_available_static_member_function_verify_eval<T>::value;
typedef T type;
};

Expand Down
8 changes: 8 additions & 0 deletions test/commitment/lpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <nil/crypto3/zk/commitments/polynomial/lpc.hpp>
#include <nil/crypto3/zk/commitments/polynomial/fri.hpp>
#include <nil/crypto3/zk/snark/systems/plonk/redshift/params.hpp>
#include <nil/crypto3/zk/commitments/type_traits.hpp>

using namespace nil::crypto3;
using namespace nil::crypto3::zk::snark;
Expand Down Expand Up @@ -74,6 +75,13 @@ BOOST_AUTO_TEST_CASE(lpc_basic_test) {

typedef zk::commitments::list_polynomial_commitment_params<merkle_hash_type, transcript_hash_type, lambda, r, m> lpc_params_type;
typedef zk::commitments::list_polynomial_commitment<FieldType, lpc_params_type, k> lpc_type;

static_assert(zk::is_commitment<fri_type>::value);
static_assert(zk::is_commitment<lpc_type>::value);
static_assert(!zk::is_commitment<merkle_hash_type>::value);
static_assert(!zk::is_commitment<merkle_tree_type>::value);
static_assert(!zk::is_commitment<std::size_t>::value);

typedef typename lpc_type::proof_type proof_type;

constexpr static const std::size_t d_extended = d;
Expand Down

0 comments on commit 5409a70

Please sign in to comment.