-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from clearmatics/mpc-separate-utilities
[MPC] Utilities for SRS generation via MPC (depends on #48)
- Loading branch information
Showing
22 changed files
with
1,769 additions
and
105 deletions.
There are no files selected for viewing
Submodule libsnark
updated
from 90660b to f240c5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env bash | ||
|
||
POT=$1 | ||
[ "" == "${POT}" ] && POT="build/src/pot-process" | ||
|
||
POT_DATA="testdata/powersoftau_response.4.bin" | ||
POT_DATA_DEGREE=16 | ||
|
||
set -e | ||
set -x | ||
|
||
# Check real data | ||
${POT} --check ${POT_DATA} ${POT_DATA_DEGREE} | ||
|
||
# Write dummy data | ||
${POT} --dummy /tmp/test_pot-6.bin 64 | ||
|
||
# Check consistency of dummy data | ||
${POT} --check /tmp/test_pot-6.bin 64 | ||
|
||
# Generate encoded Lagrange evaluation from real data | ||
${POT} --out /tmp/lagrange-4.bin ${POT_DATA} ${POT_DATA_DEGREE} | ||
|
||
# Generate encoded evaluation of Lagrange polynomials of smaller | ||
# degree, from real data | ||
${POT} \ | ||
--out /tmp/lagrange-3.bin \ | ||
--lagrange-degree $((${POT_DATA_DEGREE} / 2)) \ | ||
${POT_DATA} ${POT_DATA_DEGREE} | ||
|
||
set +x | ||
echo "==================================================================" | ||
echo "== PASSED ==" | ||
echo "==================================================================" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# mpc command | ||
|
||
Performs administrative operations related to the MPC for SRS generation. | ||
Operations performed by this command are specific to the constraint system used | ||
by zeth, relying on the circuit-agnostic `powersoftau` data and pre-computed | ||
Lagrange polynomials evaluations, as computed by the `powersoftau` command. | ||
|
||
This command can be used to generate the linear-combination data, which forms | ||
the initial "challenge" of the Phase 2 MPC. Participants compute a "resonse" | ||
for their challenge, which is then processed to create a final keypair and an | ||
auditable transcript of contributions. | ||
|
||
For the full list of options, see output of `mpc --help`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#include "include_libsnark.hpp" | ||
#include "mpc_common.hpp" | ||
|
||
#include <boost/program_options.hpp> | ||
|
||
namespace po = boost::program_options; | ||
|
||
using ppT = libff::default_ec_pp; | ||
|
||
extern subcommand *mpc_linear_combination_cmd; | ||
extern subcommand *mpc_dummy_phase2_cmd; | ||
extern subcommand *mpc_create_keypair_cmd; | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
ppT::init_public_params(); | ||
po::options_description global(""); | ||
global.add_options()("help,h", "This help")("verbose,v", "Verbose output"); | ||
|
||
po::options_description all(""); | ||
all.add(global).add_options()( | ||
"command", po::value<std::string>(), "Command to execute")( | ||
"subargs", | ||
po::value<std::vector<std::string>>(), | ||
"Arguments to command"); | ||
|
||
po::positional_options_description pos; | ||
pos.add("command", 1).add("subargs", -1); | ||
|
||
const std::map<std::string, subcommand *> commands{ | ||
{"linear-combination", mpc_linear_combination_cmd}, | ||
{"dummy-phase2", mpc_dummy_phase2_cmd}, | ||
{"create-keypair", mpc_create_keypair_cmd}, | ||
}; | ||
|
||
auto usage = [&argv, &global, &commands]() { | ||
std::cout << "Usage:\n" | ||
<< " " << argv[0] | ||
<< " [<options>] <command> <command-arguments> ...\n\n" | ||
<< global; | ||
|
||
std::cout << "\nCommands:\n"; | ||
for (const auto &cmd : commands) { | ||
std::cout << " " << cmd.first; | ||
} | ||
std::cout << std::endl; | ||
}; | ||
|
||
try { | ||
po::variables_map vm; | ||
po::parsed_options parsed = po::command_line_parser(argc, argv) | ||
.options(all) | ||
.positional(pos) | ||
.allow_unregistered() | ||
.run(); | ||
po::store(parsed, vm); | ||
|
||
if (vm.count("help")) { | ||
usage(); | ||
return 0; | ||
} | ||
|
||
const bool verbose = (bool)vm.count("verbose"); | ||
if (!verbose) { | ||
libff::inhibit_profiling_info = true; | ||
libff::inhibit_profiling_counters = true; | ||
} | ||
|
||
if (0 == vm.count("command")) { | ||
std::cerr << "error: no command specified\n"; | ||
usage(); | ||
return 1; | ||
} | ||
|
||
const std::string command(vm["command"].as<std::string>()); | ||
std::vector<std::string> subargs = | ||
po::collect_unrecognized(parsed.options, po::include_positional); | ||
subargs[0] = std::string(argv[0]) + " " + subargs[0]; | ||
|
||
subcommand *sub = commands.find(command)->second; | ||
if (sub == nullptr) { | ||
throw po::error("invalid command"); | ||
} | ||
|
||
return sub->execute(verbose, subargs); | ||
} catch (po::error &error) { | ||
std::cerr << " ERROR: " << error.what() << std::endl; | ||
usage(); | ||
} | ||
|
||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "mpc_common.hpp" | ||
|
||
#include <iostream> | ||
|
||
namespace po = boost::program_options; | ||
|
||
subcommand::subcommand(const std::string &subcommand_name) | ||
: subcommand_name(subcommand_name), verbose(false), help(false) | ||
{ | ||
} | ||
|
||
int subcommand::execute(bool verbose, const std::vector<std::string> &args) | ||
{ | ||
this->verbose = verbose; | ||
|
||
po::options_description options_desc("Options"); | ||
po::options_description all_options_desc(""); | ||
po::positional_options_description positional_options_desc; | ||
|
||
try { | ||
options_desc.add_options()("help,h", "This help"), | ||
initialize_suboptions( | ||
options_desc, all_options_desc, positional_options_desc); | ||
|
||
po::variables_map vm; | ||
po::parsed_options parsed = | ||
po::command_line_parser( | ||
std::vector<std::string>(args.begin() + 1, args.end())) | ||
.options(all_options_desc) | ||
.positional(positional_options_desc) | ||
.run(); | ||
po::store(parsed, vm); | ||
parse_suboptions(vm); | ||
|
||
if (vm.count("help")) { | ||
help = true; | ||
usage(options_desc); | ||
return 0; | ||
} | ||
} catch (po::error &error) { | ||
std::cerr << " ERROR: " << error.what() << std::endl; | ||
usage(options_desc); | ||
return 1; | ||
} | ||
|
||
// Execute and handle errors | ||
try { | ||
return execute_subcommand(); | ||
} catch (std::invalid_argument &error) { | ||
std::cerr << " ERROR: " << error.what() << std::endl; | ||
return 1; | ||
} | ||
} | ||
|
||
void subcommand::usage(const po::options_description &options) | ||
{ | ||
subcommand_usage(); | ||
std::cout << options << std::endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <boost/program_options.hpp> | ||
#include <fstream> | ||
#include <string> | ||
#include <vector> | ||
|
||
class subcommand | ||
{ | ||
protected: | ||
std::string subcommand_name; | ||
bool verbose; | ||
|
||
private: | ||
bool help; | ||
|
||
public: | ||
subcommand(const std::string &subcommand_name); | ||
int execute(bool verbose, const std::vector<std::string> &args); | ||
|
||
private: | ||
void usage(const boost::program_options::options_description &all_options); | ||
|
||
virtual void initialize_suboptions( | ||
boost::program_options::options_description &options, | ||
boost::program_options::options_description &all_options, | ||
boost::program_options::positional_options_description &pos) = 0; | ||
virtual void parse_suboptions( | ||
const boost::program_options::variables_map &vm) = 0; | ||
virtual void subcommand_usage() = 0; | ||
virtual int execute_subcommand() = 0; | ||
}; | ||
|
||
// Utility function to load data objects from a file, using a static read | ||
// method. | ||
template<typename T> inline T read_from_file(const std::string &file_name) | ||
{ | ||
std::ifstream in(file_name, std::ios_base::binary | std::ios_base::in); | ||
in.exceptions( | ||
std::ios_base::eofbit | std::ios_base::badbit | std::ios_base::failbit); | ||
return T::read(in); | ||
} |
Oops, something went wrong.