Skip to content

Commit 06769a2

Browse files
Change all tests to use google test (#82)
* Add gtest as a submodule * Migrate curve tests to gtest and rename curve base_field_char to field_char * Migrate Fpn field test to gtest and add Tonelli-Shanks params to bl12_381 * Update changelog with #79 and #82 changes Co-authored-by: Dev Ojha <[email protected]>
1 parent 14b5164 commit 06769a2

24 files changed

+339
-271
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "depends/xbyak"]
55
path = depends/xbyak
66
url = https://github.com/herumi/xbyak.git
7+
[submodule "gtest"]
8+
path = depends/gtest
9+
url = https://github.com/google/googletest.git

CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- #71 Add BLS12-381 (Thanks @yelhousni)
66
- #79 Separate field initialization from curves (Thanks @alexander-zw)
77
- #80 Add clang-tidy checks to library and CI
8+
- #82 Convert tests to use Google test (Thanks @alexander-zw)
89
### Bug fixes
910
- #75 Get rid of warning for unused constant PI, in complex field
1011
- #78 Reduce prints when inhibit_profiling_info is set
@@ -15,7 +16,12 @@
1516
_Special thanks to all downstream projects upstreaming their patches!_
1617

1718
### Breaking Changes
18-
- None!
19+
- File structure changed: All field utils are now in `libff/algebra/field_utils/`, `Fp_model` is
20+
now in `libff/algebra/fields/prime_base/`, and all other F_p^n fields in
21+
`libff/algebra/fields/prime_extension/`.
22+
- The function `base_field_char()` of all fields and curves have been renamed to `field_char()`.
23+
- The provided fields used in curves have been moved to separate files so that they can be imported
24+
separately from `[field name]_fields.hpp`. However they are still accessible from the init file.
1925

2026
### Features
2127
- #20 Improve operator+ speed for alt_bn, correct the corresponding docs, and reduce code duplication.

depends/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
add_subdirectory(gtest EXCLUDE_FROM_ALL)
2+
13
if(${CURVE} STREQUAL "BN128")
24
include_directories(ate-pairing/include)
35
include_directories(xbyak)

depends/gtest

Submodule gtest added at a325ad2

