From 3635f4567330be93394b1180e7c4d236cf9dff82 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 | 4 +-- bin/assigner/src/main.cpp | 21 +++++++++++++--- bin/recursive_gen/src/main.cpp | 42 +++++++++++-------------------- libs/assigner | 2 +- libs/blueprint | 2 +- libs/crypto3 | 2 +- 6 files changed, 36 insertions(+), 37 deletions(-) diff --git a/.github/workflows/build_linux.yml b/.github/workflows/build_linux.yml index 99c15b9e..b9a5ba40 100644 --- a/.github/workflows/build_linux.yml +++ b/.github/workflows/build_linux.yml @@ -309,7 +309,7 @@ jobs: uses: NilFoundation/evm-placeholder-verification/.github/workflows/reusable-verify-proofs.yml@5bb7c4b0790f56b3a339e33ba442816fac17ab88 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 }} @@ -404,7 +404,7 @@ jobs: uses: NilFoundation/evm-placeholder-verification/.github/workflows/reusable-verify-proofs.yml@5bb7c4b0790f56b3a339e33ba442816fac17ab88 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..53b2afda 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::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) { 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; + std::uint32_t 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); 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..8d0e06b5 160000 --- a/libs/assigner +++ b/libs/assigner @@ -1 +1 @@ -Subproject commit 430218cef592f519ab4d080d77fe397490683b64 +Subproject commit 8d0e06b54bef7f318560c3d3d055f2b53d73cf52 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