Zeth - Zerocash on Ethereum  0.8
Reference implementation of the Zeth protocol by Clearmatics
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
zethtool::commands::prove_cmd Class Reference
Inheritance diagram for zethtool::commands::prove_cmd:
Inheritance graph
[legend]
Collaboration diagram for zethtool::commands::prove_cmd:
Collaboration graph
[legend]

Public Types

using base_class = generic_subcommand< prove_cmd >
 

Public Member Functions

 prove_cmd (const std::string &subcommand_name, const std::string &description)
 
template<typename ppT , typename snarkT >
int execute_generic (const global_options &)
 
- Public Member Functions inherited from zethtool::generic_subcommand< prove_cmd >
 generic_subcommand (const std::string &subcommand_name, const std::string &description)
 
- Public Member Functions inherited from libtool::subcommand< GlobalOptionsT >
 subcommand (const std::string &subcommand_name, const std::string &description)
 
virtual ~subcommand ()
 
const std::string & description () const
 
int execute (const char *argv0, const std::vector< std::string > command_args, const GlobalOptionsT &global)
 Common code to parse options and invoke the virtual execute entrypoint. More...
 

Protected Member Functions

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. More...
 
void parse_suboptions (const boost::program_options::variables_map &vm) override
 
void subcommand_usage (const char *argv0) override
 Any command-specific output for usage. More...
 
- Protected Member Functions inherited from zethtool::generic_subcommand< prove_cmd >
void initialize_suboptions (boost::program_options::options_description &options, boost::program_options::options_description &, boost::program_options::positional_options_description &) override
 Instantiation can now set up the boost program_options structures. More...
 
void parse_suboptions (const boost::program_options::variables_map &vm) override
 
int execute_subcommand (const global_options &options) override
 
- Protected Member Functions inherited from libtool::subcommand< GlobalOptionsT >
void usage (const char *argv0, const boost::program_options::options_description &options)
 
virtual int execute_subcommand (const GlobalOptionsT &global)=0
 Execute the command using global options defined by the caller. More...
 

Protected Attributes

std::string pk_file
 
std::string assignment_file
 
std::string proof_file
 
uint16_t num_primary_inputs
 
bool profile
 
- Protected Attributes inherited from zethtool::generic_subcommand< prove_cmd >
std::string curve
 
std::string snark
 
- Protected Attributes inherited from libtool::subcommand< GlobalOptionsT >
std::string subcommand_name
 
std::string subcommand_description
 

Detailed Description

Definition at line 17 of file prove_cmd.cpp.

Member Typedef Documentation

◆ base_class

Definition at line 20 of file prove_cmd.cpp.

Constructor & Destructor Documentation

◆ prove_cmd()

zethtool::commands::prove_cmd::prove_cmd ( const std::string &  subcommand_name,
const std::string &  description 
)
inline

Definition at line 22 of file prove_cmd.cpp.

26  , profile(false)
27  {
28  }

Member Function Documentation

◆ execute_generic()

template<typename ppT , typename snarkT >
int zethtool::commands::prove_cmd::execute_generic ( const global_options )
inline

Definition at line 31 of file prove_cmd.cpp.

32  {
33  ppT::init_public_params();
34  if (!profile) {
35  libff::inhibit_profiling_info = true;
36  libff::inhibit_profiling_counters = true;
37  }
38 
39  typename snarkT::proving_key proving_key;
40  {
41  std::ifstream in_s = libtool::open_binary_input_file(pk_file);
42  snarkT::proving_key_read_bytes(proving_key, in_s);
43  }
44 
45  libsnark::r1cs_primary_input<libff::Fr<ppT>> primary;
46  libsnark::r1cs_auxiliary_input<libff::Fr<ppT>> auxiliary;
47  {
48  std::ifstream in_s =
51  primary, auxiliary, num_primary_inputs, in_s);
52  }
53 
54  typename snarkT::proof proof =
55  snarkT::generate_proof(proving_key, primary, auxiliary);
56 
57  // Write to output file
58  std::cout << "Writing proof to file: " << proof_file << "\n";
59  {
60  std::ofstream out_s = libtool::open_binary_output_file(proof_file);
61  snarkT::proof_write_bytes(proof, out_s);
62  }
63 
64  return 0;
65  }
Here is the call graph for this function:

◆ initialize_suboptions()

void zethtool::commands::prove_cmd::initialize_suboptions ( boost::program_options::options_description &  options,
boost::program_options::options_description &  all_options,
boost::program_options::positional_options_description &  pos 
)
inlineoverrideprotectedvirtual

