Fix libsnark dependency build.
This changes libsnark to build in-place, instead of copying first to a build directory. Previously, modifications made to the original sources wouldn't get rebuilt without a 'make clean' because users would be pointing to the copies. This closes #2689.
This commit is contained in:
31
src/snark/libsnark/algebra/exponentiation/exponentiation.hpp
Normal file
31
src/snark/libsnark/algebra/exponentiation/exponentiation.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
/** @file
|
||||
*****************************************************************************
|
||||
|
||||
Declaration of interfaces for (square-and-multiply) exponentiation.
|
||||
|
||||
*****************************************************************************
|
||||
* @author This file is part of libsnark, developed by SCIPR Lab
|
||||
* and contributors (see AUTHORS).
|
||||
* @copyright MIT license (see LICENSE file)
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef EXPONENTIATION_HPP_
|
||||
#define EXPONENTIATION_HPP_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "algebra/fields/bigint.hpp"
|
||||
|
||||
namespace libsnark {
|
||||
|
||||
template<typename FieldT, mp_size_t m>
|
||||
FieldT power(const FieldT &base, const bigint<m> &exponent);
|
||||
|
||||
template<typename FieldT>
|
||||
FieldT power(const FieldT &base, const unsigned long exponent);
|
||||
|
||||
} // libsnark
|
||||
|
||||
#include "algebra/exponentiation/exponentiation.tcc"
|
||||
|
||||
#endif // EXPONENTIATION_HPP_
|
||||
53
src/snark/libsnark/algebra/exponentiation/exponentiation.tcc
Normal file
53
src/snark/libsnark/algebra/exponentiation/exponentiation.tcc
Normal file
@@ -0,0 +1,53 @@
|
||||
/** @file
|
||||
*****************************************************************************
|
||||
|
||||
Implementation of interfaces for (square-and-multiply) exponentiation.
|
||||
|
||||
See exponentiation.hpp .
|
||||
|
||||
*****************************************************************************
|
||||
* @author This file is part of libsnark, developed by SCIPR Lab
|
||||
* and contributors (see AUTHORS).
|
||||
* @copyright MIT license (see LICENSE file)
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef EXPONENTIATION_TCC_
|
||||
#define EXPONENTIATION_TCC_
|
||||
|
||||
#include "common/utils.hpp"
|
||||
|
||||
namespace libsnark {
|
||||
|
||||
template<typename FieldT, mp_size_t m>
|
||||
FieldT power(const FieldT &base, const bigint<m> &exponent)
|
||||
{
|
||||
FieldT result = FieldT::one();
|
||||
|
||||
bool found_one = false;
|
||||
|
||||
for (long i = exponent.max_bits() - 1; i >= 0; --i)
|
||||
{
|
||||
if (found_one)
|
||||
{
|
||||
result = result * result;
|
||||
}
|
||||
|
||||
if (exponent.test_bit(i))
|
||||
{
|
||||
found_one = true;
|
||||
result = result * base;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename FieldT>
|
||||
FieldT power(const FieldT &base, const unsigned long exponent)
|
||||
{
|
||||
return power<FieldT>(base, bigint<1>(exponent));
|
||||
}
|
||||
|
||||
} // libsnark
|
||||
|
||||
#endif // EXPONENTIATION_TCC_
|
||||
Reference in New Issue
Block a user