Skip to content

Commit

Permalink
Pass arithmetization parameters to the cmake function assigner_ir
Browse files Browse the repository at this point in the history
  • Loading branch information
akokoshn authored and akokoshn committed Mar 12, 2024
1 parent d0bfb78 commit 917b5cc
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 43 deletions.
2 changes: 1 addition & 1 deletion bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion bin/assigner/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ int main(int argc, char *argv[]) {
if (vm.count("max-num-provers")) {
max_num_provers = vm["max-num-provers"].as<int>();
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;
}
Expand Down
44 changes: 33 additions & 11 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()

Expand All @@ -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} $<TARGET_FILE:assigner>
COMMAND_EXPAND_LISTS
VERBATIM)
Expand All @@ -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} $<TARGET_FILE:assigner>
COMMAND_EXPAND_LISTS
VERBATIM)
Expand All @@ -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} $<TARGET_FILE:assigner>
COMMAND_EXPAND_LISTS
VERBATIM)
Expand All @@ -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} $<TARGET_FILE:assigner>
COMMAND_EXPAND_LISTS
VERBATIM)
Expand All @@ -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()

Expand All @@ -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)
Expand All @@ -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()

Expand All @@ -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)
Expand Down
33 changes: 17 additions & 16 deletions examples/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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)
Expand All @@ -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()

Expand Down Expand Up @@ -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)
Expand Down
28 changes: 14 additions & 14 deletions examples/rust/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

Expand Down

0 comments on commit 917b5cc

Please sign in to comment.