Skip to content

Commit

Permalink
Print only target prover
Browse files Browse the repository at this point in the history
  • Loading branch information
akokoshn authored and nkaskov committed Jan 3, 2024
1 parent 4e1357a commit 7b4b365
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 18 deletions.
61 changes: 46 additions & 15 deletions bin/assigner/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ int curve_dependent_main(std::string bytecode_file_name,
boost::log::trivial::severity_level log_level,
const std::string &policy,
std::uint32_t max_num_provers,
std::uint32_t target_prover,
nil::blueprint::print_format circuit_output_print_format) {

constexpr std::size_t ComponentConstantColumns = 5;
Expand Down Expand Up @@ -438,6 +439,7 @@ int curve_dependent_main(std::string bytecode_file_name,
stack_size,
log_level,
max_num_provers,
target_prover,
policy,
circuit_output_print_format,
check_validity
Expand Down Expand Up @@ -474,9 +476,10 @@ int curve_dependent_main(std::string bytecode_file_name,
);
}

constexpr std::uint32_t invalid_target_prover = std::numeric_limits<std::uint32_t>::max();
// print assignment tables and circuits
ASSERT_MSG(parser_instance.assignments.size() == parser_instance.circuits.size(), "Missmatch assignments circuits size");
if (parser_instance.assignments.size() == 1) {
if (parser_instance.assignments.size() == 1 && (target_prover == 0 || target_prover == invalid_target_prover)) {
// print assignment table
std::ofstream otable;
otable.open(assignment_table_file_name, std::ios_base::binary | std::ios_base::out);
Expand Down Expand Up @@ -504,8 +507,11 @@ int curve_dependent_main(std::string bytecode_file_name,
print_circuit<nil::marshalling::option::big_endian, ArithmetizationType, ConstraintSystemType>(
parser_instance.circuits[0], parser_instance.assignments[0], false, ocircuit);
ocircuit.close();
} else if (parser_instance.assignments.size() > 1) {
for (std::uint32_t idx = 0; idx < parser_instance.assignments.size(); idx++) {
} else if (parser_instance.assignments.size() > 1 &&
(target_prover < parser_instance.assignments.size() || invalid_target_prover == invalid_target_prover)) {
std::uint32_t start_idx = (target_prover == invalid_target_prover) ? 0 : target_prover;
std::uint32_t end_idx = (target_prover == invalid_target_prover) ? parser_instance.assignments.size() : target_prover + 1;
for (std::uint32_t idx = start_idx; idx < end_idx; idx++) {
// print assignment table
std::ofstream otable;
otable.open(assignment_table_file_name + std::to_string(idx), std::ios_base::binary | std::ios_base::out);
Expand Down Expand Up @@ -535,22 +541,34 @@ int curve_dependent_main(std::string bytecode_file_name,

ocircuit.close();
}
} else {
std::cout << "No data for print: target prover " << target_prover << ", actual number of provers "
<< parser_instance.assignments.size() << std::endl;
return 1;
}

if (check_validity){
ASSERT_MSG(nil::blueprint::is_satisfied(parser_instance.circuits[0].get(), parser_instance.assignments[0].get()),
"The circuit is not satisfied");
auto assignment_it = parser_instance.assignments.begin();
for (auto& it : parser_instance.circuits) {
ASSERT_MSG(assignment_it != parser_instance.assignments.end(), "Not found assignment for circuit" );
assignment_it->set_check(true);
bool is_accessible = nil::blueprint::is_accessible(it, *assignment_it);
assignment_it->set_check(false);
ASSERT_MSG(is_accessible, ("The circuit is not satisfied on prover " + std::to_string(it.get_id())).c_str() );
assignment_it++;
if (parser_instance.assignments.size() == 1 && (target_prover == 0 || target_prover == invalid_target_prover)) {
ASSERT_MSG(nil::blueprint::is_satisfied(parser_instance.circuits[0].get(), parser_instance.assignments[0].get()),
"The circuit is not satisfied");
} else if (parser_instance.assignments.size() > 1 &&
(target_prover < parser_instance.assignments.size() || invalid_target_prover == invalid_target_prover)) {
// check only for target prover if set
std::uint32_t start_idx = (target_prover == invalid_target_prover) ? 0 : target_prover;
std::uint32_t end_idx = (target_prover == invalid_target_prover) ? parser_instance.assignments.size() : target_prover + 1;
for (std::uint32_t idx = start_idx; idx < end_idx; idx++) {
parser_instance.assignments[idx].set_check(true);
bool is_accessible =
nil::blueprint::is_satisfied(parser_instance.circuits[idx], parser_instance.assignments[idx]);
parser_instance.assignments[idx].set_check(false);
ASSERT_MSG(is_accessible, ("The circuit is not satisfied on prover " + std::to_string(idx)).c_str());
}
} else {
std::cout << "No data for check: target prover " << target_prover << ", actual number of provers "
<< parser_instance.assignments.size() << std::endl;
return 1;
}
}

return 0;
}

Expand All @@ -575,7 +593,8 @@ int main(int argc, char *argv[]) {
("print_circuit_output", "deprecated, use \"-f\" instead")
("print-circuit-output-format,f", boost::program_options::value<std::string>(), "print output of the circuit (dec, hex)")
("policy", boost::program_options::value<std::string>(), "Policy for creating circuits. Possible values: default")
("max-num-provers", boost::program_options::value<int>(), "Maximum number of provers. Possible values >= 1");
("max-num-provers", boost::program_options::value<int>(), "Maximum number of provers. Possible values >= 1")
("target-prover", boost::program_options::value<int>(), "Assignment table and circuit will be generated only for defined prover. Possible values [0, max-num-provers)");
// clang-format on


Expand Down Expand Up @@ -728,6 +747,16 @@ int main(int argc, char *argv[]) {
}
}

std::uint32_t target_prover = std::numeric_limits<std::uint32_t>::max();
if (vm.count("target-prover")) {
target_prover = vm["target-prover"].as<int>();
if (target_prover >= max_num_provers) {
std::cerr << "Invalid command line argument - target-prover. " << target_prover << " is wrong value." << std::endl;
std::cout << options_desc << std::endl;
return 1;
}
}

// We use Boost log trivial severity levels, these are string representations of their names
std::map<std::string, boost::log::trivial::severity_level> log_options{
{"trace", boost::log::trivial::trace},
Expand Down Expand Up @@ -763,6 +792,7 @@ int main(int argc, char *argv[]) {
log_options[log_level],
policy,
max_num_provers,
target_prover,
circuit_output_print_format);
break;
}
Expand All @@ -786,6 +816,7 @@ int main(int argc, char *argv[]) {
log_options[log_level],
policy,
max_num_provers,
target_prover,
circuit_output_print_format);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion libs/assigner
Submodule assigner updated 27 files
+18 −0 .github/workflows/pull_request.yml
+2 −2 include/nil/blueprint/boolean/logic_ops.hpp
+3 −3 include/nil/blueprint/comparison/comparison.hpp
+7 −7 include/nil/blueprint/curves/addition.hpp
+8 −7 include/nil/blueprint/curves/multiplication.hpp
+1 −1 include/nil/blueprint/curves/subtraction.hpp
+9 −9 include/nil/blueprint/fields/addition.hpp
+6 −6 include/nil/blueprint/fields/division.hpp
+9 −9 include/nil/blueprint/fields/multiplication.hpp
+9 −9 include/nil/blueprint/fields/subtraction.hpp
+43 −6 include/nil/blueprint/handle_component.hpp
+2 −2 include/nil/blueprint/hashes/sha2_256.hpp
+3 −3 include/nil/blueprint/hashes/sha2_512.hpp
+2 −2 include/nil/blueprint/integers/addition.hpp
+8 −8 include/nil/blueprint/integers/bit_de_composition.hpp
+4 −4 include/nil/blueprint/integers/bit_shift.hpp
+1 −1 include/nil/blueprint/integers/division.hpp
+5 −4 include/nil/blueprint/integers/division_remainder.hpp
+2 −2 include/nil/blueprint/integers/multiplication.hpp
+2 −2 include/nil/blueprint/integers/subtraction.hpp
+35 −33 include/nil/blueprint/parser.hpp
+2 −2 include/nil/blueprint/recursive_prover/fri_array_swap.hpp
+4 −4 include/nil/blueprint/recursive_prover/fri_cosets.hpp
+2 −2 include/nil/blueprint/recursive_prover/fri_lin_inter.hpp
+4 −4 include/nil/blueprint/recursive_prover/gate_arg_verifier.hpp
+2 −2 include/nil/blueprint/recursive_prover/lookup_arg_verifier.hpp
+4 −4 include/nil/blueprint/recursive_prover/permutation_arg_verifier.hpp
2 changes: 1 addition & 1 deletion libs/blueprint
Submodule blueprint updated 35 files
+7 −94 include/nil/blueprint/blueprint/plonk/assignment_proxy.hpp
+26 −0 include/nil/blueprint/components/algebra/fields/plonk/addition.hpp
+26 −0 include/nil/blueprint/components/algebra/fields/plonk/division.hpp
+25 −0 include/nil/blueprint/components/algebra/fields/plonk/division_or_zero.hpp
+43 −0 include/nil/blueprint/components/algebra/fields/plonk/logic_and_flag.hpp
+45 −0 include/nil/blueprint/components/algebra/fields/plonk/logic_or_flag.hpp
+27 −0 include/nil/blueprint/components/algebra/fields/plonk/multiplication.hpp
+24 −0 include/nil/blueprint/components/algebra/fields/plonk/multiplication_by_constant.hpp
+105 −0 include/nil/blueprint/components/algebra/fields/plonk/non_native/addition.hpp
+52 −0 include/nil/blueprint/components/algebra/fields/plonk/non_native/bit_composition.hpp
+58 −0 include/nil/blueprint/components/algebra/fields/plonk/non_native/bit_decomposition.hpp
+148 −4 include/nil/blueprint/components/algebra/fields/plonk/non_native/comparison_flag.hpp
+1 −1 include/nil/blueprint/components/algebra/fields/plonk/non_native/detail/bit_builder_component.hpp
+50 −0 include/nil/blueprint/components/algebra/fields/plonk/non_native/division_remainder.hpp
+130 −0 include/nil/blueprint/components/algebra/fields/plonk/non_native/multiplication.hpp
+104 −0 include/nil/blueprint/components/algebra/fields/plonk/non_native/subtraction.hpp
+26 −0 include/nil/blueprint/components/algebra/fields/plonk/subtraction.hpp
+66 −0 include/nil/blueprint/components/hashes/sha2/plonk/decomposition.hpp
+81 −5 include/nil/blueprint/components/hashes/sha2/plonk/sha256.hpp
+319 −0 include/nil/blueprint/components/hashes/sha2/plonk/sha256_process.hpp
+103 −88 include/nil/blueprint/utils/satisfiability_check.hpp
+6 −0 test/algebra/fields/plonk/field_operations.cpp
+2 −0 test/algebra/fields/plonk/logic_and_flag.cpp
+2 −0 test/algebra/fields/plonk/logic_or_flag.cpp
+2 −0 test/algebra/fields/plonk/non_native/addition.cpp
+3 −0 test/algebra/fields/plonk/non_native/bit_composition.cpp
+3 −0 test/algebra/fields/plonk/non_native/bit_decomposition.cpp
+3 −0 test/algebra/fields/plonk/non_native/comparison_flag.cpp
+3 −0 test/algebra/fields/plonk/non_native/division_remainder.cpp
+2 −0 test/algebra/fields/plonk/non_native/multiplication.cpp
+2 −0 test/algebra/fields/plonk/non_native/subtraction.cpp
+16 −8 test/hashes/plonk/decomposition.cpp
+8 −1 test/hashes/plonk/sha256.cpp
+13 −0 test/hashes/plonk/sha256_process.cpp
+90 −0 test/test_plonk_component.hpp
2 changes: 1 addition & 1 deletion libs/circifier

0 comments on commit 7b4b365

Please sign in to comment.