libff/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ install(
9090

9191
# Tests
9292
if ("${IS_LIBFF_PARENT}")
93+
# Tests for fpn fields.
9394
add_executable(
9495
algebra_bilinearity_test
9596
EXCLUDE_FROM_ALL
@@ -100,6 +101,7 @@ if ("${IS_LIBFF_PARENT}")
100101
algebra_bilinearity_test
101102

102103
ff
104+
gtest_main
103105
)
104106

105107
add_executable(
@@ -112,6 +114,7 @@ if ("${IS_LIBFF_PARENT}")
112114
algebra_groups_test
113115

114116
ff
117+
gtest_main
115118
)
116119

117120
add_executable(
@@ -124,6 +127,7 @@ if ("${IS_LIBFF_PARENT}")
124127
algebra_fields_test
125128

126129
ff
130+
gtest_main
127131
)
128132

129133
include(CTest)

libff/algebra/curves/alt_bn128/alt_bn128_g1.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class alt_bn128_G1 {
7272
static alt_bn128_G1 random_element();
7373

7474
static std::size_t size_in_bits() { return base_field::ceil_size_in_bits() + 1; }
75-
static bigint<base_field::num_limbs> base_field_char() { return base_field::field_char(); }
75+
static bigint<base_field::num_limbs> field_char() { return base_field::field_char(); }
7676
static bigint<scalar_field::num_limbs> order() { return scalar_field::field_char(); }
7777

7878
friend std::ostream& operator<<(std::ostream &out, const alt_bn128_G1 &g);

libff/algebra/curves/alt_bn128/alt_bn128_g2.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class alt_bn128_G2 {
7676
static alt_bn128_G2 random_element();
7777

7878
static std::size_t size_in_bits() { return twist_field::ceil_size_in_bits() + 1; }
79-
static bigint<base_field::num_limbs> base_field_char() { return base_field::field_char(); }
79+
static bigint<base_field::num_limbs> field_char() { return base_field::field_char(); }
8080
static bigint<scalar_field::num_limbs> order() { return scalar_field::field_char(); }
8181

8282
friend std::ostream& operator<<(std::ostream &out, const alt_bn128_G2 &g);

libff/algebra/curves/bls12_381/bls12_381_fields.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,20 @@ void init_bls12_381_fields()
8484

8585
/* parameters for Fq6 */
8686

87+
bls12_381_Fq6::euler = bigint<6*bls12_381_q_limbs>("20554133100346859175471782037923328603092004029368475898129200002880650925292078031236336437155417867098264344518387365893430771451315477306772392387091199574188127258130200190724479057496226394584754283339686073743682966778056496"
88+
"2327945395707855461784923849488018385374868097169740055671857527378364846985124226126804481781632034266682707672275244752919278254435312874614711930845778483008368333187290823468828236021643415690765934622950990371613607731757827"
89+
"4075669149520898024347473697702653612215721050521068924301068068177428715185971771314610791504467157081688941868360291264332276621620347148228840040620536292141825333889929315303120837632621009405712364239501893128509197213249204");
90+
bls12_381_Fq6::s = 3;
91+
bls12_381_Fq6::t = bigint<6*bls12_381_q_limbs>("5138533275086714793867945509480832150773001007342118974532300000720162731323019507809084109288854466774566086129596841473357692862828869326693098096772799893547031814532550047681119764374056598646188570834921518435920741694514124"
92+
"0581986348926963865446230962372004596343717024292435013917964381844591211746281056531701120445408008566670676918068811188229819563608828218653677982711444620752092083296822705867207059005410853922691483655737747592903401932939456"
93+
"8518917287380224506086868424425663403053930262630267231075267017044357178796492942828652697876116789270422235467090072816083069155405086787057210010155134073035456333472482328825780209408155252351428091059875473282127299303312301");
94+
bls12_381_Fq6::t_minus_1_over_2 = bigint<6*bls12_381_q_limbs>("2569266637543357396933972754740416075386500503671059487266150000360081365661509753904542054644427233387283043064798420736678846431414434663346549048386399946773515907266275023840559882187028299323094285417460759217960370847257062"
95+
"0290993174463481932723115481186002298171858512146217506958982190922295605873140528265850560222704004283335338459034405594114909781804414109326838991355722310376046041648411352933603529502705426961345741827868873796451700966469728"
96+
"4259458643690112253043434212212831701526965131315133615537633508522178589398246471414326348938058394635211117733545036408041534577702543393528605005077567036517728166736241164412890104704077626175714045529937736641063649651656150");
8797
bls12_381_Fq6::non_residue = bls12_381_Fq2(bls12_381_Fq("1"),bls12_381_Fq("1"));
98+
bls12_381_Fq6::nqr = bls12_381_Fq6(bls12_381_Fq2::one(),bls12_381_Fq2::one(),bls12_381_Fq2::zero());
99+
bls12_381_Fq temp_Fq6 = bls12_381_Fq("2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530");
100+
bls12_381_Fq6::nqr_to_t = bls12_381_Fq6(bls12_381_Fq2(temp_Fq6,temp_Fq6),bls12_381_Fq2::zero(),bls12_381_Fq2::zero());
88101
bls12_381_Fq6::Frobenius_coeffs_c1[0] = bls12_381_Fq2(bls12_381_Fq("1"), bls12_381_Fq("0"));
89102
bls12_381_Fq6::Frobenius_coeffs_c1[1] = bls12_381_Fq2(bls12_381_Fq("0"), bls12_381_Fq("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"));
90103
bls12_381_Fq6::Frobenius_coeffs_c1[2] = bls12_381_Fq2(bls12_381_Fq("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"), bls12_381_Fq("0"));
@@ -100,7 +113,29 @@ void init_bls12_381_fields()
100113

101114
/* parameters for Fq12 */
102115

116+
bls12_381_Fq12::euler = bigint<12*bls12_381_q_limbs>("84494477501354877863865367578187930377622126393420760822050568476317337611486762037414270042798116043101246277209976512094361633120467161014065554445340565539059728811354277261356050973219720027209194190487838692659063939320510475"
117+
"6684686564553744540192748080653129821509884735609423581664936489210967044046752906842048351460495822757497568452317297203089041326472891040759142912227371393980794331268602860685738444530097471818525224303042413280382576694575299"
118+
"4243167774120254336745536274773695755236419654903551716949533916736161356917292005946710404303427406932182969676190623946300563008385561067630240219756654157397637890286330848719683460121962833606725529824544406779592032379877481"
119+
"1619354467715920346231349235866829244117661464414438262378914602649540068695152163844160842304673532919059469589280333810875205899713712879737788837727657694488850147823396354062110303649461852408661125352998460333970628572435583"
120+
"1757875201144654542881444863180645429521461839597984159381168059700378199831784038278254696182778409863406365300081610922417700679768617228365246880105899509515611144499009510027533192321478957577669300457547918189673190852298371"
121+
"5647603567520167155789018111526068121587518840305926270907547770597694123975462831369590179741045378187314102710120072893107485626654026731724301176856186957627412379772915464547093068089747231550221016170764028215685592439765640");
122+
bls12_381_Fq12::s = 4;
123+
bls12_381_Fq12::t = bigint<12*bls12_381_q_limbs>("10561809687669359732983170947273491297202765799177595102756321059539667201435845254676783755349764505387655784651247064011795204140058395126758194305667570692382466101419284657669506371652465003401149273810979836582382992415063809"
124+
"4585585820569218067524093510081641227688735591951177947708117061151370880505844113355256043932561977844687196056539662150386130165809111380094892864028421424247599291408575357585717305566262183977315653037880301660047822086821912"
125+
"4280395971765031792093192034346711969404552456862943964618691739592020169614661500743338800537928425866522871209523827993287570376048195133453780027469581769674704736285791356089960432515245354200840691228068050847449004047484685"
126+
"1452419308464490043278918654483353655514707683051804782797364325331192508586894020480520105288084191614882433698660041726359400737464214109967223604715957211811106268477924544257763787956182731551082640669124807541746328571554447"
127+
"8969734400143081817860180607897580678690182729949748019922646007462547274978973004784781837022847301232925795662510201365302212584971077153545655860013237438689451393062376188753441649040184869697208662557193489773709148856537296"
128+
"4455950445940020894473627263940758515198439855038240783863443471324711765496932853921198772467630672273414262838765009111638435703331753341465537647107023369703426547471614433068386633511218403943777627021345503526960699054970705");
129+
bls12_381_Fq12::t_minus_1_over_2 = bigint<12*bls12_381_q_limbs>("5280904843834679866491585473636745648601382899588797551378160529769833600717922627338391877674882252693827892325623532005897602070029197563379097152833785346191233050709642328834753185826232501700574636905489918291191496207531904"
130+
"7292792910284609033762046755040820613844367795975588973854058530575685440252922056677628021966280988922343598028269831075193065082904555690047446432014210712123799645704287678792858652783131091988657826518940150830023911043410956"
131+
"2140197985882515896046596017173355984702276228431471982309345869796010084807330750371669400268964212933261435604761913996643785188024097566726890013734790884837352368142895678044980216257622677100420345614034025423724502023742342"
132+
"5726209654232245021639459327241676827757353841525902391398682162665596254293447010240260052644042095807441216849330020863179700368732107054983611802357978605905553134238962272128881893978091365775541320334562403770873164285777223"
133+
"9484867200071540908930090303948790339345091364974874009961323003731273637489486502392390918511423650616462897831255100682651106292485538576772827930006618719344725696531188094376720824520092434848604331278596744886854574428268648"
134+
"2227975222970010447236813631970379257599219927519120391931721735662355882748466426960599386233815336136707131419382504555819217851665876670732768823553511684851713273735807216534193316755609201971888813510672751763480349527485352");
103135
bls12_381_Fq12::non_residue = bls12_381_Fq2(bls12_381_Fq("1"),bls12_381_Fq("1"));
136+
bls12_381_Fq12::nqr = bls12_381_Fq12(bls12_381_Fq6::zero(),bls12_381_Fq6::one());
137+
bls12_381_Fq temp_Fq12 = bls12_381_Fq("3357996710086603428986649435961018971596863377125478091385687488711898724126407611022502097010210262797519903698974");
138+
bls12_381_Fq12::nqr_to_t = bls12_381_Fq12(bls12_381_Fq6::zero(),bls12_381_Fq6(bls12_381_Fq2::zero(),bls12_381_Fq2(temp_Fq12,temp_Fq12),bls12_381_Fq2::zero()));
104139
bls12_381_Fq12::Frobenius_coeffs_c1[0] = bls12_381_Fq2(bls12_381_Fq("1"),bls12_381_Fq("0"));
105140
bls12_381_Fq12::Frobenius_coeffs_c1[1] = bls12_381_Fq2(bls12_381_Fq("3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760"),bls12_381_Fq("151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027"));
106141
bls12_381_Fq12::Frobenius_coeffs_c1[2] = bls12_381_Fq2(bls12_381_Fq("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351"),bls12_381_Fq("0"));

libff/algebra/curves/bls12_381/bls12_381_g1.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class bls12_381_G1 {
6363
static bls12_381_G1 random_element();
6464

6565
static std::size_t size_in_bits() { return base_field::ceil_size_in_bits() + 1; }
66-
static bigint<base_field::num_limbs> base_field_char() { return base_field::field_char(); }
66+
static bigint<base_field::num_limbs> field_char() { return base_field::field_char(); }
6767
static bigint<scalar_field::num_limbs> order() { return scalar_field::field_char(); }
6868

6969
friend std::ostream& operator<<(std::ostream &out, const bls12_381_G1 &g);

libff/algebra/curves/bls12_381/bls12_381_g2.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class bls12_381_G2 {
7474
static bls12_381_G2 random_element();
7575

7676
static std::size_t size_in_bits() { return twist_field::ceil_size_in_bits() + 1; }
77-
static bigint<base_field::num_limbs> base_field_char() { return base_field::field_char(); }
77+
static bigint<base_field::num_limbs> field_char() { return base_field::field_char(); }
7878
static bigint<scalar_field::num_limbs> order() { return scalar_field::field_char(); }
7979

8080
friend std::ostream& operator<<(std::ostream &out, const bls12_381_G2 &g);

libff/algebra/curves/bn128/bn128_g1.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class bn128_G1 {
7676
static bn128_G1 random_element();
7777

7878
static std::size_t size_in_bits() { return bn128_Fq::ceil_size_in_bits() + 1; }
79-
static bigint<base_field::num_limbs> base_field_char() { return base_field::field_char(); }
79+
static bigint<base_field::num_limbs> field_char() { return base_field::field_char(); }
8080
static bigint<scalar_field::num_limbs> order() { return scalar_field::field_char(); }
8181

8282
friend std::ostream& operator<<(std::ostream &out, const bn128_G1 &g);

libff/algebra/curves/bn128/bn128_g2.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class bn128_G2 {
7777
static bn128_G2 random_element();
7878

7979
static std::size_t size_in_bits() { return 2*base_field::ceil_size_in_bits() + 1; }
80-
static bigint<base_field::num_limbs> base_field_char() { return base_field::field_char(); }
80+
static bigint<base_field::num_limbs> field_char() { return base_field::field_char(); }
8181
static bigint<scalar_field::num_limbs> order() { return scalar_field::field_char(); }
8282

8383
friend std::ostream& operator<<(std::ostream &out, const bn128_G2 &g);

libff/algebra/curves/edwards/edwards_g1.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class edwards_G1 {
6868
static edwards_G1 random_element();
6969

7070
static std::size_t size_in_bits() { return edwards_Fq::ceil_size_in_bits() + 1; }
71-
static bigint<base_field::num_limbs> base_field_char() { return base_field::field_char(); }
71+
static bigint<base_field::num_limbs> field_char() { return base_field::field_char(); }
7272
static bigint<scalar_field::num_limbs> order() { return scalar_field::field_char(); }
7373

7474
friend std::ostream& operator<<(std::ostream &out, const edwards_G1 &g);

libff/algebra/curves/edwards/edwards_g2.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class edwards_G2 {
7474
static edwards_G2 random_element();
7575

7676
static std::size_t size_in_bits() { return twist_field::ceil_size_in_bits() + 1; }
77-
static bigint<base_field::num_limbs> base_field_char() { return base_field::field_char(); }
77+
static bigint<base_field::num_limbs> field_char() { return base_field::field_char(); }
7878
static bigint<scalar_field::num_limbs> order() { return scalar_field::field_char(); }
7979

8080
friend std::ostream& operator<<(std::ostream &out, const edwards_G2 &g);

libff/algebra/curves/mnt/mnt4/mnt4_g1.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class mnt4_G1 {
8080
static mnt4_G1 random_element();
8181

8282
static std::size_t size_in_bits() { return mnt4_Fq::ceil_size_in_bits() + 1; }
83-
static bigint<mnt4_Fq::num_limbs> base_field_char() { return mnt4_Fq::field_char(); }
83+
static bigint<mnt4_Fq::num_limbs> field_char() { return mnt4_Fq::field_char(); }
8484
static bigint<mnt4_Fr::num_limbs> order() { return mnt4_Fr::field_char(); }
8585

8686
friend std::ostream& operator<<(std::ostream &out, const mnt4_G1 &g);

libff/algebra/curves/mnt/mnt4/mnt4_g2.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class mnt4_G2 {
8585
static mnt4_G2 random_element();
8686

8787
static std::size_t size_in_bits() { return mnt4_Fq2::ceil_size_in_bits() + 1; }
88-
static bigint<mnt4_Fq::num_limbs> base_field_char() { return mnt4_Fq::field_char(); }
88+
static bigint<mnt4_Fq::num_limbs> field_char() { return mnt4_Fq::field_char(); }
8989
static bigint<mnt4_Fr::num_limbs> order() { return mnt4_Fr::field_char(); }
9090

9191
friend std::ostream& operator<<(std::ostream &out, const mnt4_G2 &g);

libff/algebra/curves/mnt/mnt6/mnt6_g1.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class mnt6_G1 {
8080
static mnt6_G1 random_element();
8181

8282
static std::size_t size_in_bits() { return base_field::ceil_size_in_bits() + 1; }
83-
static bigint<base_field::num_limbs> base_field_char() { return base_field::field_char(); }
83+
static bigint<base_field::num_limbs> field_char() { return base_field::field_char(); }
8484
static bigint<scalar_field::num_limbs> order() { return scalar_field::field_char(); }
8585

8686
friend std::ostream& operator<<(std::ostream &out, const mnt6_G1 &g);

libff/algebra/curves/mnt/mnt6/mnt6_g2.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class mnt6_G2 {
8585
static mnt6_G2 random_element();
8686

8787
static std::size_t size_in_bits() { return twist_field::ceil_size_in_bits() + 1; }
88-
static bigint<base_field::num_limbs> base_field_char() { return base_field::field_char(); }
88+
static bigint<base_field::num_limbs> field_char() { return base_field::field_char(); }
8989
static bigint<scalar_field::num_limbs> order() { return scalar_field::field_char(); }
9090

9191
friend std::ostream& operator<<(std::ostream &out, const mnt6_G2 &g);

0 commit comments

Comments
 (0)