diff options
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | docs/journal/pages/elliptic-curves.md | 4 | ||||
| -rw-r--r-- | docs/journal/pages/field-extension.md | 10 | ||||
| -rw-r--r-- | docs/journal/pages/finite-fields.md | 11 | ||||
| -rw-r--r-- | lib/fields.ml | 6 | ||||
| -rw-r--r-- | lib/fields.mli | 8 | ||||
| -rw-r--r-- | test/test_fp.ml | 110 | ||||
| -rw-r--r-- | test/test_fp12.ml | 522 | ||||
| -rw-r--r-- | test/test_fp2.ml | 102 |
9 files changed, 404 insertions, 371 deletions
@@ -1,3 +1,3 @@ # PLONKers! -This repository contains a from-scratch implementation of a PLONK zero knowledge proof system for education purposes over the BN254 (alt_bn128) curve. +This repository contains a from-scratch implementation of a PLONK zero knowledge proof system for education purposes over the BLS12-381 curve. diff --git a/docs/journal/pages/elliptic-curves.md b/docs/journal/pages/elliptic-curves.md index 8e9695f..baecf02 100644 --- a/docs/journal/pages/elliptic-curves.md +++ b/docs/journal/pages/elliptic-curves.md @@ -2,9 +2,9 @@ # Elliptic Curves -We are implementing PLONK over the BN254 curve. Baretto-Naehrig curves are a type of elliptic curve that are designed to be pairing friendly, which we need for PLONK. +We are implementing PLONK over the BLS12-381 curve. Named after Barreto, Lynn, and Scott, BLS curves are a pairing friendly elliptic curve, which we need for PLONK. -Implementing elliptic curves is actually easier than it sounds. Elements are `(x, y)` coordinate pairs, where each of the coordinates is a field element from the prime field we previously implemented. Baretto-Naehrig curves specifically have equations of the form `y^2 = x^3 + b` for some `b ∈ Fp`. The BN254 curve we are implementing has `b = 3`. Note that there is another Barreto-Naehrig curve which is also sometimes called, BN254 with has `b = 2`, this is not our curve. +Implementing elliptic curves is actually easier than it sounds. Elements are `(x, y)` coordinate pairs, where each of the coordinates is a field element from the prime field we previously implemented. BLS curves specifically have equations of the form `y^2 = x^3 + b` for some `b ∈ Fp`. The BLS12-381 curve we are implementing has `b = 4`. Curves are abelian groups, so we can implement addition and scalar multiplication (which is just repeated addition). While the addition formula looks complicated, it actually isn't that hard to derive. Lets start with the basic idea of point addition on an elliptic curve: if you draw a straight line that passes through 3 distinct points `P`, `Q` and `R` on the curve, then `P + Q + R = 0` (where 0 is some imaginary point representing a "zero" value, i.e. additive identity, and sometimes referred to as the point at infinity). From basic algebra, we know that the slope of the line between two points is `m = (y_P - y_Q) / (x_P - x_Q)`. Also, because `R` is on the same line, we have `y_R = y_P + m(x_R - x_P)` (and equivalently `y_R = y_Q + m(x_R - x_Q)`). Figuring out how to compute `x_R` is a little more complicated (it involves cubic equations) so lets just share the formula: `x_R = m^2 - x_P - x_Q`. diff --git a/docs/journal/pages/field-extension.md b/docs/journal/pages/field-extension.md index f1ff95d..6995570 100644 --- a/docs/journal/pages/field-extension.md +++ b/docs/journal/pages/field-extension.md @@ -4,12 +4,10 @@ The other kind of field that is important for elliptic curve pairings are polynomial extension fields. These are just polynomial quotient rings over the curve's field modulo some irreducible monic polynomial (chosen as a parameter of the extension field). This concept is a _little_ complicated, and the Wikipedia article linked in the resources section does a decent job at explainng it (at least better than I can, as I lack a lot of the jargon required). -To try an explain it better, lets take the polynomial extension field of degree 2 used in BN254 pairings. This is defined as the polynomial quotient ring `Fp[x] / (1 + x^2)`, or `Fp2` for brevity, where `Fp[x]` are polynomials over the field `Fp`. With a slightly more concrete example, imagine the polynomials `a + bx` and `c + dx` belonging to `Fp2` where `a`, `b`, `c`, `d` are elements of `Fp` and `x` is some indeterminate also belonging to `Fp`. For this field, addition and multiplication are just definied to be the addition and multiplication modulo `1 + x^2` respectively of the polynomials. +To try and explain it better, lets take the polynomial extension field of degree 2 used in BLS12-381 pairings. This is defined as the polynomial quotient ring `Fp[x] / (1 + x^2)`, or `Fp2` for brevity, where `Fp[x]` are polynomials over the field `Fp`. With a slightly more concrete example, imagine the polynomials `a + bx` and `c + dx` belonging to `Fp2` where `a`, `b`, `c`, `d` are elements of `Fp` and `x` is some indeterminate also belonging to `Fp`. In code we can represent the elements of `Fp2` as a tuple of two `Fp` elements `Fp.t * Fp.t` where `(a, b)` represents `a + bx`. For this field, addition and multiplication are just definied to be the addition and multiplication modulo `1 + x^2` respectively of the polynomials. -- Addition: `(a + bx) + (c + dx) = (a + c) + (b + d)x`. Since we don't create any `x^2` terms, this is already non-divisible by `1 + x^2`. Addition in these polynomial extension fields are, therefore, very straight forward. -- Multiplication: `(a + bx) * (c + dx) = ac + adx + bcx + bdx^2`. This must be taken modulo `1 + x^2`, so `ac + adx + bcx + bdx^2 =~ ac + adx + bcx + bdx^2 - bd(1 + x^2) =~ (ac - bd) + (ad + bc)x`. - -Additionally, in code we can represent the elements of `Fp2` as a tuple of two `Fp` elements `Fp.t * Fp.t` where `(a, b)` represents `a + bx`. +- Addition: `(a + bx) + (c + dx) = (a + c) + (b + d)x`. Since we don't create any `x^2` terms, this is already non-divisible by `1 + x^2`. Addition in these polynomial extension fields are, therefore, very straight forward: `(a, b) + (c, d) = (a + b, c + d)`. +- Multiplication: `(a + bx) * (c + dx) = ac + adx + bcx + bdx^2`. This must be taken modulo `1 + x^2`, so `ac + adx + bcx + bdx^2 =~ ac + adx + bcx + bdx^2 - bd(1 + x^2) =~ (ac - bd) + (ad + bc)x`. Multiplication over `Fp2` is therefore `(a, b) * (c, d) = (ac - bd, ad + bc)`. Look familiar? It is the same as complex number multiplication - which isn't a coincidence as the complex numbers are an extension field of degree 2 over the real numbers. This same concept can be extended to polynomial extension fields of any degree, and in particular a polynomial extension field of degree 12 is also used for elliptic curve pairings (but with a different irreducible monic polynomial): @@ -23,8 +21,6 @@ Computing additive and multiplicative inverses are done by: - Additive inverse: this is just the component-wise additive inverse of the polynomial coeficients: `-(a + bx) = -a + (-b)x`. - Multiplicative inverse: this is a little more complicated, but can be done using the extended euclidean algorithm and Bézout's identity. -Furthermore, the same principles apply for the elliptic curve pairings for the BLS12-381 curve, but with different parameterization. - # Resources - [Polynomial Ring](https://en.wikipedia.org/wiki/Polynomial_ring) diff --git a/docs/journal/pages/finite-fields.md b/docs/journal/pages/finite-fields.md index 4e71672..b9f9eb4 100644 --- a/docs/journal/pages/finite-fields.md +++ b/docs/journal/pages/finite-fields.md @@ -4,21 +4,18 @@ One of the mathematical principles underpinning the PLONK proof systems are finite fields. These are used in both the PLONK circuits themselves, but also in the eliptic curve pairings necessary for the proof system. -In PLONKers!, we are building a very specific PLONK construction over the BN254 curve (sometimes referred to as "alt-bn128" or "bn128" - why? They are **B**arreto-**N**aehrig curves with a **254**-bit prime and an initially estimated security of **128** bits). This curve is defined over a finite field with a prime modulus. This sounds complicated, but it really means that: +In PLONKers!, we are building a very specific PLONK construction over the BLS12-381 curve. This curve is defined over a finite field with a prime modulus. This sounds complicated, but it really means that: -- `p = 21888242871839275222246405745257275088696311157297823662689037894645226208583`, a very large prime -- It is the set of whole numbers from `0` to `p - 1` (inclusive) +- `p = 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787`, a very large prime +- It is the set of integers from `0` to `p - 1` (inclusive) - Addition and multiplication are done modulo `p` - Substraction is the addition of the additive inverse (`-a = p - a`, so `a + (-a) = 0` for all `a`) -- Division is the multiplication by the multiplicative inverse (`1/a = a ^ (p - 2) mod p`, so `a * (1/a) = 1` for all `a` except `0`, the inverse of `0` is undefined) +- Division is the multiplication by the multiplicative inverse (`1/a = a ^ (p - 2) mod p`, so `a * (1/a) = a * a (p - 2) = a ^ (p - 1) = 1` by Fermat's little theorem for all `a` except `0`, where inverse of `0` is defined to be `0`). Note that multiplicative inverses can also be computed with the extended Euclidean algorithm and Bézout's identity. And with this we build the "numbers" that we use for PLONK and eliptic curve operations. -The BLS12-381 curve as it has some nicer properties over BN254, and may show up in a future episode :). - # Resources -- [BN254 For The Rest Of Us](https://hackmd.io/@jpw/bn254) - [BLS12-381 For The Rest Of Us](https://hackmd.io/@benjaminion/bls12-381) - [`ethereum/py_ecc`](https://github.com/ethereum/py_ecc) diff --git a/lib/fields.ml b/lib/fields.ml index 1ab2712..14f3dfd 100644 --- a/lib/fields.ml +++ b/lib/fields.ml @@ -31,7 +31,7 @@ end module Fp = struct let p = Z.of_string - "21888242871839275222246405745257275088696311157297823662689037894645226208583" + "4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787" let p_minus_2 = Z.(p - ~$2) let mod_p x = Z.erem x p @@ -164,13 +164,13 @@ module Fp12 = struct include FpN (struct let p = [| - Fp.of_string "82"; + Fp.of_string "2"; Fp.zero; Fp.zero; Fp.zero; Fp.zero; Fp.zero; - Fp.of_string "-18"; + Fp.of_string "-2"; Fp.zero; Fp.zero; Fp.zero; diff --git a/lib/fields.mli b/lib/fields.mli index 4ecad01..546618a 100644 --- a/lib/fields.mli +++ b/lib/fields.mli @@ -1,4 +1,4 @@ -(** Finite fields used by the BN254 curve and pairings *) +(** Finite fields used by the BLS12-381 curve and pairings *) module Fp : sig include Field.S @@ -9,7 +9,7 @@ module Fp : sig val to_string : t -> string (** [to_string a] returns the string representation of [a]. *) end -(* The prime field over which the BN254 curve is defined. *) +(* The prime field over which the BLS12-381 curve is defined. *) module Fp2 : sig include Field.S @@ -32,7 +32,7 @@ module Fp2 : sig val to_coeffs : t -> coeffs (** [to_coeffs a] are the polynomial coefficients of [a]. *) end -(* The polynomial field extension of degree 2 for BN254 pairings. *) +(* The polynomial field extension of degree 2 for BLS12-381 pairings. *) module Fp12 : sig include Field.S @@ -67,4 +67,4 @@ module Fp12 : sig val to_coeffs : t -> coeffs (** [to_coeffs a] are the polynomial coefficients of [a]. *) end -(* The polynomial field extension of degree 12 for BN254 pairings. *) +(* The polynomial field extension of degree 12 for BLS12-381 pairings. *) diff --git a/test/test_fp.ml b/test/test_fp.ml index feefb5d..9691bfb 100644 --- a/test/test_fp.ml +++ b/test/test_fp.ml @@ -6,143 +6,151 @@ let f = Fp.of_string let test_strconv () = let a = f - "15962132676900570984155932908734860654156982678903386073610512073739915079794" + "3992956950364942669405818869712257089296386788638306564835014403687782923490610333520388803678873783219740875733957" in Alcotest.(check string) "equals" - "15962132676900570984155932908734860654156982678903386073610512073739915079794" + "3992956950364942669405818869712257089296386788638306564835014403687782923490610333520388803678873783219740875733957" (Fp.to_string a); Alcotest.(check fp) "equals" a (Fp.of_string - "15962132676900570984155932908734860654156982678903386073610512073739915079794") + "3992956950364942669405818869712257089296386788638306564835014403687782923490610333520388803678873783219740875733957") let test_add () = Alcotest.(check fp) "equals" (f - "5034212870056682811541563993093442956024207074167934414259669251040086104221") + "2374810751739477100463590330921093690716317946317392463784626903791011820633183400586641651596983124871770987834796") (Fp.add (f - "3019612232293951348432769707427639303474751231631017441050730061639747788964") + "2539779101900456646568144715229762367285486475239783931158627624678891805390869875565288868071668287807229226543736") (f - "2014600637762731463108794285665803652549455842536916973208939189400338315257")); + "3837441205060687847313235441427235479987714291016616417958057415236151665733151389464040412654330501102436033850847")); Alcotest.(check fp) "equals" Fp.zero (Fp.add (f - "21888242871839275222246405745257275088696311157297823662689037894645226208582") + "4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559786") Fp.one); Alcotest.(check fp) "equals" (f - "7363893478117210948657131929839491162862302555393162961985689652909776739235") + "384476669312388421311524501123823125955339059132692747612224236132178269378031149492449497597195990768128059508632") (Fp.add (f - "7363893478117210948657131929839491162862302555393162961985689652909776739235") + "384476669312388421311524501123823125955339059132692747612224236132178269378031149492449497597195990768128059508632") Fp.zero) let test_sub () = Alcotest.(check fp) "equals" (f - "1647997538064335793847192302859723563372189463772006638527106196094592175035") + "165319330386450259644373203077974807220645910781758561016457044290634131611762591723983872825173884569834926691719") (Fp.sub (f - "17522329235179667504196475280824254606128390327458085261948007699233694805172") + "1405893192175380362982591361710914795706649812325486837308052211302962206739907466200494461868518523181162574586698") (f - "15874331697115331710349282977964531042756200863686078623420901503139102630137")); + "1240573861788930103338218158632939988486003901543728276291595167012328075128144874476510589043344638611327647894979")); Alcotest.(check fp) "equals" (f - "21888242871839275222246405745257275088696311157297823662689037894645226208582") + "4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559786") (Fp.sub Fp.zero Fp.one); Alcotest.(check fp) "equals" (f - "1550460075629904631277637708383660261580971272511193857451434052003108082807") + "273700764787627457799060044282637660524549878241623469690390886482859643881080320614421407637255214635882056143889") (Fp.sub (f - "1550460075629904631277637708383660261580971272511193857451434052003108082807") + "273700764787627457799060044282637660524549878241623469690390886482859643881080320614421407637255214635882056143889") Fp.zero) let test_mul () = Alcotest.(check fp) "equals" (f - "20539703399960180369319660518633290048071922000666914740466234074847854697757") + "1560876702381502869417555148367252552481105620035123238299609747598054883306126748205686202973654059380727975591234") (Fp.mul (f - "16652515618518207323315643285221741056245295412987863357779458647516886387587") + "279547634005300029102205018299671482205774783353195390298355861578412563978526787881524215497557795647889312315751") (f - "15388577223719168739739036375931130294575142146897880107473273404618844312776")); + "3427620255462168869577649592045372288347103136173632621660416459924986394929772961627679067072044927454006261449499")); + Alcotest.(check fp) + "equals" + (f + "593967545910422807191227856826044389349650065275129056544730655947755371733753954313104753215106376170448509392675") + (Fp.mul + (f + "593967545910422807191227856826044389349650065275129056544730655947755371733753954313104753215106376170448509392675") + Fp.one); Alcotest.(check fp) "equals" Fp.zero (Fp.mul (f - "10935302729977221140784701859408855206669147633587285404353277660075789680922") + "703545455926396945740715333992050752005021427598800842803073904307617362496908026217784215025628566198772571250209") Fp.zero) let test_div () = Alcotest.(check fp) - "equals" Fp.zero + "equals" + (f + "2059618063413968434526823257816555562470552560374598768804163111617667105525168050037627517320850541807313010917014") (Fp.div (f - "18116615978164648621644052928628515074324534642679951563606417178540650964031") - Fp.zero); + "1381636354886970246730091838529094596789078057530348045495053859864349304785635308306479084085939937199744370598307") + (f + "688727003716696760215586516252987190967903805200491271639028323343688532340510486329341963276230891156889916003308")); Alcotest.(check fp) "equals" (f - "7363953525538778156567393633860492517850968441297156550375719598579598367322") + "2348053930693773880547098734394756539121977002913164528291476932235726021574920900040357432776074408113136192282638") (Fp.div (f - "7363953525538778156567393633860492517850968441297156550375719598579598367322") + "2348053930693773880547098734394756539121977002913164528291476932235726021574920900040357432776074408113136192282638") Fp.one); Alcotest.(check fp) - "equals" - (f - "7790294916104464264789490491726462498925424319049857352064036320409088886798") + "equals" Fp.zero (Fp.div (f - "4322946717978085483115008694110144245819367528797529184678953776094386598796") - (f - "14108716032053518963412902325315866377355891041801503021777950559570482464634")) + "1347873489628120094114318613072587370478512551696948280446283440627587705929216354976256274092780667293679712470563") + Fp.zero) let test_neg () = Alcotest.(check fp) "equals" (f - "21888242871839275222246405745257275088696311157297823662689037894645226208565") - (Fp.neg (f "18")); + "1775670041761213755815401858726796002231574244090972443195008370472258001347895474907169245049301843890576532344557") + (Fp.neg + (f + "2226739513460453637602387967009108154325308575848035442137049765651773649142942389535518384079713820147317740215230")); Alcotest.(check fp) "equals" (f - "21888242871839275222246405745257275088696311157297823662689037894645226208565") - (f "-18"); - Alcotest.(check fp) - "equals" Fp.zero - (let a = - f - "17892529277404961739509303065517565646363806323806017705817770169891693557191" - in - Fp.add a (Fp.neg a)) + "-267753732583775504900422651862463267675519388944913356213411204915826527539794931857138413100398101938254677755732") + (Fp.neg + (f + "267753732583775504900422651862463267675519388944913356213411204915826527539794931857138413100398101938254677755732")); + let a = + f + "2497097842558359777178016466699043409599265754417843473351354622561745125294339148741115501035447061946244255033869" + in + Alcotest.(check fp) "equals" Fp.zero (Fp.add a (Fp.neg a)) let test_inv () = - Alcotest.(check fp) "equals" Fp.zero (Fp.inv Fp.zero); Alcotest.(check fp) "equals" (f - "14812345552713361047837749161990489217154524375614120373819285291721752372748") + "752719029789714125672585145391317961774250034420382245434007703830544244069267564372796838570703363298508273612998") (Fp.inv (f - "1160181877204925047836599448201084379181489517022839288462621953652233427695")); - Alcotest.(check fp) - "equals" Fp.one - (let a = - f - "17876831255806984619368587498426968568242044248616647019388897055879503636463" - in - Fp.mul a (Fp.inv a)) + "74640385774984699849001899276665348548471758265379665870133980059008860817791552369863298623063427760979069744495")); + let a = + f + "736160090838971531915667613244838885092950617728976245438065331888702337925537742686895723638527382814325809582891" + in + Alcotest.(check fp) "equals" Fp.one (Fp.mul a (Fp.inv a)); + Alcotest.(check fp) "equals" Fp.zero (Fp.inv Fp.zero) let tests = Alcotest. diff --git a/test/test_fp12.ml b/test/test_fp12.ml index e8ee6e9..2918018 100644 --- a/test/test_fp12.ml +++ b/test/test_fp12.ml @@ -22,309 +22,335 @@ let f c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 = let test_strconv () = let a = f - "4043700123595047491019396268386735516906248466322395048554330205778635891095" - "17221541359217652326358277858052631750810340224824921020179729243890155450597" - "2105430645710237792513582393166705872936983935586482637993019277236322297450" - "2750996376970369945896925750392113510825235148588986538251053617614577105984" - "19171164063617800757530920435617715964562251753299218441532022528480014971616" - "1869375785868235117470731287362599916254253000340764413892607328405734271000" - "18046224689788806059892088736232887972325780082048441908207440036617200097851" - "4394211309271417113975629390800575238025478427766436761683137388029266830025" - "18976283199790418408537367722034555229341657915689268301157926107621754668892" - "11126421063345725721927802506124285540060967019186245779441292497972981623917" - "3667157790183584710110277841377835880117476685194559992478342202253216897519" - "927625112157687680628039629075950684431926799823332260093299130490211782953" + "2916030131112425910736728833294966280877348127497066861802260324152389116184665963977658957216391196180579077474202" + "1519862437235303187188961557435602349317662069421862747209181232217613587604953767705018210876984976062405524645622" + "296645580800680675009621881920997395213790816778008448436221746142308017377314413585580661715141084537701545554168" + "1981557211956889095227901276564616817712990386953892187870249475222326830471202728108345999615285753394142232132312" + "833361220704354884434302513333442088322974161003072803264824357410372777926316698647896734024111451895881451892941" + "2711755601893075919832148493574676626069798533950866837790424822014009949251210477322950287178868808802513013310092" + "371213053563436252645940045458060653872935108881239949520789125958735351804960527435344045802826289621926519389359" + "504151947300534428538773393472324784669777301827817398729819216017440270289061739490404467920801765270857364809526" + "3563993255617322600585910657699631528415397776575273554957383151855598758349437838089591153976674032653746780002367" + "1396274584009387615887886835913193518070291009462177144922465656390031512961216497255957290669783178741610222179461" + "1791645971276582626341761994075837917473870474245353102664092427839586202945803660199735855654457386807016012521755" + "171029163675750402723404477137748189341455451129895111449568566066650114642345344282976819697533131681587059212847" in Alcotest.(check string) "equals" - "(4043700123595047491019396268386735516906248466322395048554330205778635891095, \ - 17221541359217652326358277858052631750810340224824921020179729243890155450597, \ - 2105430645710237792513582393166705872936983935586482637993019277236322297450, \ - 2750996376970369945896925750392113510825235148588986538251053617614577105984, \ - 19171164063617800757530920435617715964562251753299218441532022528480014971616, \ - 1869375785868235117470731287362599916254253000340764413892607328405734271000, \ - 18046224689788806059892088736232887972325780082048441908207440036617200097851, \ - 4394211309271417113975629390800575238025478427766436761683137388029266830025, \ - 18976283199790418408537367722034555229341657915689268301157926107621754668892, \ - 11126421063345725721927802506124285540060967019186245779441292497972981623917, \ - 3667157790183584710110277841377835880117476685194559992478342202253216897519, \ - 927625112157687680628039629075950684431926799823332260093299130490211782953)" + "(2916030131112425910736728833294966280877348127497066861802260324152389116184665963977658957216391196180579077474202, \ + 1519862437235303187188961557435602349317662069421862747209181232217613587604953767705018210876984976062405524645622, \ + 296645580800680675009621881920997395213790816778008448436221746142308017377314413585580661715141084537701545554168, \ + 1981557211956889095227901276564616817712990386953892187870249475222326830471202728108345999615285753394142232132312, \ + 833361220704354884434302513333442088322974161003072803264824357410372777926316698647896734024111451895881451892941, \ + 2711755601893075919832148493574676626069798533950866837790424822014009949251210477322950287178868808802513013310092, \ + 371213053563436252645940045458060653872935108881239949520789125958735351804960527435344045802826289621926519389359, \ + 504151947300534428538773393472324784669777301827817398729819216017440270289061739490404467920801765270857364809526, \ + 3563993255617322600585910657699631528415397776575273554957383151855598758349437838089591153976674032653746780002367, \ + 1396274584009387615887886835913193518070291009462177144922465656390031512961216497255957290669783178741610222179461, \ + 1791645971276582626341761994075837917473870474245353102664092427839586202945803660199735855654457386807016012521755, \ + 171029163675750402723404477137748189341455451129895111449568566066650114642345344282976819697533131681587059212847)" (Fp12.to_string a); Alcotest.(check fp12) "equals" a (Fp12.of_string - "(4043700123595047491019396268386735516906248466322395048554330205778635891095, \ - 17221541359217652326358277858052631750810340224824921020179729243890155450597, \ - 2105430645710237792513582393166705872936983935586482637993019277236322297450, \ - 2750996376970369945896925750392113510825235148588986538251053617614577105984, \ - 19171164063617800757530920435617715964562251753299218441532022528480014971616, \ - 1869375785868235117470731287362599916254253000340764413892607328405734271000, \ - 18046224689788806059892088736232887972325780082048441908207440036617200097851, \ - 4394211309271417113975629390800575238025478427766436761683137388029266830025, \ - 18976283199790418408537367722034555229341657915689268301157926107621754668892, \ - 11126421063345725721927802506124285540060967019186245779441292497972981623917, \ - 3667157790183584710110277841377835880117476685194559992478342202253216897519, \ - 927625112157687680628039629075950684431926799823332260093299130490211782953)") + "(2916030131112425910736728833294966280877348127497066861802260324152389116184665963977658957216391196180579077474202, \ + 1519862437235303187188961557435602349317662069421862747209181232217613587604953767705018210876984976062405524645622, \ + 296645580800680675009621881920997395213790816778008448436221746142308017377314413585580661715141084537701545554168, \ + 1981557211956889095227901276564616817712990386953892187870249475222326830471202728108345999615285753394142232132312, \ + 833361220704354884434302513333442088322974161003072803264824357410372777926316698647896734024111451895881451892941, \ + 2711755601893075919832148493574676626069798533950866837790424822014009949251210477322950287178868808802513013310092, \ + 371213053563436252645940045458060653872935108881239949520789125958735351804960527435344045802826289621926519389359, \ + 504151947300534428538773393472324784669777301827817398729819216017440270289061739490404467920801765270857364809526, \ + 3563993255617322600585910657699631528415397776575273554957383151855598758349437838089591153976674032653746780002367, \ + 1396274584009387615887886835913193518070291009462177144922465656390031512961216497255957290669783178741610222179461, \ + 1791645971276582626341761994075837917473870474245353102664092427839586202945803660199735855654457386807016012521755, \ + 171029163675750402723404477137748189341455451129895111449568566066650114642345344282976819697533131681587059212847)") let test_add () = Alcotest.(check fp12) "equals" (f - "679260298844574254658098201490432118201156332014499464072357045783567899838" - "20475919004872449640122744615447506207327525242658307088113520342244945960358" - "13871507983041033919567680142670451553603213953814376172488380435196942700234" - "12850228783435933341205418383649786138378876239236074742023644779482238243459" - "19010719217928472625414626459816630843435532005804375842636239357951625824869" - "353361581120153434542711822928079088462937368808804124349150015227948541179" - "2029344792912984928013093110746176734910474788192840468383948530606464616319" - "224761504179229810724248011021312391012380553234009782153212961210341755046" - "451562162093432102273792043296344588613930115373088228912224071742712972688" - "5192895932298088819213348659049985277006861383184245302543708664337039108570" - "10158021158623517100717170235733910390453779591048565291341062723228765172235" - "6131225099025722618175290550608959453389007048060581783437013508345590116498") + "1417698107936940251656853016453631673853953147794130703688156638303717713671579717506241150013821790861974661084813" + "792288135695906690561617515571635410409198000683556573960320145107387958915155976496080156825242313681095297946173" + "2768807922396056277686625334834708552295944254902517947671122565749281453035333584699101299898802848306012061095298" + "2123881407946793111417208152438015687323592268938277556863437509152647876437818767678349242386974498402005202252863" + "2187596370412268256703110817541663861182466938952767216748358682929146876456187725141523524643928591960953548660596" + "393424626160571421097297466792791400640147184023365772807809662595160957839353777097312935007211617993177100557093" + "880317360010960432313524952239370498461080789740307126320280928593363595069130509033792099592053747116656782052243" + "1645244777451315328185153783354613920940580832479907771177820667317430957113220304491940597182965422762751259531468" + "3550205573265255320534629007751052347537068281527380931777085738915760806622336640463301064769220645662052425173228" + "2957590738957628570740580103912486294937061504675093251592653444372362940930349147902523627092157366967470420527935" + "882876052288115399116926554091482448039746502161453564572609371822751787193338655553501889234120032702517679348070" + "1930706352132404339144090579209142276523501987246090592288999425964598202756156585453497036577529225701774908717617") (Fp12.add (f - "14931999610250342822030012252237969020436152669397159687161020814914197553139" - "12068226242492634649534499085073865283608802649550864019460178310983959118324" - "15769101094691500511973604469451833156840504999292195446944541933407840361132" - "20661609727890788633981333469033291135323566204416455059932944861978471695116" - "2057793890244571119199475975000207559112876700179056915158665930334537872900" - "11480126761539027368178757662940649318911799819183985288507182880644544939911" - "15222168687843425176374981940657799055412877920628856347415463739277380226421" - "2974457513962516407820830877389422281088143975054414666387703223401043716592" - "2348424488598693892192985411549003709285821026463716905647047910644187358017" - "1405728804825785845835731479206008540235534323879806803684210051642564930503" - "101209029551192918234450299377855172547700667160377054726060383975488192056" - "3837972317546152247347794409250781678377461931560089048310163797757975030964") + "3159920112550153431066628439665589032819589113436943826256968434878458171469430959332402305608699902549825494548481" + "280477632787313770308256716090223370904109239916966236801520233572575817285128701723410768518512359978230649258938" + "1413291885782085817633040683653940857250625455659320078914008351676709667450062537779617175392659654164452433135" + "1390203788953831203284410955429001727804727066121899705177902792997039912748042065096210386797318190962813044260483" + "2450327257338258979467333234199279439466897651669281394853367065946750995514548983056158869109063641273013270171923" + "49857405203040712095496579185765642444889317234755469422130724151910605131192922290259073202130142411211432065900" + "253274012167990632051406165976175533248954578500167998516665746125111248103572214467996880864844594029272028226548" + "2512128876430470827829664804162664940531442892318313783768490289055976632958517172224489818357368867918187485939206" + "2511525475294446153720884061140214935737412169338105798844746660622109445888838301856505039889558164997842986900428" + "451706832780583443878249787673165328239847678451875576597273825449492634194044862642622017818494316682101584595802" + "1683349459646826044538749514744448857687163920507629663198009179347076226082396279224364058411096505586649366819639" + "3974781563482596547935340466735509564309044585338123627615570048595283414895855463786352214200921789080075770352068") (f - "7635503560433506654874491694509738186461314819915163439600374125514596555282" - "8407692762379814990588245530373640923718722593107443068653342031260986842034" - "19990649760188808629840481418475893485459020111820004388232876396434328547685" - "14076861927384419929470490659873770091751621192117443344779737812148992756926" - "16952925327683901506215150484816423284322655305625318927477573427617087951969" - "10761477691420401288610359905244704858247448706922642498531005029228629809851" - "8695418976908834973884516915345652768193908024861807783657522685974310598481" - "19138546862055988625149822878889165198620547735477418778454547632454524247037" - "19991380545334013432327212377004615968024420246207194985954214055743751823254" - "3787167127472302973377617179843976736771327059304438498859498612694474178067" - "10056812129072324182482719936356055217906078923888188236615002339253276980179" - "2293252781479570370827496141358177775011545116500492735126849710587615085534")) + "2260187550608454214008014402523946797591246854296194762763246339549291192692986622616526473534137552350043439096119" + "511810502908592920253360799481412039505088760766590337158799911534812141630027274772669388306729953702864648687235" + "2767394630510274191868992294151054611438693629446858627592208557397604743367883522161321682723410188651847608662163" + "733677618992961908132797197009013959518865202816377851685534716155607963689776702582138855589656307439192157992380" + "3739678668295676670653567409078288578272452107222493707227049753106427531432476606528052284663880614725834551048460" + "343567220957530709001800887607025758195257866788610303385678938443250352708160854807053861805081475581965668491193" + "627043347842969800262118786263194965212126211240139127803615182468252346965558294565795218727209153087384753825695" + "3135525456242511893773278804927853136966020760100601872741388514385485974645540996710138407954612218882458046152049" + "1038680097970809166813744946610837411799656112189275132932339078293651360733498338606796024879662480664209438272800" + "2505883906177045126862330316239320966697213826223217674995379618922870306736304285259901609273663050285368835932133" + "3201936147862956747995966865082937746909465401592831786706658328599707211601780240771825459952039191153762585088218" + "1958334343871475184626539938209536868771340221846974850005487513493346438351138986109832451505623100659593410925336")) let test_sub () = Alcotest.(check fp12) "equals" (f - "15908474088103139349886914563506292774722223644332289754060839597966653834354" - "19468903649148034186312004419961428100646897361413592524656745617046188826035" - "20540424982179362114876198805467627146603412559474874139719472903688974870756" - "3836429692597588529548840838826971241597957436931516374758207719178743608230" - "21830559190270609452459668428089768514857874053026274870545746135494880807637" - "5094374349680316463579780211124660738607018927208960054407665339551047398929" - "7728234632902120206027219485831149847929538205910753111981192796954456596100" - "2797876891638629746607000964279680713235660341952882093805056848165107637974" - "20166472943390066070248168796595470736094244718893955128106082062464538994586" - "8546845534299398595494998189880141057663506092846353038384036300074765595661" - "7640210579555013309302740819505903099659293665740634778638035680546457444740" - "3192553841734433576752699604744306986632824540885364664410616569041893968411") + "3302553944936288011643395671890771075571681497159638881272954830827032367567008527963007902081284851370109804229088" + "1325613031177529576144133538277886189350713619747637107688493489251401019269067393891544567500333097532571295283794" + "3805255956365341597630104644739730607199485990454731216235200520270319979759735375470238244426461522848732645582242" + "2196648721276981988563328503938139938892211137934773085385114495500234983523501262753359657102847886110587423847168" + "3127437766993370361458146465170019288005821048579194846864914178670867461423375299988432458740055968314665322852862" + "304945425395469061969770290304380737390462915026224192936198947728056343810591328414986653474492012551032004415019" + "2898307448689798982565686407038926323813195077028289552653420593797301256143759131171602797144787818249441315719452" + "674009870830843433167645711241932305602524166984274071941075647458161614707730864745757064001444935162367045177204" + "2760889607303326695193484568465692094448033282205796091080018189800885357661894534974811614871035999947711045979301" + "2465323220280373332375030075978100795801342439922963455067792787314361987131732699585556895639364795485192470795614" + "462958911565986865956219637782395139191579025158444312444715041695023763530435579920580737009932406540462434608374" + "14550393435262095234314415188176353354796522697068473155585578156413100948935579460238797182191051302482608867277") (Fp12.sub (f - "5805569491354595219543071656122507705698138220857222292204195295279450601031" - "17420719132934791902466958306912320433737206386115661558254952724857268395785" - "21564681492345603655791194192870315392117291559066745915830361772947234817173" - "7363339439810905491416846001351733412151827187008974189515031471804719866657" - "5964238426350559010840925430005390298918195823963418235621473678586444898238" - "873115171021014455523200811995796381744624930869754151259564914798828757746" - "8607593416247573654022275265889687194660698389188174609607223866074250581700" - "2291604495963149906293106357908558324864001579812690483933454399450635462628" - "2165237414593688322174293381001286773184870016162493277320233445405434254297" - "4415812194973427285927546678028778558625701011516473497601642289339094142740" - "19571255403751560226173444762325349082722761181407645654936453607532580779671" - "21613798221463787690278203646027059887353673424639892424379955754772967467245") + "114317628434492963777402547849225713944776016754894887425944137970903990856299568127855965746861193102831803855316" + "1330794661088328866278324379190307844831119113153984231090294723464336866838414732790104240513879124233936645760267" + "682820077349712942685831444808782244087203729856631577095597078287950646118454900284542224718937099449247565866211" + "2541805122017509324170461754319871504234807303251243066972862129561163635712011474187055436290675207110973141933982" + "1585987320332076449717837598835656901185075640110364982460903446073741042896123764904487910931516635414792416504104" + "3029921088799501823177617262500676237655541421229492749172325122297154015204189311942027019239102400007326816752478" + "3054107585261413780374328134970411595453992746307388247345687054213359783238069725343576833043890842660602939094799" + "2309483918573673457387618324019124385250281417691549513680788506763996313932998444275730969230142990401946675524438" + "310396503003474175635473989154522083036639984599220642030249532719094826962716266890748453669266805253958158027929" + "2840133932637102618284847584546851376950163903653961618550546053481349534178385214905314575658907893167318610878599" + "2890090158956375957317541802200870597875764625368236090436583145261778498800959259599762835295546592450919644184906" + "1374278753306173607307190341006418462639850053984896307033910269789945759389518149771029935845353541978592690401828") (f - "11785338275090731091902562837873490019672225733822756200832393591958022975260" - "19840058355626032938401359632208167421786620181999892696287245002456305778333" - "1024256510166241540914995387402688245513878999591871776110888869258259946417" - "3526909747213316961868005162524762170553869750077457814756823752625976258427" - "6021922107919224780627662747172896872756632928234967027764765437736790299184" - "17666983693179973214189826346128410731833917160958617759540937469893007567400" - "879358783345453447995055780058537346731160183277421497626031069119793985600" - "21381970476163795381932511138886152700324652395157632052817435445930754033237" - "3887007343042897474172530329663091125786936454566361811903189277586121468294" - "17757209532513303912678954233405912589658506075967944121906643883909554755662" - "11931044824196546916870703942819445983063467515667010876298417926986123334931" - "18421244379729354113525504041282752900720848883754527759969339185731073498834")) + "814173238719872345551796701694358794929977339534263891485047443267903273780128904607535692794592005770616272186015" + "5181629910799290134190840912421655480405493406347123401801234212935847569347338898559673013546026701365350476473" + "879973676206038738473516625804955793444600559340908246192454694141662316849557389256991609421491240638409192843756" + "345156400740527335607133250381731565342596165316469981587747634060928652188510211433695779187827321000385718086814" + "2460959108560373481677480959401541769736137411470178020928047403526905231963586329358743081320476331138021366211029" + "2724975663404032761207846972196295500265078506203268556236126174569097671393597983527040365764610387456294812337459" + "155800136571614797808641727931485271640797669279098694692266460416058527094310594171974035899103024411161623375347" + "1635474047742830024219972612777192079647757250707275441739712859305834699225267579529973905228698055239579630347234" + "1551916450921814873859779246424734145145489522332432436282289479042241119791659596358624467927246469344141384608415" + "374810712356729285909817508568750581148821463730998163482753266166987547046652515319757680019543097682126140082985" + "2427131247390389091361322164418475458684185600209791777991868103566754735270523679679182098285614185910457209576532" + "1359728359870911512072875925818242109285053531287827833878324691633532658440582570310791138663162490676110081534551")) let test_mul () = Alcotest.(check fp12) "equals" (f - "8823818978915783805181616565331969040878879797819598481454052588850485460611" - "17342067505254006854696747055377366784894036844497398369789366435506766106061" - "4460181749512451599930853254947317081415316509251200956882755476302030517218" - "2989864541505855655981241407648859030899418844639260896292378000523322285734" - "6131563575961041210659641231208875099164513998741365855416959149114746613493" - "612999273383988699209096180042826466871099791087758060034530146827776903037" - "217824396591541203076315004412144321172659947882959179658988780407547464397" - "1334243229555105018807996840445782461460452800783774966111589924865137740068" - "9401225268817633060698359209750296257708832438926305447978974797074462742256" - "3122452964485047360743410379835632005339027686211128544529227625617933632632" - "14516783584152973770104960644065406423218736942455586740443875151798452381730" - "12862141850291214733449100168455302645220941815281926312862226415725812746384") + "2769459291334042016045760656318365999112422715283761607268389276474674836440707023143101799859934899202748797427386" + "3361320093180761939725550094168988000971274999740984587588968831333492275445713065388295550504330088713053119659248" + "2548058068324782003511582863560967716415975732420681850701575946506718185654529020546234051591864142079999479468312" + "2832018745467737515819525261173821675791848574299575461716718224691533072415952644294554311485484240251461998553646" + "3439704161884893823555257769651271148320755007087117925446721974393201492838174177133034642764840371798879036849279" + "2281104732151119255911652385082379793572539700746943286088110168179780216568371455040179036953876759046938448866990" + "2015349705563352245995128836142944307288590644854023576468059839756795566611952082365200188828979549227984715122487" + "155159649148811540561459146065591286181994346958123489722131136875807099831440751360149754587770106079973431322217" + "3667366500769490085341434481129794744757896765430211409460846330993398960673516540894555067887119647442948261891721" + "3443457215989773083210277336336386477319698634144615905045854619225124817069488127578774116205921282424119802129140" + "1398097189476533387592939930766583747023012857085645758824473894144850073357928429202288558262130720000402076976850" + "905934421424989755770709842314968754142619338124544865909393071018998472742701334456268966551948065227132135928541") (Fp12.mul (f - "6948967768617865944982899667620023648328221475287539300508042248094743234515" - "7046400706491288955917718293112336819412128352636241964184889420272069832482" - "1176385575279124403880126584953866531215702698901662691243262531090208747274" - "6157271231395572936222356741453701249917009400986329923156898473163776867375" - "12602932002327759785860910268394732588446182568984616056718210781632617905768" - "7847224741347352395417620596844584634592185397547160260075268300188382673626" - "21730909569914770152829996303596551818955608830043144814027154110020524163458" - "1493315682700915812470161997513890424122703532295699240379189380245672216242" - "14446940862282451624845471434002447742900901850076724275325798511063686417572" - "18469655736724097735553911099641627340281327622528778814612181953467122960165" - "15159629442965085480595880613882183287914599282250274300979165401891091065171" - "8682857601265363140507477056634677315927213720928334491216000329988109481408") + "3188965852511671063713365520426013860876038913881062821253377695122765059224885667839392639969816734037104670613244" + "739230562742065869428711570131322565650363017363321772468200996729374315480859067980217062249942447699717461975435" + "2176703902856768340923498396069790708726027328202399564021031361317557749307316024777712001130489797595255105145574" + "2670928296575291897567182668008518066900700368725847572099438663375532458643254583023716168915531437800319570762359" + "490493474292589590290985164041744408386694847492050815490827814231625948304243075844177545163347050487540031351408" + "1447231287355316410460109761296716454406840030157949463466429671839408681857143198732909489409168758850527959693128" + "380566892947120789169176467967036122180970212567524587253946816937505290817541604787685483045734490086808180188209" + "1933270752469040734962325106835008701319037970034715630543772447121736485673581521720004281570522954301236757912058" + "3764384355623541980227347862260938586306933471250237826985597550572856756424268613647164167330369743152591888002476" + "1255883430247624307681915611919079518991014033717687609361032678352309027109569694756330457157678676849112845044093" + "249133888792184767833878049631213302737617830806417857850257246800963239084169262142539368627987584542252728578744" + "1318313694940289353002371656163361499247765041433217402587131255038015671326878036168961275846882909253309634498906") (f - "5267072325748027197742556153957640105461859359409691382355149691412842189062" - "13860225074612684828895475883488906402030398480017068545098320878551171693332" - "20528308977578979501461405548916487126143884599548116314684440223357844484106" - "14900301117804943437504093273693765829216713590821036756558659587614078075181" - "10865416682957561387095694744822715017167214136582183104864204620302886498987" - "8614907467168717704558609396284593818308913710372720444790049949006894118578" - "2911296271706596100511566654004168334006140030049210923581225120516133875480" - "11692632339396190822067214084116224973400417552783595347053750081499566156074" - "21198428102722495178821959702584364354987690338890265399399765532216055913782" - "11893302225633376608282656573764224393980787558045497315206166758262569839656" - "1338072636057400393635925588044072398176682615943934513151529301522509187278" - "12959329259704037762362242830752770509395329838916184355704828609736076981548")) + "4001873370591540083496166250646055711726072422193724090307974274629729343800446490612585626259709075180407919102622" + "2381691022154841244422795422272821831958572984018765292538573818425881254555104379811082907429249497777931833833376" + "280598032905619331801221212082915377532443217602049470185527116036623938978512431470105010230000261635064479395726" + "3201267635033507671570742561753619101772478174192594656326090148928091568774524367063003457402869495752556937283287" + "235662028814856435814177059372599670172928395505573490987559673717902910667854381750212127270270615977469099765899" + "2767542260487979603817786865232490339768738539649093598109993837852031223891091898135323929286876809238782193512589" + "461931201117817542257036959941540589433085255840277245099857960931805762867169082291827137797005994717405863452458" + "2352905815802217650777604705491663515805476928982110124837855837463020809344910768781112298539176325025716749994185" + "565988735302527395594598223791239663211041041894166833196313968046686963510638275205734606307498578656794695467639" + "635003532145447302815810457639392294067051414008441966927557377389534021035755093764489766183353612834453688937680" + "3326309082927816928671114598367626403152435253065767331209692366852408397633791132983761483456881458862714270033581" + "1847549737499226286135589532836789142960266552488220324407653442999952545023129510122014859030811553097538193595356")) let test_div () = Alcotest.(check fp12) "equals" (f - "1096803581874169670960297098779105899780688007924067918320102919752182708300" - "9995875973811579901417242213630515940173375903459966681878798696090228036787" - "3366236069588813741179351217208783720698794654464062357207288742843117814761" - "2611740726020013650358809493530292337327075703423177538682869561017208504928" - "16978038323586267447042278676006098836832469726377502891390302026928324356346" - "13990225310798549460842507817183211861953629723187315670443012263170556910620" - "15708725132415572278184615188378799388286737910276549406045149828302331760548" - "13922646542487508952487824019581303897151102688875549649032880615524477708715" - "13989849264798557614151062706464075549675061655681620590943048073671802304949" - "2999450488895033272886335121147596204573319911571544116922024695423270495206" - "1707193605930465946700519771750791799447293109947880961206685427498523417284" - "416569712948182390436868324476465553831984173593246113696858459452543126794") + "1088191120450889471008080434220823822724481466713997839230930280979494944365169538570720787371316135622615380704907" + "763586133645656306504237229020782434670077269496450825440272754809264673423806612505833519243290624472723147173348" + "1707679080535042433675444210439209318150111604054543396361463652314045859894921581420249937947110141828350610877993" + "827719249543693888899520078226963351508440005829157207139779006188312805663643955920764377010883516024971471412392" + "1670976992567442264594092472913962112664205686219416536583345959321143994394979677168463645851734273195131213548769" + "1332580825428383428915357054358964399667499601326760579660311040723405346096321805018432619765572146789465208947413" + "3022912129472159846831339528062355962231308863485628015140274259231118064888526224703517916104229049483242824113499" + "2614858795056328963792613930127519383950909788846840302217657952676013771314600089040168561513165821379236778779390" + "3042455406421231680689024574442362895780321848721368922808317665636039424337674315246068583526430967830075629358278" + "1915688907907831828287174596392774041948474822125277657742586455558627195848534825636734762819155454967137835530417" + "2699429829070728410559484094948933802442497083319705661264366297393973601594198492466505856394860764197145873591205" + "2556773905133270246408876485939744407521607167628527716285291299155235848448290034403167143189795397270468361200924") (Fp12.div (f - "16891629574128548079304072179932861694695268028581829895449988812958151889068" - "5773428070121667584587697155448628787499399401530717395380822743509515712302" - "1510014905380928573966817876817322588036636044829790691311576928625055774713" - "3484897069108570642536176082552988040898002350875200634245641433336320087452" - "19718291166133617007547736703319040673297932826425091870865978392072812281568" - "17859744514917983533340674875779802110474596234481900219886514483092059069870" - "20437324654495856958641082802073814921383894147185666216954188982917904332878" - "2960345167483834491960471912580543338504765185419418826135735944240543975007" - "7431248571303067589896102358092670922459603228321352003423446458656336374356" - "3753895253518515147013086017379029828017667525827529804307831430901850392657" - "2406550068803257825161686151282932146056678185052400200434529815433282715522" - "21527499377571830635005139066287650700499729934985849257468301501456435601873") + "553519384159409545394828443365875904103984936708617615018997854922725722045050663916872183987860344110881458839300" + "2551179480580905827815816507015793090462143539258201052682699476482990332142911858021207505604703941240285222712127" + "3293736434413374618351634015836468677887129730347082720891859721435831590023521317591181426300262391017914412314452" + "1126069844494917325334876146715289301900746396397803311418144330973830221622870125903645445357364929754717926022010" + "2948659636755282229787876268434177316237104051743077525585857738600440901412973493286500817512218767732685063028927" + "2364444973260657648984604501944196434318571008532303451512979193388627541667853845350145766007457933492528774608364" + "1543784379424065791608190347537667949396972361188055194366508310148735469329834791944686050406146949830424922635676" + "911931132736808617483189599074438345466177318795470132404606720436237726817086490751673788994970605241869953651718" + "735198991681366730725229643665191010980125457374997642991474607960460778691571711798267933027111316714986161192182" + "97010038858965734213682017802148146496114737698885571098652579465016354652266840122234009349707468786023755170643" + "2327540194916374633650422506254589901440606348243254413955101853356793690734868276236653592467951864568737565156462" + "2819837983673746453085471900604194981619924849353466195641626861041559460819593939717905185795048926505935561664940") (f - "67887943195798695261820949337218985472375672292075296753186878599440520768" - "13221092658007783265664390560083928475990190337014855192393579704007489867413" - "8425295182175543772634645537444676197117770070441758278552491787485944955143" - "5452242309254919322497256021853961886147467857551647992384478388934952465010" - "16002819843715475015659395477967729218897925694288387242539104147750372425731" - "4793967772144214427321198219730753130655544135281827339549013053471477208473" - "16160972968990591254495688451831377777703706141098146685039319374528010898494" - "2937205914155151267440505688406167297438304682690886695251911934863243504008" - "5856027318101378740288921481950609018965696470858373478768113198173003568240" - "21786389593140873764454033633721078549985584303110658965932205813679697655177" - "15295386324750102363077755441279089627233550655637004662790687327895590046305" - "824194856810356908268669154202468264046536936033436850379538516763834225090")); + "3659460078149879001326507968005835143443273255368528177408849590512039955706053472882397547960477348262898117834992" + "1411887134534869698530903323518776142275919065091117458618790951859171627994980372213450665325067823376007037339496" + "1370180038531956719537291195447646815964136047415891792957615965221930267663030748831633577127678514914661955764546" + "2940156517138858640290129479419494068549288339660729264664218260452822733746997136205496907651633687825963363247525" + "939869771623157928890792782966937726297983662565406960493067262901149914939870089700504524656981164130396303206617" + "2835423297696274650004757144329922009277352017479256469999713870412075023214829435523270461062113497323069970866657" + "3223415582396100811749718836855028104928416515236239249071829048255916532185741487948072584341519903713918326301135" + "3682126611207831212310201819657665427809296346090344016066649599364174095299298762483592987469818157989734232939857" + "1350350826667854275057334687660534971455319159947207878924976406309061336504357452346590883878730254593697158913399" + "2486364747653101657306704833360712823201299556169280757882865190162919666627645426290188904278660748092056268744369" + "1615429309095368427137050356678981375951561384670799935192898670305508950053725720249524621420395227999560990386034" + "485555330932470122639034055733320699175008602546225368389195384633967594821038350260245866636580552683463223464005")); Alcotest.(check fp12) "equals" Fp12.zero (Fp12.div (f - "10958220273304108960140356770617266772375080927415838618895832830305759889705" - "13465260772194793648511483227951827021566341247163835532611618114997996407962" - "1157075537382478623643205191944067608345124553202251720110826577009049375217" - "7922926335100307301932417560040310453147890695990664992454446037098126700673" - "3854197206315666756465194050813560230806692032959567144432084335025504342749" - "12002208660574246630553852361550751902863562816424890461995942000992537163163" - "10597191987670354308027891589666620382959026949753684566516632297755284416880" - "15420627205969290772283713743732187786100671782123230284737435344240576449936" - "6802543793339110195182347217544705545690730554181808318302725682544596347672" - "5569849441110190591622396996506105482399895437826867255519649816379826212708" - "17852423389543152155949451338445708565476874751681072167786506882830599204858" - "10904113524921192396634981424155901832103292272159174385913687952131455889939") + "2363095163847131454975167851617986026737599557880578661124850689113964885453223688395116630767021081071861181923384" + "603730799793826726418275010088472602074783832643744332283635509909458807205331337394866376596471524093229001264001" + "468280384918428881309534413155999744540798384749005987590963756021655141222823418191220262201621882943300938983522" + "3531967301631406423135320989786899549878860332140476451698049944658024523778751586015243193559362530400101760521047" + "3328304605311853921199900198543165990884781662436100871445779045643983518867920209644497734859723122592756134964592" + "1705357535555824874328863505240453699271685052327246065134812663169822635879254751692466868718919685541722500307553" + "1943162376863013487975764682713653412656066573367251902046789065188971130502469488995800280459140695452496695113013" + "577564390313055436293383452509271549231018927510471100349442569739931728983831439647811621690255225862401826847692" + "1363712630403203093135964563411368345118664271008137801123819674077813980993708066842046609086405074439025674212952" + "476292231642492692401964083527458570753957231499794532035187199649731575181835012328774344557854564086912070179718" + "355737467024789378626103721103250809692871887649120960319877490924413542062808880331179181598955424666257053945034" + "356372965698149812539584039654274766468102724556855527351368208179947933904344169138032198394319512433308318932125") Fp12.zero) let test_neg () = - let a = - f - "18605205790937513393061432931422829429842719850592922039475732913063240424554" - "12407214612973176394609465088181275180209573721437502280700981704118114513425" - "2302243975397132977902561193046139882549564197439606156078083357011819270659" - "2738285309128644623205322608750527409463641342449273398277873439071000338246" - "19319592312706960701826229795892663067089215313407329629222255259911759030857" - "15763745279656661838570297050636906941374326329806024351274342505301090350445" - "20130480934439181563277666741994991665705808107265248886754964759388131724731" - "9620877890335010684997930792443932455373413343757491049206285380122715424492" - "14909574107785408299854013106123871467362127317944663380391766106267340888712" - "10461986004179838170014598182006536556751491190190190100041874184540493450411" - "6739235625602005139923788170786820709848060227361018450724656857473350332405" - "19431892743074308896971441056213912607074572676149412002826263167122874131180" - in Alcotest.(check fp12) "equals" (f - "3283037080901761829184972813834445658853591306704901623213304981581985784029" - "9481028258866098827636940657075999908486737435860321381988056190527111695158" - "19585998896442142244343844552211135206146746959858217506610954537633406937924" - "19149957562710630599041083136506747679232669814848550264411164455574225870337" - "2568650559132314520420175949364612021607095843890494033466782634733467177726" - "6124497592182613383676108694620368147321984827491799311414695389344135858138" - "1757761937400093658968739003262283422990503050032574775934073135257094483852" - "12267364981504264537248474952813342633322897813540332613482752514522510784091" - "6978668764053866922392392639133403621334183839353160282297271788377885319871" - "11426256867659437052231807563250738531944819967107633562647163710104732758172" - "15149007246237270082322617574470454378848250929936805211964381037171875876178" - "2456350128764966325274964689043362481621738481148411659862774727522352077403") - (Fp12.neg a); - Alcotest.(check fp12) "equals" Fp12.zero (Fp12.add a (Fp12.neg a)) - -let test_inv () = + "3239016682797318685312208982528307830172802538201642963600043396394832879722910379590968867830840935131031900043317" + "3316038793989753908571740206096060941727103212792388906703728120542085172528115130585397465339510398334734129411689" + "3357295947947428750797875951523040991297856178658428300568137974581540870728043828339177627553146775126133031283698" + "3567976935861330059298612795341805547834764304660787129519245303497771596167467391720755408530196349862783108290491" + "2445650416160796961403637763709895351193054475902059348755902313520489259893661399593635632193390173859657188640229" + "3610497391498930888615065924582074283508545064142386323512527153957393455707077329761314789089101265786887578144482" + "3589721763488203139404385680541349261261989278408893195672284347139129229101382380760913715230886365608535849527204" + "2778204787525050919644284985114187680759605423708903374245942501811486358282974409669013992430271345558444913612161" + "1230519620266756695697652504847058612962080294010175955178467015082305671262155988462080859479913781149026452107381" + "886176932117428879649099925925308847718649044800815717037071716335947041678497415529440658441347478453638038087367" + "2887111936704023752478188750772227065214720424150139981491903072650356763615004307799929002447126451849190724989712" + "1682046371583137799485170506948051010786599812304576451543936485337302185465632275557970031518260231147006483255452") + (Fp12.neg + (f + "763392872424348708105580843207596326384080281737364921732014739729198770767927484851718761298174728906862372516470" + "686370761231913484846049619639843214829779607146618978628330015581946477962722733857290163789505265703160143148098" + "645113607274238642619913874212863165259026641280579584763920161542490779762794036103510001575868888911761241276089" + "434432619360337334119177030394098608722118515278220755812812832626260054323370472721932220598819314175111164269296" + "1556759139060870432014152062026008805363828344036948536576155822603542390597176464849051996935625490178237083919558" + "391912163722736504802723901153829873048337755796621561819530982166638194783760534681372840039914398251006694415305" + "412687791733464254013404145194554895294893541530114689659773788984902421389455483681773913898129298429358423032583" + "1224204767696616473773504840621716475797277396230104511086115634312545292207863454773673636698744318479449358947626" + "2771889934954910697720137320888845543594802525928831930153591121041725979228681875980606769649101882888867820452406" + "3116232623104238513768689899810595308838233775138192168294986419788084608812340448913246970687668185584256234472420" + "1115297618517643640939601074963677091342162395788867903840155063473674886875833556642758626681889212188703547570075" + "2320363183638529593932619318787853145770283007634431433788121650786729465025205588884717597610755432890887789304335")); let a = f - "15197869645782446670819580844615631526100380266853121434256548370382659320138" - "10627543309547787009232419754376077894952590471427078354138646744158189540404" - "1814853692665074057505353520795390518070085772159341335189512049618927636539" - "11949689541137973499672139858049132789842194843731146425512744199284215943929" - "5222524330918035510176216749476274803906609211476272648212097633307220079528" - "1792818538678490572371603393885403657547207673498243448285801833280210496863" - "16829525197006006684314306774471847704562973817716113268985730574839165072949" - "7542402845708551026929617848839344008856126285276324754388571567846639434824" - "21407871464337343446060102809062189530922585055434671430220200406655129284823" - "7295283709695804870206659116059355882732810218144222393403721923307577665189" - "506076349945751079801619684510142633510371851040994638301723710643137761400" - "15937885146743516578215731869138888251078571985851131433165556423836493883525" + "2674558880713508459106932371829324741448390140653164261219319038425967521792347569735421320255051555408127538024015" + "1914723839108830765501130412748560724031028943530932535891511671410855782791457159429778693319997311838427348346378" + "3021973199857248001042125312750465993235517612274584564622791388866663313917106430659996196237919521405386843462441" + "3761958525158545572974997634091967142510400252155830344612188100969775348634350061099793454227378256560196009908443" + "3618734350748331834526994589505038579770921366815827658550850282532958723895236679190825120046817084128189749265250" + "488365730138835632910385460035400647546564592760382101839256044839585728519725036243750547131502053120566329146944" + "2119646654779707056589738808274831187534166025276869384226648001479446094360244733779046613609347706465404873145183" + "2109322561472002509234198537752063171525572756955153278721066909767387890382129255374889767835518536381876879064150" + "2450430019100289140572386801682598523440075744249597570754470315214309867432755926641266067266701184192347340619326" + "3352475614513689261233943415274904340597894417713417066363229302051596280805260004926141273265080428045835405419808" + "69266478339261496228055134969514420300702979045657486091933776002846046696437437849394365115164989340639838867842" + "2843981689624126130615870214705260595090587151890382137278946280653679908751415441829465678567867845269130967508296" in + Alcotest.(check fp12) "equals" Fp12.zero (Fp12.add a (Fp12.neg a)) + +let test_inv () = Alcotest.(check fp12) "equals" (f - "436429649161332244395200468656153955501103571619671423360095979722406060064" - "19703427263517091380071693461996431052346066551061427941406447796972979677580" - "15237458399375262953488655963555676274913157914525801452145663231325785397699" - "2568813005168407627948623044089020521091876501727292526455053390191076786825" - "8374585028324530814788669886595948808089637355106119111322101373159005027675" - "16623336649804830435561507464164224551227223481434415016873158702848533912284" - "17257110226070417269020755132573578358005004798648012375153436547242639978919" - "3888702150606092681263295431645552248270206784952216927162406167861231226331" - "20825319057083721423157488310478166863959825321685333239108930700513089934153" - "8539103339131261762185833769478780195064228372509888611941063026151125653390" - "19940593141145190804508553299020265737918480914795758132715084668534344174565" - "11454523167593227976588122484560257616164530826320021248044988267657603586353") - (Fp12.inv a); + "1547319709794669291105429180299582165003006608953164424633137062061940120223896065736698269606199927463220884999258" + "2229043319885080125966458766562809098808970927864341323462479235857714537012516233189229849451799838681367686171307" + "1980274252624688015134481064209114532028847100768727191977892931021655209304333319806229181953416610279953385689067" + "1948290523106701151503209932124501084773933042706460502698986147627963103342770392074740246981217822228805152386972" + "522633451827910717214069798171839632324964227981942625500365625992561034846979785542487047252109174193627509714092" + "1244053992071895450467490323919864998680089193720663303110097628761750124906567322727867537406466019596688807924278" + "3476701950080900029803275488221106535824844690090772206016679533425021841071305380076286619524329127415515567054333" + "3065850315308290754435371266738032144868130262782483539178816046641998452348105495939997221589229661912588379674066" + "2392491300711489422370748577220666945538613353002735797782418460438049930733920617970213613898822014210835944834040" + "1173137184917550579787317192980011551320012099102485803075850833795097962214090106348862499493761112552319932918820" + "3406347090157530227104698471818164619480373110731540070686223372928278377689489890330832774676223610700660150476974" + "3017743790597235667250653583289611819318563679226746319993832881306778651947200069220317772337394197851536681648266") + (Fp12.inv + (f + "1066191393679157186707843782051189795202804303471471356012317309373237976010857447807331244600689281404118732720147" + "753294877122124702466251517057371154665171085030386866043649010161854535245979686863130228117275163812848081871401" + "886566903832042606674724679912862710846499242777068730080835673252912500400028170713071004839135039984643138460876" + "658200382089078840575771577494391841520083861514392781529525824935640632454096656712137944876117974116204118697106" + "1183978516593322586363599350906068179900722774061030457309879697391349269870026908217421181592364329737352869389689" + "1946928416933944132589965348968615256315821474187900596913502511936717875608751629236563781006294687855876561767169" + "1249631166116600052962820896700453582677375439104493105102825905588560663631803960549367536439622707780650550564546" + "63632093830057160223602690892969802263563020427366974647497230658520946774736415658749391367225787900071853983109" + "2570948575383773011575976710959847035212095732731231075623317581301368347106876766957200960715335828838071035611160" + "1506142752724262259445751072821307942893924549254798204919026959551954497518486564947410351229100287104962536882857" + "578672450059892855276008711721559049708792194100323752623613112905842590085833660168948006422975904828320438023386" + "2076603552112451030180447061945851308784183837427998418875612110088729657242386906133974913226866321849639097656040")); + let a = + f + "1208966610438465338305389577023182898477810750073179153177193479414956729633609159004857811454106784276506729547971" + "878117770070592886292851651285756003086947577201631030994180684887176394897698780758224530257083732256620268399253" + "548196222937805369043152681944575146709916830808914429680607869555582475847707614178025431399396440947081154824656" + "120361898306611803235948449800937268776271657170546616625010657073903311070901802070685247720941506976164148116041" + "3964636105168373611333255357861614192436971141483140416935414390820244461762503816156256779876668577147472156490209" + "2392093471959448428928572333380043862138927289251828500295961424616922247930393751398948013241811775753517425589689" + "2313367322768114403468619467839971138575666376558527747639381694440360798797866017560151588773556227064940467796470" + "1208381860711933470736945041380525333495094437324245697710669671036306045819919163619533369357722960726957896456492" + "2227820701107578290372462312147333757161380867430446354901322687892665157518793755620366301150191448063025386430447" + "1411863135366961368181181760640483990438018759158132983046914387827694179968324546478953773237400394923749152695783" + "3323709210754140447864882614412202218853338035811625935497215960147856051658231463810236408935190367064958795421190" + "143983650378758285583688397712444406640456446054354147618017894683334939480068047602380254998161328315616611277083" + in Alcotest.(check fp12) "equals" Fp12.one (Fp12.mul a (Fp12.inv a)); Alcotest.(check fp12) "equals" Fp12.zero (Fp12.inv Fp12.zero) diff --git a/test/test_fp2.ml b/test/test_fp2.ml index 828583f..e0bb5ba 100644 --- a/test/test_fp2.ml +++ b/test/test_fp2.ml @@ -7,109 +7,115 @@ let f c0 c1 = Fp2.of_coeffs Fp.(of_string c0, of_string c1) let test_strconv () = let a = f - "10107500267655288533860407941350647620522758874612469022754124115798347851255" - "4272490765421360074221748579109824733865223751122700688342039244846082709245" + "3216159770949743003016282596382810410524821318260601360202344327568616081946682522800622973525694628320886337554707" + "3042776432360195460319296407183823967792916594876398306463713661277272294244991791711647871371679651495395139475044" in Alcotest.(check string) "equals" - "(10107500267655288533860407941350647620522758874612469022754124115798347851255, \ - 4272490765421360074221748579109824733865223751122700688342039244846082709245)" + "(3216159770949743003016282596382810410524821318260601360202344327568616081946682522800622973525694628320886337554707, \ + 3042776432360195460319296407183823967792916594876398306463713661277272294244991791711647871371679651495395139475044)" (Fp2.to_string a); Alcotest.(check fp2) "equals" a (Fp2.of_string - "(10107500267655288533860407941350647620522758874612469022754124115798347851255, \ - 4272490765421360074221748579109824733865223751122700688342039244846082709245)") + "(3216159770949743003016282596382810410524821318260601360202344327568616081946682522800622973525694628320886337554707, \ + 3042776432360195460319296407183823967792916594876398306463713661277272294244991791711647871371679651495395139475044)") let test_add () = Alcotest.(check fp2) "equals" (f - "2863935846698150146497381873035561276727058128903565528503671733559822376250" - "14401928050079391824950970163870648129396875197878295136665664481048699468020") + "1510922689064524402660706287794383764925405808912063605538062764260624404168626064439638568280286334446426980599265" + "1496432034719009204104939852773510654757730640471573422565456754717202107187391202678306935556569591898047519241723") (Fp2.add (f - "14324043627524728108674506634258156009885262437468906348349536322248493484364" - "18029279639026325195296840766401583521358381131411036066373305410616713471095") + "2704945784483088396721340837125430974578228372397373052449492346866782679603876968318204562585444722881993787072969" + "3352713865626504319356760967861765786693715633606160360950371888464145243153004345983441305675063325004158251106532") (f - "10428135091012697260069280984034680355538106848732482842843173305956555100469" - "18260891282892341851900535142726339696734805223765082732981396965077212205508")) + "2808386459803103399357155276404856946904060256453698438420628553517873375055586960564121634823857275602327466086083" + "2146127724314172278165968710647649024620897826804420946947143002377088514525224721137553259010521930931783540694978")) let test_sub () = Alcotest.(check fp2) "equals" (f - "15120500054601708444564040485468985282448658084430827774523947688586748960053" - "9100764362236999328461500289225313390908509119277966267226462796263537316381") + "2746233490314206119922872871732785027444344635498924519980558228449368171837071387946659139045523440232024909392314" + "2448129066313268798189916410701811180368378842353203391514920640569880371240863965817664159595772806445686456192024") (Fp2.sub (f - "14293698145849566696549634796503386029017218475989635574509430094951523306687" - "19456315000973730806536321027874670859833970960897936694996600353725317883622") + "3718052663769508561298229087440516584831920387492170643569413395812990566524218001757670372308077205706322080181599" + "2341793402065270422967665886452846002018783895673345084011697286747619532326972232127106898002302648025798998240672") (f - "21061440963087133474232000056291675835264871548856631462674520301010000555217" - "10355550638736731478074820738649357468925461841619970427770137557461780567241")) + "971819173455302441375356215707731557387575751993246123588855167363622394687146613811011233262553765474297170789285" + "3896073890973669018195539301486938978207287873259149577828834782301770811576946130752130367535545505618006814608435")) let test_mul () = Alcotest.(check fp2) "equals" (f - "11432323160814065864909960700129434587946493783507438700207928706738844119449" - "3577409691447205319998726389612822121306006806114173782377028664710279109705") + "1885423083277797471109639559263547433578030928072896554966830817836333890642646249004478238507722056220637045498600" + "3207243584937107335460533661085834171833693638143693295511055862451917226660443578426964769719700546772951496395996") (Fp2.mul (f - "11986626879605260056244902575435385107082913504490111545527498340756305531092" - "4818173862427609729222592608595100262022473140100027294220533759712947640512") + "803369954224906884563405258732068127499444124373729560274472206073891173218445424518997451866034346092384213329883" + "503859036923320084991265627572913800252671955497792544998415381318131015579573065357816625000610831510288652298964") (f - "10960597259346866798564665428177212161645337477705428048049421023510569201652" - "17436818457664572454171416757524427055427814808946492827966722145668155530853")) + "1859749334750628929451690227707687335137511133983531364679291438693098079713802711484547274759649760701831974491385" + "319479918179863684323943763511758417353324391274148720422945903908894556320269100349817409794148843141967413849647")) let test_div () = Alcotest.(check fp2) "equals" (f - "13419365922711575620625084257870785388560921645234544455343469677828280907673" - "10223115143172140697158827396733687716959251907957043435822040517781915535192") + "2325686290754200682121145718202670986494244660819308027034132423071687323315606671884154529323382987150473976768330" + "3239216598855324114836362759253541458361602150483475976924117760584009168234436493512552837300363568825071136536608") (Fp2.div (f - "5246975579657097196126930177221162000731887408914575127136817635764078403513" - "8292723131410576043572459680046943309298666101925027054973960663999641620758") + "2688262090907385109797388649018262997913625856978785865546511105491589076903808300443238242582958974774562346365422" + "620412794822327085382870755739471012462590600882879640428242176258125002321042095639472359615918267969245549940520") (f - "1886591325401429366956197735571233984030593880349024014320016420187469008836" - "1695527069488388814625626614375814226660393081483975270883481133990211272753")); + "117974554526362724345489824744262248121856237810884003402927315860807227932189517320482013911923392063068425858030" + "2142419467175775193318602789320722018616077971991495171114531437934768498979157636382154413194108550314043215582110")); Alcotest.(check fp2) "equals" Fp2.zero (Fp2.div (f - "15575901816686564911695664888216387456052221682627972942517791604577648718373" - "4074937799975106177793779962697923305068793270789454615564141613169465455800") + "2856688501118144969553652456291973087251256250655576140296976320844142067655542164500037157598802323742365765731618" + "91558039329695554504260627328728230183446829018778898668517468830173959679663774362827298058047294625048351979470") Fp2.zero) let test_neg () = - let a = - f - "15368678686417640939410004345384562254158052587497136227450829712392291541108" - "12426777655707647255726782198814182406150331554284032768572910376412464025883" - in Alcotest.(check fp2) "equals" (f - "6519564185421634282836401399872712834538258569800687435238208182252934667475" - "9461465216131627966519623546443092682545979603013790894116127518232762182700") - (Fp2.neg a); - Alcotest.(check fp2) "equals" Fp2.zero (Fp2.add a (Fp2.neg a)) - -let test_inv () = + "1652265803669885112428961827998763844356192502384525464729566587325430585803412442963299000002746518202319166455569" + "3148086661203569599939489297515929514901363299142047909817073525316870145634606314218990062256965667072857382426277") + (Fp2.neg + (f + "2350143751551782280988827997737140312200690317554482420602491548798601064687425421479388629126269145835575106104218" + "854322894018097793478300528219974641655519520796959975514984610807161504856231550223697566872049996965036890133510")); let a = f - "5846831721439900768152735149922159251212076902324998439686567351122268450217" - "15974811941941150933977163259953349229614582170845394085548476048658545196484" + "3755242969290908447416997081739091519087375707422634859355840356380094840094873991320874195734523076514815397321243" + "1849949402789644720627099830974848465908019020270918322229375845176468537369459245375868854333718071380139986243176" in + Alcotest.(check fp2) "equals" Fp2.zero (Fp2.add a (Fp2.neg a)) + +let test_inv () = Alcotest.(check fp2) "equals" (f - "1787014003341926122725734505165381529419163570425444088707405348791540627564" - "3072592406275333378136945391036461572636993084074366352517366836269594879853") - (Fp2.inv a); + "3171328058141487552606964490094256865782521411579367440944677919764391101552560722992448953525776730005333301011061" + "117788241764364141558165207260211125711335775044260038750142676288749728539425977597521263176199168588971967704898") + (Fp2.inv + (f + "3132683201126346359997649079543944507328912651674927308673497534307262164772016129965211842871422381557518724206099" + "135021294749983899985272892787067246478709822352712818248214312648840971448796031511036377049998504006594698872092")); + let a = + f + "1091358140339556525084474003788455245476134161423421088817134261365285167798938852556734938868755532003979871690585" + "3020178740353647556832143367266239362247768279656392658297101610073850568065890310189767257933036353291058805033028" + in Alcotest.(check fp2) "equals" Fp2.one (Fp2.mul a (Fp2.inv a)); Alcotest.(check fp2) "equals" Fp2.zero (Fp2.inv Fp2.zero) |
