-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c6b3a6
commit b291453
Showing
4 changed files
with
194 additions
and
18 deletions.
There are no files selected for viewing
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
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,143 @@ | ||
/* | ||
* mmx_postool.cpp | ||
* | ||
* Created on: Apr 5, 2024 | ||
* Author: mad | ||
*/ | ||
|
||
#include <mmx/pos/Prover.h> | ||
#include <mmx/pos/verify.h> | ||
|
||
#include <vnx/vnx.h> | ||
#include <cmath> | ||
|
||
using namespace mmx; | ||
|
||
|
||
int main(int argc, char** argv) | ||
{ | ||
mmx::secp256k1_init(); | ||
|
||
std::map<std::string, std::string> options; | ||
options["f"] = "file"; | ||
options["n"] = "iter"; | ||
options["r"] = "threads"; | ||
options["v"] = "verbose"; | ||
options["file"] = "plot files"; | ||
options["iter"] = "number of iterations"; | ||
options["threads"] = "number of threads"; | ||
|
||
vnx::write_config("log_level", 2); | ||
|
||
vnx::init("mmx_postool", argc, argv, options); | ||
|
||
bool verbose = false; | ||
int num_iter = 100; | ||
int num_threads = 16; | ||
int plot_filter = 4; | ||
std::vector<std::string> file_names; | ||
|
||
vnx::read_config("verbose", verbose); | ||
vnx::read_config("file", file_names); | ||
vnx::read_config("iter", num_iter); | ||
vnx::read_config("threads", num_threads); | ||
|
||
if(verbose) { | ||
std::cout << "Threads: " << num_threads << std::endl; | ||
std::cout << "Iterations: " << num_iter << std::endl; | ||
} | ||
|
||
struct summary_t { | ||
std::string file; | ||
bool valid = false; | ||
std::atomic<uint32_t> num_pass {0}; | ||
std::atomic<uint32_t> num_fail {0}; | ||
}; | ||
|
||
std::mutex mutex; | ||
std::vector<std::shared_ptr<summary_t>> result; | ||
|
||
for(const auto& file_name : file_names) | ||
{ | ||
auto out = std::make_shared<summary_t>(); | ||
out->file = file_name; | ||
try { | ||
auto prover = std::make_shared<pos::Prover>(file_name); | ||
prover->debug = true; | ||
auto header = prover->get_header(); | ||
if(verbose) { | ||
std::cout << "[" << file_name << "]" << std::endl; | ||
std::cout << "Size: " << (header->has_meta ? "HDD" : "SSD") << " K" << header->ksize << " C" << prover->get_clevel() | ||
<< " (" << header->plot_size / pow(1024, 3) << " GiB)" << std::endl; | ||
std::cout << "Plot ID: " << prover->get_plot_id().to_string() << std::endl; | ||
std::cout << "Contract: " << (header->contract ? header->contract->to_string() : std::string("N/A")) << std::endl; | ||
} | ||
out->valid = true; | ||
|
||
for(int iter = 0; iter < num_iter && vnx::do_run(); ++iter) | ||
{ | ||
const hash_t challenge(std::to_string(iter)); | ||
try { | ||
const auto qualities = prover->get_qualities(challenge, plot_filter); | ||
|
||
for(const auto& entry : qualities) | ||
{ | ||
if(verbose) { | ||
std::lock_guard<std::mutex> lock(mutex); | ||
std::cout << "[" << iter << "] index = " << entry.index << ", quality = " << entry.quality.to_string() << std::endl; | ||
} | ||
std::vector<uint32_t> proof; | ||
if(entry.proof.size()) { | ||
proof = entry.proof; | ||
} else { | ||
proof = prover->get_full_proof(challenge, entry.index).proof; | ||
} | ||
try { | ||
const auto quality = pos::verify(proof, challenge, header->plot_id, plot_filter, header->ksize); | ||
if(quality != entry.quality) { | ||
throw std::logic_error("invalid quality"); | ||
} | ||
if(verbose) { | ||
std::lock_guard<std::mutex> lock(mutex); | ||
std::cout << "Proof " << entry.index << " passed: "; | ||
for(const auto X : proof) { | ||
std::cout << X << " "; | ||
} | ||
std::cout << std::endl; | ||
} | ||
out->num_pass++; | ||
} | ||
catch(const std::exception& ex) { | ||
std::lock_guard<std::mutex> lock(mutex); | ||
std::cerr << "Threw: " << ex.what() << std::endl; | ||
out->num_fail++; | ||
} | ||
} | ||
} | ||
catch(const std::exception& ex) { | ||
std::lock_guard<std::mutex> lock(mutex); | ||
std::cerr << "Threw: " << ex.what() << std::endl; | ||
out->num_fail++; | ||
} | ||
} | ||
} | ||
catch(const std::exception& ex) { | ||
std::cerr << "Failed to open plot " << file_name << ": " << ex.what() << std::endl; | ||
} | ||
result.push_back(out); | ||
} | ||
|
||
for(auto entry : result) | ||
{ | ||
std::cout << "[" << entry->file << "]" << std::endl; | ||
const auto expected = uint64_t(num_iter) << plot_filter; | ||
std::cout << "Pass: " << entry->num_pass << " / " << expected << std::endl; | ||
std::cout << "Fail: " << entry->num_fail << " / " << expected << std::endl; | ||
} | ||
vnx::close(); | ||
|
||
mmx::secp256k1_free(); | ||
return 0; | ||
} | ||
|
||
|