Zeth - Zerocash on Ethereum  0.8
Reference implementation of the Zeth protocol by Clearmatics
split_keypair_cmd.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 "libtool/tool_util.hpp"
8 
9 namespace zethtool
10 {
11 
12 namespace commands
13 {
14 
15 class split_keypair_cmd : public generic_subcommand<split_keypair_cmd>
16 {
17 public:
19 
21  const std::string &subcommand_name, const std::string &description)
23  {
24  }
25 
26  template<typename ppT, typename snarkT>
28  {
29  ppT::init_public_params();
30  libff::inhibit_profiling_info = true;
31  libff::inhibit_profiling_counters = true;
32 
33  typename snarkT::keypair keypair;
34  {
35  std::ifstream in_s = libtool::open_binary_input_file(keypair_file);
36  snarkT::keypair_read_bytes(keypair, in_s);
37  }
38 
39  if (!vk_file.empty()) {
40  std::ofstream out_s = libtool::open_binary_output_file(vk_file);
41  snarkT::verification_key_write_bytes(keypair.vk, out_s);
42  }
43 
44  if (!pk_file.empty()) {
45  std::ofstream out_s = libtool::open_binary_output_file(pk_file);
46  snarkT::proving_key_write_bytes(keypair.pk, out_s);
47  }
48 
49  return 0;
50  }
51 
52 protected:
54  boost::program_options::options_description &options,
55  boost::program_options::options_description &all_options,
56  boost::program_options::positional_options_description &pos) override
57  {
58  base_class::initialize_suboptions(options, all_options, pos);
59 
60  options.add_options()(
61  "vk-file,v",
62  po::value<std::string>(),
63  "Verification key file (optional)")(
64  "pk-file,p",
65  po::value<std::string>(),
66  "Proving key file (optional)");
67 
68  all_options.add(options).add_options()(
69  "keypair-file,k", po::value<std::string>(), "Keypair file");
70  pos.add("keypair-file", 1);
71  }
72 
74  const boost::program_options::variables_map &vm) override
75  {
77 
78  if (vm.count("keypair-file") == 0) {
79  throw po::error("keypair file not specified");
80  }
81 
82  keypair_file = vm["keypair-file"].as<std::string>();
83  vk_file = vm.count("vk-file") ? vm["vk-file"].as<std::string>() : "";
84  pk_file = vm.count("pk-file") ? vm["pk-file"].as<std::string>() : "";
85 
86  if (vk_file.empty() && pk_file.empty()) {
87  throw po::error("no VK or PK file specified");
88  }
89  }
90 
91  void subcommand_usage(const char *argv0) override
92  {
93  std::cout << "Usage:\n"
94  " "
95  << argv0 << " split-keypair <options> [keypair_file]\n";
96  }
97 
98  std::string keypair_file;
99  std::string vk_file;
100  std::string pk_file;
101 };
102 
103 } // namespace commands
104 
106  "split-keypair",
107  "Extract the verification key / proving key from a keypair.");
108 
109 } // namespace zethtool
zethtool::generic_subcommand< split_keypair_cmd >::parse_suboptions
void parse_suboptions(const boost::program_options::variables_map &vm) override
Definition: tool_common.hpp:111
libtool::subcommand::description
const std::string & description() const
commands
Definition: __init__.py:1
zethtool::generic_subcommand< split_keypair_cmd >::initialize_suboptions
void initialize_suboptions(boost::program_options::options_description &options, boost::program_options::options_description &, boost::program_options::positional_options_description &) override
Definition: tool_common.hpp:97
tool_util.hpp
zethtool::commands::split_keypair_cmd::pk_file
std::string pk_file
Definition: split_keypair_cmd.cpp:100
zethtool::commands::split_keypair_cmd::split_keypair_cmd
split_keypair_cmd(const std::string &subcommand_name, const std::string &description)
Definition: split_keypair_cmd.cpp:20
zethtool::generic_subcommand
Definition: tool_common.hpp:87
split_keypair_cmd.hpp
zethtool::commands::split_keypair_cmd::initialize_suboptions
void initialize_suboptions(boost::program_options::options_description &options, boost::program_options::options_description &all_options, boost::program_options::positional_options_description &pos) override
Instantiation can now set up the boost program_options structures.
Definition: split_keypair_cmd.cpp:53
global_options
Definition: mpc_subcommand.hpp:15
zethtool::commands::split_keypair_cmd::subcommand_usage
void subcommand_usage(const char *argv0) override
Any command-specific output for usage.
Definition: split_keypair_cmd.cpp:91
libtool::open_binary_output_file
std::ofstream open_binary_output_file(const std::string &filename)
Utility function to open a binary file for writing, with appropriate flags.
Definition: tool_util.cpp:19
libtool::subcommand::subcommand_name
std::string subcommand_name
Definition: subcommand.hpp:54
zethtool::commands::split_keypair_cmd
Definition: split_keypair_cmd.cpp:15
libtool::open_binary_input_file
std::ifstream open_binary_input_file(const std::string &filename)
Definition: tool_util.cpp:10
zethtool::commands::split_keypair_cmd::parse_suboptions
void parse_suboptions(const boost::program_options::variables_map &vm) override
Definition: split_keypair_cmd.cpp:73
zethtool::commands::split_keypair_cmd::execute_generic
int execute_generic(const global_options &)
Definition: split_keypair_cmd.cpp:27
zethtool::split_keypair_cmd
zeth_subcommand * split_keypair_cmd
Definition: split_keypair_cmd.cpp:105
libtool::subcommand
Class representing a tool subcommand.
Definition: subcommand.hpp:18
zethtool::commands::split_keypair_cmd::vk_file
std::string vk_file
Definition: split_keypair_cmd.cpp:99
zethtool
Definition: dump_proof_cmd.cpp:11
zethtool::commands::split_keypair_cmd::keypair_file
std::string keypair_file
Definition: split_keypair_cmd.cpp:98