Instantiation can now set up the boost program_options structures.

Implements libtool::subcommand< GlobalOptionsT >.

Definition at line 68 of file prove_cmd.cpp.

72  {
73  base_class::initialize_suboptions(options, all_options, pos);
74 
75  options.add_options()(
76  "primary_inputs,p",
77  po::value<uint16_t>(),
78  "Number of primary inputs (default: 1)")(
79  "profile,r", "Enable profiling output");
80 
81  all_options.add(options).add_options()(
82  "pk_file", po::value<std::string>(), "Proving key file");
83  all_options.add_options()(
84  "assignment_file", po::value<std::string>(), "Assignment file");
85  all_options.add_options()(
86  "proof_file", po::value<std::string>(), "(Output) Proof file");
87 
88  pos.add("pk_file", 1);
89  pos.add("assignment_file", 1);
90  pos.add("proof_file", 1);
91  }
Here is the call graph for this function:

◆ parse_suboptions()

void zethtool::commands::prove_cmd::parse_suboptions ( const boost::program_options::variables_map &  vm)
inlineoverrideprotectedvirtual

Instantiation can record any command-specific information from the parsed variables_map.

Implements libtool::subcommand< GlobalOptionsT >.

Definition at line 93 of file prove_cmd.cpp.

95  {
97 
98  if (vm.count("pk_file") == 0) {
99  throw po::error("pk_file not specified");
100  }
101  if (vm.count("assignment_file") == 0) {
102  throw po::error("assignment_file not specified");
103  }
104  if (vm.count("proof_file") == 0) {
105  throw po::error("proof_file not specified");
106  }
107 
108  pk_file = vm["pk_file"].as<std::string>();
109  assignment_file = vm["assignment_file"].as<std::string>();
110  proof_file = vm["proof_file"].as<std::string>();
111  if (vm.count("primary_inputs")) {
112  num_primary_inputs = vm["primary_inputs"].as<uint16_t>();
113  }
114  profile = (bool)vm.count("profile");
115  }
Here is the call graph for this function:

◆ subcommand_usage()

void zethtool::commands::prove_cmd::subcommand_usage ( const char *  argv0)
inlineoverrideprotectedvirtual

Any command-specific output for usage.

Implements libtool::subcommand< GlobalOptionsT >.

Definition at line 117 of file prove_cmd.cpp.

118  {
119  std::cout << "Usage:\n"
120  " "
121  << argv0
122  << " prove [pk_file] [assignment_file] [proof_file]\n";
123  }

Member Data Documentation

◆ assignment_file

std::string zethtool::commands::prove_cmd::assignment_file
protected

Definition at line 126 of file prove_cmd.cpp.

◆ num_primary_inputs

uint16_t zethtool::commands::prove_cmd::num_primary_inputs
protected

Definition at line 128 of file prove_cmd.cpp.

◆ pk_file

std::string zethtool::commands::prove_cmd::pk_file
protected

Definition at line 125 of file prove_cmd.cpp.

◆ profile

bool zethtool::commands::prove_cmd::profile
protected

Definition at line 129 of file prove_cmd.cpp.

◆ proof_file

std::string zethtool::commands::prove_cmd::proof_file
protected

Definition at line 127 of file prove_cmd.cpp.


The documentation for this class was generated from the following file:
zethtool::generic_subcommand< prove_cmd >::parse_suboptions
void parse_suboptions(const boost::program_options::variables_map &vm) override
Definition: tool_common.hpp:111
zethtool::commands::prove_cmd::base_class
generic_subcommand< prove_cmd > base_class
Definition: prove_cmd.cpp:20
libtool::subcommand::description
const std::string & description() const
zethtool::generic_subcommand< prove_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
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::prove_cmd::assignment_file
std::string assignment_file
Definition: prove_cmd.cpp:126
libtool::open_binary_input_file
std::ifstream open_binary_input_file(const std::string &filename)
Definition: tool_util.cpp:10
libzeth::r1cs_variable_assignment_read_bytes
void r1cs_variable_assignment_read_bytes(libsnark::r1cs_variable_assignment< FieldT > &assignment, std::istream &in_s)
zethtool::commands::prove_cmd::pk_file
std::string pk_file
Definition: prove_cmd.cpp:125
zethtool::commands::prove_cmd::proof_file
std::string proof_file
Definition: prove_cmd.cpp:127
zethtool::commands::prove_cmd::num_primary_inputs
uint16_t num_primary_inputs
Definition: prove_cmd.cpp:128
zethtool::commands::prove_cmd::profile
bool profile
Definition: prove_cmd.cpp:129