Zeth - Zerocash on Ethereum  0.8
Reference implementation of the Zeth protocol by Clearmatics
evaluator_from_lagrange.tcc
Go to the documentation of this file.
1 // Copyright (c) 2015-2022 Clearmatics Technologies Ltd
2 //
3 // SPDX-License-Identifier: LGPL-3.0+
4 
5 #ifndef __ZETH_CORE_EVALUATOR_FROM_LAGRANGE_TCC__
6 #define __ZETH_CORE_EVALUATOR_FROM_LAGRANGE_TCC__
7 
8 #include "libzeth/core/evaluator_from_lagrange.hpp"
9 #include "libzeth/core/multi_exp.hpp"
10 
11 namespace libzeth
12 {
13 
14 template<typename ppT, typename GroupT>
15 evaluator_from_lagrange<ppT, GroupT>::evaluator_from_lagrange(
16  const std::vector<GroupT> &powers,
17  libfqfft::evaluation_domain<libff::Fr<ppT>> &domain)
18  : powers(powers), domain(domain)
19 {
20  // Lagrange polynomials have order <= m-1, requiring at least m
21  // entries in powers (0, ..., m-1) in order to evaluate.
22  assert(powers.size() >= domain.m);
23 }
24 
25 template<typename ppT, typename GroupT>
26 GroupT evaluator_from_lagrange<ppT, GroupT>::evaluate_from_lagrange_factors(
27  const std::map<size_t, libff::Fr<ppT>> &lagrange_factors)
28 {
29  // libfqfft::evaluation_domain modifies an incoming vector of factors.
30  // Write the factors into the vector (it must be large enough to hold
31  // domain.m entries), and then run iFFT to transform to coefficients.
32  std::vector<libff::Fr<ppT>> coefficients(domain.m, libff::Fr<ppT>::zero());
33  for (auto it : lagrange_factors) {
34  const size_t lagrange_idx = it.first;
35  const libff::Fr<ppT> &lagrange_factor = it.second;
36 
37  assert(lagrange_idx < domain.m);
38  if (!lagrange_factor.is_zero()) {
39  coefficients[lagrange_idx] = lagrange_factor;
40  }
41  }
42 
43  domain.iFFT(coefficients);
44  return multi_exp<ppT, GroupT>(powers, coefficients);
45 }
46 
47 } // namespace libzeth
48 
49 #endif // __ZETH_CORE_EVALUATOR_FROM_LAGRANGE_TCC__