mirror of https://github.com/zcash/libsnark.git
Change most assert_except into assert.
This commit is contained in:
parent
8b422be264
commit
9ada3f84ab
|
@ -6,7 +6,6 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#include "algebra/curves/alt_bn128/alt_bn128_g1.hpp"
|
||||
#include "common/assert_except.hpp"
|
||||
|
||||
namespace libsnark {
|
||||
|
||||
|
@ -257,7 +256,7 @@ alt_bn128_G1 alt_bn128_G1::add(const alt_bn128_G1 &other) const
|
|||
alt_bn128_G1 alt_bn128_G1::mixed_add(const alt_bn128_G1 &other) const
|
||||
{
|
||||
#ifdef DEBUG
|
||||
assert_except(other.is_special());
|
||||
assert(other.is_special());
|
||||
#endif
|
||||
|
||||
// handle special cases having to do with O
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#include "algebra/curves/alt_bn128/alt_bn128_g2.hpp"
|
||||
#include "common/assert_except.hpp"
|
||||
|
||||
namespace libsnark {
|
||||
|
||||
|
@ -267,7 +266,7 @@ alt_bn128_G2 alt_bn128_G2::add(const alt_bn128_G2 &other) const
|
|||
alt_bn128_G2 alt_bn128_G2::mixed_add(const alt_bn128_G2 &other) const
|
||||
{
|
||||
#ifdef DEBUG
|
||||
assert_except(other.is_special());
|
||||
assert(other.is_special());
|
||||
#endif
|
||||
|
||||
// handle special cases having to do with O
|
||||
|
|
|
@ -15,16 +15,15 @@
|
|||
#define BASIC_RADIX2_DOMAIN_TCC_
|
||||
|
||||
#include "algebra/evaluation_domain/domains/basic_radix2_domain_aux.hpp"
|
||||
#include "common/assert_except.hpp"
|
||||
|
||||
namespace libsnark {
|
||||
|
||||
template<typename FieldT>
|
||||
basic_radix2_domain<FieldT>::basic_radix2_domain(const size_t m) : evaluation_domain<FieldT>(m)
|
||||
{
|
||||
assert_except(m > 1);
|
||||
assert(m > 1);
|
||||
const size_t logm = log2(m);
|
||||
assert_except(logm <= (FieldT::s));
|
||||
assert(logm <= (FieldT::s));
|
||||
|
||||
omega = get_root_of_unity<FieldT>(m);
|
||||
}
|
||||
|
@ -33,7 +32,7 @@ template<typename FieldT>
|
|||
void basic_radix2_domain<FieldT>::FFT(std::vector<FieldT> &a)
|
||||
{
|
||||
enter_block("Execute FFT");
|
||||
assert_except(a.size() == this->m);
|
||||
assert(a.size() == this->m);
|
||||
_basic_radix2_FFT(a, omega);
|
||||
leave_block("Execute FFT");
|
||||
}
|
||||
|
@ -42,7 +41,7 @@ template<typename FieldT>
|
|||
void basic_radix2_domain<FieldT>::iFFT(std::vector<FieldT> &a)
|
||||
{
|
||||
enter_block("Execute inverse FFT");
|
||||
assert_except(a.size() == this->m);
|
||||
assert(a.size() == this->m);
|
||||
_basic_radix2_FFT(a, omega.inverse());
|
||||
|
||||
const FieldT sconst = FieldT(a.size()).inverse();
|
||||
|
@ -92,7 +91,7 @@ FieldT basic_radix2_domain<FieldT>::compute_Z(const FieldT &t)
|
|||
template<typename FieldT>
|
||||
void basic_radix2_domain<FieldT>::add_poly_Z(const FieldT &coeff, std::vector<FieldT> &H)
|
||||
{
|
||||
assert_except(H.size() == this->m+1);
|
||||
assert(H.size() == this->m+1);
|
||||
H[this->m] += coeff;
|
||||
H[0] -= coeff;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "algebra/fields/field_utils.hpp"
|
||||
#include "common/profiling.hpp"
|
||||
#include "common/utils.hpp"
|
||||
#include "common/assert_except.hpp"
|
||||
|
||||
namespace libsnark {
|
||||
|
||||
|
@ -39,7 +38,7 @@ template<typename FieldT>
|
|||
void _basic_serial_radix2_FFT(std::vector<FieldT> &a, const FieldT &omega)
|
||||
{
|
||||
const size_t n = a.size(), logn = log2(n);
|
||||
assert_except(n == (1u << logn));
|
||||
assert(n == (1u << logn));
|
||||
|
||||
/* swapping in place (from Storer's book) */
|
||||
for (size_t k = 0; k < n; ++k)
|
||||
|
@ -79,7 +78,7 @@ void _basic_parallel_radix2_FFT_inner(std::vector<FieldT> &a, const FieldT &omeg
|
|||
|
||||
const size_t m = a.size();
|
||||
const size_t log_m = log2(m);
|
||||
assert_except(m == 1ul<<log_m);
|
||||
assert(m == 1ul<<log_m);
|
||||
|
||||
if (log_m < log_cpus)
|
||||
{
|
||||
|
@ -190,7 +189,7 @@ std::vector<FieldT> _basic_radix2_lagrange_coeffs(const size_t m, const FieldT &
|
|||
return std::vector<FieldT>(1, FieldT::one());
|
||||
}
|
||||
|
||||
assert_except(m == (1u << log2(m)));
|
||||
assert(m == (1u << log2(m)));
|
||||
|
||||
const FieldT omega = get_root_of_unity<FieldT>(m);
|
||||
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
/** @file
|
||||
*****************************************************************************
|
||||
|
||||
Declaration of interfaces for the "extended radix-2" evaluation domain.
|
||||
|
||||
Roughly, the domain has size m = 2^{k+1} and consists of
|
||||
"the m-th roots of unity" union "a coset of these roots".
|
||||
|
||||
*****************************************************************************
|
||||
* @author This file is part of libsnark, developed by SCIPR Lab
|
||||
* and contributors (see AUTHORS).
|
||||
* @copyright MIT license (see LICENSE file)
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef EXTENDED_RADIX2_DOMAIN_HPP_
|
||||
#define EXTENDED_RADIX2_DOMAIN_HPP_
|
||||
|
||||
#include "algebra/evaluation_domain/evaluation_domain.hpp"
|
||||
|
||||
namespace libsnark {
|
||||
|
||||
template<typename FieldT>
|
||||
class extended_radix2_domain : public evaluation_domain<FieldT> {
|
||||
public:
|
||||
|
||||
size_t small_m;
|
||||
FieldT omega;
|
||||
FieldT shift;
|
||||
|
||||
extended_radix2_domain(const size_t m);
|
||||
|
||||
void FFT(std::vector<FieldT> &a);
|
||||
void iFFT(std::vector<FieldT> &a);
|
||||
void cosetFFT(std::vector<FieldT> &a, const FieldT &g);
|
||||
void icosetFFT(std::vector<FieldT> &a, const FieldT &g);
|
||||
std::vector<FieldT> lagrange_coeffs(const FieldT &t);
|
||||
FieldT get_element(const size_t idx);
|
||||
FieldT compute_Z(const FieldT &t);
|
||||
void add_poly_Z(const FieldT &coeff, std::vector<FieldT> &H);
|
||||
void divide_by_Z_on_coset(std::vector<FieldT> &P);
|
||||
|
||||
};
|
||||
|
||||
} // libsnark
|
||||
|
||||
#include "algebra/evaluation_domain/domains/extended_radix2_domain.tcc"
|
||||
|
||||
#endif // EXTENDED_RADIX2_DOMAIN_HPP_
|
|
@ -1,181 +0,0 @@
|
|||
/** @file
|
||||
*****************************************************************************
|
||||
|
||||
Implementation of interfaces for the "extended radix-2" evaluation domain.
|
||||
|
||||
See extended_radix2_domain.hpp .
|
||||
|
||||
*****************************************************************************
|
||||
* @author This file is part of libsnark, developed by SCIPR Lab
|
||||
* and contributors (see AUTHORS).
|
||||
* @copyright MIT license (see LICENSE file)
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef EXTENDED_RADIX2_DOMAIN_TCC_
|
||||
|
||||
#include "algebra/evaluation_domain/domains/basic_radix2_domain_aux.hpp"
|
||||
#include "common/assert_except.hpp"
|
||||
|
||||
namespace libsnark {
|
||||
|
||||
template<typename FieldT>
|
||||
extended_radix2_domain<FieldT>::extended_radix2_domain(const size_t m) : evaluation_domain<FieldT>(m)
|
||||
{
|
||||
assert_except(m > 1);
|
||||
|
||||
const size_t logm = log2(m);
|
||||
|
||||
assert_except(logm == FieldT::s + 1);
|
||||
|
||||
small_m = m/2;
|
||||
omega = get_root_of_unity<FieldT>(small_m);
|
||||
shift = coset_shift<FieldT>();
|
||||
}
|
||||
|
||||
template<typename FieldT>
|
||||
void extended_radix2_domain<FieldT>::FFT(std::vector<FieldT> &a)
|
||||
{
|
||||
assert_except(a.size() == this->m);
|
||||
|
||||
std::vector<FieldT> a0(small_m, FieldT::zero());
|
||||
std::vector<FieldT> a1(small_m, FieldT::zero());
|
||||
|
||||
const FieldT shift_to_small_m = shift^bigint<1>(small_m);
|
||||
|
||||
FieldT shift_i = FieldT::one();
|
||||
for (size_t i = 0; i < small_m; ++i)
|
||||
{
|
||||
a0[i] = a[i] + a[small_m + i];
|
||||
a1[i] = shift_i * (a[i] + shift_to_small_m * a[small_m + i]);
|
||||
|
||||
shift_i *= shift;
|
||||
}
|
||||
|
||||
_basic_radix2_FFT(a0, omega);
|
||||
_basic_radix2_FFT(a1, omega);
|
||||
|
||||
for (size_t i = 0; i < small_m; ++i)
|
||||
{
|
||||
a[i] = a0[i];
|
||||
a[i+small_m] = a1[i];
|
||||
}
|
||||
}
|
||||
|
||||
template<typename FieldT>
|
||||
void extended_radix2_domain<FieldT>::iFFT(std::vector<FieldT> &a)
|
||||
{
|
||||
assert_except(a.size() == this->m);
|
||||
|
||||
// note: this is not in-place
|
||||
std::vector<FieldT> a0(a.begin(), a.begin() + small_m);
|
||||
std::vector<FieldT> a1(a.begin() + small_m, a.end());
|
||||
|
||||
const FieldT omega_inverse = omega.inverse();
|
||||
_basic_radix2_FFT(a0, omega_inverse);
|
||||
_basic_radix2_FFT(a1, omega_inverse);
|
||||
|
||||
const FieldT shift_to_small_m = shift^bigint<1>(small_m);
|
||||
const FieldT sconst = (FieldT(small_m) * (FieldT::one()-shift_to_small_m)).inverse();
|
||||
|
||||
const FieldT shift_inverse = shift.inverse();
|
||||
FieldT shift_inverse_i = FieldT::one();
|
||||
|
||||
for (size_t i = 0; i < small_m; ++i)
|
||||
{
|
||||
a[i] = sconst * (-shift_to_small_m * a0[i] + shift_inverse_i * a1[i]);
|
||||
a[i+small_m] = sconst * (a0[i] - shift_inverse_i * a1[i]);
|
||||
|
||||
shift_inverse_i *= shift_inverse;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename FieldT>
|
||||
void extended_radix2_domain<FieldT>::cosetFFT(std::vector<FieldT> &a, const FieldT &g)
|
||||
{
|
||||
_multiply_by_coset(a, g);
|
||||
FFT(a);
|
||||
}
|
||||
|
||||
template<typename FieldT>
|
||||
void extended_radix2_domain<FieldT>::icosetFFT(std::vector<FieldT> &a, const FieldT &g)
|
||||
{
|
||||
iFFT(a);
|
||||
_multiply_by_coset(a, g.inverse());
|
||||
}
|
||||
|
||||
template<typename FieldT>
|
||||
std::vector<FieldT> extended_radix2_domain<FieldT>::lagrange_coeffs(const FieldT &t)
|
||||
{
|
||||
const std::vector<FieldT> T0 = _basic_radix2_lagrange_coeffs(small_m, t);
|
||||
const std::vector<FieldT> T1 = _basic_radix2_lagrange_coeffs(small_m, t * shift.inverse());
|
||||
|
||||
std::vector<FieldT> result(this->m, FieldT::zero());
|
||||
|
||||
const FieldT t_to_small_m = t ^ bigint<1>(small_m);
|
||||
const FieldT shift_to_small_m = shift ^ bigint<1>(small_m);
|
||||
const FieldT one_over_denom = (shift_to_small_m - FieldT::one()).inverse();
|
||||
const FieldT T0_coeff = (t_to_small_m - shift_to_small_m) * (-one_over_denom);
|
||||
const FieldT T1_coeff = (t_to_small_m - FieldT::one()) * one_over_denom;
|
||||
for (size_t i = 0; i < small_m; ++i)
|
||||
{
|
||||
result[i] = T0[i] * T0_coeff;
|
||||
result[i+small_m] = T1[i] * T1_coeff;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename FieldT>
|
||||
FieldT extended_radix2_domain<FieldT>::get_element(const size_t idx)
|
||||
{
|
||||
if (idx < small_m)
|
||||
{
|
||||
return omega^idx;
|
||||
}
|
||||
else
|
||||
{
|
||||
return shift*(omega^(idx-small_m));
|
||||
}
|
||||
}
|
||||
|
||||
template<typename FieldT>
|
||||
FieldT extended_radix2_domain<FieldT>::compute_Z(const FieldT &t)
|
||||
{
|
||||
return ((t^small_m) - FieldT::one()) * ((t^small_m) - (shift^small_m));
|
||||
}
|
||||
|
||||
template<typename FieldT>
|
||||
void extended_radix2_domain<FieldT>::add_poly_Z(const FieldT &coeff, std::vector<FieldT> &H)
|
||||
{
|
||||
assert_except(H.size() == this->m+1);
|
||||
const FieldT shift_to_small_m = shift^small_m;
|
||||
|
||||
H[this->m] += coeff;
|
||||
H[small_m] -= coeff * (shift_to_small_m + FieldT::one());
|
||||
H[0] += coeff * shift_to_small_m;
|
||||
}
|
||||
|
||||
template<typename FieldT>
|
||||
void extended_radix2_domain<FieldT>::divide_by_Z_on_coset(std::vector<FieldT> &P)
|
||||
{
|
||||
const FieldT coset = FieldT::multiplicative_generator;
|
||||
|
||||
const FieldT coset_to_small_m = coset^small_m;
|
||||
const FieldT shift_to_small_m = shift^small_m;
|
||||
|
||||
const FieldT Z0 = (coset_to_small_m - FieldT::one()) * (coset_to_small_m - shift_to_small_m);
|
||||
const FieldT Z1 = (coset_to_small_m*shift_to_small_m - FieldT::one()) * (coset_to_small_m * shift_to_small_m - shift_to_small_m);
|
||||
|
||||
const FieldT Z0_inverse = Z0.inverse();
|
||||
const FieldT Z1_inverse = Z1.inverse();
|
||||
|
||||
for (size_t i = 0; i < small_m; ++i)
|
||||
{
|
||||
P[i] *= Z0_inverse;
|
||||
P[i+small_m] *= Z1_inverse;
|
||||
}
|
||||
}
|
||||
|
||||
} // libsnark
|
||||
|
||||
#endif // EXTENDED_RADIX2_DOMAIN_TCC_
|
|
@ -1,50 +0,0 @@
|
|||
/** @file
|
||||
*****************************************************************************
|
||||
|
||||
Declaration of interfaces for the "step radix-2" evaluation domain.
|
||||
|
||||
Roughly, the domain has size m = 2^k + 2^r and consists of
|
||||
"the 2^k-th roots of unity" union "a coset of 2^r-th roots of unity".
|
||||
|
||||
*****************************************************************************
|
||||
* @author This file is part of libsnark, developed by SCIPR Lab
|
||||
* and contributors (see AUTHORS).
|
||||
* @copyright MIT license (see LICENSE file)
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef STEP_RADIX2_DOMAIN_HPP_
|
||||
#define STEP_RADIX2_DOMAIN_HPP_
|
||||
|
||||
#include "algebra/evaluation_domain/evaluation_domain.hpp"
|
||||
|
||||
namespace libsnark {
|
||||
|
||||
template<typename FieldT>
|
||||
class step_radix2_domain : public evaluation_domain<FieldT> {
|
||||
public:
|
||||
|
||||
size_t big_m;
|
||||
size_t small_m;
|
||||
FieldT omega;
|
||||
FieldT big_omega;
|
||||
FieldT small_omega;
|
||||
|
||||
step_radix2_domain(const size_t m);
|
||||
|
||||
void FFT(std::vector<FieldT> &a);
|
||||
void iFFT(std::vector<FieldT> &a);
|
||||
void cosetFFT(std::vector<FieldT> &a, const FieldT &g);
|
||||
void icosetFFT(std::vector<FieldT> &a, const FieldT &g);
|
||||
std::vector<FieldT> lagrange_coeffs(const FieldT &t);
|
||||
FieldT get_element(const size_t idx);
|
||||
FieldT compute_Z(const FieldT &t);
|
||||
void add_poly_Z(const FieldT &coeff, std::vector<FieldT> &H);
|
||||
void divide_by_Z_on_coset(std::vector<FieldT> &P);
|
||||
|
||||
};
|
||||
|
||||
} // libsnark
|
||||
|
||||
#include "algebra/evaluation_domain/domains/step_radix2_domain.tcc"
|
||||
|
||||
#endif // STEP_RADIX2_DOMAIN_HPP_
|
|
@ -1,248 +0,0 @@
|
|||
/** @file
|
||||
*****************************************************************************
|
||||
|
||||
Implementation of interfaces for the "step radix-2" evaluation domain.
|
||||
|
||||
See step_radix2_domain.hpp .
|
||||
|
||||
*****************************************************************************
|
||||
* @author This file is part of libsnark, developed by SCIPR Lab
|
||||
* and contributors (see AUTHORS).
|
||||
* @copyright MIT license (see LICENSE file)
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef STEP_RADIX2_DOMAIN_TCC_
|
||||
|
||||
#include "algebra/evaluation_domain/domains/basic_radix2_domain_aux.hpp"
|
||||
#include "common/assert_except.hpp"
|
||||
|
||||
namespace libsnark {
|
||||
|
||||
template<typename FieldT>
|
||||
step_radix2_domain<FieldT>::step_radix2_domain(const size_t m) : evaluation_domain<FieldT>(m)
|
||||
{
|
||||
assert_except(m > 1);
|
||||
|
||||
big_m = 1ul<<(log2(m)-1);
|
||||
small_m = m - big_m;
|
||||
|
||||
assert_except(small_m == 1ul<<log2(small_m));
|
||||
|
||||
omega = get_root_of_unity<FieldT>(1ul<<log2(m)); // rounded!
|
||||
big_omega = omega.squared();
|
||||
small_omega = get_root_of_unity<FieldT>(small_m);
|
||||
}
|
||||
|
||||
template<typename FieldT>
|
||||
void step_radix2_domain<FieldT>::FFT(std::vector<FieldT> &a)
|
||||
{
|
||||
assert_except(a.size() == this->m);
|
||||
std::vector<FieldT> c(big_m, FieldT::zero());
|
||||
std::vector<FieldT> d(big_m, FieldT::zero());
|
||||
|
||||
FieldT omega_i = FieldT::one();
|
||||
for (size_t i = 0; i < big_m; ++i)
|
||||
{
|
||||
c[i] = (i < small_m ? a[i] + a[i+big_m] : a[i]);
|
||||
d[i] = omega_i * (i < small_m ? a[i] - a[i+big_m] : a[i]);
|
||||
omega_i *= omega;
|
||||
}
|
||||
|
||||
std::vector<FieldT> e(small_m, FieldT::zero());
|
||||
const size_t compr = 1ul<<(log2(big_m) - log2(small_m));
|
||||
for (size_t i = 0; i < small_m; ++i)
|
||||
{
|
||||
for (size_t j = 0; j < compr; ++j)
|
||||
{
|
||||
e[i] += d[i + j * small_m];
|
||||
}
|
||||
}
|
||||
|
||||
_basic_radix2_FFT(c, omega.squared());
|
||||
_basic_radix2_FFT(e, get_root_of_unity<FieldT>(small_m));
|
||||
|
||||
for (size_t i = 0; i < big_m; ++i)
|
||||
{
|
||||
a[i] = c[i];
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < small_m; ++i)
|
||||
{
|
||||
a[i+big_m] = e[i];
|
||||
}
|
||||
}
|
||||
|
||||
template<typename FieldT>
|
||||
void step_radix2_domain<FieldT>::iFFT(std::vector<FieldT> &a)
|
||||
{
|
||||
assert_except(a.size() == this->m);
|
||||
|
||||
std::vector<FieldT> U0(a.begin(), a.begin() + big_m);
|
||||
std::vector<FieldT> U1(a.begin() + big_m, a.end());
|
||||
|
||||
_basic_radix2_FFT(U0, omega.squared().inverse());
|
||||
_basic_radix2_FFT(U1, get_root_of_unity<FieldT>(small_m).inverse());
|
||||
|
||||
const FieldT U0_size_inv = FieldT(big_m).inverse();
|
||||
for (size_t i = 0; i < big_m; ++i)
|
||||
{
|
||||
U0[i] *= U0_size_inv;
|
||||
}
|
||||
|
||||
const FieldT U1_size_inv = FieldT(small_m).inverse();
|
||||
for (size_t i = 0; i < small_m; ++i)
|
||||
{
|
||||
U1[i] *= U1_size_inv;
|
||||
}
|
||||
|
||||
std::vector<FieldT> tmp = U0;
|
||||
FieldT omega_i = FieldT::one();
|
||||
for (size_t i = 0; i < big_m; ++i)
|
||||
{
|
||||
tmp[i] *= omega_i;
|
||||
omega_i *= omega;
|
||||
}
|
||||
|
||||
// save A_suffix
|
||||
for (size_t i = small_m; i < big_m; ++i)
|
||||
{
|
||||
a[i] = U0[i];
|
||||
}
|
||||
|
||||
const size_t compr = 1ul<<(log2(big_m) - log2(small_m));
|
||||
for (size_t i = 0; i < small_m; ++i)
|
||||
{
|
||||
for (size_t j = 1; j < compr; ++j)
|
||||
{
|
||||
U1[i] -= tmp[i + j * small_m];
|
||||
}
|
||||
}
|
||||
|
||||
const FieldT omega_inv = omega.inverse();
|
||||
FieldT omega_inv_i = FieldT::one();
|
||||
for (size_t i = 0; i < small_m; ++i)
|
||||
{
|
||||
U1[i] *= omega_inv_i;
|
||||
omega_inv_i *= omega_inv;
|
||||
}
|
||||
|
||||
// compute A_prefix
|
||||
const FieldT over_two = FieldT(2).inverse();
|
||||
for (size_t i = 0; i < small_m; ++i)
|
||||
{
|
||||
a[i] = (U0[i]+U1[i]) * over_two;
|
||||
}
|
||||
|
||||
// compute B2
|
||||
for (size_t i = 0; i < small_m; ++i)
|
||||
{
|
||||
a[big_m + i] = (U0[i]-U1[i]) * over_two;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename FieldT>
|
||||
void step_radix2_domain<FieldT>::cosetFFT(std::vector<FieldT> &a, const FieldT &g)
|
||||
{
|
||||
_multiply_by_coset(a, g);
|
||||
FFT(a);
|
||||
}
|
||||
|
||||
template<typename FieldT>
|
||||
void step_radix2_domain<FieldT>::icosetFFT(std::vector<FieldT> &a, const FieldT &g)
|
||||
{
|
||||
iFFT(a);
|
||||
_multiply_by_coset(a, g.inverse());
|
||||
}
|
||||
|
||||
template<typename FieldT>
|
||||
std::vector<FieldT> step_radix2_domain<FieldT>::lagrange_coeffs(const FieldT &t)
|
||||
{
|
||||
std::vector<FieldT> inner_big = _basic_radix2_lagrange_coeffs(big_m, t);
|
||||
std::vector<FieldT> inner_small = _basic_radix2_lagrange_coeffs(small_m, t * omega.inverse());
|
||||
|
||||
std::vector<FieldT> result(this->m, FieldT::zero());
|
||||
|
||||
const FieldT L0 = (t^small_m)-(omega^small_m);
|
||||
const FieldT omega_to_small_m = omega^small_m;
|
||||
const FieldT big_omega_to_small_m = big_omega ^ small_m;
|
||||
FieldT elt = FieldT::one();
|
||||
for (size_t i = 0; i < big_m; ++i)
|
||||
{
|
||||
result[i] = inner_big[i] * L0 * (elt - omega_to_small_m).inverse();
|
||||
elt *= big_omega_to_small_m;
|
||||
}
|
||||
|
||||
const FieldT L1 = ((t^big_m)-FieldT::one()) * ((omega^big_m) - FieldT::one()).inverse();
|
||||
|
||||
for (size_t i = 0; i < small_m; ++i)
|
||||
{
|
||||
result[big_m + i] = L1 * inner_small[i];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename FieldT>
|
||||
FieldT step_radix2_domain<FieldT>::get_element(const size_t idx)
|
||||
{
|
||||
if (idx < big_m)
|
||||
{
|
||||
return big_omega^idx;
|
||||
}
|
||||
else
|
||||
{
|
||||
return omega * (small_omega^(idx-big_m));
|
||||
}
|
||||
}
|
||||
|
||||
template<typename FieldT>
|
||||
FieldT step_radix2_domain<FieldT>::compute_Z(const FieldT &t)
|
||||
{
|
||||
return ((t^big_m) - FieldT::one()) * ((t^small_m) - (omega^small_m));
|
||||
}
|
||||
|
||||
template<typename FieldT>
|
||||
void step_radix2_domain<FieldT>::add_poly_Z(const FieldT &coeff, std::vector<FieldT> &H)
|
||||
{
|
||||
assert_except(H.size() == this->m+1);
|
||||
const FieldT omega_to_small_m = omega^small_m;
|
||||
|
||||
H[this->m] += coeff;
|
||||
H[big_m] -= coeff * omega_to_small_m;
|
||||
H[small_m] -= coeff;
|
||||
H[0] += coeff * omega_to_small_m;
|
||||
}
|
||||
|
||||
template<typename FieldT>
|
||||
void step_radix2_domain<FieldT>::divide_by_Z_on_coset(std::vector<FieldT> &P)
|
||||
{
|
||||
// (c^{2^k}-1) * (c^{2^r} * w^{2^{r+1}*i) - w^{2^r})
|
||||
const FieldT coset = FieldT::multiplicative_generator;
|
||||
|
||||
const FieldT Z0 = (coset^big_m) - FieldT::one();
|
||||
const FieldT coset_to_small_m_times_Z0 = (coset^small_m) * Z0;
|
||||
const FieldT omega_to_small_m_times_Z0 = (omega^small_m) * Z0;
|
||||
const FieldT omega_to_2small_m = omega^(2*small_m);
|
||||
FieldT elt = FieldT::one();
|
||||
|
||||
for (size_t i = 0; i < big_m; ++i)
|
||||
{
|
||||
P[i] *= (coset_to_small_m_times_Z0 * elt - omega_to_small_m_times_Z0).inverse();
|
||||
elt *= omega_to_2small_m;
|
||||
}
|
||||
|
||||
// (c^{2^k}*w^{2^k}-1) * (c^{2^k} * w^{2^r} - w^{2^r})
|
||||
|
||||
const FieldT Z1 = ((((coset*omega)^big_m) - FieldT::one()) * (((coset * omega)^small_m) - (omega^small_m)));
|
||||
const FieldT Z1_inverse = Z1.inverse();
|
||||
|
||||
for (size_t i = 0; i < small_m; ++i)
|
||||
{
|
||||
P[big_m + i] *= Z1_inverse;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // libsnark
|
||||
|
||||
#endif // STEP_RADIX2_DOMAIN_TCC_
|
|
@ -22,18 +22,15 @@
|
|||
#include <cassert>
|
||||
#include "algebra/fields/field_utils.hpp"
|
||||
#include "algebra/evaluation_domain/domains/basic_radix2_domain.hpp"
|
||||
#include "algebra/evaluation_domain/domains/extended_radix2_domain.hpp"
|
||||
#include "algebra/evaluation_domain/domains/step_radix2_domain.hpp"
|
||||
#include "common/assert_except.hpp"
|
||||
|
||||
namespace libsnark {
|
||||
|
||||
template<typename FieldT>
|
||||
std::shared_ptr<evaluation_domain<FieldT> > get_evaluation_domain(const size_t min_size)
|
||||
{
|
||||
assert_except(min_size > 1);
|
||||
assert(min_size > 1);
|
||||
const size_t log_min_size = log2(min_size);
|
||||
assert_except(log_min_size <= (FieldT::s+1));
|
||||
assert(log_min_size <= (FieldT::s+1));
|
||||
|
||||
std::shared_ptr<evaluation_domain<FieldT> > result;
|
||||
if (min_size == (1u << log_min_size))
|
||||
|
@ -44,7 +41,7 @@ std::shared_ptr<evaluation_domain<FieldT> > get_evaluation_domain(const size_t m
|
|||
{
|
||||
print_indent(); printf("* Selected domain: extended_radix2\n");
|
||||
}
|
||||
result.reset(new extended_radix2_domain<FieldT>(min_size));
|
||||
assert(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -76,7 +73,7 @@ std::shared_ptr<evaluation_domain<FieldT> > get_evaluation_domain(const size_t m
|
|||
{
|
||||
print_indent(); printf("* Selected domain: extended_radix2\n");
|
||||
}
|
||||
result.reset(new extended_radix2_domain<FieldT>(big + rounded_small));
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -85,7 +82,7 @@ std::shared_ptr<evaluation_domain<FieldT> > get_evaluation_domain(const size_t m
|
|||
{
|
||||
print_indent(); printf("* Selected domain: step_radix2\n");
|
||||
}
|
||||
result.reset(new step_radix2_domain<FieldT>(big + rounded_small));
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,8 +92,8 @@ std::shared_ptr<evaluation_domain<FieldT> > get_evaluation_domain(const size_t m
|
|||
template<typename FieldT>
|
||||
FieldT lagrange_eval(const size_t m, const std::vector<FieldT> &domain, const FieldT &t, const size_t idx)
|
||||
{
|
||||
assert_except(m == domain.size());
|
||||
assert_except(idx < m);
|
||||
assert(m == domain.size());
|
||||
assert(idx < m);
|
||||
|
||||
FieldT num = FieldT::one();
|
||||
FieldT denom = FieldT::one();
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#include <climits>
|
||||
#include <cstring>
|
||||
#include "sodium.h"
|
||||
#include "common/assert_except.hpp"
|
||||
|
||||
namespace libsnark {
|
||||
|
||||
|
@ -32,12 +31,12 @@ bigint<n>::bigint(const char* s) /// Initialize from a string containing an inte
|
|||
|
||||
for (size_t i = 0; i < l; ++i)
|
||||
{
|
||||
assert_except(s[i] >= '0' && s[i] <= '9');
|
||||
assert(s[i] >= '0' && s[i] <= '9');
|
||||
s_copy[i] = s[i] - '0';
|
||||
}
|
||||
|
||||
mp_size_t limbs_written = mpn_set_str(this->data, s_copy, l, 10);
|
||||
assert_except(limbs_written <= n);
|
||||
assert(limbs_written <= n);
|
||||
|
||||
delete[] s_copy;
|
||||
}
|
||||
|
@ -54,7 +53,7 @@ bigint<n>::bigint(const mpz_t r) /// Initialize from MPZ element
|
|||
mpz_fdiv_q_2exp(k, k, GMP_NUMB_BITS);
|
||||
}
|
||||
|
||||
assert_except(mpz_sgn(k) == 0);
|
||||
assert(mpz_sgn(k) == 0);
|
||||
mpz_clear(k);
|
||||
}
|
||||
|
||||
|
@ -187,7 +186,7 @@ inline void bigint<n>::div_qr(bigint<n-d+1>& quotient, bigint<d>& remainder,
|
|||
const bigint<n>& dividend, const bigint<d>& divisor)
|
||||
{
|
||||
static_assert(n >= d, "dividend must not be smaller than divisor for bigint::div_qr");
|
||||
assert_except(divisor.data[d-1] != 0);
|
||||
assert(divisor.data[d-1] != 0);
|
||||
mpn_tdiv_qr(quotient.data, remainder.data, 0, dividend.data, n, divisor.data, d);
|
||||
}
|
||||
|
||||
|
@ -224,7 +223,7 @@ inline bool bigint<n>::operator>(const bigint<n>& other) const
|
|||
template<mp_size_t n>
|
||||
bigint<n>& bigint<n>::randomize()
|
||||
{
|
||||
assert_except(GMP_NUMB_BITS == sizeof(mp_limb_t) * 8);
|
||||
assert(GMP_NUMB_BITS == sizeof(mp_limb_t) * 8);
|
||||
|
||||
randombytes_buf(this->data, sizeof(mp_limb_t) * n);
|
||||
|
||||
|
@ -263,12 +262,12 @@ std::istream& operator>>(std::istream &in, bigint<n> &b)
|
|||
|
||||
for (size_t i = 0; i < l; ++i)
|
||||
{
|
||||
assert_except(s[i] >= '0' && s[i] <= '9');
|
||||
assert(s[i] >= '0' && s[i] <= '9');
|
||||
s_copy[i] = s[i] - '0';
|
||||
}
|
||||
|
||||
mp_size_t limbs_written = mpn_set_str(b.data, s_copy, l, 10);
|
||||
assert_except(limbs_written <= n);
|
||||
assert(limbs_written <= n);
|
||||
|
||||
delete[] s_copy;
|
||||
#endif
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#define FIELD_UTILS_TCC_
|
||||
|
||||
#include "common/utils.hpp"
|
||||
#include "common/assert_except.hpp"
|
||||
|
||||
namespace libsnark {
|
||||
|
||||
|
@ -25,8 +24,8 @@ template<typename FieldT>
|
|||
FieldT get_root_of_unity(const size_t n)
|
||||
{
|
||||
const size_t logn = log2(n);
|
||||
assert_except(n == (1u << logn));
|
||||
assert_except(logn <= FieldT::s);
|
||||
assert(n == (1u << logn));
|
||||
assert(logn <= FieldT::s);
|
||||
|
||||
FieldT omega = FieldT::root_of_unity;
|
||||
for (size_t i = FieldT::s; i > logn; --i)
|
||||
|
@ -65,7 +64,7 @@ std::vector<FieldT> pack_int_vector_into_field_element_vector(const std::vector<
|
|||
template<typename FieldT>
|
||||
std::vector<FieldT> pack_bit_vector_into_field_element_vector(const bit_vector &v, const size_t chunk_bits)
|
||||
{
|
||||
assert_except(chunk_bits <= FieldT::capacity());
|
||||
assert(chunk_bits <= FieldT::capacity());
|
||||
|
||||
const size_t repacked_size = div_ceil(v.size(), chunk_bits);
|
||||
std::vector<FieldT> result(repacked_size);
|
||||
|
@ -143,7 +142,7 @@ bit_vector convert_field_element_to_bit_vector(const FieldT &el, const size_t bi
|
|||
template<typename FieldT>
|
||||
FieldT convert_bit_vector_to_field_element(const bit_vector &v)
|
||||
{
|
||||
assert_except(v.size() <= FieldT::size_in_bits());
|
||||
assert(v.size() <= FieldT::size_in_bits());
|
||||
|
||||
FieldT res = FieldT::zero();
|
||||
FieldT c = FieldT::one();
|
||||
|
@ -165,7 +164,7 @@ void batch_invert(std::vector<FieldT> &vec)
|
|||
|
||||
for (auto el : vec)
|
||||
{
|
||||
assert_except(!el.is_zero());
|
||||
assert(!el.is_zero());
|
||||
prod.emplace_back(acc);
|
||||
acc = acc * el;
|
||||
}
|
||||
|
|
|
@ -173,13 +173,13 @@ void Fp_model<n,modulus>::mul_reduce(const bigint<n> &other)
|
|||
/* calculate res = res + k * mod * b^i */
|
||||
mp_limb_t carryout = mpn_addmul_1(res+i, modulus.data, n, k);
|
||||
carryout = mpn_add_1(res+n+i, res+n+i, n-i, carryout);
|
||||
assert_except(carryout == 0);
|
||||
assert(carryout == 0);
|
||||
}
|
||||
|
||||
if (mpn_cmp(res+n, modulus.data, n) >= 0)
|
||||
{
|
||||
const mp_limb_t borrow = mpn_sub(res+n, res+n, n, modulus.data, n);
|
||||
assert_except(borrow == 0);
|
||||
assert(borrow == 0);
|
||||
}
|
||||
|
||||
mpn_copyi(this->mont_repr.data, res+n, n);
|
||||
|
@ -203,7 +203,7 @@ Fp_model<n,modulus>::Fp_model(const long x, const bool is_unsigned)
|
|||
else
|
||||
{
|
||||
const mp_limb_t borrow = mpn_sub_1(this->mont_repr.data, modulus.data, n, -x);
|
||||
assert_except(borrow == 0);
|
||||
assert(borrow == 0);
|
||||
}
|
||||
|
||||
mul_reduce(Rsquared);
|
||||
|
@ -391,7 +391,7 @@ Fp_model<n,modulus>& Fp_model<n,modulus>::operator+=(const Fp_model<n,modulus>&
|
|||
if (carry || mpn_cmp(scratch, modulus.data, n) >= 0)
|
||||
{
|
||||
const mp_limb_t borrow = mpn_sub(scratch, scratch, n+1, modulus.data, n);
|
||||
assert_except(borrow == 0);
|
||||
assert(borrow == 0);
|
||||
}
|
||||
|
||||
mpn_copyi(this->mont_repr.data, scratch, n);
|
||||
|
@ -483,7 +483,7 @@ Fp_model<n,modulus>& Fp_model<n,modulus>::operator-=(const Fp_model<n,modulus>&
|
|||
}
|
||||
|
||||
const mp_limb_t borrow = mpn_sub(scratch, scratch, n+1, other.mont_repr.data, n);
|
||||
assert_except(borrow == 0);
|
||||
assert(borrow == 0);
|
||||
|
||||
mpn_copyi(this->mont_repr.data, scratch, n);
|
||||
}
|
||||
|
@ -626,7 +626,7 @@ Fp_model<n,modulus>& Fp_model<n,modulus>::invert()
|
|||
this->inv_cnt++;
|
||||
#endif
|
||||
|
||||
assert_except(!this->is_zero());
|
||||
assert(!this->is_zero());
|
||||
|
||||
bigint<n> g; /* gp should have room for vn = n limbs */
|
||||
|
||||
|
@ -637,7 +637,7 @@ Fp_model<n,modulus>& Fp_model<n,modulus>::invert()
|
|||
|
||||
/* computes gcd(u, v) = g = u*s + v*t, so s*u will be 1 (mod v) */
|
||||
const mp_size_t gn = mpn_gcdext(g.data, s, &sn, this->mont_repr.data, n, v.data, n);
|
||||
assert_except(gn == 1 && g.data[0] == 1); /* inverse exists */
|
||||
assert(gn == 1 && g.data[0] == 1); /* inverse exists */
|
||||
|
||||
mp_limb_t q; /* division result fits into q, as sn <= n+1 */
|
||||
/* sn < 0 indicates negative sn; will fix up later */
|
||||
|
@ -658,7 +658,7 @@ Fp_model<n,modulus>& Fp_model<n,modulus>::invert()
|
|||
if (sn < 0)
|
||||
{
|
||||
const mp_limb_t borrow = mpn_sub_n(this->mont_repr.data, modulus.data, this->mont_repr.data, n);
|
||||
assert_except(borrow == 0);
|
||||
assert(borrow == 0);
|
||||
}
|
||||
|
||||
mul_reduce(Rcubed);
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
#ifndef KC_MULTIEXP_TCC_
|
||||
#define KC_MULTIEXP_TCC_
|
||||
|
||||
#include "common/assert_except.hpp"
|
||||
|
||||
namespace libsnark {
|
||||
|
||||
template<typename T1, typename T2, mp_size_t n>
|
||||
|
@ -52,7 +50,7 @@ knowledge_commitment<T1, T2> kc_multi_exp_with_mixed_addition(const knowledge_co
|
|||
while (index_it != vec.indices.end() && *index_it < max_idx)
|
||||
{
|
||||
const size_t scalar_position = (*index_it) - min_idx;
|
||||
assert_except(scalar_position < scalar_length);
|
||||
assert(scalar_position < scalar_length);
|
||||
|
||||
const FieldT scalar = *(scalar_start + scalar_position);
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
|
||||
#include "common/profiling.hpp"
|
||||
#include "common/utils.hpp"
|
||||
#include "common/assert_except.hpp"
|
||||
#include "algebra/scalar_multiplication/wnaf.hpp"
|
||||
|
||||
namespace libsnark {
|
||||
|
@ -120,7 +119,7 @@ T naive_exp(typename std::vector<T>::const_iterator vec_start,
|
|||
bigint<FieldT::num_limbs> scalar_bigint = scalar_it->as_bigint();
|
||||
result = result + opt_window_wnaf_exp(*vec_it, scalar_bigint, scalar_bigint.num_bits());
|
||||
}
|
||||
assert_except(scalar_it == scalar_end);
|
||||
assert(scalar_it == scalar_end);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -140,7 +139,7 @@ T naive_plain_exp(typename std::vector<T>::const_iterator vec_start,
|
|||
{
|
||||
result = result + (*scalar_it) * (*vec_it);
|
||||
}
|
||||
assert_except(scalar_it == scalar_end);
|
||||
assert(scalar_it == scalar_end);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -186,15 +185,15 @@ T multi_exp_inner(typename std::vector<T>::const_iterator vec_start,
|
|||
opt_q.emplace_back(ordered_exponent<n>(i, scalar_it->as_bigint()));
|
||||
}
|
||||
std::make_heap(opt_q.begin(),opt_q.end());
|
||||
assert_except(scalar_it == scalar_end);
|
||||
assert(scalar_it == scalar_end);
|
||||
|
||||
if (vec_len != odd_vec_len)
|
||||
{
|
||||
g.emplace_back(T::zero());
|
||||
opt_q.emplace_back(ordered_exponent<n>(odd_vec_len - 1, bigint<n>(0ul)));
|
||||
}
|
||||
assert_except(g.size() % 2 == 1);
|
||||
assert_except(opt_q.size() == g.size());
|
||||
assert(g.size() % 2 == 1);
|
||||
assert(opt_q.size() == g.size());
|
||||
|
||||
T opt_result = T::zero();
|
||||
|
||||
|
@ -330,7 +329,7 @@ T multi_exp_with_mixed_addition(typename std::vector<T>::const_iterator vec_star
|
|||
const size_t chunks,
|
||||
const bool use_multiexp)
|
||||
{
|
||||
assert_except(std::distance(vec_start, vec_end) == std::distance(scalar_start, scalar_end));
|
||||
assert(std::distance(vec_start, vec_end) == std::distance(scalar_start, scalar_end));
|
||||
enter_block("Process scalar vector");
|
||||
auto value_it = vec_start;
|
||||
auto scalar_it = scalar_start;
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include <cassert>
|
||||
#include <sstream>
|
||||
#include "common/utils.hpp"
|
||||
#include "common/assert_except.hpp"
|
||||
|
||||
namespace libsnark {
|
||||
|
||||
|
@ -70,7 +69,7 @@ T reserialize(const T &obj)
|
|||
ss << obj;
|
||||
T tmp;
|
||||
ss >> tmp;
|
||||
assert_except(obj == tmp);
|
||||
assert(obj == tmp);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue