From 9c01bb632db2c1af001644018fde9171601d7750 Mon Sep 17 00:00:00 2001 From: Andrey Nefedov Date: Thu, 3 Oct 2024 22:05:12 +0000 Subject: [PATCH] Save proof data only with --save-proof-data arg --- transpiler/test/evm.cpp | 627 +++++++++++++++++++++------------------- 1 file changed, 333 insertions(+), 294 deletions(-) diff --git a/transpiler/test/evm.cpp b/transpiler/test/evm.cpp index 15cd3b11fe..876c638259 100644 --- a/transpiler/test/evm.cpp +++ b/transpiler/test/evm.cpp @@ -415,6 +415,19 @@ void print_public_input(ColumnType &public_input, std::string filename) { pi_stream.close(); } +bool have_arg(std::string arg) { + for (std::size_t i = 0; i < std::size_t(boost::unit_test::framework::master_test_suite().argc); i++) { + if (std::string(boost::unit_test::framework::master_test_suite().argv[i]) == arg) { + return true; + } + } + return false; +} + +bool should_save_proof_data() { + return have_arg("--save-proof-data"); +} + std::string public_input_filename = "public_input.inp"; BOOST_AUTO_TEST_SUITE(placeholder_circuit1) @@ -493,42 +506,45 @@ BOOST_FIXTURE_TEST_CASE(transpiler_test, test_initializer) { ); printer.print(); - typename placeholder_private_preprocessor::preprocessed_data_type - lpc_preprocessed_private_data = - placeholder_private_preprocessor::process( - constraint_system, - assignments.private_table(), - desc - ); + if (should_save_proof_data()) { + typename placeholder_private_preprocessor::preprocessed_data_type + lpc_preprocessed_private_data = + placeholder_private_preprocessor::process( + constraint_system, + assignments.private_table(), + desc + ); - auto lpc_proof = placeholder_prover::process( - lpc_preprocessed_public_data, - lpc_preprocessed_private_data, - desc, - constraint_system, - lpc_scheme - ); + auto lpc_proof = placeholder_prover::process( + lpc_preprocessed_public_data, + lpc_preprocessed_private_data, + desc, + constraint_system, + lpc_scheme + ); - print_placeholder_proof_with_params( - lpc_preprocessed_public_data, - lpc_proof, - lpc_scheme, - desc, - output - ); - print_public_input( - desc.public_input_columns == 0 ? std::vector({}) : assignments.public_input(0), - output + "/" + public_input_filename - ); + print_placeholder_proof_with_params( + lpc_preprocessed_public_data, + lpc_proof, + lpc_scheme, + desc, + output + ); + print_public_input( + desc.public_input_columns == 0 ? std::vector({}) + : assignments.public_input(0), + output + "/" + public_input_filename + ); - auto verifier_res = placeholder_verifier::process( - lpc_preprocessed_public_data.common_data, - lpc_proof, - desc, - constraint_system, - lpc_scheme - ); - BOOST_CHECK(verifier_res); + auto verifier_res = placeholder_verifier::process( + lpc_preprocessed_public_data.common_data, + lpc_proof, + desc, + constraint_system, + lpc_scheme + ); + BOOST_CHECK(verifier_res); + } } BOOST_AUTO_TEST_SUITE_END() @@ -614,42 +630,45 @@ BOOST_FIXTURE_TEST_CASE(transpiler_test, test_initializer) { ); printer.print(); - typename placeholder_private_preprocessor::preprocessed_data_type - lpc_preprocessed_private_data = - placeholder_private_preprocessor::process( - constraint_system, - assignments.private_table(), - desc - ); + if (should_save_proof_data()) { + typename placeholder_private_preprocessor::preprocessed_data_type + lpc_preprocessed_private_data = + placeholder_private_preprocessor::process( + constraint_system, + assignments.private_table(), + desc + ); - auto lpc_proof = placeholder_prover::process( - lpc_preprocessed_public_data, - lpc_preprocessed_private_data, - desc, - constraint_system, - lpc_scheme - ); + auto lpc_proof = placeholder_prover::process( + lpc_preprocessed_public_data, + lpc_preprocessed_private_data, + desc, + constraint_system, + lpc_scheme + ); - print_placeholder_proof_with_params( - lpc_preprocessed_public_data, - lpc_proof, - lpc_scheme, - desc, - output - ); - print_public_input( - desc.public_input_columns == 0 ? std::vector({}) : assignments.public_input(0), - output + "/" + public_input_filename - ); + print_placeholder_proof_with_params( + lpc_preprocessed_public_data, + lpc_proof, + lpc_scheme, + desc, + output + ); + print_public_input( + desc.public_input_columns == 0 ? std::vector({}) + : assignments.public_input(0), + output + "/" + public_input_filename + ); - auto verifier_res = placeholder_verifier::process( - lpc_preprocessed_public_data.common_data, - lpc_proof, - desc, - constraint_system, - lpc_scheme - ); - BOOST_CHECK(verifier_res); + auto verifier_res = placeholder_verifier::process( + lpc_preprocessed_public_data.common_data, + lpc_proof, + desc, + constraint_system, + lpc_scheme + ); + BOOST_CHECK(verifier_res); + } } BOOST_AUTO_TEST_SUITE_END() @@ -735,42 +754,45 @@ BOOST_FIXTURE_TEST_CASE(transpiler_test, test_initializer) { ); printer.print(); - typename placeholder_private_preprocessor::preprocessed_data_type - lpc_preprocessed_private_data = - placeholder_private_preprocessor::process( - constraint_system, - assignments.private_table(), - desc - ); + if (should_save_proof_data()) { + typename placeholder_private_preprocessor::preprocessed_data_type + lpc_preprocessed_private_data = + placeholder_private_preprocessor::process( + constraint_system, + assignments.private_table(), + desc + ); - auto lpc_proof = placeholder_prover::process( - lpc_preprocessed_public_data, - lpc_preprocessed_private_data, - desc, - constraint_system, - lpc_scheme - ); + auto lpc_proof = placeholder_prover::process( + lpc_preprocessed_public_data, + lpc_preprocessed_private_data, + desc, + constraint_system, + lpc_scheme + ); - print_placeholder_proof_with_params( - lpc_preprocessed_public_data, - lpc_proof, - lpc_scheme, - desc, - output - ); - print_public_input( - desc.public_input_columns == 0 ? std::vector({}) : assignments.public_input(0), - output + "/" + public_input_filename - ); + print_placeholder_proof_with_params( + lpc_preprocessed_public_data, + lpc_proof, + lpc_scheme, + desc, + output + ); + print_public_input( + desc.public_input_columns == 0 ? std::vector({}) + : assignments.public_input(0), + output + "/" + public_input_filename + ); - auto verifier_res = placeholder_verifier::process( - lpc_preprocessed_public_data.common_data, - lpc_proof, - desc, - constraint_system, - lpc_scheme - ); - BOOST_CHECK(verifier_res); + auto verifier_res = placeholder_verifier::process( + lpc_preprocessed_public_data.common_data, + lpc_proof, + desc, + constraint_system, + lpc_scheme + ); + BOOST_CHECK(verifier_res); + } } BOOST_AUTO_TEST_SUITE_END() @@ -855,42 +877,45 @@ BOOST_FIXTURE_TEST_CASE(transpiler_test, test_initializer) { ); printer.print(); - typename placeholder_private_preprocessor::preprocessed_data_type - lpc_preprocessed_private_data = - placeholder_private_preprocessor::process( - constraint_system, - assignments.private_table(), - desc - ); + if (should_save_proof_data()) { + typename placeholder_private_preprocessor::preprocessed_data_type + lpc_preprocessed_private_data = + placeholder_private_preprocessor::process( + constraint_system, + assignments.private_table(), + desc + ); - auto lpc_proof = placeholder_prover::process( - lpc_preprocessed_public_data, - lpc_preprocessed_private_data, - desc, - constraint_system, - lpc_scheme - ); + auto lpc_proof = placeholder_prover::process( + lpc_preprocessed_public_data, + lpc_preprocessed_private_data, + desc, + constraint_system, + lpc_scheme + ); - print_placeholder_proof_with_params( - lpc_preprocessed_public_data, - lpc_proof, - lpc_scheme, - desc, - output - ); - print_public_input( - desc.public_input_columns == 0 ? std::vector({}) : assignments.public_input(0), - output + "/" + public_input_filename - ); + print_placeholder_proof_with_params( + lpc_preprocessed_public_data, + lpc_proof, + lpc_scheme, + desc, + output + ); + print_public_input( + desc.public_input_columns == 0 ? std::vector({}) + : assignments.public_input(0), + output + "/" + public_input_filename + ); - auto verifier_res = placeholder_verifier::process( - lpc_preprocessed_public_data.common_data, - lpc_proof, - desc, - constraint_system, - lpc_scheme - ); - BOOST_CHECK(verifier_res); + auto verifier_res = placeholder_verifier::process( + lpc_preprocessed_public_data.common_data, + lpc_proof, + desc, + constraint_system, + lpc_scheme + ); + BOOST_CHECK(verifier_res); + } } BOOST_AUTO_TEST_SUITE_END() @@ -975,42 +1000,45 @@ BOOST_FIXTURE_TEST_CASE(transpiler_test, test_initializer) { ); printer.print(); - typename placeholder_private_preprocessor::preprocessed_data_type - lpc_preprocessed_private_data = - placeholder_private_preprocessor::process( - constraint_system, - assignments.private_table(), - desc - ); + if (should_save_proof_data()) { + typename placeholder_private_preprocessor::preprocessed_data_type + lpc_preprocessed_private_data = + placeholder_private_preprocessor::process( + constraint_system, + assignments.private_table(), + desc + ); - auto lpc_proof = placeholder_prover::process( - lpc_preprocessed_public_data, - lpc_preprocessed_private_data, - desc, - constraint_system, - lpc_scheme - ); + auto lpc_proof = placeholder_prover::process( + lpc_preprocessed_public_data, + lpc_preprocessed_private_data, + desc, + constraint_system, + lpc_scheme + ); - print_placeholder_proof_with_params( - lpc_preprocessed_public_data, - lpc_proof, - lpc_scheme, - desc, - output - ); - print_public_input( - desc.public_input_columns == 0 ? std::vector({}) : assignments.public_input(0), - output + "/" + public_input_filename - ); + print_placeholder_proof_with_params( + lpc_preprocessed_public_data, + lpc_proof, + lpc_scheme, + desc, + output + ); + print_public_input( + desc.public_input_columns == 0 ? std::vector({}) + : assignments.public_input(0), + output + "/" + public_input_filename + ); - auto verifier_res = placeholder_verifier::process( - lpc_preprocessed_public_data.common_data, - lpc_proof, - desc, - constraint_system, - lpc_scheme - ); - BOOST_CHECK(verifier_res); + auto verifier_res = placeholder_verifier::process( + lpc_preprocessed_public_data.common_data, + lpc_proof, + desc, + constraint_system, + lpc_scheme + ); + BOOST_CHECK(verifier_res); + } } BOOST_FIXTURE_TEST_CASE(transpiler_test100, test_initializer) { @@ -1058,42 +1086,45 @@ BOOST_FIXTURE_TEST_CASE(transpiler_test100, test_initializer) { ); printer.print(); - typename placeholder_private_preprocessor::preprocessed_data_type - lpc_preprocessed_private_data = - placeholder_private_preprocessor::process( - constraint_system, - assignments.private_table(), - desc - ); + if (should_save_proof_data()) { + typename placeholder_private_preprocessor::preprocessed_data_type + lpc_preprocessed_private_data = + placeholder_private_preprocessor::process( + constraint_system, + assignments.private_table(), + desc + ); - auto lpc_proof = placeholder_prover::process( - lpc_preprocessed_public_data, - lpc_preprocessed_private_data, - desc, - constraint_system, - lpc_scheme - ); + auto lpc_proof = placeholder_prover::process( + lpc_preprocessed_public_data, + lpc_preprocessed_private_data, + desc, + constraint_system, + lpc_scheme + ); - print_placeholder_proof_with_params( - lpc_preprocessed_public_data, - lpc_proof, - lpc_scheme, - desc, - output - ); - print_public_input( - desc.public_input_columns == 0 ? std::vector({}) : assignments.public_input(0), - output + "/" + public_input_filename - ); + print_placeholder_proof_with_params( + lpc_preprocessed_public_data, + lpc_proof, + lpc_scheme, + desc, + output + ); + print_public_input( + desc.public_input_columns == 0 ? std::vector({}) + : assignments.public_input(0), + output + "/" + public_input_filename + ); - auto verifier_res = placeholder_verifier::process( - lpc_preprocessed_public_data.common_data, - lpc_proof, - desc, - constraint_system, - lpc_scheme - ); - BOOST_CHECK(verifier_res); + auto verifier_res = placeholder_verifier::process( + lpc_preprocessed_public_data.common_data, + lpc_proof, + desc, + constraint_system, + lpc_scheme + ); + BOOST_CHECK(verifier_res); + } } BOOST_AUTO_TEST_SUITE_END() @@ -1177,42 +1208,45 @@ BOOST_FIXTURE_TEST_CASE(transpiler_test, test_initializer) { ); printer.print(); - typename placeholder_private_preprocessor::preprocessed_data_type - lpc_preprocessed_private_data = - placeholder_private_preprocessor::process( - constraint_system, - assignments.private_table(), - desc - ); + if (should_save_proof_data()) { + typename placeholder_private_preprocessor::preprocessed_data_type + lpc_preprocessed_private_data = + placeholder_private_preprocessor::process( + constraint_system, + assignments.private_table(), + desc + ); - auto lpc_proof = placeholder_prover::process( - lpc_preprocessed_public_data, - lpc_preprocessed_private_data, - desc, - constraint_system, - lpc_scheme - ); + auto lpc_proof = placeholder_prover::process( + lpc_preprocessed_public_data, + lpc_preprocessed_private_data, + desc, + constraint_system, + lpc_scheme + ); - print_placeholder_proof_with_params( - lpc_preprocessed_public_data, - lpc_proof, - lpc_scheme, - desc, - output - ); - print_public_input( - desc.public_input_columns == 0 ? std::vector({}) : assignments.public_input(0), - output + "/" + public_input_filename - ); + print_placeholder_proof_with_params( + lpc_preprocessed_public_data, + lpc_proof, + lpc_scheme, + desc, + output + ); + print_public_input( + desc.public_input_columns == 0 ? std::vector({}) + : assignments.public_input(0), + output + "/" + public_input_filename + ); - auto verifier_res = placeholder_verifier::process( - lpc_preprocessed_public_data.common_data, - lpc_proof, - desc, - constraint_system, - lpc_scheme - ); - BOOST_CHECK(verifier_res); + auto verifier_res = placeholder_verifier::process( + lpc_preprocessed_public_data.common_data, + lpc_proof, + desc, + constraint_system, + lpc_scheme + ); + BOOST_CHECK(verifier_res); + } } BOOST_AUTO_TEST_SUITE_END() @@ -1295,42 +1329,45 @@ BOOST_FIXTURE_TEST_CASE(transpiler_test, test_initializer) { ); printer.print(); - typename placeholder_private_preprocessor::preprocessed_data_type - lpc_preprocessed_private_data = - placeholder_private_preprocessor::process( - constraint_system, - assignments.private_table(), - desc - ); + if (should_save_proof_data()) { + typename placeholder_private_preprocessor::preprocessed_data_type + lpc_preprocessed_private_data = + placeholder_private_preprocessor::process( + constraint_system, + assignments.private_table(), + desc + ); - auto lpc_proof = placeholder_prover::process( - lpc_preprocessed_public_data, - lpc_preprocessed_private_data, - desc, - constraint_system, - lpc_scheme - ); + auto lpc_proof = placeholder_prover::process( + lpc_preprocessed_public_data, + lpc_preprocessed_private_data, + desc, + constraint_system, + lpc_scheme + ); - print_placeholder_proof_with_params( - lpc_preprocessed_public_data, - lpc_proof, - lpc_scheme, - desc, - output - ); - print_public_input( - desc.public_input_columns == 0 ? std::vector({}) : assignments.public_input(0), - output + "/" + public_input_filename - ); + print_placeholder_proof_with_params( + lpc_preprocessed_public_data, + lpc_proof, + lpc_scheme, + desc, + output + ); + print_public_input( + desc.public_input_columns == 0 ? std::vector({}) + : assignments.public_input(0), + output + "/" + public_input_filename + ); - auto verifier_res = placeholder_verifier::process( - lpc_preprocessed_public_data.common_data, - lpc_proof, - desc, - constraint_system, - lpc_scheme - ); - BOOST_CHECK(verifier_res); + auto verifier_res = placeholder_verifier::process( + lpc_preprocessed_public_data.common_data, + lpc_proof, + desc, + constraint_system, + lpc_scheme + ); + BOOST_CHECK(verifier_res); + } } // TODO implement for EVM @@ -1472,14 +1509,6 @@ struct placeholder_kzg_test_fixture_v2 desc ); - auto kzg_proof = placeholder_prover::process( - kzg_preprocessed_public_data, - std::move(kzg_preprocessed_private_data), - desc, - constraint_system, - kzg_scheme - ); - std::string output = std::string("circuit_kzg_") + curve_name(); auto printer = nil::blueprint::kzg_evm_verifier_printer( @@ -1493,30 +1522,40 @@ struct placeholder_kzg_test_fixture_v2 ); printer.print(); - using common_data_type = typename placeholder_public_preprocessor:: - preprocessed_data_type::common_data_type; + if (should_save_proof_data()) { + auto kzg_proof = placeholder_prover::process( + kzg_preprocessed_public_data, + std::move(kzg_preprocessed_private_data), + desc, + constraint_system, + kzg_scheme + ); - print_placeholder_proof_with_params( - kzg_preprocessed_public_data, - kzg_proof, - kzg_scheme, - desc, - output - ); - print_public_input( - desc.public_input_columns == 0 ? std::vector({}) - : assignments.public_input(0), - output + "/" + public_input_filename - ); + using common_data_type = typename placeholder_public_preprocessor:: + preprocessed_data_type::common_data_type; - bool verifier_res = placeholder_verifier::process( - kzg_preprocessed_public_data.common_data, - kzg_proof, - desc, - constraint_system, - kzg_scheme - ); - BOOST_CHECK(verifier_res); + print_placeholder_proof_with_params( + kzg_preprocessed_public_data, + kzg_proof, + kzg_scheme, + desc, + output + ); + print_public_input( + desc.public_input_columns == 0 ? std::vector({}) + : assignments.public_input(0), + output + "/" + public_input_filename + ); + + bool verifier_res = placeholder_verifier::process( + kzg_preprocessed_public_data.common_data, + kzg_proof, + desc, + constraint_system, + kzg_scheme + ); + BOOST_CHECK(verifier_res); + } return true; }