From 1d10784c75bb484a8c34f46fbdcce933dc46614f Mon Sep 17 00:00:00 2001 From: akokoshn Date: Thu, 14 Mar 2024 18:42:05 +0200 Subject: [PATCH] Set public input sizes --- .github/workflows/build_linux.yml | 12 ++++----- bin/assigner/src/main.cpp | 25 +++++++++++++----- bin/recursive_gen/src/main.cpp | 42 +++++++++++-------------------- libs/assigner | 2 +- libs/blueprint | 2 +- libs/crypto3 | 2 +- multi_gen_and_check.sh | 14 +++++------ 7 files changed, 49 insertions(+), 50 deletions(-) diff --git a/.github/workflows/build_linux.yml b/.github/workflows/build_linux.yml index 99c15b9e..d86d4ec3 100644 --- a/.github/workflows/build_linux.yml +++ b/.github/workflows/build_linux.yml @@ -306,10 +306,10 @@ jobs: always() && !cancelled() && (needs.handle-syncwith.result == 'success' || needs.handle-syncwith.result == 'skipped') && needs.build-and-test-linux.result == 'success' - uses: NilFoundation/evm-placeholder-verification/.github/workflows/reusable-verify-proofs.yml@5bb7c4b0790f56b3a339e33ba442816fac17ab88 + uses: NilFoundation/evm-placeholder-verification/.github/workflows/reusable-verify-proofs.yml@2a0ef5fc67e97be8e3c7b59338cf9eecd030c57d with: artifact-name: ${{ needs.build-and-test-linux.outputs.transpiler-artifact-name }} - evm-placeholder-verification-ref: 202fbd0402eda22ae91348800dea7366110b1501 + evm-placeholder-verification-ref: 2a0ef5fc67e97be8e3c7b59338cf9eecd030c57d refs: ${{ needs.handle-syncwith.outputs.prs-refs }} test-names: ${{ needs.build-and-test-linux.outputs.evm-targets }} @@ -323,11 +323,11 @@ jobs: always() && !cancelled() && (needs.handle-syncwith.result == 'success' || needs.handle-syncwith.result == 'skipped') && needs.build-and-test-linux.result == 'success' - uses: NilFoundation/proof-producer/.github/workflows/reusable-generate-proofs-linux.yml@b1e380040b4714b6ad5fe9223555d854c49cf065 + uses: NilFoundation/proof-producer/.github/workflows/reusable-generate-proofs-linux.yml@4ddd85878d66f9b916e9fbdafe51180058e5bdaa with: artifact-name: ${{ needs.build-and-test-linux.outputs.examples-artifact-name }} # Update next line if you need new version of proof producer - proof-producer-ref: d6d8d18cd7a6e15dd9497140350efadb6af5179b + proof-producer-ref: 4ddd85878d66f9b916e9fbdafe51180058e5bdaa refs: ${{ needs.handle-syncwith.outputs.prs-refs }} targets: ${{ needs.build-and-test-linux.outputs.prover-targets }} @@ -401,10 +401,10 @@ jobs: (needs.handle-syncwith.result == 'success' || needs.handle-syncwith.result == 'skipped') && needs.build-and-test-linux.result == 'success' && needs.merge-proofs-to-transpiler-output.result == 'success' - uses: NilFoundation/evm-placeholder-verification/.github/workflows/reusable-verify-proofs.yml@5bb7c4b0790f56b3a339e33ba442816fac17ab88 + uses: NilFoundation/evm-placeholder-verification/.github/workflows/reusable-verify-proofs.yml@2a0ef5fc67e97be8e3c7b59338cf9eecd030c57d with: artifact-name: ${{ needs.merge-proofs-to-transpiler-output.outputs.merged-artifact-name }} - evm-placeholder-verification-ref: 202fbd0402eda22ae91348800dea7366110b1501 + evm-placeholder-verification-ref: 2a0ef5fc67e97be8e3c7b59338cf9eecd030c57d refs: ${{ needs.handle-syncwith.outputs.prs-refs }} test-names: ${{ needs.build-and-test-linux.outputs.evm-targets }} diff --git a/bin/assigner/src/main.cpp b/bin/assigner/src/main.cpp index 2e8de5a2..1a8bbc5b 100644 --- a/bin/assigner/src/main.cpp +++ b/bin/assigner/src/main.cpp @@ -69,7 +69,7 @@ using namespace nil::blueprint; template void print_circuit(const circuit_proxy &circuit_proxy, const assignment_proxy &table_proxy, - bool rename_required, std::ostream &out = std::cout) { + bool multi_prover, std::uint32_t idx, std::ostream &out = std::cout) { using TTypeBase = nil::marshalling::field_type; using value_marshalling_type = nil::crypto3::marshalling::types::plonk_constraint_system; @@ -90,7 +90,7 @@ void print_circuit(const circuit_proxy &circuit_proxy, used_copy_constraints.push_back(copy_constraints[it]); } - if (rename_required) { + if (multi_prover && idx > 0) { const auto& used_rows = table_proxy.get_used_rows(); std::uint32_t local_row = 0; for (const auto &row : used_rows) { @@ -128,13 +128,26 @@ void print_circuit(const circuit_proxy &circuit_proxy, used_lookup_tables.push_back(lookup_tables[it]); } + + // fill public input sizes + nil::crypto3::marshalling::types::public_input_sizes_type public_input_sizes; + using public_input_size_type = typename nil::crypto3::marshalling::types::public_input_sizes_type::element_type; + const auto public_input_size = table_proxy.public_inputs_amount(); + for (std::uint32_t i = 0; i < public_input_size; i++) { + public_input_sizes.value().push_back(public_input_size_type(table_proxy.public_input_column_size(i))); + } + if (multi_prover) { + public_input_sizes.value().push_back(public_input_size_type(table_proxy.shared_column_size(0))); + } + auto filled_val = value_marshalling_type(std::make_tuple( nil::crypto3::marshalling::types::fill_plonk_gates(used_gates), nil::crypto3::marshalling::types::fill_plonk_copy_constraints(used_copy_constraints), nil::crypto3::marshalling::types::fill_plonk_lookup_gates(used_lookup_gates), - nil::crypto3::marshalling::types::fill_plonk_lookup_tables(used_lookup_tables) - )); + nil::crypto3::marshalling::types::fill_plonk_lookup_tables(used_lookup_tables), + public_input_sizes + )); std::vector cv; cv.resize(filled_val.length(), 0x00); @@ -559,7 +572,7 @@ int curve_dependent_main(std::string bytecode_file_name, } print_circuit( - assigner_instance.circuits[0], assigner_instance.assignments[0], false, ocircuit); + assigner_instance.circuits[0], assigner_instance.assignments[0], false, 0, ocircuit); ocircuit.close(); } } else if (assigner_instance.assignments.size() > 1 && @@ -596,7 +609,7 @@ int curve_dependent_main(std::string bytecode_file_name, ASSERT_MSG(idx < assigner_instance.circuits.size(), "Not found circuit"); print_circuit( - assigner_instance.circuits[idx], assigner_instance.assignments[idx], (idx > 0), ocircuit); + assigner_instance.circuits[idx], assigner_instance.assignments[idx], true, idx, ocircuit); ocircuit.close(); } diff --git a/bin/recursive_gen/src/main.cpp b/bin/recursive_gen/src/main.cpp index 03940240..6d84e60b 100644 --- a/bin/recursive_gen/src/main.cpp +++ b/bin/recursive_gen/src/main.cpp @@ -177,8 +177,6 @@ int main(int argc, char *argv[]) { It'll be better to create an empty folder for output") ("skip-verification", "Used with gen-test-proof, if set - skips verifiyng the generated proof") ("multi-prover", "Pass this flag if input circuit is a part of larger circuit, divided for faster paralel proving") - ("public-input-rows,p", boost::program_options::value(), "Used public input column rows") - ("shared-rows,s", boost::program_options::value(), "Used shared rows") ("elliptic-curve-type,e", boost::program_options::value(), "Native elliptic curve type (pallas, vesta, ed25519, bls12381)"); // clang-format on @@ -303,38 +301,12 @@ int curve_dependent_main( return 1; } - std::uint32_t public_input_rows = 50; - if (vm.count("public-input-rows")) { - public_input_rows = vm["public-input-rows"].as(); } - - std::uint32_t shared_rows = 50; - if (vm.count("shared-rows")) { - if( !vm.count("shared-rows") ) - std::cout << "shared-rows parameter will be ignored because it is single-prover example" << std::endl; - shared_rows = vm["shared-rows"].as(); - } - using parameters_policy = ParametersPolicy; constexpr std::size_t WitnessColumns = parameters_policy::WitnessColumns; constexpr std::size_t PublicInputColumns = is_multi_prover? parameters_policy::PublicInputColumns + 1: parameters_policy::PublicInputColumns; constexpr std::size_t ConstantColumns = parameters_policy::ComponentConstantColumns + parameters_policy::LookupConstantColumns; constexpr std::size_t SelectorColumns = parameters_policy::ComponentSelectorColumns + parameters_policy::LookupSelectorColumns; - std::cout << "WitnessColumns = " << WitnessColumns << std::endl; - std::cout << "PublicInputColumns = " << PublicInputColumns << std::endl; - std::cout << "ConstantColumns = " << ConstantColumns << ": LookupConstantColumns = " << parameters_policy::LookupConstantColumns << std::endl; - std::cout << "SelectorColumns = " << SelectorColumns << ": LookupSelectorColumns = " << parameters_policy::LookupSelectorColumns << std::endl; - - std::vector public_input_sizes(PublicInputColumns); - for(std::size_t i = 0; i < PublicInputColumns; i++){ - public_input_sizes[i] = public_input_rows; - } - if( is_multi_prover ) - public_input_sizes[PublicInputColumns - 1] = shared_rows; - - zk::snark::plonk_table_description desc( - WitnessColumns, PublicInputColumns, ConstantColumns, SelectorColumns); - // Circuit-specific parameter using ConstraintSystemType = nil::crypto3::zk::snark::plonk_constraint_system; @@ -364,6 +336,7 @@ int curve_dependent_main( } ConstraintSystemType constraint_system; + std::vector public_input_sizes(PublicInputColumns); { std::ifstream ifile; ifile.open(circuit_file_name, std::ios_base::binary | std::ios_base::in); @@ -389,9 +362,16 @@ int curve_dependent_main( constraint_system = nil::crypto3::marshalling::types::make_plonk_constraint_system( marshalled_data ); + + for(std::size_t i = 0; i < constraint_system.public_input_sizes_num(); i++){ + public_input_sizes[i] = constraint_system.public_input_size(i); + std::cout << "Public input size " << i << " = " << public_input_sizes[i] << std::endl; + } } AssignmentTableType assignment_table; + zk::snark::plonk_table_description desc( + WitnessColumns, PublicInputColumns, ConstantColumns, SelectorColumns); { std::ifstream iassignment; iassignment.open(assignment_table_file_name, std::ios_base::binary | std::ios_base::in); @@ -419,6 +399,12 @@ int curve_dependent_main( ); desc.rows_amount = assignment_table.rows_amount(); } + + std::cout << "WitnessColumns = " << desc.witness_columns << std::endl; + std::cout << "PublicInputColumns = " << desc.public_input_columns << std::endl; + std::cout << "ConstantColumns = " << desc.constant_columns << ": LookupConstantColumns = " << parameters_policy::LookupConstantColumns << std::endl; + std::cout << "SelectorColumns = " << desc.selector_columns << ": LookupSelectorColumns = " << parameters_policy::LookupSelectorColumns << std::endl; + std::vector> columns_rotations; const std::size_t Lambda = parameters_policy::lambda; diff --git a/libs/assigner b/libs/assigner index 430218ce..da77d320 160000 --- a/libs/assigner +++ b/libs/assigner @@ -1 +1 @@ -Subproject commit 430218cef592f519ab4d080d77fe397490683b64 +Subproject commit da77d320a90ca8602a2f7e0e6eed00e8cb02bbb4 diff --git a/libs/blueprint b/libs/blueprint index c2c7bc85..fde02cb0 160000 --- a/libs/blueprint +++ b/libs/blueprint @@ -1 +1 @@ -Subproject commit c2c7bc8534c4f3d4dabf0c4e0356002dd22530cd +Subproject commit fde02cb041a0d4603dd80b9318a66179d98acd65 diff --git a/libs/crypto3 b/libs/crypto3 index e74da0f4..5df15560 160000 --- a/libs/crypto3 +++ b/libs/crypto3 @@ -1 +1 @@ -Subproject commit e74da0f4feccb81678ccc0e7bf5179828cde575d +Subproject commit 5df15560a68f42d0fef94bad3cc7321ebb983aba diff --git a/multi_gen_and_check.sh b/multi_gen_and_check.sh index 82ff6c4a..e5d5d431 100755 --- a/multi_gen_and_check.sh +++ b/multi_gen_and_check.sh @@ -3,8 +3,8 @@ mkdir -p ./recursive ninja -C build merkle_poseidon_3provers_cpp_example_generate_both -j4 # Generate proof and verifier for 1st piece -./build/bin/recursive_gen/recursive_gen -m gen-input -i ./examples/inputs/merkle_poseidon_3provers_public.inp -t ./build/examples/cpp/assignment_merkle_poseidon_3provers_cpp_example.tbl0 -c ./build/examples/cpp/circuit_merkle_poseidon_3provers_cpp_example.crct0 -o ./recursive -e pallas -p 1 -s 3 --multi-prover -./build/bin/recursive_gen/recursive_gen -m gen-verifier -i ./examples/inputs/merkle_poseidon_3provers_public.inp -t ./build/examples/cpp/assignment_merkle_poseidon_3provers_cpp_example.tbl0 -c ./build/examples/cpp/circuit_merkle_poseidon_3provers_cpp_example.crct0 -o ./recursive -e pallas -p 1 -s 3 --multi-prover +./build/bin/recursive_gen/recursive_gen -m gen-input -i ./examples/inputs/merkle_poseidon_3provers_public.inp -t ./build/examples/cpp/assignment_merkle_poseidon_3provers_cpp_example.tbl0 -c ./build/examples/cpp/circuit_merkle_poseidon_3provers_cpp_example.crct0 -o ./recursive -e pallas --multi-prover +./build/bin/recursive_gen/recursive_gen -m gen-verifier -i ./examples/inputs/merkle_poseidon_3provers_public.inp -t ./build/examples/cpp/assignment_merkle_poseidon_3provers_cpp_example.tbl0 -c ./build/examples/cpp/circuit_merkle_poseidon_3provers_cpp_example.crct0 -o ./recursive -e pallas --multi-prover # Copy 1st piece files to placeholder_verifier example cp -rf ./recursive/placeholder_verifier.cpp ./examples/cpp/placeholder_verifier.cpp @@ -15,8 +15,8 @@ ninja -C build placeholder_verifier_cpp_example -j4 ./build/bin/assigner/assigner -i ./examples/inputs/placeholder_verifier.inp -b ./build/examples/cpp/placeholder_verifier_cpp_example.ll -c recursive/circuit.crct -t recursive/assignment.tbl --max-num-provers 100 -e pallas --check --column-sizes {15,1,2,0,60,0} # Generate proof and verifier for 2nd piece -./build/bin/recursive_gen/recursive_gen -m gen-input -i ./examples/inputs/merkle_poseidon_3provers_public.inp -t ./build/examples/cpp/assignment_merkle_poseidon_3provers_cpp_example.tbl1 -c ./build/examples/cpp/circuit_merkle_poseidon_3provers_cpp_example.crct1 -o ./recursive -e pallas -p 1 -s 3 --multi-prover -./build/bin/recursive_gen/recursive_gen -m gen-verifier -i ./examples/inputs/merkle_poseidon_3provers_public.inp -t ./build/examples/cpp/assignment_merkle_poseidon_3provers_cpp_example.tbl1 -c ./build/examples/cpp/circuit_merkle_poseidon_3provers_cpp_example.crct1 -o ./recursive -e pallas -p 1 -s 3 --multi-prover +./build/bin/recursive_gen/recursive_gen -m gen-input -i ./examples/inputs/merkle_poseidon_3provers_public.inp -t ./build/examples/cpp/assignment_merkle_poseidon_3provers_cpp_example.tbl1 -c ./build/examples/cpp/circuit_merkle_poseidon_3provers_cpp_example.crct1 -o ./recursive -e pallas --multi-prover +./build/bin/recursive_gen/recursive_gen -m gen-verifier -i ./examples/inputs/merkle_poseidon_3provers_public.inp -t ./build/examples/cpp/assignment_merkle_poseidon_3provers_cpp_example.tbl1 -c ./build/examples/cpp/circuit_merkle_poseidon_3provers_cpp_example.crct1 -o ./recursive -e pallas --multi-prover # Copy 2nd piece files to placeholder_verifier example cp -rf ./recursive/placeholder_verifier.cpp ./examples/cpp/placeholder_verifier.cpp @@ -27,8 +27,8 @@ ninja -C build placeholder_verifier_cpp_example -j4 ./build/bin/assigner/assigner -i ./examples/inputs/placeholder_verifier.inp -b ./build/examples/cpp/placeholder_verifier_cpp_example.ll -c recursive/circuit.crct -t recursive/assignment.tbl --max-num-provers 100 -e pallas --check --column-sizes {15,1,2,0,60,0} # Generate proof and verifier for 3rd piece -./build/bin/recursive_gen/recursive_gen -m gen-input -i ./examples/inputs/merkle_poseidon_3provers_public.inp -t ./build/examples/cpp/assignment_merkle_poseidon_3provers_cpp_example.tbl2 -c ./build/examples/cpp/circuit_merkle_poseidon_3provers_cpp_example.crct2 -o ./recursive -e pallas -p 1 -s 3 --multi-prover -./build/bin/recursive_gen/recursive_gen -m gen-verifier -i ./examples/inputs/merkle_poseidon_3provers_public.inp -t ./build/examples/cpp/assignment_merkle_poseidon_3provers_cpp_example.tbl2 -c ./build/examples/cpp/circuit_merkle_poseidon_3provers_cpp_example.crct2 -o ./recursive -e pallas -p 1 -s 3 --multi-prover +./build/bin/recursive_gen/recursive_gen -m gen-input -i ./examples/inputs/merkle_poseidon_3provers_public.inp -t ./build/examples/cpp/assignment_merkle_poseidon_3provers_cpp_example.tbl2 -c ./build/examples/cpp/circuit_merkle_poseidon_3provers_cpp_example.crct2 -o ./recursive -e pallas --multi-prover +./build/bin/recursive_gen/recursive_gen -m gen-verifier -i ./examples/inputs/merkle_poseidon_3provers_public.inp -t ./build/examples/cpp/assignment_merkle_poseidon_3provers_cpp_example.tbl2 -c ./build/examples/cpp/circuit_merkle_poseidon_3provers_cpp_example.crct2 -o ./recursive -e pallas --multi-prover # Copy 3rd piece files to placeholder_verifier example cp -rf ./recursive/placeholder_verifier.cpp ./examples/cpp/placeholder_verifier.cpp @@ -36,4 +36,4 @@ cp -rf ./recursive/placeholder_verifier.inp ./examples/inputs/placeholder_verifi # Assign it ninja -C build placeholder_verifier_cpp_example -j4 -./build/bin/assigner/assigner -i ./examples/inputs/placeholder_verifier.inp -b ./build/examples/cpp/placeholder_verifier_cpp_example.ll -c recursive/circuit.crct -t recursive/assignment.tbl --max-num-provers 100 -e pallas --check --column-sizes {15,1,2,0,60,0} \ No newline at end of file +./build/bin/assigner/assigner -i ./examples/inputs/placeholder_verifier.inp -b ./build/examples/cpp/placeholder_verifier_cpp_example.ll -c recursive/circuit.crct -t recursive/assignment.tbl --max-num-provers 100 -e pallas --check --column-sizes {15,1,2,0,60,0}