Skip to content

Commit c47bd61

Browse files
Fixed linting errors and added debug mode to CI (#101)
1 parent 9769030 commit c47bd61

21 files changed

+106
-89
lines changed

.clang-tidy

+2-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ Checks:
1919
-readability-isolate-declaration,
2020
-readability-magic-numbers,
2121
-readability-function-size,
22-
22+
-clang-diagnostic-deprecated-copy
2323
WarningsAsErrors:
2424
''
2525

26-
HeaderFilterRegex: 'libff/*.(hpp|tcc|cpp)'
27-
28-
26+
HeaderFilterRegex: 'libff/*.(hpp|tcc|cpp)'

.github/workflows/integrate.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: main
2+
3+
on: push
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- name: python_setup
11+
uses: actions/setup-python@v2
12+
with:
13+
python-version: 3.8
14+
- name: before_install
15+
run: |
16+
sudo apt-get install build-essential git libboost-all-dev cmake libgmp3-dev libssl-dev libsodium-dev libprocps-dev pkg-config gcc-10 g++-10
17+
sudo apt-get install clang-tidy
18+
git submodule init && git submodule update
19+
mkdir build
20+
cd build
21+
PATH=$PATH:${PWD}
22+
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DUSE_CLANG_TIDY=ON ..
23+
- name: run_clang_tidy
24+
id: clang_tidy
25+
run: |
26+
cd build
27+
OUTPUT=$(python3 run-clang-tidy.py ../libff/algebra ../libff/common -quiet 2>&1)
28+
echo "::set-output name=OUTPUT::$OUTPUT"
29+
COUNT=$(echo $OUTPUT | grep "warning:" | wc -l)
30+
echo "::set-output name=COUNT::$COUNT"
31+
- name: check_errors
32+
if: steps.clang_tidy.outputs.COUNT > 0
33+
run: |
34+
echo "Clang-tidy failed. Please look at the run_clang_tidy step to see the details."
35+
exit 1
36+
- name: tests
37+
run: |
38+
cd build
39+
make
40+
make check
41+
- name: run_debug
42+
run: |
43+
rm -r build
44+
mkdir build
45+
cd build
46+
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DUSE_CLANG_TIDY=OFF -DDEBUG=ON ..
47+
make
48+
make check

.github/workflows/main.yml

-27
This file was deleted.

CMakeLists.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
cmake_minimum_required(VERSION 2.8)
22

33
project (libff)
4-
54
# Default to RelWithDebInfo configuration if no configuration is explicitly specified.
65
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
76
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Build type on single-configuration generators" FORCE)
@@ -12,7 +11,7 @@ set(
1211
"BN128"
1312
CACHE
1413
STRING
15-
"Default curve: one of ALT_BN128, BLS12_381, BN128, EDWARDS, MNT4, MNT6"
14+
"Default curve: one of BLS12_381, ALT_BN128, BN128, EDWARDS, MNT4, MNT6"
1615
)
1716

1817
option(
@@ -234,4 +233,4 @@ if ("${IS_LIBFF_PARENT}")
234233
# Add a 'make clang-tidy' target that runs clang-tidy using checks specified in .clang-tidy
235234
include(clang-tidy.cmake)
236235
endif()
237-
add_subdirectory(libff)
236+
add_subdirectory(libff)

clang-tidy.cmake

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if(USE_CLANG_TIDY)
1616
message("Using clang-tidy. Creating target... To run, use: make clang-tidy")
1717
add_custom_target(
1818
clang-tidy
19-
COMMAND python3 run-clang-tidy.py -quiet 2>&1
19+
COMMAND python3 run-clang-tidy.py ../libff/algebra ../libff/common -quiet 2>&1
2020
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
2121
)
2222
else()
@@ -27,5 +27,4 @@ if(USE_CLANG_TIDY)
2727
else()
2828
message(FATAL_ERROR "clang-tidy not found. Aborting...")
2929
endif()
30-
endif()
31-
30+
endif()

libff/algebra/curves/edwards/edwards_pairing.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ struct extended_edwards_G1_projective {
246246
T.print();
247247
}
248248

249-
void test_invariant()
249+
static void test_invariant()
250250
{
251251
assert(T*Z == X*Y);
252252
}
@@ -464,7 +464,7 @@ struct extended_edwards_G2_projective {
464464
T.print();
465465
}
466466

467-
void test_invariant()
467+
static void test_invariant()
468468
{
469469
assert(T*Z == X*Y);
470470
}

libff/algebra/curves/mnt/mnt4/mnt4_pairing.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ struct extended_mnt4_G2_projective {
403403
T.print();
404404
}
405405

406-
void test_invariant()
406+
static void test_invariant()
407407
{
408408
assert(T == Z.squared());
409409
}

libff/algebra/curves/mnt/mnt6/mnt6_pairing.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ struct extended_mnt6_G2_projective {
409409
T.print();
410410
}
411411

412-
void test_invariant()
412+
static void test_invariant()
413413
{
414414
assert(T == Z.squared());
415415
}

libff/algebra/fields/binary/gf128.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
#include <sodium/randombytes.h>
77

8-
#include "libff/algebra/fields/binary/gf128.hpp"
98
#include "libff/algebra/field_utils/algorithms.hpp"
9+
#include "libff/algebra/fields/binary/gf128.hpp"
1010

1111
#ifdef USE_ASM
1212
#include <emmintrin.h>
13-
#include <smmintrin.h>
1413
#include <immintrin.h>
14+
#include <smmintrin.h>
1515
#endif
1616

1717
namespace libff {
@@ -77,7 +77,7 @@ gf128& gf128::operator*=(const gf128 &other)
7777
/* load the two operands and the modulus into 128-bit registers */
7878
const __m128i a = _mm_loadu_si128((const __m128i*) &(this->value_));
7979
const __m128i b = _mm_loadu_si128((const __m128i*) &(other.value_));
80-
const __m128i modulus = _mm_loadl_epi64((const __m128i*) &(this->modulus_));
80+
const __m128i modulus = _mm_loadl_epi64((const __m128i*) &(libff::gf128::modulus_));
8181

8282
/* compute the 256-bit result of a * b with the 64x64-bit multiplication
8383
intrinsic */
@@ -215,7 +215,7 @@ gf128 gf128::inverse() const
215215
{
216216
/* entering the loop a = el^{2^{2^i}-1} */
217217
gf128 b = a;
218-
for (size_t j = 0; j < (1ul<<i); ++j)
218+
for (size_t j = 0; j < (1UL<<i); ++j)
219219
{
220220
b.square();
221221
}

libff/algebra/fields/binary/gf128.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ class gf128 {
9292
template<mp_size_t n>
9393
static constexpr bigint<n> field_char() { return bigint<n>(2); }
9494

95-
friend std::ostream& operator<<(std::ostream &out, const gf128 &p);
96-
friend std::istream& operator>>(std::istream &in, gf128 &p);
95+
friend std::ostream& operator<<(std::ostream &out, const gf128 &el);
96+
friend std::istream& operator>>(std::istream &in, gf128 &el);
9797
private:
9898
/* little-endian */
9999
uint64_t value_[2];

libff/algebra/fields/binary/gf192.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
#include <sodium/randombytes.h>
77

8-
#include "libff/algebra/fields/binary/gf192.hpp"
98
#include "libff/algebra/field_utils/algorithms.hpp"
9+
#include "libff/algebra/fields/binary/gf192.hpp"
1010

1111
#ifdef USE_ASM
1212
#include <emmintrin.h>
13-
#include <smmintrin.h>
1413
#include <immintrin.h>
14+
#include <smmintrin.h>
1515
#endif
1616

1717
namespace libff {
@@ -84,7 +84,7 @@ gf192& gf192::operator*=(const gf192 &other)
8484
const __m128i ab0 = _mm_set_epi64x(this->value_[0], other.value_[0]);
8585
const __m128i ab1 = _mm_set_epi64x(this->value_[1], other.value_[1]);
8686
const __m128i ab2 = _mm_set_epi64x(this->value_[2], other.value_[2]);
87-
const __m128i modulus = _mm_loadl_epi64((const __m128i*) &(this->modulus_));
87+
const __m128i modulus = _mm_loadl_epi64((const __m128i*) &(libff::gf192::modulus_));
8888

8989
/* here we implement a Karatsuba-like approach for multiplying 3-limb numbers.
9090
given
@@ -258,7 +258,7 @@ gf192 gf192::inverse() const
258258
{
259259
/* entering the loop a = el^{2^{2^i}-1} */
260260
gf192 b = a;
261-
for (size_t j = 0; j < (1ul<<i); ++j)
261+
for (size_t j = 0; j < (1UL<<i); ++j)
262262
{
263263
b.square();
264264
}
@@ -278,7 +278,7 @@ gf192 gf192::inverse() const
278278
}
279279

280280
/* now result = el^{2^128-2}, prev_result = el^{2^64-2} */
281-
for (size_t i = 0; i < (1ul<<6); ++i) {
281+
for (size_t i = 0; i < (1UL<<6); ++i) {
282282
result.square();
283283
}
284284
prev_result.square();

libff/algebra/fields/binary/gf192.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ class gf192 {
9292
template<mp_size_t n>
9393
static constexpr bigint<n> field_char() { return bigint<n>(2); }
9494

95-
friend std::ostream& operator<<(std::ostream &out, const gf192 &p);
96-
friend std::istream& operator>>(std::istream &in, gf192 &p);
95+
friend std::ostream& operator<<(std::ostream &out, const gf192 &el);
96+
friend std::istream& operator>>(std::istream &in, gf192 &el);
9797
private:
9898
/* little-endian */
9999
uint64_t value_[3];

libff/algebra/fields/binary/gf256.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
#include <sodium/randombytes.h>
77

8-
#include "libff/algebra/fields/binary/gf256.hpp"
98
#include "libff/algebra/field_utils/algorithms.hpp"
9+
#include "libff/algebra/fields/binary/gf256.hpp"
1010

1111
#ifdef USE_ASM
1212
#include <emmintrin.h>
13-
#include <smmintrin.h>
1413
#include <immintrin.h>
14+
#include <smmintrin.h>
1515
#endif
1616

1717
namespace libff {
@@ -158,7 +158,7 @@ gf256& gf256::operator*=(const gf256 &other)
158158
const __m128i a_high = _mm_loadu_si128((const __m128i*) &(this->value_[2]));
159159
const __m128i b_low = _mm_loadu_si128((const __m128i*) &(other.value_[0]));
160160
const __m128i b_high = _mm_loadu_si128((const __m128i*) &(other.value_[2]));
161-
const __m128i modulus = _mm_loadl_epi64((const __m128i*) &(this->modulus_));
161+
const __m128i modulus = _mm_loadl_epi64((const __m128i*) &(libff::gf256::modulus_));
162162

163163
__m128i m00 = _mm_clmulepi64_si128(a_low, b_low, 0x00);
164164
__m128i m01 = _mm_clmulepi64_si128(a_low, b_low, 0x10);
@@ -338,7 +338,7 @@ gf256 gf256::inverse() const
338338
{
339339
/* entering the loop a = el^{2^{2^i}-1} */
340340
gf256 b = a;
341-
for (size_t j = 0; j < (1ul<<i); ++j)
341+
for (size_t j = 0; j < (1UL<<i); ++j)
342342
{
343343
b.square();
344344
}

libff/algebra/fields/binary/gf256.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ class gf256 {
9494
template<mp_size_t n>
9595
static constexpr bigint<n> field_char() { return bigint<n>(2); }
9696

97-
friend std::ostream& operator<<(std::ostream &out, const gf256 &p);
98-
friend std::istream& operator>>(std::istream &in, gf256 &p);
97+
friend std::ostream& operator<<(std::ostream &out, const gf256 &el);
98+
friend std::istream& operator>>(std::istream &in, gf256 &el);
9999
private:
100100
/* little-endian */
101101
uint64_t value_[4];

libff/algebra/fields/binary/gf32.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
#include <sodium/randombytes.h>
77

8-
#include "libff/algebra/fields/binary/gf32.hpp"
98
#include "libff/algebra/field_utils/algorithms.hpp"
9+
#include "libff/algebra/fields/binary/gf32.hpp"
1010

1111
#ifdef USE_ASM
1212
#include <emmintrin.h>
13-
#include <smmintrin.h>
1413
#include <immintrin.h>
14+
#include <smmintrin.h>
1515
#endif
1616

1717
namespace libff {
@@ -73,14 +73,14 @@ gf32& gf32::operator*=(const gf32 &other)
7373

7474
for (uint32_t i = 0; i < 32; ++i)
7575
{
76-
if (other.value_ & (1ull << i))
76+
if ((other.value_ & (1ULL << i)) != 0U)
7777
{
7878
result ^= shifted;
7979
}
80-
if (shifted & (1ul << 31))
80+
if ((shifted & (1UL << 31)) != 0U)
8181
{
8282
shifted <<= 1;
83-
shifted ^= this->modulus_;
83+
shifted ^= libff::gf32::modulus_;
8484
}
8585
else
8686
{
@@ -176,7 +176,7 @@ gf32 gf32::inverse() const
176176
{
177177
/* entering the loop a = el^{2^{2^i}-1} */
178178
gf32 b = a;
179-
for (size_t j = 0; j < (1ul<<i); ++j)
179+
for (size_t j = 0; j < (1UL<<i); ++j)
180180
{
181181
b.square();
182182
}

libff/algebra/fields/binary/gf32.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ class gf32 {
8989
template<mp_size_t n>
9090
static constexpr bigint<n> field_char() { return bigint<n>(2); }
9191

92-
friend std::ostream& operator<<(std::ostream &out, const gf32 &p);
93-
friend std::istream& operator>>(std::istream &in, gf32 &p);
92+
friend std::ostream& operator<<(std::ostream &out, const gf32 &el);
93+
friend std::istream& operator>>(std::istream &in, gf32 &el);
9494
private:
9595
uint32_t value_;
9696
};

libff/algebra/fields/binary/gf64.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
#include <sodium/randombytes.h>
77

8-
#include "libff/algebra/fields/binary/gf64.hpp"
98
#include "libff/algebra/field_utils/algorithms.hpp"
9+
#include "libff/algebra/fields/binary/gf64.hpp"
1010

1111
#ifdef USE_ASM
1212
#include <emmintrin.h>
13-
#include <smmintrin.h>
1413
#include <immintrin.h>
14+
#include <smmintrin.h>
1515
#endif
1616

1717
namespace libff {
@@ -67,7 +67,7 @@ gf64& gf64::operator*=(const gf64 &other)
6767
/* Does not require *this and other to be different, and therefore
6868
also works for squaring, implemented below. */
6969
#ifdef USE_ASM
70-
const __m128i modulus = _mm_loadl_epi64((const __m128i*)&(this->modulus_));
70+
const __m128i modulus = _mm_loadl_epi64((const __m128i*)&(libff::gf64::modulus_));
7171
const __m128i mul128 = _mm_clmulepi64_si128(_mm_loadl_epi64((const __m128i*)&(this->value_)),
7272
_mm_loadl_epi64((const __m128i*)&(other.value_)), 0);
7373

0 commit comments

Comments
 (0)