Zecale - Reconciling Privacy and Scalability on Smart-Contract Chains  0.5
Reference implementation of the Zecale protocol by Clearmatics
proto_utils.tcc
Go to the documentation of this file.
1 // Copyright (c) 2015-2022 Clearmatics Technologies Ltd
2 //
3 // SPDX-License-Identifier: LGPL-3.0+
4 
5 #ifndef __ZECALE_SERIALIZATION_PROTO_UTILS_TCC__
6 #define __ZECALE_SERIALIZATION_PROTO_UTILS_TCC__
7 
8 #include "libzecale/serialization/proto_utils.hpp"
9 
10 #include <cstring>
11 #include <libff/algebra/curves/public_params.hpp>
12 #include <libzeth/core/extended_proof.hpp>
13 #include <libzeth/serialization/proto_utils.hpp>
14 
15 namespace libzecale
16 {
17 
18 template<typename nppT, typename wppT, typename nsnarkT, typename wsnarkT>
19 void aggregator_configuration_to_proto(
20  zecale_proto::AggregatorConfiguration &config)
21 {
22  config.set_nested_snark_name(nsnarkT::name);
23  config.set_wrapper_snark_name(wsnarkT::name);
24  libzeth::pairing_parameters_to_proto<nppT>(
25  *config.mutable_nested_pairing_parameters());
26  libzeth::pairing_parameters_to_proto<wppT>(
27  *config.mutable_wrapper_pairing_parameters());
28 }
29 
30 template<typename ppT, typename apiHandlerT>
31 nested_transaction<ppT, typename apiHandlerT::snark> nested_transaction_from_proto(
32  const zecale_proto::NestedTransaction &grpc_transaction_obj)
33 {
34  using snark = typename apiHandlerT::snark;
35  std::string app_name = grpc_transaction_obj.application_name();
36  libzeth::extended_proof<ppT, snark> ext_proof =
37  apiHandlerT::extended_proof_from_proto(
38  grpc_transaction_obj.extended_proof());
39  const std::string &parameters_str(grpc_transaction_obj.parameters());
40  std::vector<uint8_t> parameters(
41  (const uint8_t *)(parameters_str.data()),
42  (const uint8_t *)(parameters_str.data() + parameters_str.size()));
43 
44  const uint32_t fee = uint32_t(grpc_transaction_obj.fee_in_wei());
45  return nested_transaction<ppT, snark>(app_name, ext_proof, parameters, fee);
46 }
47 
48 } // namespace libzecale
49 
50 #endif // __ZECALE_SERIALIZATION_PROTO_UTILS_TCC__