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

Commit

Permalink
lpc and fri template parameters updated #109
Browse files Browse the repository at this point in the history
  • Loading branch information
e.tatuzova committed Feb 21, 2023
1 parent 3b044eb commit 50120f5
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 91 deletions.
36 changes: 12 additions & 24 deletions include/nil/crypto3/zk/commitments/detail/polynomial/basic_fri.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,12 @@ namespace nil {
* <https://eprint.iacr.org/2019/1400.pdf>
*/
template<typename FieldType, typename MerkleTreeHashType, typename TranscriptHashType,
std::size_t M, std::size_t BatchSize, bool IsConstSize>
std::size_t M, std::size_t BatchesNum>
struct basic_batched_fri {
BOOST_STATIC_ASSERT_MSG(M == 2, "unsupported m value!");

constexpr static const std::size_t m = M;
constexpr static const std::size_t leaf_size = BatchSize;
constexpr static const std::size_t batches_num = 4;
constexpr static const bool is_const_size = IsConstSize;
constexpr static const std::size_t batches_num = BatchesNum;

typedef FieldType field_type;
typedef MerkleTreeHashType merkle_tree_hash_type;
Expand All @@ -84,8 +82,7 @@ namespace nil {
typedef std::vector<polynomial_value_type> polynomial_values_type;

// For initial proof only
typedef typename select_container<is_const_size, polynomial_values_type, leaf_size>::type
polynomials_values_type;
typedef typename std::vector<polynomial_values_type> polynomials_values_type;

// For other rounds
typedef std::vector<polynomial_values_type> rounds_polynomial_values_type;
Expand Down Expand Up @@ -113,26 +110,18 @@ namespace nil {

// TODO: Better if we can construct params_type from any batch size to another
params_type(
const typename basic_batched_fri<FieldType, MerkleTreeHashType, TranscriptHashType, M,
1, false>::params_type &obj) {
r = obj.r;
max_degree = obj.max_degree;
D = obj.D;
step_list = obj.step_list;
}

params_type(
const typename basic_batched_fri<FieldType, MerkleTreeHashType, TranscriptHashType, M,
1, true>::params_type &obj) {
const typename basic_batched_fri<FieldType, MerkleTreeHashType, TranscriptHashType, M, BatchesNum>::params_type &obj) {
r = obj.r;
max_degree = obj.max_degree;
D = obj.D;
step_list = obj.step_list;
batches_num = obj.batches_num;
}

params_type() {};

std::size_t r;
std::size_t batches_num;
std::size_t max_degree;
std::vector<std::shared_ptr<math::evaluation_domain<FieldType>>> D;
std::vector<std::size_t> step_list;
Expand Down Expand Up @@ -180,7 +169,7 @@ namespace nil {
std::is_base_of<
commitments::detail::basic_batched_fri<
typename FRI::field_type, typename FRI::merkle_tree_hash_type,
typename FRI::transcript_hash_type, FRI::m, FRI::leaf_size, FRI::is_const_size>,
typename FRI::transcript_hash_type, FRI::m, FRI::batches_num>,
FRI>::value,
bool>::type = true>
static typename FRI::commitment_type commit(const typename FRI::precommitment_type &P) {
Expand All @@ -192,7 +181,7 @@ namespace nil {
std::is_base_of<
commitments::detail::basic_batched_fri<
typename FRI::field_type, typename FRI::merkle_tree_hash_type,
typename FRI::transcript_hash_type, FRI::m, FRI::leaf_size, FRI::is_const_size>,
typename FRI::transcript_hash_type, FRI::m, FRI::batches_num>,
FRI>::value,
bool>::type = true>
static std::array<typename FRI::commitment_type, list_size>
Expand All @@ -215,7 +204,7 @@ namespace nil {
std::is_base_of<
commitments::detail::basic_batched_fri<
typename FRI::field_type, typename FRI::merkle_tree_hash_type,
typename FRI::transcript_hash_type, FRI::m, FRI::leaf_size, FRI::is_const_size>,
typename FRI::transcript_hash_type, FRI::m, FRI::batches_num>,
FRI>::value,
bool>::type = true>
static typename FRI::precommitment_type
Expand Down Expand Up @@ -272,7 +261,7 @@ namespace nil {
std::is_base_of<
commitments::detail::basic_batched_fri<
typename FRI::field_type, typename FRI::merkle_tree_hash_type,
typename FRI::transcript_hash_type, FRI::m, FRI::leaf_size, FRI::is_const_size>,
typename FRI::transcript_hash_type, FRI::m, FRI::batches_num>,
FRI>::value,
bool>::type = true>
static typename FRI::precommitment_type
Expand All @@ -292,7 +281,7 @@ namespace nil {
std::is_base_of<
commitments::detail::basic_batched_fri<
typename FRI::field_type, typename FRI::merkle_tree_hash_type,
typename FRI::transcript_hash_type, FRI::m, FRI::leaf_size, FRI::is_const_size>,
typename FRI::transcript_hash_type, FRI::m, FRI::batches_num>,
FRI>::value,
bool>::type = true>
static typename std::enable_if<
Expand Down Expand Up @@ -364,7 +353,7 @@ namespace nil {
std::is_base_of<
commitments::detail::basic_batched_fri<
typename FRI::field_type, typename FRI::merkle_tree_hash_type,
typename FRI::transcript_hash_type, FRI::m, FRI::leaf_size, FRI::is_const_size>,
typename FRI::transcript_hash_type, FRI::m, FRI::batches_num>,
FRI>::value,
bool>::type = true>
static typename std::enable_if<
Expand Down Expand Up @@ -595,7 +584,6 @@ namespace nil {
std::vector<typename FRI::round_proof_type> round_proofs;
std::unique_ptr<typename FRI::merkle_tree_type> p_tree = std::make_unique<typename FRI::merkle_tree_type>(combined_Q_precommitment);
typename FRI::merkle_tree_type T_next = combined_Q_precommitment;
typename FRI::rounds_polynomial_values_type values;

PolynomialType f = combined_Q;
for (std::size_t i = 0; i < fri_params.step_list.size() - 1; i++) {
Expand Down
29 changes: 14 additions & 15 deletions include/nil/crypto3/zk/commitments/polynomial/fri.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,26 @@ namespace nil {
* <https://eprint.iacr.org/2019/1400.pdf>
*/
template<typename FieldType,
typename MerkleTreeHashType,
typename TranscriptHashType,
std::size_t M,
std::size_t BatchedSize = 0,
bool IsConstSize = (bool)BatchedSize>
typename MerkleTreeHashType,
typename TranscriptHashType,
std::size_t M,
std::size_t BatchesNum = 4
>
struct fri : public detail::basic_batched_fri<FieldType,
MerkleTreeHashType,
TranscriptHashType,
M,
BatchedSize,
IsConstSize> {
BatchesNum
> {

using basic_fri = detail::basic_batched_fri<FieldType,
MerkleTreeHashType,
TranscriptHashType,
M,
BatchedSize,
IsConstSize>;
BatchesNum
>;
constexpr static const std::size_t m = basic_fri::m;
constexpr static const std::size_t leaf_size = basic_fri::leaf_size;
constexpr static const bool is_const_size = IsConstSize;
constexpr static const std::size_t batches_num = basic_fri::batches_num;

using field_type = typename basic_fri::field_type;
using merkle_tree_hash_type = typename basic_fri::merkle_tree_hash_type;
Expand All @@ -105,8 +104,8 @@ namespace nil {
typename FRI::merkle_tree_hash_type,
typename FRI::transcript_hash_type,
FRI::m,
FRI::leaf_size,
FRI::is_const_size>,
FRI::batches_num
>,
FRI>::value,
bool>::type = true>
static typename FRI::basic_fri::proof_type proof_eval(
Expand All @@ -126,8 +125,8 @@ namespace nil {
typename FRI::merkle_tree_hash_type,
typename FRI::transcript_hash_type,
FRI::m,
FRI::leaf_size,
FRI::is_const_size>,
FRI::batches_num
>,
FRI>::value,
bool>::type = true>
static bool verify_eval(
Expand Down
30 changes: 13 additions & 17 deletions include/nil/crypto3/zk/commitments/polynomial/lpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,15 @@ namespace nil {
namespace commitments {

template<typename MerkleTreeHashType, typename TranscriptHashType, std::size_t Lambda = 40,
std::size_t R = 1, std::size_t M = 2, std::size_t BatchSize = 0, bool IsConstSize = false>
std::size_t R = 1, std::size_t M = 2, std::size_t BatchesNum = 4>
struct list_polynomial_commitment_params {
typedef MerkleTreeHashType merkle_hash_type;
typedef TranscriptHashType transcript_hash_type;

constexpr static const std::size_t lambda = Lambda;
constexpr static const std::size_t r = R;
constexpr static const std::size_t m = M;
constexpr static const std::size_t leaf_size = BatchSize;
constexpr static const bool is_const_size = IsConstSize;
constexpr static const std::size_t batches_num = BatchesNum;
};
/**
* @brief Based on the FRI Commitment description from \[RedShift].
Expand All @@ -77,28 +76,29 @@ namespace nil {
struct batched_list_polynomial_commitment
: public detail::basic_batched_fri<FieldType, typename LPCParams::merkle_hash_type,
typename LPCParams::transcript_hash_type, LPCParams::m,
LPCParams::leaf_size, LPCParams::is_const_size> {
LPCParams::batches_num> {

using merkle_hash_type = typename LPCParams::merkle_hash_type;

constexpr static const std::size_t lambda = LPCParams::lambda;
constexpr static const std::size_t r = LPCParams::r;
constexpr static const std::size_t m = LPCParams::m;
constexpr static const std::size_t leaf_size = LPCParams::leaf_size;
constexpr static const std::size_t batches_num = LPCParams::batches_num;
constexpr static const bool is_const_size = LPCParams::is_const_size;

typedef LPCParams lpc_params;

typedef typename containers::merkle_proof<merkle_hash_type, 2> merkle_proof_type;

using basic_fri = detail::basic_batched_fri<FieldType, typename LPCParams::merkle_hash_type,
typename LPCParams::transcript_hash_type, m, leaf_size,
is_const_size>;
typename LPCParams::transcript_hash_type, m, batches_num
>;

using precommitment_type = typename basic_fri::precommitment_type;
using commitment_type = typename basic_fri::commitment_type;
using field_type = FieldType;
using polynomials_values_type = typename basic_fri::polynomials_values_type;
using params_type = typename basic_fri::params_type;

struct proof_type {
bool operator==(const proof_type &rhs) const {
Expand All @@ -107,9 +107,7 @@ namespace nil {
bool operator!=(const proof_type &rhs) const {
return !(rhs == *this);
}
typedef typename std::conditional<
is_const_size, std::array<std::vector<typename FieldType::value_type>, leaf_size>,
std::vector<std::vector<typename FieldType::value_type>>>::type z_type;
typedef std::vector<std::vector<typename FieldType::value_type>> z_type;

std::array<z_type, 4> z;
commitment_type combined_Q_root;
Expand All @@ -118,16 +116,16 @@ namespace nil {
};
};

template<typename FieldType, typename LPCParams, std::size_t BatchSize, bool IsConstSize>
template<typename FieldType, typename LPCParams>
using batched_lpc = batched_list_polynomial_commitment<
FieldType, commitments::list_polynomial_commitment_params<
typename LPCParams::merkle_hash_type, typename LPCParams::transcript_hash_type,
LPCParams::lambda, LPCParams::r, LPCParams::m, BatchSize, IsConstSize>>;
template<typename FieldType, typename LPCParams, std::size_t BatchSize, bool IsConstSize>
LPCParams::lambda, LPCParams::r, LPCParams::m, LPCParams::batches_num>>;
template<typename FieldType, typename LPCParams>
using lpc = batched_list_polynomial_commitment<
FieldType, list_polynomial_commitment_params<
typename LPCParams::merkle_hash_type, typename LPCParams::transcript_hash_type,
LPCParams::lambda, LPCParams::r, LPCParams::m, BatchSize, IsConstSize>>;
LPCParams::lambda, LPCParams::r, LPCParams::m, LPCParams::batches_num>>;

template<typename FieldType, typename LPCParams>
using list_polynomial_commitment = batched_list_polynomial_commitment<FieldType, LPCParams>;
Expand Down Expand Up @@ -244,9 +242,7 @@ namespace nil {
std::array<typename LPC::proof_type::z_type, 4> z;

for (std::size_t k = 0; k < 4; k++) {
if constexpr (!LPC::is_const_size) {
z[k].resize(g[k].size());
}
z[k].resize(g[k].size());

// Prepare U_interpolation_points and denominator_polynom
for (std::size_t polynom_index = 0; polynom_index < g[k].size(); polynom_index++) {
Expand Down
Loading

0 comments on commit 50120f5

Please sign in to comment.