diff options
Diffstat (limited to 'test/test_pairing.ml')
| -rw-r--r-- | test/test_pairing.ml | 210 |
1 files changed, 0 insertions, 210 deletions
diff --git a/test/test_pairing.ml b/test/test_pairing.ml index 2d698ba..d3cdb35 100644 --- a/test/test_pairing.ml +++ b/test/test_pairing.ml @@ -61,185 +61,6 @@ let test_pairing () = "77870636695957247485070729371505785036022507830356763789646790529980989972767478012625350608049848760401081873614"; |] ))) -module G1 = E -module G2 = E2 -module Fp = Plonkers.Bls12_381.Fields.Fp -module Fp2 = Plonkers.Bls12_381.Fields.Fp2 -module Fp12 = Plonkers.Bls12_381.Fields.Fp12 - -let reference_pairing (pt : G1.t) (q : G2.t) : Fp12.t = - let extend p = - match G1.to_coords p with - | None -> failwith "point at infinity" - | Some (x, y) -> Fp12.(of_f x, of_f y) - in - let twist p = - let o, z = Fp.(one, zero) in - let w = Fp12.of_coeffs [| z; o; z; z; z; z; z; z; z; z; z; z |] in - let w2 = Fp12.(w * w) in - let w3 = Fp12.(w2 * w) in - let w2inv = Fp12.inv w2 in - let w3inv = Fp12.inv w3 in - let iso a = - let c = Fp2.to_coeffs a in - let r0 = Fp.(c.(0) - c.(1)) in - let r6 = c.(1) in - Fp12.of_coeffs [| r0; z; z; z; z; z; r6; z; z; z; z; z |] - in - match G2.to_coords p with - | None -> failwith "point at infinity" - | Some (x, y) -> - let nx, ny = (iso x, iso y) in - Fp12.(nx * w2inv, ny * w3inv) - in - let line_function q1 q2 p = - let x1, y1 = twist q1 in - let x2, y2 = twist q2 in - let x, y = extend p in - let two = Fp12.(one + one) in - let three = Fp12.(two + one) in - let extra l = Fp12.((l * (x - x1)) + y1 - y) in - if G2.equal q1 q2 then - let l = Fp12.(three * x1 * x1 / (two * y1)) in - extra l - else if G2.(equal q1 ~-q2) then Fp12.(x - x1) - else - let l = Fp12.((y2 - y1) / (x2 - x1)) in - extra l - in - let ci = - [| - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - -1; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - -1; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - 0; - -1; - 0; - 0; - -1; - 0; - -1; - -1; - |] - in - let l = 63 in - let c = - Array.to_seqi ci - |> Seq.fold_left - (fun c (i, bit) -> - let ci = Z.(~$bit * (one lsl i)) in - Z.(c + ci)) - Z.zero - in - Alcotest.(check string) "c computation" "-d201000000010000" (Z.format "%x" c); - let k = 12 in - let r = G1.n in - let miller_loop () = - let f = ref Fp12.one in - let t = ref q in - (if ci.(l) = -1 then t := G2.(~- (!t))); - for i = l - 1 downto 0 do - (f := Fp12.(!f * !f * line_function !t !t pt)); - (t := G2.(!t + !t)); - if ci.(i) = 1 then ( - (f := Fp12.(!f * line_function !t q pt)); - t := G2.(!t + q)) - else if ci.(i) = -1 then ( - (f := Fp12.(!f * line_function !t G2.(~-q) pt)); - t := G2.(!t - q)) - done; - f := Fp12.(pow !f Z.(((pow p k) - one) / r)); - !f - in - miller_loop () - -(* https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-pairing-friendly-curves-11#name-test-vectors-of-optimal-ate *) -let test_vector () = - Alcotest.(check Primitives.Testables.fp12) - "equals" - (Primitives.Literals.fp12 - [| - "0x11619b45f61edfe3b47a15fac19442526ff489dcda25e59121d9931438907dfd448299a87dde3a649bdba96e84d54558"; - "0x153ce14a76a53e205ba8f275ef1137c56a566f638b52d34ba3bf3bf22f277d70f76316218c0dfd583a394b8448d2be7f"; - "0x095668fb4a02fe930ed44767834c915b283b1c6ca98c047bd4c272e9ac3f3ba6ff0b05a93e59c71fba77bce995f04692"; - "0x16deedaa683124fe7260085184d88f7d036b86f53bb5b7f1fc5e248814782065413e7d958d17960109ea006b2afdeb5f"; - "0x09c92cf02f3cd3d2f9d34bc44eee0dd50314ed44ca5d30ce6a9ec0539be7a86b121edc61839ccc908c4bdde256cd6048"; - "0x111061f398efc2a97ff825b04d21089e24fd8b93a47e41e60eae7e9b2a38d54fa4dedced0811c34ce528781ab9e929c7"; - "0x01ecfcf31c86257ab00b4709c33f1c9c4e007659dd5ffc4a735192167ce197058cfb4c94225e7f1b6c26ad9ba68f63bc"; - "0x08890726743a1f94a8193a166800b7787744a8ad8e2f9365db76863e894b7a11d83f90d873567e9d645ccf725b32d26f"; - "0x0e61c752414ca5dfd258e9606bac08daec29b3e2c57062669556954fb227d3f1260eedf25446a086b0844bcd43646c10"; - "0x0fe63f185f56dd29150fc498bbeea78969e7e783043620db33f75a05a0a2ce5c442beaff9da195ff15164c00ab66bdde"; - "0x10900338a92ed0b47af211636f7cfdec717b7ee43900eee9b5fc24f0000c5874d4801372db478987691c566a8c474978"; - "0x1454814f3085f0e6602247671bc408bbce2007201536818c901dbd4d2095dd86c1ec8b888e59611f60a301af7776be3d"; - |]) - (reference_pairing - (f1 - ( "0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb", - "0x08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1" - )) - (f2 - ( [| - "0x024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8"; - "0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e"; - |], - [| - "0x0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801"; - "0x0606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be"; - |] ))) - let test_bilinearity () = let a = Z.of_string @@ -274,37 +95,6 @@ let tests = [ test_case "Generator" `Slow test_generator; test_case "Pairing" `Slow test_pairing; - test_case "Vector" `Slow test_vector; test_case "Bilinearity" `Slow test_bilinearity; test_case "Inverse" `Slow test_inverse; ] - -(* - - 2675223149320665921521646202693247640790817874364255298732398972560239127864099887300921329285059103920214926247256 - 3268798540077874559188095304926415053902298079662269128631117894259354335713488241073281881110999874366368799440511 - 1437178847597838002205538891928304392505606959215308674013885606166925907773842499174371404735625830937323828692626 - 3520140447471844017044610248175793726488927385800919015247604269617056365166670232096113218155158979455637700602719 - 1506178926806320088529997600140680210913802140271006315226533143967895395199677036726919792764738011159067846598728 - 2626389147790168154036854297373352480470342009417426750876875476996308393122833154115295241935326582225976246741447 - 296397698419227591881949966489408966385204245298227609919201225879400018157857419730816679383241778672627140748220 - 1313697571675342986569886099636226306168713170654435514582366343380736958596157600562325204551377354604385651577455 - 2213584337862344967755109385575965635901738814384224456257761298779336140589044234514789656471272705700109501099024 - 2447141669618865772796042211991982778148438817099153092725275403399894819927527860344663177024354496855213527711198 - 2549209626480291013679779981989983528616421847439035724344204595297044667359758911489614886787335613326952862534008 - 3129088482270901242825355060993467433985308559466438813154852238956177342064351887308381291879994227300431734160957 - - 3408834164464458755751340723502736743445402614640994055433339214424916442641449510670327077303074893591740399366532 - 2985109681965551998729853692589086816773373894582799980668893018622694710052537683611179103960880088106135761730552 - 1919447955347661378578718469488414822573562393353397544098339472673901193098010131520945815709482515519580400649694 - 3768852223465146588376856999319887014310182817224079248864544031503472971152354238612814108575933872882790245947613 - 2882199334237819327910933128503231887000342950792587449681715803095618652567681747054312179958427092970985872417068 - 3422530699431057164272214746732420251187996107911604796521410492464898975786244888623921224036357050064415400932838 - 3268798540077874559188095304926415053902298079662269128631117894259354335713488241073281881110999874366368799440511 -X 1313697571675342986569886099636226306168713170654435514582366343380736958596157600562325204551377354604385651577455 - 3520140447471844017044610248175793726488927385800919015247604269617056365166670232096113218155158979455637700602719 -X 2447141669618865772796042211991982778148438817099153092725275403399894819927527860344663177024354496855213527711198 - 2626389147790168154036854297373352480470342009417426750876875476996308393122833154115295241935326582225976246741447 -X 3129088482270901242825355060993467433985308559466438813154852238956177342064351887308381291879994227300431734160957 - - *) |
