frontend/worldcoin_mpc/
parameters.rs

1use shared_types::Fr;
2
3/// The dimension of the encoding matrix (row)
4pub const ENCODING_MATRIX_NUM_VARS_ROWS: usize = 2;
5/// The dimension of the encoding matrix (column)
6pub const ENCODING_MATRIX_NUM_VARS_COLS: usize = 2;
7
8/// The modulo of the ring Z/2^16Z (used for our galois ring GR4)
9pub const GR4_MODULUS: u64 = 65536;
10
11/// The number of parties that we are secret sharing over
12pub const NUM_PARTIES: usize = 3;
13
14/// The number of bits of the element in the ring Z/2^16Z
15pub const GR4_ELEM_BIT_LENGTH: u64 = 16;
16
17/// The number of 4 chunks in the iris/mask code for one eye
18/// the number of 16384 comes from: 3200 -> padding -> 4096 * 4 = 16384
19pub const MPC_NUM_IRIS_4_CHUNKS: usize = 16384 / 4;
20
21/// The actual encoding matrix
22/// It's a square matrix, meaning the size of it is 2^(ENCODING_MATRIX_NUM_VARS)^2
23/// a.k.a. 2^(ENCODING_MATRIX_NUM_VARS*2)
24/// a little hack to use from_raw to make sure this encoding matrix can be declared
25/// as a const
26pub const ENCODING_MATRIX: [Fr; 1
27    << (ENCODING_MATRIX_NUM_VARS_ROWS + ENCODING_MATRIX_NUM_VARS_COLS)] = [
28    Fr::one(),
29    Fr::zero(),
30    Fr::zero(),
31    Fr::zero(),
32    Fr::from_raw([58082, 0, 0, 0]),
33    Fr::one(),
34    Fr::zero(),
35    Fr::zero(),
36    Fr::from_raw([60579, 0, 0, 0]),
37    Fr::from_raw([25194, 0, 0, 0]),
38    Fr::one(),
39    Fr::zero(),
40    Fr::from_raw([17325, 0, 0, 0]),
41    Fr::from_raw([51956, 0, 0, 0]),
42    Fr::from_raw([57011, 0, 0, 0]),
43    Fr::one(),
44];
45
46/// The actual encoding matrix, but in u64
47pub const ENCODING_MATRIX_U64: [u64; 1
48    << (ENCODING_MATRIX_NUM_VARS_ROWS + ENCODING_MATRIX_NUM_VARS_COLS)] = [
49    1, 0, 0, 0, 58082, 1, 0, 0, 60579, 25194, 1, 0, 17325, 51956, 57011, 1,
50];
51
52/// The actual encoding matrix transposed, also in u64
53pub const ENCODING_MATRIX_U64_TRANSPOSE: [u64; 1
54    << (ENCODING_MATRIX_NUM_VARS_ROWS + ENCODING_MATRIX_NUM_VARS_COLS)] = [
55    1, 58082, 60579, 17325, 0, 1, 25194, 51956, 0, 0, 1, 57011, 0, 0, 0, 1,
56];
57
58/// The number of wirings for the galois ring GR4 multiplication
59/// GR4: GR(2^16, 4) is a Galois extension of Z/2^16Z over the monic
60/// polynomial x^4 - x - 1
61/// The formula for multiplying two GR4 ring elements is:
62/// say a = a0, a1, a2, a3
63/// and b = b0, b1, b2, b3
64/// then a * b = [ a3*b1 + a2*b2 + a1*b3 + a0*b0,
65///                a3*b2 + a2*b3 + a3*b1 + a2*b2 + a1*b3 + a1*b0 + a0*b1,
66///                a3*b3 + a3*b2 + a2*b3 + a2*b0 + a1*b1 + a0*b2,
67///                a3*b3 + a3*b0 + a2*b1 + a1*b2 + a0*b3]
68/// Thus, the number of wirings for each coefficient is: sum(4, 7, 6, 5) = 22
69pub const GR4_NUM_WIRINGS: usize = 22;
70
71/// The actual wirings for the galois ring GR4 multiplication
72pub const GR4_MULTIPLICATION_WIRINGS: [(u32, u32, u32); GR4_NUM_WIRINGS] = [
73    // a*b[0]
74    (0, 0, 0),
75    (0, 1, 3),
76    (0, 2, 2),
77    (0, 3, 1),
78    // a*b[1]
79    (1, 0, 1),
80    (1, 1, 0),
81    (1, 1, 3),
82    (1, 2, 2),
83    (1, 3, 1),
84    (1, 2, 3),
85    (1, 3, 2),
86    // a*b[2]
87    (2, 0, 2),
88    (2, 1, 1),
89    (2, 2, 0),
90    (2, 2, 3),
91    (2, 3, 2),
92    (2, 3, 3),
93    // a*b[4]
94    (3, 0, 3),
95    (3, 1, 2),
96    (3, 2, 1),
97    (3, 3, 0),
98    (3, 3, 3),
99];
100
101/// The actual evaluation points used by the three parties
102/// They are 1, x, 1 + x
103pub const EVALUATION_POINTS_U64: [[u64; 4]; 3] = [[1, 0, 0, 0], [0, 1, 0, 0], [1, 1, 0, 0]];
104
105/// Test data given by Inversed.
106/// Because they give only the masked iris codes, we need to generate random iris codes, and
107/// calculate the corresponding mask codes to produce their masked iris codes.
108pub const TEST_MASKED_IRIS_CODES: [[u64; 4]; 20] = [
109    [0, 0, 1, 1],
110    [0, 1, 65535, 0],
111    [65535, 1, 0, 0],
112    [0, 0, 1, 1],
113    [1, 1, 0, 0],
114    [0, 65535, 1, 1],
115    [1, 0, 0, 0],
116    [1, 0, 1, 1],
117    [0, 1, 1, 65535],
118    [0, 0, 0, 1],
119    [65535, 65535, 0, 0],
120    [1, 1, 0, 1],
121    [0, 0, 1, 0],
122    [1, 0, 0, 0],
123    [1, 0, 0, 0],
124    [65535, 1, 1, 1],
125    [1, 0, 0, 1],
126    [1, 65535, 0, 0],
127    [0, 1, 0, 0],
128    [0, 65535, 0, 0],
129];
130
131/// Test data given by Inversed.
132/// These are the result of encoding the masked iris code quadruplets into a GR4 element
133pub const TEST_GR4_ELEMENTS: [[u64; 4]; 20] = [
134    [0, 0, 1, 57012],
135    [0, 1, 25193, 60481],
136    [65535, 7455, 30151, 34631],
137    [0, 0, 1, 57012],
138    [1, 58083, 20237, 3745],
139    [0, 65535, 40343, 5056],
140    [1, 58082, 60579, 17325],
141    [1, 58082, 60580, 8801],
142    [0, 1, 25195, 43430],
143    [0, 0, 0, 1],
144    [65535, 7453, 45299, 61791],
145    [1, 58083, 20237, 3746],
146    [0, 0, 1, 57011],
147    [1, 58082, 60579, 17325],
148    [1, 58082, 60579, 17325],
149    [65535, 7455, 30152, 26107],
150    [1, 58082, 60579, 17326],
151    [1, 58081, 35385, 30905],
152    [0, 1, 25194, 51956],
153    [0, 65535, 40342, 13580],
154];
155
156/// Test data given by Inversed.
157/// These represents the slopes of the one degree polynomial that encodes
158/// the secret shares.
159pub const TEST_RANDOMNESSES: [[u64; 4]; 20] = [
160    [62791, 4515, 39759, 11512],
161    [36426, 12484, 23448, 55897],
162    [8790, 45739, 57847, 1581],
163    [28451, 64021, 7347, 60655],
164    [60790, 59010, 16989, 23542],
165    [19979, 8251, 55079, 46499],
166    [61291, 64096, 12598, 40943],
167    [62320, 28246, 40494, 33118],
168    [61171, 64822, 29618, 2235],
169    [46726, 22873, 29045, 1091],
170    [10943, 58396, 27495, 9620],
171    [13950, 36926, 41062, 21391],
172    [22845, 50864, 2278, 14600],
173    [40492, 7720, 50764, 49223],
174    [64506, 20573, 50634, 7478],
175    [46864, 56026, 58160, 58665],
176    [13565, 42432, 52136, 11986],
177    [21898, 26161, 4811, 24926],
178    [465, 13962, 3685, 38102],
179    [61856, 254, 16676, 4017],
180];
181
182/// Test data given by Inversed.
183/// These represents the expected shares for each of the three parties
184pub const TEST_SHARES: [[[u64; 4]; 20]; 3] = [
185    [
186        [62791, 4515, 39760, 2988],
187        [36426, 12485, 48641, 50842],
188        [8789, 53194, 22462, 36212],
189        [28451, 64021, 7348, 52131],
190        [60791, 51557, 37226, 27287],
191        [19979, 8250, 29886, 51555],
192        [61292, 56642, 7641, 58268],
193        [62321, 20792, 35538, 41919],
194        [61171, 64823, 54813, 45665],
195        [46726, 22873, 29045, 1092],
196        [10942, 313, 7258, 5875],
197        [13951, 29473, 61299, 25137],
198        [22845, 50864, 2279, 6075],
199        [40493, 266, 45807, 1012],
200        [64507, 13119, 45677, 24803],
201        [46863, 63481, 22776, 19236],
202        [13566, 34978, 47179, 29312],
203        [21899, 18706, 40196, 55831],
204        [465, 13963, 28879, 24522],
205        [61856, 253, 57018, 17597],
206    ],
207    [
208        [11512, 8767, 4516, 31235],
209        [55897, 26788, 37677, 18393],
210        [1580, 17826, 10354, 26942],
211        [60655, 23570, 64022, 64359],
212        [23543, 11343, 13711, 20734],
213        [46499, 941, 48594, 60135],
214        [40944, 29244, 59139, 29923],
215        [33119, 22448, 23290, 49295],
216        [2235, 63407, 24481, 7512],
217        [1091, 47817, 22873, 29046],
218        [9619, 28016, 38159, 23750],
219        [21392, 27888, 57163, 44808],
220        [14600, 37445, 50865, 59289],
221        [49224, 16725, 2763, 2553],
222        [7479, 64530, 15616, 2423],
223        [58664, 47448, 20642, 18731],
224        [11987, 18097, 37475, 3926],
225        [24927, 39369, 61546, 35716],
226        [38102, 38568, 39156, 55641],
227        [4017, 336, 40596, 30256],
228    ],
229    [
230        [8767, 13282, 44275, 42747],
231        [26787, 39272, 61125, 8754],
232        [10370, 63565, 2665, 28523],
233        [23570, 22055, 5833, 59478],
234        [18797, 4817, 30700, 44276],
235        [942, 9192, 38137, 41098],
236        [36699, 27804, 6201, 5330],
237        [29903, 50694, 63784, 16877],
238        [63406, 62693, 54099, 9747],
239        [47817, 5154, 51918, 30137],
240        [20562, 20876, 118, 33370],
241        [35342, 64814, 32689, 663],
242        [37445, 22773, 53143, 8353],
243        [24180, 24445, 53527, 51776],
244        [6449, 19567, 714, 9901],
245        [39992, 37938, 13266, 11860],
246        [25552, 60529, 24075, 15912],
247        [46825, 65530, 821, 60642],
248        [38567, 52530, 42841, 28207],
249        [337, 590, 57272, 34273],
250    ],
251];