Zeth - Zerocash on Ethereum  0.8
Reference implementation of the Zeth protocol by Clearmatics
powersoftau_utils.cpp
Go to the documentation of this file.
1 // Copyright (c) 2015-2022 Clearmatics Technologies Ltd
2 //
3 // SPDX-License-Identifier: LGPL-3.0+
4 
6 
7 #include <libff/algebra/fields/fp2.hpp>
8 
9 namespace libzeth
10 {
11 
12 template<>
13 void read_powersoftau_g2<libff::alt_bn128_pp>(
14  std::istream &in, libff::alt_bn128_G2 &out)
15 {
16  uint8_t marker;
17  in.read((char *)&marker, 1);
18 
19  switch (marker) {
20  case 0x00:
21  // zero
22  out = libff::alt_bn128_G2::zero();
23  break;
24 
25  case 0x04:
26  // Uncompressed
27  read_powersoftau_fp2(in, out.X);
28  read_powersoftau_fp2(in, out.Y);
29  out.Z = libff::alt_bn128_Fq2::one();
30  break;
31 
32  default:
33  assert(false);
34  break;
35  }
36 }
37 
38 template<>
39 void write_powersoftau_g2<libff::alt_bn128_pp>(
40  std::ostream &out, const libff::alt_bn128_G2 &g2)
41 {
42  if (g2.is_zero()) {
43  const uint8_t zero = 0;
44  out.write((const char *)&zero, 1);
45  return;
46  }
47 
48  libff::alt_bn128_G2 copy(g2);
49  copy.to_affine_coordinates();
50 
51  const uint8_t marker = 0x04;
52  out.write((const char *)&marker, 1);
53  write_powersoftau_fp2(out, copy.X);
54  write_powersoftau_fp2(out, copy.Y);
55 }
56 
57 } // namespace libzeth
libzeth
Definition: binary_operation.hpp:15
powersoftau_utils.hpp