Zeth - Zerocash on Ethereum  0.8
Reference implementation of the Zeth protocol by Clearmatics
mpc_common.hpp
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 __ZETH_MPC_CLI_COMMON_HPP__
6 #define __ZETH_MPC_CLI_COMMON_HPP__
7 
10 #include "mpc_subcommand.hpp"
11 
12 #include <boost/program_options.hpp>
13 #include <fstream>
14 #include <map>
15 #include <string>
16 #include <vector>
17 
18 // interface for ReadableT types:
19 // {
20 // static ReadableT read(std::istream &in);
21 // }
22 
23 // Utility function to load data objects from a file, using a static read
24 // method. Type must satisfy ReadableT constraints above.
25 template<typename ReadableT>
26 inline ReadableT read_from_file(const std::string &file_name)
27 {
28  std::ifstream in(file_name, std::ios_base::binary | std::ios_base::in);
29  in.exceptions(
30  std::ios_base::eofbit | std::ios_base::badbit | std::ios_base::failbit);
31  return ReadableT::read(in);
32 }
33 
34 // Load data objects from a file, similarly to read_from_file, while computing
35 // the hash of the serialized structure. Type must satisfy ReadableT
36 // constraints above.
37 template<typename ReadableT>
38 inline ReadableT read_from_file_and_hash(
39  const std::string &file_name, libzeth::mpc_hash_t out_hash)
40 {
41  std::ifstream inf(file_name, std::ios_base::binary | std::ios_base::in);
43  in.exceptions(
44  std::ios_base::eofbit | std::ios_base::badbit | std::ios_base::failbit);
45  ReadableT v = ReadableT::read(in);
46  in.get_hash(out_hash);
47  return v;
48 }
49 
57 
59 int mpc_main(
60  const std::map<std::string, mpc_subcommand *> &commands,
61  const ProtoboardInitFn &pb_init,
62  int argc,
63  char **argv);
64 
65 #endif // __ZETH_MPC_CLI_COMMON_HPP__
mpc_dummy_phase2_cmd
mpc_subcommand * mpc_dummy_phase2_cmd
Definition: mpc_dummy_phase2.cpp:116
commands
Definition: __init__.py:1
mpc_phase2_contribute_cmd
mpc_subcommand * mpc_phase2_contribute_cmd
Definition: mpc_phase2_contribute.cpp:167
read_from_file
ReadableT read_from_file(const std::string &file_name)
Definition: mpc_common.hpp:26
mpc_hash.hpp
libzeth::mpc_hash_t
size_t[MPC_HASH_ARRAY_LENGTH] mpc_hash_t
Definition: mpc_hash.hpp:21
mpc_phase2_verify_transcript_cmd
mpc_subcommand * mpc_phase2_verify_transcript_cmd
Definition: mpc_phase2_verify_transcript.cpp:214
mpc_phase2_verify_contribution_cmd
mpc_subcommand * mpc_phase2_verify_contribution_cmd
Definition: mpc_phase2_verify_contribution.cpp:142
mpc_subcommand.hpp
libzeth::hash_istream_wrapper::get_hash
void get_hash(typename HashT::OutBuffer out_hash)
mpc_main
int mpc_main(const std::map< std::string, mpc_subcommand * > &commands, const ProtoboardInitFn &pb_init, int argc, char **argv)
Main entry point into the mpc command for a given circuit.
Definition: mpc_common.cpp:43
libtool::subcommand
Class representing a tool subcommand.
Definition: subcommand.hpp:18
libzeth::hash_istream_wrapper
Wrap some istream, hashing all data as it is read.
Definition: hash_stream.hpp:32
mpc_phase2_begin_cmd
mpc_subcommand * mpc_phase2_begin_cmd
Definition: mpc_phase2_begin.cpp:119
mpc_linear_combination_cmd
mpc_subcommand * mpc_linear_combination_cmd
Definition: mpc_linear_combination.cpp:177
mpc_create_keypair_cmd
mpc_subcommand * mpc_create_keypair_cmd
Definition: mpc_create_keypair.cpp:187
include_libsnark.hpp
read_from_file_and_hash
ReadableT read_from_file_and_hash(const std::string &file_name, libzeth::mpc_hash_t out_hash)
Definition: mpc_common.hpp:38
ProtoboardInitFn
std::function< void(libsnark::protoboard< Field > &)> ProtoboardInitFn
Definition: mpc_subcommand.hpp:13