server.rs 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  1. #[cfg(target_feature = "avx2")]
  2. use std::arch::x86_64::*;
  3. use std::fs::File;
  4. use std::io::BufReader;
  5. use std::io::Read;
  6. use std::io::Seek;
  7. use std::io::SeekFrom;
  8. use std::time::Instant;
  9. use crate::aligned_memory::*;
  10. use crate::arith::*;
  11. use crate::client::PublicParameters;
  12. use crate::client::Query;
  13. use crate::gadget::*;
  14. use crate::params::*;
  15. use crate::poly::*;
  16. use crate::util::*;
  17. use rayon::prelude::*;
  18. pub fn coefficient_expansion(
  19. v: &mut Vec<PolyMatrixNTT>,
  20. g: usize,
  21. stop_round: usize,
  22. params: &Params,
  23. v_w_left: &Vec<PolyMatrixNTT>,
  24. v_w_right: &Vec<PolyMatrixNTT>,
  25. v_neg1: &Vec<PolyMatrixNTT>,
  26. max_bits_to_gen_right: usize,
  27. ) {
  28. let poly_len = params.poly_len;
  29. for r in 0..g {
  30. let num_in = 1 << r;
  31. let num_out = 2 * num_in;
  32. let t = (poly_len / (1 << r)) + 1;
  33. let neg1 = &v_neg1[r];
  34. let action_expand = |(i, v_i): (usize, &mut PolyMatrixNTT)| {
  35. if (stop_round > 0 && r > stop_round && (i % 2) == 1)
  36. || (stop_round > 0
  37. && r == stop_round
  38. && (i % 2) == 1
  39. && (i / 2) >= max_bits_to_gen_right)
  40. {
  41. return;
  42. }
  43. let mut ct = PolyMatrixRaw::zero(params, 2, 1);
  44. let mut ct_auto = PolyMatrixRaw::zero(params, 2, 1);
  45. let mut ct_auto_1 = PolyMatrixRaw::zero(params, 1, 1);
  46. let mut ct_auto_1_ntt = PolyMatrixNTT::zero(params, 1, 1);
  47. let mut w_times_ginv_ct = PolyMatrixNTT::zero(params, 2, 1);
  48. let mut ginv_ct_left = PolyMatrixRaw::zero(params, params.t_exp_left, 1);
  49. let mut ginv_ct_left_ntt = PolyMatrixNTT::zero(params, params.t_exp_left, 1);
  50. let mut ginv_ct_right = PolyMatrixRaw::zero(params, params.t_exp_right, 1);
  51. let mut ginv_ct_right_ntt = PolyMatrixNTT::zero(params, params.t_exp_right, 1);
  52. let (w, _gadget_dim, gi_ct, gi_ct_ntt) = match (r != 0) && (i % 2 == 0) {
  53. true => (
  54. &v_w_left[r],
  55. params.t_exp_left,
  56. &mut ginv_ct_left,
  57. &mut ginv_ct_left_ntt,
  58. ),
  59. false => (
  60. &v_w_right[r],
  61. params.t_exp_right,
  62. &mut ginv_ct_right,
  63. &mut ginv_ct_right_ntt,
  64. ),
  65. };
  66. // if i < num_in {
  67. // let (src, dest) = v.split_at_mut(num_in);
  68. // scalar_multiply(&mut dest[i], neg1, &src[i]);
  69. // }
  70. from_ntt(&mut ct, &v_i);
  71. automorph(&mut ct_auto, &ct, t);
  72. gadget_invert_rdim(gi_ct, &ct_auto, 1);
  73. to_ntt_no_reduce(gi_ct_ntt, &gi_ct);
  74. ct_auto_1
  75. .data
  76. .as_mut_slice()
  77. .copy_from_slice(ct_auto.get_poly(1, 0));
  78. to_ntt(&mut ct_auto_1_ntt, &ct_auto_1);
  79. multiply(&mut w_times_ginv_ct, w, &gi_ct_ntt);
  80. let mut idx = 0;
  81. for j in 0..2 {
  82. for n in 0..params.crt_count {
  83. for z in 0..poly_len {
  84. let sum = (*v_i).data[idx]
  85. + w_times_ginv_ct.data[idx]
  86. + j * ct_auto_1_ntt.data[n * poly_len + z];
  87. (*v_i).data[idx] = barrett_coeff_u64(params, sum, n);
  88. idx += 1;
  89. }
  90. }
  91. }
  92. };
  93. let (src, dest) = v.split_at_mut(num_in);
  94. src.par_iter_mut()
  95. .zip(dest.par_iter_mut())
  96. .for_each(|(s, d)| {
  97. scalar_multiply(d, neg1, s);
  98. });
  99. v[0..num_in]
  100. .par_iter_mut()
  101. .enumerate()
  102. .for_each(action_expand);
  103. v[num_in..num_out]
  104. .par_iter_mut()
  105. .enumerate()
  106. .for_each(action_expand);
  107. }
  108. }
  109. pub fn regev_to_gsw<'a>(
  110. v_gsw: &mut Vec<PolyMatrixNTT<'a>>,
  111. v_inp: &Vec<PolyMatrixNTT<'a>>,
  112. v: &PolyMatrixNTT<'a>,
  113. params: &'a Params,
  114. idx_factor: usize,
  115. idx_offset: usize,
  116. ) {
  117. assert!(v.rows == 2);
  118. assert!(v.cols == 2 * params.t_conv);
  119. v_gsw.par_iter_mut().enumerate().for_each(|(i, ct)| {
  120. let mut ginv_c_inp = PolyMatrixRaw::zero(params, 2 * params.t_conv, 1);
  121. let mut ginv_c_inp_ntt = PolyMatrixNTT::zero(params, 2 * params.t_conv, 1);
  122. let mut tmp_ct_raw = PolyMatrixRaw::zero(params, 2, 1);
  123. let mut tmp_ct = PolyMatrixNTT::zero(params, 2, 1);
  124. for j in 0..params.t_gsw {
  125. let idx_ct = i * params.t_gsw + j;
  126. let idx_inp = idx_factor * (idx_ct) + idx_offset;
  127. ct.copy_into(&v_inp[idx_inp], 0, 2 * j + 1);
  128. from_ntt(&mut tmp_ct_raw, &v_inp[idx_inp]);
  129. gadget_invert(&mut ginv_c_inp, &tmp_ct_raw);
  130. to_ntt(&mut ginv_c_inp_ntt, &ginv_c_inp);
  131. multiply(&mut tmp_ct, v, &ginv_c_inp_ntt);
  132. ct.copy_into(&tmp_ct, 0, 2 * j);
  133. }
  134. });
  135. }
  136. pub const MAX_SUMMED: usize = 1 << 6;
  137. pub const PACKED_OFFSET_2: i32 = 32;
  138. #[cfg(target_feature = "avx2")]
  139. pub fn multiply_reg_by_database(
  140. out: &mut Vec<PolyMatrixNTT>,
  141. db: &[u64],
  142. v_firstdim: &[u64],
  143. params: &Params,
  144. dim0: usize,
  145. num_per: usize,
  146. ) {
  147. let ct_rows = 2;
  148. let ct_cols = 1;
  149. let pt_rows = 1;
  150. let pt_cols = 1;
  151. // assert!(dim0 * ct_rows >= MAX_SUMMED);
  152. let mut sums_out_n0_u64 = AlignedMemory64::new(4);
  153. let mut sums_out_n2_u64 = AlignedMemory64::new(4);
  154. for z in 0..params.poly_len {
  155. let idx_a_base = z * (ct_cols * dim0 * ct_rows);
  156. let mut idx_b_base = z * (num_per * pt_cols * dim0 * pt_rows);
  157. for i in 0..num_per {
  158. for c in 0..pt_cols {
  159. let mut inner_limit = MAX_SUMMED;
  160. let mut outer_limit = dim0 * ct_rows / inner_limit;
  161. if MAX_SUMMED > dim0 * ct_rows {
  162. inner_limit = dim0 * ct_rows;
  163. outer_limit = 1;
  164. }
  165. let mut sums_out_n0_u64_acc = [0u64, 0, 0, 0];
  166. let mut sums_out_n2_u64_acc = [0u64, 0, 0, 0];
  167. for o_jm in 0..outer_limit {
  168. unsafe {
  169. let mut sums_out_n0 = _mm256_setzero_si256();
  170. let mut sums_out_n2 = _mm256_setzero_si256();
  171. for i_jm in 0..inner_limit / 4 {
  172. let jm = o_jm * inner_limit + (4 * i_jm);
  173. let b_inp_1 = *db.get_unchecked(idx_b_base) as i64;
  174. idx_b_base += 1;
  175. let b_inp_2 = *db.get_unchecked(idx_b_base) as i64;
  176. idx_b_base += 1;
  177. let b = _mm256_set_epi64x(b_inp_2, b_inp_2, b_inp_1, b_inp_1);
  178. let v_a = v_firstdim.get_unchecked(idx_a_base + jm) as *const u64;
  179. let a = _mm256_load_si256(v_a as *const __m256i);
  180. let a_lo = a;
  181. let a_hi_hi = _mm256_srli_epi64(a, PACKED_OFFSET_2);
  182. let b_lo = b;
  183. let b_hi_hi = _mm256_srli_epi64(b, PACKED_OFFSET_2);
  184. sums_out_n0 =
  185. _mm256_add_epi64(sums_out_n0, _mm256_mul_epu32(a_lo, b_lo));
  186. sums_out_n2 =
  187. _mm256_add_epi64(sums_out_n2, _mm256_mul_epu32(a_hi_hi, b_hi_hi));
  188. }
  189. // reduce here, otherwise we will overflow
  190. _mm256_store_si256(
  191. sums_out_n0_u64.as_mut_ptr() as *mut __m256i,
  192. sums_out_n0,
  193. );
  194. _mm256_store_si256(
  195. sums_out_n2_u64.as_mut_ptr() as *mut __m256i,
  196. sums_out_n2,
  197. );
  198. for idx in 0..4 {
  199. let val = sums_out_n0_u64[idx];
  200. sums_out_n0_u64_acc[idx] =
  201. barrett_coeff_u64(params, val + sums_out_n0_u64_acc[idx], 0);
  202. }
  203. for idx in 0..4 {
  204. let val = sums_out_n2_u64[idx];
  205. sums_out_n2_u64_acc[idx] =
  206. barrett_coeff_u64(params, val + sums_out_n2_u64_acc[idx], 1);
  207. }
  208. }
  209. }
  210. for idx in 0..4 {
  211. sums_out_n0_u64_acc[idx] =
  212. barrett_coeff_u64(params, sums_out_n0_u64_acc[idx], 0);
  213. sums_out_n2_u64_acc[idx] =
  214. barrett_coeff_u64(params, sums_out_n2_u64_acc[idx], 1);
  215. }
  216. // output n0
  217. let (crt_count, poly_len) = (params.crt_count, params.poly_len);
  218. let mut n = 0;
  219. let mut idx_c = c * (crt_count * poly_len) + n * (poly_len) + z;
  220. out[i].data[idx_c] =
  221. barrett_coeff_u64(params, sums_out_n0_u64_acc[0] + sums_out_n0_u64_acc[2], 0);
  222. idx_c += pt_cols * crt_count * poly_len;
  223. out[i].data[idx_c] =
  224. barrett_coeff_u64(params, sums_out_n0_u64_acc[1] + sums_out_n0_u64_acc[3], 0);
  225. // output n1
  226. n = 1;
  227. idx_c = c * (crt_count * poly_len) + n * (poly_len) + z;
  228. out[i].data[idx_c] =
  229. barrett_coeff_u64(params, sums_out_n2_u64_acc[0] + sums_out_n2_u64_acc[2], 1);
  230. idx_c += pt_cols * crt_count * poly_len;
  231. out[i].data[idx_c] =
  232. barrett_coeff_u64(params, sums_out_n2_u64_acc[1] + sums_out_n2_u64_acc[3], 1);
  233. }
  234. }
  235. }
  236. }
  237. #[cfg(not(target_feature = "avx2"))]
  238. pub fn multiply_reg_by_database(
  239. out: &mut Vec<PolyMatrixNTT>,
  240. db: &[u64],
  241. v_firstdim: &[u64],
  242. params: &Params,
  243. dim0: usize,
  244. num_per: usize,
  245. ) {
  246. let ct_rows = 2;
  247. let ct_cols = 1;
  248. let pt_rows = 1;
  249. let pt_cols = 1;
  250. for z in 0..params.poly_len {
  251. let idx_a_base = z * (ct_cols * dim0 * ct_rows);
  252. let mut idx_b_base = z * (num_per * pt_cols * dim0 * pt_rows);
  253. for i in 0..num_per {
  254. for c in 0..pt_cols {
  255. let mut sums_out_n0_0 = 0u128;
  256. let mut sums_out_n0_1 = 0u128;
  257. let mut sums_out_n1_0 = 0u128;
  258. let mut sums_out_n1_1 = 0u128;
  259. for jm in 0..(dim0 * pt_rows) {
  260. let b = db[idx_b_base];
  261. idx_b_base += 1;
  262. let v_a0 = v_firstdim[idx_a_base + jm * ct_rows];
  263. let v_a1 = v_firstdim[idx_a_base + jm * ct_rows + 1];
  264. let b_lo = b as u32;
  265. let b_hi = (b >> 32) as u32;
  266. let v_a0_lo = v_a0 as u32;
  267. let v_a0_hi = (v_a0 >> 32) as u32;
  268. let v_a1_lo = v_a1 as u32;
  269. let v_a1_hi = (v_a1 >> 32) as u32;
  270. // do n0
  271. sums_out_n0_0 += ((v_a0_lo as u64) * (b_lo as u64)) as u128;
  272. sums_out_n0_1 += ((v_a1_lo as u64) * (b_lo as u64)) as u128;
  273. // do n1
  274. sums_out_n1_0 += ((v_a0_hi as u64) * (b_hi as u64)) as u128;
  275. sums_out_n1_1 += ((v_a1_hi as u64) * (b_hi as u64)) as u128;
  276. }
  277. // output n0
  278. let (crt_count, poly_len) = (params.crt_count, params.poly_len);
  279. let mut n = 0;
  280. let mut idx_c = c * (crt_count * poly_len) + n * (poly_len) + z;
  281. out[i].data[idx_c] = (sums_out_n0_0 % (params.moduli[0] as u128)) as u64;
  282. idx_c += pt_cols * crt_count * poly_len;
  283. out[i].data[idx_c] = (sums_out_n0_1 % (params.moduli[0] as u128)) as u64;
  284. // output n1
  285. n = 1;
  286. idx_c = c * (crt_count * poly_len) + n * (poly_len) + z;
  287. out[i].data[idx_c] = (sums_out_n1_0 % (params.moduli[1] as u128)) as u64;
  288. idx_c += pt_cols * crt_count * poly_len;
  289. out[i].data[idx_c] = (sums_out_n1_1 % (params.moduli[1] as u128)) as u64;
  290. }
  291. }
  292. }
  293. }
  294. pub fn generate_random_db_and_get_item<'a>(
  295. params: &'a Params,
  296. item_idx: usize,
  297. ) -> (PolyMatrixRaw<'a>, AlignedMemory64) {
  298. let mut rng = get_seeded_rng();
  299. let instances = params.instances;
  300. let trials = params.n * params.n;
  301. let dim0 = 1 << params.db_dim_1;
  302. let num_per = 1 << params.db_dim_2;
  303. let num_items = dim0 * num_per;
  304. let db_size_words = instances * trials * num_items * params.poly_len;
  305. let mut v = AlignedMemory64::new(db_size_words);
  306. let mut item = PolyMatrixRaw::zero(params, params.instances * params.n, params.n);
  307. for instance in 0..instances {
  308. for trial in 0..trials {
  309. for i in 0..num_items {
  310. let ii = i % num_per;
  311. let j = i / num_per;
  312. let mut db_item = PolyMatrixRaw::random_rng(params, 1, 1, &mut rng);
  313. db_item.reduce_mod(params.pt_modulus);
  314. if i == item_idx {
  315. item.copy_into(&db_item, instance * params.n + trial / params.n, trial % params.n);
  316. }
  317. for z in 0..params.poly_len {
  318. db_item.data[z] =
  319. recenter_mod(db_item.data[z], params.pt_modulus, params.modulus);
  320. }
  321. let db_item_ntt = db_item.ntt();
  322. for z in 0..params.poly_len {
  323. let idx_dst = calc_index(
  324. &[instance, trial, z, ii, j],
  325. &[instances, trials, params.poly_len, num_per, dim0],
  326. );
  327. v[idx_dst] = db_item_ntt.data[z]
  328. | (db_item_ntt.data[params.poly_len + z] << PACKED_OFFSET_2);
  329. }
  330. }
  331. }
  332. }
  333. (item, v)
  334. }
  335. pub fn load_item_from_seek<'a, T: Seek + Read>(
  336. params: &'a Params,
  337. seekable: &mut T,
  338. instance: usize,
  339. trial: usize,
  340. item_idx: usize,
  341. ) -> PolyMatrixRaw<'a> {
  342. let db_item_size = params.db_item_size;
  343. let instances = params.instances;
  344. let trials = params.n * params.n;
  345. let chunks = instances * trials;
  346. let bytes_per_chunk = f64::ceil(db_item_size as f64 / chunks as f64) as usize;
  347. let logp = f64::ceil(f64::log2(params.pt_modulus as f64)) as usize;
  348. let modp_words_per_chunk = f64::ceil((bytes_per_chunk * 8) as f64 / logp as f64) as usize;
  349. assert!(modp_words_per_chunk <= params.poly_len);
  350. let idx_item_in_file = item_idx * db_item_size;
  351. let idx_chunk = instance * trials + trial;
  352. let idx_poly_in_file = idx_item_in_file + idx_chunk * bytes_per_chunk;
  353. let mut out = PolyMatrixRaw::zero(params, 1, 1);
  354. let seek_result = seekable.seek(SeekFrom::Start(idx_poly_in_file as u64));
  355. if seek_result.is_err() {
  356. return out;
  357. }
  358. let mut data = vec![0u8; 2 * bytes_per_chunk];
  359. let bytes_read = seekable
  360. .read(&mut data.as_mut_slice()[0..bytes_per_chunk])
  361. .unwrap();
  362. let modp_words_read = f64::ceil((bytes_read * 8) as f64 / logp as f64) as usize;
  363. assert!(modp_words_read <= params.poly_len);
  364. for i in 0..modp_words_read {
  365. out.data[i] = read_arbitrary_bits(&data, i * logp, logp);
  366. assert!(out.data[i] <= params.pt_modulus);
  367. }
  368. out
  369. }
  370. pub fn load_db_from_seek<T: Seek + Read>(params: &Params, seekable: &mut T) -> AlignedMemory64 {
  371. let instances = params.instances;
  372. let trials = params.n * params.n;
  373. let dim0 = 1 << params.db_dim_1;
  374. let num_per = 1 << params.db_dim_2;
  375. let num_items = dim0 * num_per;
  376. let db_size_words = instances * trials * num_items * params.poly_len;
  377. let mut v = AlignedMemory64::new(db_size_words);
  378. for instance in 0..instances {
  379. for trial in 0..trials {
  380. for i in 0..num_items {
  381. let ii = i % num_per;
  382. let j = i / num_per;
  383. let mut db_item = load_item_from_seek(params, seekable, instance, trial, i);
  384. // db_item.reduce_mod(params.pt_modulus);
  385. for z in 0..params.poly_len {
  386. db_item.data[z] =
  387. recenter_mod(db_item.data[z], params.pt_modulus, params.modulus);
  388. }
  389. let db_item_ntt = db_item.ntt();
  390. for z in 0..params.poly_len {
  391. let idx_dst = calc_index(
  392. &[instance, trial, z, ii, j],
  393. &[instances, trials, params.poly_len, num_per, dim0],
  394. );
  395. v[idx_dst] = db_item_ntt.data[z]
  396. | (db_item_ntt.data[params.poly_len + z] << PACKED_OFFSET_2);
  397. }
  398. }
  399. }
  400. }
  401. v
  402. }
  403. pub fn load_file_unsafe(data: &mut [u64], file: &mut File) {
  404. let data_as_u8_mut = unsafe { data.align_to_mut::<u8>().1 };
  405. file.read_exact(data_as_u8_mut).unwrap();
  406. }
  407. pub fn load_file(data: &mut [u64], file: &mut File) {
  408. let mut reader = BufReader::with_capacity(1 << 24, file);
  409. let mut buf = [0u8; 8];
  410. for i in 0..data.len() {
  411. reader.read(&mut buf).unwrap();
  412. data[i] = u64::from_ne_bytes(buf);
  413. }
  414. }
  415. pub fn load_preprocessed_db_from_file(params: &Params, file: &mut File) -> AlignedMemory64 {
  416. let instances = params.instances;
  417. let trials = params.n * params.n;
  418. let dim0 = 1 << params.db_dim_1;
  419. let num_per = 1 << params.db_dim_2;
  420. let num_items = dim0 * num_per;
  421. let db_size_words = instances * trials * num_items * params.poly_len;
  422. let mut v = AlignedMemory64::new(db_size_words);
  423. let v_mut_slice = v.as_mut_slice();
  424. let now = Instant::now();
  425. load_file(v_mut_slice, file);
  426. println!("Done loading ({} ms).", now.elapsed().as_millis());
  427. v
  428. }
  429. pub fn fold_ciphertexts(
  430. params: &Params,
  431. v_cts: &mut Vec<PolyMatrixRaw>,
  432. v_folding: &Vec<PolyMatrixNTT>,
  433. v_folding_neg: &Vec<PolyMatrixNTT>,
  434. ) {
  435. if v_cts.len() == 1 {
  436. return;
  437. }
  438. let further_dims = log2(v_cts.len() as u64) as usize;
  439. let ell = v_folding[0].cols / 2;
  440. let mut ginv_c = PolyMatrixRaw::zero(&params, 2 * ell, 1);
  441. let mut ginv_c_ntt = PolyMatrixNTT::zero(&params, 2 * ell, 1);
  442. let mut prod = PolyMatrixNTT::zero(&params, 2, 1);
  443. let mut sum = PolyMatrixNTT::zero(&params, 2, 1);
  444. let mut num_per = v_cts.len();
  445. for cur_dim in 0..further_dims {
  446. num_per = num_per / 2;
  447. for i in 0..num_per {
  448. gadget_invert(&mut ginv_c, &v_cts[i]);
  449. to_ntt(&mut ginv_c_ntt, &ginv_c);
  450. multiply(
  451. &mut prod,
  452. &v_folding_neg[further_dims - 1 - cur_dim],
  453. &ginv_c_ntt,
  454. );
  455. gadget_invert(&mut ginv_c, &v_cts[num_per + i]);
  456. to_ntt(&mut ginv_c_ntt, &ginv_c);
  457. multiply(
  458. &mut sum,
  459. &v_folding[further_dims - 1 - cur_dim],
  460. &ginv_c_ntt,
  461. );
  462. add_into(&mut sum, &prod);
  463. from_ntt(&mut v_cts[i], &sum);
  464. }
  465. }
  466. }
  467. pub fn pack<'a>(
  468. params: &'a Params,
  469. v_ct: &Vec<PolyMatrixRaw>,
  470. v_w: &Vec<PolyMatrixNTT>,
  471. ) -> PolyMatrixNTT<'a> {
  472. assert!(v_ct.len() >= params.n * params.n);
  473. assert!(v_w.len() == params.n);
  474. assert!(v_ct[0].rows == 2);
  475. assert!(v_ct[0].cols == 1);
  476. assert!(v_w[0].rows == (params.n + 1));
  477. assert!(v_w[0].cols == params.t_conv);
  478. let mut result = PolyMatrixNTT::zero(params, params.n + 1, params.n);
  479. let mut ginv = PolyMatrixRaw::zero(params, params.t_conv, 1);
  480. let mut ginv_nttd = PolyMatrixNTT::zero(params, params.t_conv, 1);
  481. let mut prod = PolyMatrixNTT::zero(params, params.n + 1, 1);
  482. let mut ct_1 = PolyMatrixRaw::zero(params, 1, 1);
  483. let mut ct_2 = PolyMatrixRaw::zero(params, 1, 1);
  484. let mut ct_2_ntt = PolyMatrixNTT::zero(params, 1, 1);
  485. for c in 0..params.n {
  486. let mut v_int = PolyMatrixNTT::zero(&params, params.n + 1, 1);
  487. for r in 0..params.n {
  488. let w = &v_w[r];
  489. let ct = &v_ct[r * params.n + c];
  490. ct_1.get_poly_mut(0, 0).copy_from_slice(ct.get_poly(0, 0));
  491. ct_2.get_poly_mut(0, 0).copy_from_slice(ct.get_poly(1, 0));
  492. to_ntt(&mut ct_2_ntt, &ct_2);
  493. gadget_invert(&mut ginv, &ct_1);
  494. to_ntt(&mut ginv_nttd, &ginv);
  495. multiply(&mut prod, &w, &ginv_nttd);
  496. add_into_at(&mut v_int, &ct_2_ntt, 1 + r, 0);
  497. add_into(&mut v_int, &prod);
  498. }
  499. result.copy_into(&v_int, 0, c);
  500. }
  501. result
  502. }
  503. pub fn encode(params: &Params, v_packed_ct: &Vec<PolyMatrixRaw>) -> Vec<u8> {
  504. let q1 = 4 * params.pt_modulus;
  505. let q1_bits = log2_ceil(q1) as usize;
  506. let q2 = Q2_VALUES[params.q2_bits as usize];
  507. let q2_bits = params.q2_bits as usize;
  508. let num_bits = params.instances
  509. * ((q2_bits * params.n * params.poly_len)
  510. + (q1_bits * params.n * params.n * params.poly_len));
  511. let round_to = 64;
  512. let num_bytes_rounded_up = ((num_bits + round_to - 1) / round_to) * round_to / 8;
  513. let mut result = vec![0u8; num_bytes_rounded_up];
  514. let mut bit_offs = 0;
  515. for instance in 0..params.instances {
  516. let packed_ct = &v_packed_ct[instance];
  517. let mut first_row = packed_ct.submatrix(0, 0, 1, packed_ct.cols);
  518. let mut rest_rows = packed_ct.submatrix(1, 0, packed_ct.rows - 1, packed_ct.cols);
  519. first_row.apply_func(|x| rescale(x, params.modulus, q2));
  520. rest_rows.apply_func(|x| rescale(x, params.modulus, q1));
  521. let data = result.as_mut_slice();
  522. for i in 0..params.n * params.poly_len {
  523. write_arbitrary_bits(data, first_row.data[i], bit_offs, q2_bits);
  524. bit_offs += q2_bits;
  525. }
  526. for i in 0..params.n * params.n * params.poly_len {
  527. write_arbitrary_bits(data, rest_rows.data[i], bit_offs, q1_bits);
  528. bit_offs += q1_bits;
  529. }
  530. }
  531. result
  532. }
  533. pub fn get_v_folding_neg<'a>(
  534. params: &'a Params,
  535. v_folding: &Vec<PolyMatrixNTT<'a>>,
  536. ) -> Vec<PolyMatrixNTT<'a>> {
  537. let gadget_ntt = build_gadget(params, 2, 2 * params.t_gsw).ntt(); // TODO: make this better
  538. let v_folding_neg = (0..params.db_dim_2)
  539. .into_par_iter()
  540. .map(|i| {
  541. let mut ct_gsw_inv = PolyMatrixRaw::zero(params, 2, 2 * params.t_gsw);
  542. invert(&mut ct_gsw_inv, &v_folding[i].raw());
  543. let mut ct_gsw_neg = PolyMatrixNTT::zero(params, 2, 2 * params.t_gsw);
  544. add(&mut ct_gsw_neg, &gadget_ntt, &ct_gsw_inv.ntt());
  545. ct_gsw_neg
  546. })
  547. .collect();
  548. v_folding_neg
  549. }
  550. pub fn expand_query<'a>(
  551. params: &'a Params,
  552. public_params: &PublicParameters<'a>,
  553. query: &Query<'a>,
  554. ) -> (AlignedMemory64, Vec<PolyMatrixNTT<'a>>) {
  555. let dim0 = 1 << params.db_dim_1;
  556. let further_dims = params.db_dim_2;
  557. let mut v_reg_reoriented;
  558. let mut v_folding;
  559. let num_bits_to_gen = params.t_gsw * further_dims + dim0;
  560. let g = log2_ceil_usize(num_bits_to_gen);
  561. let right_expanded = params.t_gsw * further_dims;
  562. let stop_round = log2_ceil_usize(right_expanded);
  563. let mut v = Vec::new();
  564. for _ in 0..(1 << g) {
  565. v.push(PolyMatrixNTT::zero(params, 2, 1));
  566. }
  567. v[0].copy_into(&query.ct.as_ref().unwrap().ntt(), 0, 0);
  568. let v_conversion = &public_params.v_conversion.as_ref().unwrap()[0];
  569. let v_w_left = public_params.v_expansion_left.as_ref().unwrap();
  570. let v_w_right = public_params.v_expansion_right.as_ref().unwrap();
  571. let v_neg1 = params.get_v_neg1();
  572. let mut v_reg_inp = Vec::with_capacity(dim0);
  573. let mut v_gsw_inp = Vec::with_capacity(right_expanded);
  574. if further_dims > 0 {
  575. coefficient_expansion(
  576. &mut v,
  577. g,
  578. stop_round,
  579. params,
  580. &v_w_left,
  581. &v_w_right,
  582. &v_neg1,
  583. params.t_gsw * params.db_dim_2,
  584. );
  585. for i in 0..dim0 {
  586. v_reg_inp.push(v[2 * i].clone());
  587. }
  588. for i in 0..right_expanded {
  589. v_gsw_inp.push(v[2 * i + 1].clone());
  590. }
  591. } else {
  592. coefficient_expansion(
  593. &mut v,
  594. g,
  595. 0,
  596. params,
  597. &v_w_left,
  598. &v_w_left,
  599. &v_neg1,
  600. 0,
  601. );
  602. for i in 0..dim0 {
  603. v_reg_inp.push(v[i].clone());
  604. }
  605. }
  606. let v_reg_sz = dim0 * 2 * params.poly_len;
  607. v_reg_reoriented = AlignedMemory64::new(v_reg_sz);
  608. reorient_reg_ciphertexts(params, v_reg_reoriented.as_mut_slice(), &v_reg_inp);
  609. v_folding = Vec::new();
  610. for _ in 0..params.db_dim_2 {
  611. v_folding.push(PolyMatrixNTT::zero(params, 2, 2 * params.t_gsw));
  612. }
  613. regev_to_gsw(&mut v_folding, &v_gsw_inp, &v_conversion, params, 1, 0);
  614. (v_reg_reoriented, v_folding)
  615. }
  616. pub fn process_query(
  617. params: &Params,
  618. public_params: &PublicParameters,
  619. query: &Query,
  620. db: &[u64],
  621. ) -> Vec<u8> {
  622. let dim0 = 1 << params.db_dim_1;
  623. let num_per = 1 << params.db_dim_2;
  624. let db_slice_sz = dim0 * num_per * params.poly_len;
  625. let v_packing = public_params.v_packing.as_ref();
  626. let mut v_reg_reoriented;
  627. let v_folding;
  628. if params.expand_queries {
  629. let now = Instant::now();
  630. (v_reg_reoriented, v_folding) = expand_query(params, public_params, query);
  631. println!("expansion (took {} us).", now.elapsed().as_micros());
  632. } else {
  633. v_reg_reoriented = AlignedMemory64::new(query.v_buf.as_ref().unwrap().len());
  634. v_reg_reoriented
  635. .as_mut_slice()
  636. .copy_from_slice(query.v_buf.as_ref().unwrap());
  637. v_folding = query
  638. .v_ct
  639. .as_ref()
  640. .unwrap()
  641. .iter()
  642. .map(|x| x.ntt())
  643. .collect();
  644. }
  645. let v_folding_neg = get_v_folding_neg(params, &v_folding);
  646. let v_packed_ct = (0..params.instances)
  647. .into_par_iter()
  648. .map(|instance| {
  649. let mut intermediate = Vec::with_capacity(num_per);
  650. let mut intermediate_raw = Vec::with_capacity(num_per);
  651. for _ in 0..num_per {
  652. intermediate.push(PolyMatrixNTT::zero(params, 2, 1));
  653. intermediate_raw.push(PolyMatrixRaw::zero(params, 2, 1));
  654. }
  655. let mut v_ct = Vec::new();
  656. for trial in 0..(params.n * params.n) {
  657. let idx = (instance * (params.n * params.n) + trial) * db_slice_sz;
  658. let cur_db = &db[idx..(idx + db_slice_sz)];
  659. multiply_reg_by_database(
  660. &mut intermediate,
  661. cur_db,
  662. v_reg_reoriented.as_slice(),
  663. params,
  664. dim0,
  665. num_per,
  666. );
  667. for i in 0..intermediate.len() {
  668. from_ntt(&mut intermediate_raw[i], &intermediate[i]);
  669. }
  670. fold_ciphertexts(params, &mut intermediate_raw, &v_folding, &v_folding_neg);
  671. v_ct.push(intermediate_raw[0].clone());
  672. }
  673. let packed_ct = pack(params, &v_ct, &v_packing);
  674. packed_ct.raw()
  675. })
  676. .collect();
  677. encode(params, &v_packed_ct)
  678. }
  679. #[cfg(test)]
  680. mod test {
  681. use super::*;
  682. use crate::client::*;
  683. use rand::{prelude::SmallRng, Rng};
  684. const TEST_PREPROCESSED_DB_PATH: &'static str = "/home/samir/wiki/enwiki-20220320.dbp";
  685. fn get_params() -> Params {
  686. get_fast_expansion_testing_params()
  687. }
  688. fn dec_reg<'a>(
  689. params: &'a Params,
  690. ct: &PolyMatrixNTT<'a>,
  691. client: &mut Client<'a, SmallRng>,
  692. scale_k: u64,
  693. ) -> u64 {
  694. let dec = client.decrypt_matrix_reg(ct).raw();
  695. let mut val = dec.data[0] as i64;
  696. if val >= (params.modulus / 2) as i64 {
  697. val -= params.modulus as i64;
  698. }
  699. let val_rounded = f64::round(val as f64 / scale_k as f64) as i64;
  700. if val_rounded == 0 {
  701. 0
  702. } else {
  703. 1
  704. }
  705. }
  706. fn dec_gsw<'a>(
  707. params: &'a Params,
  708. ct: &PolyMatrixNTT<'a>,
  709. client: &mut Client<'a, SmallRng>,
  710. ) -> u64 {
  711. let dec = client.decrypt_matrix_reg(ct).raw();
  712. let idx = 2 * (params.t_gsw - 1) * params.poly_len + params.poly_len; // this offset should encode a large value
  713. let mut val = dec.data[idx] as i64;
  714. if val >= (params.modulus / 2) as i64 {
  715. val -= params.modulus as i64;
  716. }
  717. if i64::abs(val) < (1i64 << 10) {
  718. 0
  719. } else {
  720. 1
  721. }
  722. }
  723. #[test]
  724. fn coefficient_expansion_is_correct() {
  725. let params = get_params();
  726. let v_neg1 = params.get_v_neg1();
  727. let mut seeded_rng = get_seeded_rng();
  728. let mut client = Client::init(&params, &mut seeded_rng);
  729. let public_params = client.generate_keys();
  730. let mut v = Vec::new();
  731. for _ in 0..(1 << (params.db_dim_1 + 1)) {
  732. v.push(PolyMatrixNTT::zero(&params, 2, 1));
  733. }
  734. let target = 7;
  735. let scale_k = params.modulus / params.pt_modulus;
  736. let mut sigma = PolyMatrixRaw::zero(&params, 1, 1);
  737. sigma.data[target] = scale_k;
  738. v[0] = client.encrypt_matrix_reg(&sigma.ntt());
  739. let test_ct = client.encrypt_matrix_reg(&sigma.ntt());
  740. let v_w_left = public_params.v_expansion_left.unwrap();
  741. let v_w_right = public_params.v_expansion_right.unwrap();
  742. coefficient_expansion(
  743. &mut v,
  744. params.g(),
  745. params.stop_round(),
  746. &params,
  747. &v_w_left,
  748. &v_w_right,
  749. &v_neg1,
  750. params.t_gsw * params.db_dim_2,
  751. );
  752. assert_eq!(dec_reg(&params, &test_ct, &mut client, scale_k), 0);
  753. for i in 0..v.len() {
  754. if i == target {
  755. assert_eq!(dec_reg(&params, &v[i], &mut client, scale_k), 1);
  756. } else {
  757. assert_eq!(dec_reg(&params, &v[i], &mut client, scale_k), 0);
  758. }
  759. }
  760. }
  761. #[test]
  762. fn regev_to_gsw_is_correct() {
  763. let mut params = get_params();
  764. params.db_dim_2 = 1;
  765. let mut seeded_rng = get_seeded_rng();
  766. let mut client = Client::init(&params, &mut seeded_rng);
  767. let public_params = client.generate_keys();
  768. let mut enc_constant = |val| {
  769. let mut sigma = PolyMatrixRaw::zero(&params, 1, 1);
  770. sigma.data[0] = val;
  771. client.encrypt_matrix_reg(&sigma.ntt())
  772. };
  773. let v = &public_params.v_conversion.unwrap()[0];
  774. let bits_per = get_bits_per(&params, params.t_gsw);
  775. let mut v_inp_1 = Vec::new();
  776. let mut v_inp_0 = Vec::new();
  777. for i in 0..params.t_gsw {
  778. let val = 1u64 << (bits_per * i);
  779. v_inp_1.push(enc_constant(val));
  780. v_inp_0.push(enc_constant(0));
  781. }
  782. let mut v_gsw = Vec::new();
  783. v_gsw.push(PolyMatrixNTT::zero(&params, 2, 2 * params.t_gsw));
  784. regev_to_gsw(&mut v_gsw, &v_inp_1, v, &params, 1, 0);
  785. assert_eq!(dec_gsw(&params, &v_gsw[0], &mut client), 1);
  786. regev_to_gsw(&mut v_gsw, &v_inp_0, v, &params, 1, 0);
  787. assert_eq!(dec_gsw(&params, &v_gsw[0], &mut client), 0);
  788. }
  789. #[test]
  790. fn multiply_reg_by_database_is_correct() {
  791. let params = get_params();
  792. let mut seeded_rng = get_seeded_rng();
  793. let dim0 = 1 << params.db_dim_1;
  794. let num_per = 1 << params.db_dim_2;
  795. let scale_k = params.modulus / params.pt_modulus;
  796. let target_idx = seeded_rng.gen::<usize>() % (dim0 * num_per);
  797. let target_idx_dim0 = target_idx / num_per;
  798. let target_idx_num_per = target_idx % num_per;
  799. let mut client = Client::init(&params, &mut seeded_rng);
  800. _ = client.generate_keys();
  801. let (corr_item, db) = generate_random_db_and_get_item(&params, target_idx);
  802. let mut v_reg = Vec::new();
  803. for i in 0..dim0 {
  804. let val = if i == target_idx_dim0 { scale_k } else { 0 };
  805. let sigma = PolyMatrixRaw::single_value(&params, val).ntt();
  806. v_reg.push(client.encrypt_matrix_reg(&sigma));
  807. }
  808. let v_reg_sz = dim0 * 2 * params.poly_len;
  809. let mut v_reg_reoriented = AlignedMemory64::new(v_reg_sz);
  810. reorient_reg_ciphertexts(&params, v_reg_reoriented.as_mut_slice(), &v_reg);
  811. let mut out = Vec::with_capacity(num_per);
  812. for _ in 0..dim0 {
  813. out.push(PolyMatrixNTT::zero(&params, 2, 1));
  814. }
  815. multiply_reg_by_database(
  816. &mut out,
  817. db.as_slice(),
  818. v_reg_reoriented.as_slice(),
  819. &params,
  820. dim0,
  821. num_per,
  822. );
  823. // decrypt
  824. let dec = client.decrypt_matrix_reg(&out[target_idx_num_per]).raw();
  825. let mut dec_rescaled = PolyMatrixRaw::zero(&params, 1, 1);
  826. for z in 0..params.poly_len {
  827. dec_rescaled.data[z] = rescale(dec.data[z], params.modulus, params.pt_modulus);
  828. }
  829. for z in 0..params.poly_len {
  830. // println!("{:?} {:?}", dec_rescaled.data[z], corr_item.data[z]);
  831. assert_eq!(dec_rescaled.data[z], corr_item.data[z]);
  832. }
  833. }
  834. #[test]
  835. fn fold_ciphertexts_is_correct() {
  836. let params = get_params();
  837. let mut seeded_rng = get_seeded_rng();
  838. let dim0 = 1 << params.db_dim_1;
  839. let num_per = 1 << params.db_dim_2;
  840. let scale_k = params.modulus / params.pt_modulus;
  841. let target_idx = seeded_rng.gen::<usize>() % (dim0 * num_per);
  842. let target_idx_num_per = target_idx % num_per;
  843. let mut client = Client::init(&params, &mut seeded_rng);
  844. _ = client.generate_keys();
  845. let mut v_reg = Vec::new();
  846. for i in 0..num_per {
  847. let val = if i == target_idx_num_per { scale_k } else { 0 };
  848. let sigma = PolyMatrixRaw::single_value(&params, val).ntt();
  849. v_reg.push(client.encrypt_matrix_reg(&sigma));
  850. }
  851. let mut v_reg_raw = Vec::new();
  852. for i in 0..num_per {
  853. v_reg_raw.push(v_reg[i].raw());
  854. }
  855. let bits_per = get_bits_per(&params, params.t_gsw);
  856. let mut v_folding = Vec::new();
  857. for i in 0..params.db_dim_2 {
  858. let bit = ((target_idx_num_per as u64) & (1 << (i as u64))) >> (i as u64);
  859. let mut ct_gsw = PolyMatrixNTT::zero(&params, 2, 2 * params.t_gsw);
  860. for j in 0..params.t_gsw {
  861. let value = (1u64 << (bits_per * j)) * bit;
  862. let sigma = PolyMatrixRaw::single_value(&params, value);
  863. let sigma_ntt = to_ntt_alloc(&sigma);
  864. let ct = client.encrypt_matrix_reg(&sigma_ntt);
  865. ct_gsw.copy_into(&ct, 0, 2 * j + 1);
  866. let prod = &to_ntt_alloc(client.get_sk_reg()) * &sigma_ntt;
  867. let ct = &client.encrypt_matrix_reg(&prod);
  868. ct_gsw.copy_into(&ct, 0, 2 * j);
  869. }
  870. v_folding.push(ct_gsw);
  871. }
  872. let gadget_ntt = build_gadget(&params, 2, 2 * params.t_gsw).ntt();
  873. let mut v_folding_neg = Vec::new();
  874. let mut ct_gsw_inv = PolyMatrixRaw::zero(&params, 2, 2 * params.t_gsw);
  875. for i in 0..params.db_dim_2 {
  876. invert(&mut ct_gsw_inv, &v_folding[i].raw());
  877. let mut ct_gsw_neg = PolyMatrixNTT::zero(&params, 2, 2 * params.t_gsw);
  878. add(&mut ct_gsw_neg, &gadget_ntt, &ct_gsw_inv.ntt());
  879. v_folding_neg.push(ct_gsw_neg);
  880. }
  881. fold_ciphertexts(&params, &mut v_reg_raw, &v_folding, &v_folding_neg);
  882. // decrypt
  883. assert_eq!(
  884. dec_reg(&params, &v_reg_raw[0].ntt(), &mut client, scale_k),
  885. 1
  886. );
  887. }
  888. fn full_protocol_is_correct_for_params(params: &Params) {
  889. let mut seeded_rng = get_seeded_rng();
  890. let target_idx = seeded_rng.gen::<usize>() % (params.db_dim_1 + params.db_dim_2);
  891. let mut client = Client::init(params, &mut seeded_rng);
  892. let public_params = client.generate_keys();
  893. let query = client.generate_query(target_idx);
  894. let (corr_item, db) = generate_random_db_and_get_item(params, target_idx);
  895. let response = process_query(params, &public_params, &query, db.as_slice());
  896. let result = client.decode_response(response.as_slice());
  897. let p_bits = log2_ceil(params.pt_modulus) as usize;
  898. let corr_result = corr_item.to_vec(p_bits, params.modp_words_per_chunk());
  899. assert_eq!(result.len(), corr_result.len());
  900. for z in 0..corr_result.len() {
  901. assert_eq!(result[z], corr_result[z], "at {:?}", z);
  902. }
  903. }
  904. fn full_protocol_is_correct_for_params_real_db(params: &Params) {
  905. let mut seeded_rng = get_seeded_rng();
  906. let target_idx = seeded_rng.gen::<usize>() % (params.db_dim_1 + params.db_dim_2);
  907. let mut client = Client::init(params, &mut seeded_rng);
  908. let public_params = client.generate_keys();
  909. let query = client.generate_query(target_idx);
  910. let mut file = File::open(TEST_PREPROCESSED_DB_PATH).unwrap();
  911. let db = load_preprocessed_db_from_file(params, &mut file);
  912. let response = process_query(params, &public_params, &query, db.as_slice());
  913. let result = client.decode_response(response.as_slice());
  914. let corr_result = vec![0x42, 0x5a, 0x68];
  915. for z in 0..corr_result.len() {
  916. assert_eq!(result[z], corr_result[z]);
  917. }
  918. }
  919. #[test]
  920. fn full_protocol_is_correct() {
  921. full_protocol_is_correct_for_params(&get_params());
  922. }
  923. #[test]
  924. #[ignore]
  925. fn larger_full_protocol_is_correct() {
  926. let cfg_expand = r#"
  927. {
  928. 'n': 2,
  929. 'nu_1': 10,
  930. 'nu_2': 6,
  931. 'p': 512,
  932. 'q2_bits': 21,
  933. 's_e': 85.83255142749422,
  934. 't_gsw': 10,
  935. 't_conv': 4,
  936. 't_exp_left': 16,
  937. 't_exp_right': 56,
  938. 'instances': 1,
  939. 'db_item_size': 9000 }
  940. "#;
  941. let cfg = cfg_expand;
  942. let cfg = cfg.replace("'", "\"");
  943. let params = params_from_json(&cfg);
  944. full_protocol_is_correct_for_params(&params);
  945. full_protocol_is_correct_for_params_real_db(&params);
  946. }
  947. // #[test]
  948. // fn full_protocol_is_correct_20_256() {
  949. // full_protocol_is_correct_for_params(&params_from_json(&CFG_20_256.replace("'", "\"")));
  950. // }
  951. // #[test]
  952. // fn full_protocol_is_correct_16_100000() {
  953. // full_protocol_is_correct_for_params(&params_from_json(&CFG_16_100000.replace("'", "\"")));
  954. // }
  955. #[test]
  956. #[ignore]
  957. fn full_protocol_is_correct_real_db_16_100000() {
  958. full_protocol_is_correct_for_params_real_db(&params_from_json(
  959. &CFG_16_100000.replace("'", "\""),
  960. ));
  961. }
  962. }