From 917b5ccb9fa35224bc3485b14ffe9f3c451ec35a Mon Sep 17 00:00:00 2001 From: akokoshn Date: Fri, 8 Mar 2024 11:41:56 +0200 Subject: [PATCH] Pass arithmetization parameters to the cmake function assigner_ir --- bin/CMakeLists.txt | 2 +- bin/assigner/src/main.cpp | 2 +- examples/CMakeLists.txt | 44 +++++++++++++++++++++++++++--------- examples/cpp/CMakeLists.txt | 33 ++++++++++++++------------- examples/rust/CMakeLists.txt | 28 +++++++++++------------ 5 files changed, 66 insertions(+), 43 deletions(-) diff --git a/bin/CMakeLists.txt b/bin/CMakeLists.txt index f26e9db95..78189ff78 100644 --- a/bin/CMakeLists.txt +++ b/bin/CMakeLists.txt @@ -34,7 +34,7 @@ set(WITNESS_COLUMNS 15 CACHE STRING "Number of witness columns") set(PUBLIC_INPUT_COLUMNS 1 CACHE STRING "Number of public input columns") set(COMPONENT_CONSTANT_COLUMNS 5 CACHE STRING "Number of component constant columns") set(LOOKUP_CONSTANT_COLUMNS 30 CACHE STRING "Number of lookup constant columns") -set(COMPONENT_SELECTOR_COLUMNS 50 CACHE STRING "Number of lookup selector columns") +set(COMPONENT_SELECTOR_COLUMNS 50 CACHE STRING "Number of component selector columns") set(LOOKUP_SELECTOR_COLUMNS 6 CACHE STRING "Number of lookup selector columns") set(SECURITY_PARAMETER_LAMBDA 9 CACHE STRING "Number of FRI queries") set(SECURITY_PARAMETER_GRINDING_BITS 0 CACHE STRING "Number of FRI grinding bits") diff --git a/bin/assigner/src/main.cpp b/bin/assigner/src/main.cpp index 9a15d4a28..2e8de5a2e 100644 --- a/bin/assigner/src/main.cpp +++ b/bin/assigner/src/main.cpp @@ -838,7 +838,7 @@ int main(int argc, char *argv[]) { if (vm.count("max-num-provers")) { max_num_provers = vm["max-num-provers"].as(); if (max_num_provers < 1) { - std::cerr << "Invalid command line argument - max-num-provers. " << max_num_provers << " is wrong value." << std::endl; + std::cerr << "Invalid command line argument --max-num-provers. " << max_num_provers << " is wrong value." << std::endl; std::cout << options_desc << std::endl; return 1; } diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 76f7e54da..9f4138b73 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,15 +1,32 @@ set(INPUTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/inputs) #generate assignment table and circuit -function(assign_ir target binary_name input private_input curve_type max_num_provers_amount) +function(assign_ir) + list(POP_FRONT ARGV target) + list(POP_FRONT ARGV binary_name) + list(POP_FRONT ARGV input) + list(POP_FRONT ARGV private_input) + list(POP_FRONT ARGV curve_type) + list(POP_FRONT ARGV arithmetization) + if(NOT arithmetization STREQUAL "none") + set(witness_cols ${arithmetization}) + list(POP_FRONT ARGV public_input_cols) + list(POP_FRONT ARGV component_constant_cols) + list(POP_FRONT ARGV lookup_constant_cols) + list(POP_FRONT ARGV component_selector_cols) + list(POP_FRONT ARGV lookup_selector_cols) + set(arithmetization_flag --column-sizes) + set(arithmetization_amount ${witness_cols} ${public_input_cols} ${component_constant_cols} ${lookup_constant_cols} ${component_selector_cols} ${lookup_selector_cols}) + endif() + list(POP_FRONT ARGV max_num_provers_amount) if(NOT max_num_provers_amount EQUAL 0) set(max_num_provers_flag --max-num-provers) set(max_num_provers_amount ${max_num_provers_amount}) endif() - if(NOT private_input STREQUAL "") - set (minus_p -p) + if(NOT private_input STREQUAL "none") + set(minus_p -p) set(private_input_string ${INPUTS_DIR}/${private_input}) endif() @@ -20,6 +37,7 @@ function(assign_ir target binary_name input private_input curve_type max_num_pro -e ${curve_type} --generate-type circuit ${max_num_provers_flag} ${max_num_provers_amount} + ${arithmetization_flag} ${arithmetization_amount} DEPENDS ${target} $ COMMAND_EXPAND_LISTS VERBATIM) @@ -33,6 +51,7 @@ function(assign_ir target binary_name input private_input curve_type max_num_pro -t assignment_${target}.tbl -e ${curve_type} --check --generate-type circuit-assignment ${max_num_provers_flag} ${max_num_provers_amount} + ${arithmetization_flag} ${arithmetization_amount} DEPENDS ${target} ${INPUTS_DIR}/${input} $ COMMAND_EXPAND_LISTS VERBATIM) @@ -45,6 +64,7 @@ function(assign_ir target binary_name input private_input curve_type max_num_pro -t assignment_${target}.tbl -e ${curve_type} --check --generate-type assignment ${max_num_provers_flag} ${max_num_provers_amount} + ${arithmetization_flag} ${arithmetization_amount} DEPENDS ${target} ${INPUTS_DIR}/${input} $ COMMAND_EXPAND_LISTS VERBATIM) @@ -55,6 +75,7 @@ function(assign_ir target binary_name input private_input curve_type max_num_pro -e ${curve_type} --generate-type size_estimation ${max_num_provers_flag} ${max_num_provers_amount} + ${arithmetization_flag} ${arithmetization_amount} DEPENDS ${target} $ COMMAND_EXPAND_LISTS VERBATIM) @@ -66,21 +87,22 @@ function(assign_ir target binary_name input private_input curve_type max_num_pro --generate-type public-input-column --input-column ${target}_input_column.inp -e ${curve_type} + ${arithmetization_flag} ${arithmetization_amount} DEPENDS ${target} ${INPUTS_DIR}/${input} COMMAND_EXPAND_LISTS VERBATIM) endfunction() -function(gen_proof target input curve_type provers_amount) +function(gen_proof target curve_type provers_amount) if(provers_amount EQUAL 0) - gen_single_proof(${target} ${input} ${curve_type} 0) + gen_single_proof(${target} ${curve_type} 0) else() add_custom_target(${target}_prove) foreach(prover_num RANGE 1 ${provers_amount}) math(EXPR prover_num_minus_1 "${prover_num} - 1") - gen_single_proof(${target} ${input} ${curve_type} ${prover_num}) + gen_single_proof(${target} ${curve_type} ${prover_num}) add_dependencies(${target}_prove ${target}_prove${prover_num_minus_1}) endforeach() @@ -94,7 +116,7 @@ function(gen_proof target input curve_type provers_amount) endif() endfunction() -function(gen_single_proof target input curve_type provers_amount) +function(gen_single_proof target curve_type provers_amount) if(NOT provers_amount EQUAL 0) set(multi_prover_flag --multi-prover) @@ -115,16 +137,16 @@ function(gen_single_proof target input curve_type provers_amount) VERBATIM) endfunction() -function(gen_evm_verifier target input curve_type provers_amount) +function(gen_evm_verifier target curve_type provers_amount) if(provers_amount EQUAL 0) - gen_single_evm_verifier(${target} ${input} ${curve_type} 0) + gen_single_evm_verifier(${target} ${curve_type} 0) else() add_custom_target(${target}_evm_verifier) foreach(prover_num RANGE 1 ${provers_amount}) math(EXPR prover_num_minus_1 "${prover_num} - 1") - gen_single_evm_verifier(${target} ${input} ${curve_type} ${prover_num}) + gen_single_evm_verifier(${target} ${curve_type} ${prover_num}) add_dependencies(${target}_evm_verifier ${target}_evm_verifier${prover_num_minus_1}) endforeach() @@ -137,7 +159,7 @@ function(gen_evm_verifier target input curve_type provers_amount) add_dependencies(${target}_evm_verifier ${target}_copy_input_for_evm_verifier) endfunction() -function(gen_single_evm_verifier target input curve_type provers_amount) +function(gen_single_evm_verifier target curve_type provers_amount) if(NOT provers_amount EQUAL 0) set(multi_prover_flag --multi-prover) diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt index 70abcc5c3..a78ce2e71 100644 --- a/examples/cpp/CMakeLists.txt +++ b/examples/cpp/CMakeLists.txt @@ -9,12 +9,13 @@ function(add_example_without_proving example_target) set(prefix ARG) set(noValues "") set(singleValues INPUT PRIVATE_INPUT CURVE_TYPE MAX_NUM_PROVERS) - set(multiValues SOURCES COMPILER_OPTIONS) + set(multiValues SOURCES COMPILER_OPTIONS ARITHMETIZARION) cmake_parse_arguments(${prefix} "${noValues}" "${singleValues}" "${multiValues}" ${ARGN}) + add_circuit(${example_target} SOURCES ${ARG_SOURCES} COMPILER_OPTIONS ${ARG_COMPILER_OPTIONS} @@ -51,20 +52,20 @@ function(add_example_without_proving example_target) add_dependencies(compile_cpp_examples ${example_target}) - if(DEFINED ARG_PRIVATE_INPUT) - if(DEFINED ARG_MAX_NUM_PROVERS) - assign_ir(${example_target} ${binary_name} ${ARG_INPUT} ${ARG_PRIVATE_INPUT} ${ARG_CURVE_TYPE} ${ARG_MAX_NUM_PROVERS}) - else() - assign_ir(${example_target} ${binary_name} ${ARG_INPUT} ${ARG_PRIVATE_INPUT} ${ARG_CURVE_TYPE} 0) - endif() - else() - if(DEFINED ARG_MAX_NUM_PROVERS) - assign_ir(${example_target} ${binary_name} ${ARG_INPUT} "" ${ARG_CURVE_TYPE} ${ARG_MAX_NUM_PROVERS}) - else() - assign_ir(${example_target} ${binary_name} ${ARG_INPUT} "" ${ARG_CURVE_TYPE} 0) - endif() + if(NOT DEFINED ARG_PRIVATE_INPUT) + set(ARG_PRIVATE_INPUT "none") + endif() + + if(NOT DEFINED ARG_MAX_NUM_PROVERS) + set(ARG_MAX_NUM_PROVERS 0) + endif() + + if(NOT DEFINED ARG_ARITHMETIZARION) + set(ARG_ARITHMETIZARION "none") endif() + assign_ir(${example_target} ${binary_name} ${ARG_INPUT} ${ARG_PRIVATE_INPUT} ${ARG_CURVE_TYPE} ${ARG_ARITHMETIZARION} ${ARG_MAX_NUM_PROVERS}) + add_dependencies(cpp_examples_generate_tbl ${example_target}_generate_tbl) add_dependencies(cpp_examples_generate_crct ${example_target}_generate_crct) add_dependencies(cpp_examples_generate_both ${example_target}_generate_both) @@ -88,11 +89,11 @@ function(add_example_with_proving example_target) set(ARG_MAX_NUM_PROVERS 0) endif() - gen_proof(${example_target} ${ARG_INPUT} ${ARG_CURVE_TYPE} ${ARG_MAX_NUM_PROVERS}) + gen_proof(${example_target} ${ARG_CURVE_TYPE} ${ARG_MAX_NUM_PROVERS}) add_dependencies(prove_cpp_examples ${example_target}_prove) if(GENERATE_EVM_VERIFIER) - gen_evm_verifier(${example_target} ${ARG_INPUT} ${ARG_CURVE_TYPE} ${ARG_MAX_NUM_PROVERS}) + gen_evm_verifier(${example_target} ${ARG_CURVE_TYPE} ${ARG_MAX_NUM_PROVERS}) add_dependencies(prove_cpp_examples ${example_target}_evm_verifier) endif() @@ -149,7 +150,7 @@ add_example_without_proving(compare_less_than_cpp SOURCES compare/less_than.cpp add_example_without_proving(balances_tree_cpp_example SOURCES balances_tree.cpp INPUT balances_tree_public.inp PRIVATE_INPUT balances_tree_private.inp CURVE_TYPE pallas) add_example_without_proving(eddsa_signature_verification_cpp SOURCES eddsa_signature_verification.cpp INPUT eddsa_signature_verification.inp CURVE_TYPE pallas) -add_example_without_proving(zkbridge_cpp SOURCES zkbridge.cpp INPUT zkbridge.inp CURVE_TYPE pallas) +add_example_without_proving(zkbridge_cpp SOURCES zkbridge.cpp INPUT zkbridge.inp CURVE_TYPE pallas ARITHMETIZARION 15 1 5 30 50 6) add_example_with_proving(private_input_cpp SOURCES private_input.cpp INPUT private_input_public.inp PRIVATE_INPUT private_input_private.inp CURVE_TYPE pallas) add_example_with_proving(private_input_array_cpp SOURCES private_input_array.cpp INPUT private_input_array_public.inp PRIVATE_INPUT private_input_array_private.inp CURVE_TYPE pallas) diff --git a/examples/rust/CMakeLists.txt b/examples/rust/CMakeLists.txt index 057984d14..0021a40b0 100644 --- a/examples/rust/CMakeLists.txt +++ b/examples/rust/CMakeLists.txt @@ -36,20 +36,20 @@ function(add_rust_example_without_proving example_target) set(binary_name ${EXAMPLES_BINARY_DIR}/${ARG_EXAMPLE_NAME}.ll) - if(DEFINED ARG_PRIVATE_INPUT) - if(DEFINED ARG_MAX_NUM_PROVERS) - assign_ir(${example_target} ${binary_name} ${ARG_INPUT} ${ARG_PRIVATE_INPUT} ${ARG_CURVE_TYPE} ${ARG_MAX_NUM_PROVERS}) - else() - assign_ir(${example_target} ${binary_name} ${ARG_INPUT} ${ARG_PRIVATE_INPUT} ${ARG_CURVE_TYPE} 0) - endif() - else() - if(DEFINED ARG_MAX_NUM_PROVERS) - assign_ir(${example_target} ${binary_name} ${ARG_INPUT} "" ${ARG_CURVE_TYPE} ${ARG_MAX_NUM_PROVERS}) - else() - assign_ir(${example_target} ${binary_name} ${ARG_INPUT} "" ${ARG_CURVE_TYPE} 0) - endif() + if(NOT DEFINED ARG_PRIVATE_INPUT) + set(ARG_PRIVATE_INPUT "none") endif() + if(NOT DEFINED ARG_MAX_NUM_PROVERS) + set(ARG_MAX_NUM_PROVERS 0) + endif() + + if(NOT DEFINED ARG_ARITHMETIZARION) + set(ARG_ARITHMETIZARION "none") + endif() + + assign_ir(${example_target} ${binary_name} ${ARG_INPUT} ${ARG_PRIVATE_INPUT} ${ARG_CURVE_TYPE} ${ARG_ARITHMETIZARION} ${ARG_MAX_NUM_PROVERS}) + add_dependencies(rust_examples_generate_crct ${example_target}_generate_crct) add_dependencies(rust_examples_generate_tbl ${example_target}_generate_tbl) add_dependencies(rust_examples_generate_both ${example_target}_generate_both) @@ -72,11 +72,11 @@ function(add_rust_example_with_proving example_target) set(ARG_MAX_NUM_PROVERS 0) endif() - gen_proof(${example_target} ${ARG_INPUT} ${ARG_CURVE_TYPE} ${ARG_MAX_NUM_PROVERS}) + gen_proof(${example_target} ${ARG_CURVE_TYPE} ${ARG_MAX_NUM_PROVERS}) add_dependencies(prove_rust_examples ${example_target}_prove) if(GENERATE_EVM_VERIFIER) - gen_evm_verifier(${example_target} ${ARG_INPUT} ${ARG_CURVE_TYPE} ${ARG_MAX_NUM_PROVERS}) + gen_evm_verifier(${example_target} ${ARG_CURVE_TYPE} ${ARG_MAX_NUM_PROVERS}) add_dependencies(prove_rust_examples ${example_target}_evm_verifier) endif()