package octez-libs

  1. Overview
  2. Docs
A package that contains multiple base libraries used by the Octez suite

Install

Dune Dependency

Authors

Maintainers

Sources

tezos-18.1.tar.gz
sha256=aa2f5bc99cc4ca2217c52a1af2a2cdfd3b383208cb859ca2e79ca0903396ca1d
sha512=d68bb3eb615e3dcccc845fddfc9901c95b3c6dc8e105e39522ce97637b1308a7fa7aa1d271351d5933febd7476b2819e1694f31198f1f0919681f1f9cc97cb3a

doc/src/octez-libs.mec/bls12_381_ref.ml.html

Source file bls12_381_ref.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
(**
  The equation of G1 is x^3 + 4 = y^2
*)

module Fq = Ff.MakeFp (struct
  let prime_order =
    (* 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787 in decimal *)
    Z.of_string
      "0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab"
end)

module Fp = Ff.MakeFp (struct
  let prime_order =
    Z.of_string
      "0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001"
end)

module G1 = struct
  module Projective =
    Ec.MakeProjectiveWeierstrass (Fq) (Fp)
      (struct
        let a = Fq.zero

        let b = Fq.of_string "4"

        (* See https://github.com/zkcrypto/bls12_381/blob/main/src/notes/design.rs
           The value has been obtained by running the following code in SAGE
           ```
           def g1_h(x):
           	 return ((x-1)**2) // 3
           param = -0xd201000000010000
           g1_h(param)
           ```
        *)
        let cofactor = Z.of_string "76329603384216526031706109802092473003"

        (*
           https://github.com/zkcrypto/bls12_381/blob/main/src/g1.rs#L572
           ```
           x: Fp::from_raw_unchecked([
                0x5cb3_8790_fd53_0c16,
                0x7817_fc67_9976_fff5,
                0x154f_95c7_143b_a1c1,
                0xf0ae_6acd_f3d0_e747,
                0xedce_6ecc_21db_f440,
                0x1201_7741_9e0b_fb75,
            ]),
            y: Fp::from_raw_unchecked([
                0xbaac_93d5_0ce7_2271,
                0x8c22_631a_7918_fd8e,
                0xdd59_5f13_5707_25ce,
                0x51ac_5829_5040_5194,
                0x0e1c_8c3f_ad00_59c0,
                0x0bbc_3efc_5008_a26a,
            ]),
            z: Fp::one(),
            ```
            Using decimal representation, computed using
            ```
            Z.(to_string (of_string "0x..."))
            ```
        *)
        let bytes_generator =
          Bytes.concat
            Bytes.empty
            [
              Fq.(
                to_bytes
                  (of_string
                     "3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507"));
              Fq.(
                to_bytes
                  (of_string
                     "1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569"));
              Fq.(to_bytes one);
            ]
      end)

  module Affine =
    Ec.MakeAffineWeierstrass (Fq) (Fp)
      (struct
        let a = Fq.zero

        let b = Fq.of_string "4"

        (* See https://github.com/zkcrypto/bls12_381/blob/main/src/notes/design.rs
           The value has been obtained by running the following code in SAGE
           ```
           def g1_h(x):
           	 return ((x-1)**2) // 3
           param = -0xd201000000010000
           g1_h(param)
           ```
        *)
        let cofactor = Z.of_string "76329603384216526031706109802092473003"

        (*
           https://github.com/zkcrypto/bls12_381/blob/main/src/g1.rs#L572
           ```
           x: Fp::from_raw_unchecked([
                0x5cb3_8790_fd53_0c16,
                0x7817_fc67_9976_fff5,
                0x154f_95c7_143b_a1c1,
                0xf0ae_6acd_f3d0_e747,
                0xedce_6ecc_21db_f440,
                0x1201_7741_9e0b_fb75,
            ]),
            y: Fp::from_raw_unchecked([
                0xbaac_93d5_0ce7_2271,
                0x8c22_631a_7918_fd8e,
                0xdd59_5f13_5707_25ce,
                0x51ac_5829_5040_5194,
                0x0e1c_8c3f_ad00_59c0,
                0x0bbc_3efc_5008_a26a,
            ]),
            ```
            Using decimal representation, computed using
            ```
            Z.(to_string (of_string "0x..."))
            ```
        *)
        let bytes_generator =
          Bytes.concat
            Bytes.empty
            [
              Fq.(
                to_bytes
                  (of_string
                     "3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507"));
              Fq.(
                to_bytes
                  (of_string
                     "1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569"));
            ]
      end)
end

module Fq2 =
  Ff.MakeFp2
    (Fq)
    (struct
      let nsr = Fq.of_string "4"
    end)

(* TODO: require to implement sqrt_opt for Fq2. Not yet available in ocaml-ff *)

(* module G2 = struct
 *   module Projective =
 *     Ec.MakeProjectiveWeierstrass (Fq2) (Fp)
 *       (struct
 *         let a = Fq2.zero
 * 
 *         let b = Fq2.of_string "4"
 * 
 *         let cofactor =
 *           Z.of_string_base
 *             16
 *             "5d543a95414e7f1091d50792876a202cd91de4547085abaa68a205b2e5a7ddfa628f1cb4d9e82ef21537e293a6691ae1616ec6e786f0c70cf1c38e31c7238e5"
 * 
 *         (\*
 *            https://github.com/zkcrypto/bls12_381/blob/main/src/g1.rs#L572
 *            ```
 *            x: Fp::from_raw_unchecked([
 *                 0x5cb3_8790_fd53_0c16,
 *                 0x7817_fc67_9976_fff5,
 *                 0x154f_95c7_143b_a1c1,
 *                 0xf0ae_6acd_f3d0_e747,
 *                 0xedce_6ecc_21db_f440,
 *                 0x1201_7741_9e0b_fb75,
 *             ]),
 *             y: Fp::from_raw_unchecked([
 *                 0xbaac_93d5_0ce7_2271,
 *                 0x8c22_631a_7918_fd8e,
 *                 0xdd59_5f13_5707_25ce,
 *                 0x51ac_5829_5040_5194,
 *                 0x0e1c_8c3f_ad00_59c0,
 *                 0x0bbc_3efc_5008_a26a,
 *             ]),
 *             z: Fp::one(),
 *             ```
 *             Using decimal representation, computed using
 *             ```
 *             Z.(to_string (of_string "0x..."))
 *             ```
 *         *\)
 *         let bytes_generator =
 *           Bytes.concat
 *             Bytes.empty
 *             [ Fq.(
 *                 to_bytes
 *                   (of_string
 *                      "3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507"));
 *               Fq.(
 *                 to_bytes
 *                   (of_string
 *                      "1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569"));
 *               Fq.(to_bytes one) ]
 *       end)
 * 
 *   module Affine =
 *     Ec.MakeAffineWeierstrass (Fq2) (Fp)
 *       (struct
 *         let a = Fq2.zero
 * 
 *         let b = Fq2.of_string "4"
 * 
 *         let cofactor =
 *           Z.of_string_base
 *             16
 *             "5d543a95414e7f1091d50792876a202cd91de4547085abaa68a205b2e5a7ddfa628f1cb4d9e82ef21537e293a6691ae1616ec6e786f0c70cf1c38e31c7238e5"
 * 
 *         let bytes_generator =
 *           Bytes.concat
 *             Bytes.empty
 *             [ Fq.(
 *                 to_bytes
 *                   (of_string
 *                      "3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507"));
 *               Fq.(
 *                 to_bytes
 *                   (of_string
 *                      "1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569"))
 *             ]
 *       end)
 * end *)
OCaml

Innovation. Community. Security.