module Pairing = Plonkers.Bls12_381.Pairing module E = Plonkers.Bls12_381.Curves.E module E2 = Plonkers.Bls12_381.Curves.E2 module Gt = Plonkers.Bls12_381.Pairing.Gt let gt = Primitives.Testables.gt let f1 = Primitives.Literals.e let f2 = Primitives.Literals.e2 let ft = Primitives.Literals.gt let test_generator () = Alcotest.(check gt) "equals" (ft [| "3408834164464458755751340723502736743445402614640994055433339214424916442641449510670327077303074893591740399366532"; "1017299873256115394687936133146817339783508925356207904663165117501336940438300180831508525168135575931758510829235"; "1919447955347661378578718469488414822573562393353397544098339472673901193098010131520945815709482515519580400649694"; "233557331756520805040932826416017142246700002714928636467514104620558679338483625829873520553081791155104026612174"; "2882199334237819327910933128503231887000342950792587449681715803095618652567681747054312179958427092970985872417068"; "579878855790610229145575079003483905368886712027403088810647643659132674704592975818766405092658613973478871626949"; "3268798540077874559188095304926415053902298079662269128631117894259354335713488241073281881110999874366368799440511"; "2688711983546324406847903726099677850388169649284572370749691792743294691894680263880362424577638309433508620982332"; "3520140447471844017044610248175793726488927385800919015247604269617056365166670232096113218155158979455637700602719"; "1555267885602801620621747613743921378408444002839854792606782732724136830563310004098024452104661167182680744848589"; "2626389147790168154036854297373352480470342009417426750876875476996308393122833154115295241935326582225976246741447"; "873321072950766150592434764742436722571574260472569072177205897167854308426485977134306337249021436737462538398830"; |]) Pairing.(e E.g E2.g) let test_pairing () = Alcotest.(check gt) "equals" (ft [| "448697226789963268348912232951073713452968894642929214443994147359412138639526655164503406978236522025734912852606"; "151261630108668103390829365027365404889205408289235816621708275624780812413761415129004835746255625267607732639563"; "2909423043708809630024534763367123821438139353180175913125076930835302419897651130667995073651726848611333745205986"; "952434542917010958697197601576391780800301526127664682598671275809818228531516224262590129674712650458795890584553"; "1478486475752483299362722402760792915820803227192648258365429143818886181422874016577411765850893129689832973264031"; "652834415768413017856200607794773610957395062979681182931987046704660733141291027961343651372030380321651719802520"; "951656253138365825024367899445523415181713017704780705176410361641958854486267870078190603032432549582347900417624"; "1991042670420833845569811948628174796662344145916123310837646809687525541032370298949411402142207368319354069329317"; "2920440541157943770850967007055029075931555684879417457120436377239540586798148490244301682350449674796660182631922"; "3554199917981379540114579517242213458150684556713432050906212290132174074734340424484104596198947386114933622334567"; "1091458823916905664137346388296576506864216891159041434853650685402092824487985812791698734521558868411023155785769"; "43181594668188258041148789943396863898539176535733231639633582884332884962913532441125648697214326572900496337037"; |]) (Pairing.e (f1 ( "1759244594739438101652572364306631993712897577542654736932660460743445183171945408603399266474637228371219384150089", "2746850152127019659862408918732227356169104535991470589122155020934454571292242598343702169898773975726309716165198" )) (f2 ( [| "1256740661954421835404627287451128275298916640367011495362432993289541383031490867768256365295187693751267667845404"; "3717522504942038420636575612519050548073203872805747528897870222147344374794751097864928254417486766328132878640824"; |], [| "2512342532199657251630152291613780551312453521116783301133995957210838938697636876773382152437204041044762830468417"; "77870636695957247485070729371505785036022507830356763789646790529980989972767478012625350608049848760401081873614"; |] ))) let test_bilinearity () = let a = Z.of_string "49635613352584733781027070618160862805950329685486063826980172894235303933946" in let b = Z.of_string "4249060523776624689160540763312478010481990280247166863389957742757316747171" in Alcotest.(check bool) "equals" true (Pairing.check [ (E.(scalar_mul a g), E2.(scalar_mul b g)); (E.(neg @@ scalar_mul b g), E2.(scalar_mul a g)); ]) let test_inverse () = let a = f1 ( "91452683776864857297317878636149143411849300822645600833640900844653175011086096281183060418629991226462334719230", "2771533846423619448760061452592233431921571821664938471039058787579168163258312047422278741446979265860731259685588" ) in let t = Pairing.e a E2.g in let tinv = Pairing.e E.(neg a) E2.g in Alcotest.(check gt) "equals" (Gt.inv t) tinv; Alcotest.(check gt) "equals" Gt.id (Gt.dot t tinv) let tests = Alcotest. [ test_case "Generator" `Slow test_generator; test_case "Pairing" `Slow test_pairing; test_case "Bilinearity" `Slow test_bilinearity; test_case "Inverse" `Slow test_inverse; ]