Skip to content

Commit

Permalink
Move aritmetization params to CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
aleasims authored and ETatuzova committed Feb 5, 2024
1 parent 3fbe2ee commit 11544ac
Show file tree
Hide file tree
Showing 15 changed files with 4,120 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ jobs:
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: b1e380040b4714b6ad5fe9223555d854c49cf065
proof-producer-ref: 0924fe046e08c8ae10e9df226cfd0a39b069d355
refs: ${{ needs.handle-syncwith.outputs.prs-refs }}
targets: ${{ needs.build-and-test-linux.outputs.prover-targets }}

Expand Down
15 changes: 15 additions & 0 deletions bin/assigner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ if (CPACK_PACKAGE_VERSION)
add_compile_definitions(${UPPER_CURRENT_PROJECT_NAME}_VERSION=${CPACK_PACKAGE_VERSION})
endif()

set(WITNESS_COLUMNS 15 CACHE INT "Number of witness columns")
set(PUBLIC_INPUT_COLUMNS 1 CACHE INT "Number of public input columns")
set(COMPONENT_CONSTANT_COLUMNS 5 CACHE INT "Number of component constant columns")
set(LOOKUP_CONSTANT_COLUMNS 30 CACHE INT "Number of lookup constant columns")
set(COMPONENT_SELECTOR_COLUMNS 30 CACHE INT "Number of lookup selector columns")
set(LOOKUP_SELECTOR_COLUMNS 6 CACHE INT "Number of lookup selector columns")

add_definitions(-DASSIGNER_WITNESS_COLUMNS=${WITNESS_COLUMNS})
add_definitions(-DASSIGNER_PUBLIC_INPUT_COLUMNS=${PUBLIC_INPUT_COLUMNS})
add_definitions(-DASSIGNER_COMPONENT_CONSTANT_COLUMNS=${COMPONENT_CONSTANT_COLUMNS})
add_definitions(-DASSIGNER_LOOKUP_CONSTANT_COLUMNS=${LOOKUP_CONSTANT_COLUMNS})
add_definitions(-DASSIGNER_COMPONENT_SELECTOR_COLUMNS=${COMPONENT_SELECTOR_COLUMNS})
add_definitions(-DASSIGNER_LOOKUP_SELECTOR_COLUMNS=${LOOKUP_SELECTOR_COLUMNS})
#HASH, LAMBDA, GRINDING_BITS is not used in the current version of the assigner

# get header files; only needed by CMake generators,
# expr.g., for creating proper Xcode projects
set(${CURRENT_PROJECT_NAME}_HEADERS)
Expand Down
45 changes: 35 additions & 10 deletions bin/assigner/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@

#include <ios>

#include <nil/crypto3/hash/sha2.hpp>
#include <nil/crypto3/hash/poseidon.hpp>

#include <nil/marshalling/status_type.hpp>
#include <nil/marshalling/field_type.hpp>
#include <nil/marshalling/endianness.hpp>
Expand Down Expand Up @@ -392,6 +395,15 @@ bool read_json(
return true;
}

struct ParametersPolicy {
constexpr static const std::size_t WitnessColumns = ASSIGNER_WITNESS_COLUMNS;
constexpr static const std::size_t PublicInputColumns = ASSIGNER_PUBLIC_INPUT_COLUMNS;
constexpr static const std::size_t ComponentConstantColumns = ASSIGNER_COMPONENT_CONSTANT_COLUMNS;
constexpr static const std::size_t LookupConstantColumns = ASSIGNER_LOOKUP_CONSTANT_COLUMNS;
constexpr static const std::size_t ComponentSelectorColumns = ASSIGNER_COMPONENT_SELECTOR_COLUMNS;
constexpr static const std::size_t LookupSelectorColumns = ASSIGNER_LOOKUP_SELECTOR_COLUMNS;
};

template<typename BlueprintFieldType>
int curve_dependent_main(std::string bytecode_file_name,
std::string public_input_file_name,
Expand All @@ -403,18 +415,19 @@ int curve_dependent_main(std::string bytecode_file_name,
boost::log::trivial::severity_level log_level,
const std::string &policy,
std::uint32_t max_num_provers,
std::uint32_t max_lookup_rows,
std::uint32_t target_prover,
nil::blueprint::print_format circuit_output_print_format) {

constexpr std::size_t ComponentConstantColumns = 5;
constexpr std::size_t LookupConstantColumns = 30;
constexpr std::size_t ComponentSelectorColumns = 30;
constexpr std::size_t LookupSelectorConstantColumns = 6;
constexpr std::size_t ComponentConstantColumns = ParametersPolicy::ComponentConstantColumns;
constexpr std::size_t LookupConstantColumns = ParametersPolicy::LookupConstantColumns;
constexpr std::size_t ComponentSelectorColumns = ParametersPolicy::ComponentSelectorColumns;
constexpr std::size_t LookupSelectorColumns = ParametersPolicy::LookupSelectorColumns;

constexpr std::size_t WitnessColumns = 15;
constexpr std::size_t PublicInputColumns = 1;
constexpr std::size_t WitnessColumns = ParametersPolicy::WitnessColumns;
constexpr std::size_t PublicInputColumns = ParametersPolicy::PublicInputColumns;
constexpr std::size_t ConstantColumns = ComponentConstantColumns + LookupConstantColumns;
constexpr std::size_t SelectorColumns = ComponentSelectorColumns + LookupSelectorConstantColumns;
constexpr std::size_t SelectorColumns = ComponentSelectorColumns + LookupSelectorColumns;

using ArithmetizationParams =
zk::snark::plonk_arithmetization_params<WitnessColumns, PublicInputColumns, ConstantColumns, SelectorColumns>;
Expand Down Expand Up @@ -462,7 +475,6 @@ int curve_dependent_main(std::string bytecode_file_name,
// pack lookup tables
if (parser_instance.circuits[0].get_reserved_tables().size() > 0) {
std::vector <std::size_t> lookup_columns_indices;
const std::uint32_t max_usable_rows = 500000;
lookup_columns_indices.resize(LookupConstantColumns);
// fill ComponentConstantColumns, ComponentConstantColumns + 1, ...
std::iota(lookup_columns_indices.begin(), lookup_columns_indices.end(), ComponentConstantColumns);
Expand All @@ -475,7 +487,7 @@ int curve_dependent_main(std::string bytecode_file_name,
lookup_columns_indices,
ComponentSelectorColumns,
0,
max_usable_rows
max_lookup_rows
);
}

Expand Down Expand Up @@ -597,6 +609,7 @@ int main(int argc, char *argv[]) {
("print-circuit-output-format,f", boost::program_options::value<std::string>(), "print output of the circuit (dec, hex)")
("policy", boost::program_options::value<std::string>(), "Policy for creating circuits. Possible values: default")
("max-num-provers", boost::program_options::value<int>(), "Maximum number of provers. Possible values >= 1")
("max-lookup-rows", boost::program_options::value<int>(), "Maximum number of provers. Possible values >= 1")
("target-prover", boost::program_options::value<int>(), "Assignment table and circuit will be generated only for defined prover. Possible values [0, max-num-provers)");
// clang-format on

Expand Down Expand Up @@ -750,6 +763,16 @@ int main(int argc, char *argv[]) {
}
}

std::uint32_t max_lookup_rows = 500000;
if (vm.count("max-lookup-rows")) {
max_lookup_rows = vm["max-lookup-rows"].as<int>();
if (max_lookup_rows < 1) {
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;
}
}

std::uint32_t target_prover = std::numeric_limits<std::uint32_t>::max();
if (vm.count("target-prover")) {
target_prover = vm["target-prover"].as<int>();
Expand Down Expand Up @@ -795,6 +818,7 @@ int main(int argc, char *argv[]) {
log_options[log_level],
policy,
max_num_provers,
max_lookup_rows,
target_prover,
circuit_output_print_format);
break;
Expand All @@ -819,11 +843,12 @@ int main(int argc, char *argv[]) {
log_options[log_level],
policy,
max_num_provers,
max_lookup_rows,
target_prover,
circuit_output_print_format);
break;
}
};

return 0;
}
}
126 changes: 126 additions & 0 deletions bin/recursive_gen/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#---------------------------------------------------------------------------#
# Copyright (c) 2018-2022 Mikhail Komarov <[email protected]>
# Copyright (c) 2020-2022 Nikita Kaskov <[email protected]>
#
# Distributed under the Boost Software License, Version 1.0
# See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt
#---------------------------------------------------------------------------#

cmake_minimum_required(VERSION 3.5)

cm_find_package(CM)
include(CMDeploy)
include(CMSetupVersion)

cm_project(recursive_gen WORKSPACE_NAME ${CMAKE_WORKSPACE_NAME} LANGUAGES ASM C CXX)

if(NOT CMAKE_CROSSCOMPILING)
find_package(Boost COMPONENTS REQUIRED filesystem log log_setup program_options thread system)
elseif(CMAKE_CROSSCOMPILING)
if(NOT TARGET boost)
include(ExternalProject)
set(Boost_LIBRARIES boost_random)
externalproject_add(boost
PREFIX ${CMAKE_BINARY_DIR}/libs/boost
GIT_REPOSITORY [email protected]:boostorg/boost.git
GIT_TAG boost-1.77.0
BUILD_IN_SOURCE TRUE
CMAKE_ARGS -DCMAKE_CROSSCOMPILING_EMULATOR=${CMAKE_CROSSCOMPILING_EMULATOR} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
BUILD_COMMAND cmake --build . --target ${Boost_LIBRARIES}
INSTALL_COMMAND "")
else()
set(Boost_LIBRARIES boost_random)
endif()
endif()

string(TOUPPER ${CURRENT_PROJECT_NAME} UPPER_CURRENT_PROJECT_NAME)

if (CPACK_PACKAGE_VERSION)
add_compile_definitions(${UPPER_CURRENT_PROJECT_NAME}_VERSION=${CPACK_PACKAGE_VERSION})
endif()


set(WITNESS_COLUMNS 15 CACHE INT "Number of witness columns")
set(PUBLIC_INPUT_COLUMNS 1 CACHE INT "Number of public input columns")
set(COMPONENT_CONSTANT_COLUMNS 5 CACHE INT "Number of component constant columns")
set(LOOKUP_CONSTANT_COLUMNS 30 CACHE INT "Number of lookup constant columns")
set(COMPONENT_SELECTOR_COLUMNS 30 CACHE INT "Number of lookup selector columns")
set(LOOKUP_SELECTOR_COLUMNS 6 CACHE INT "Number of lookup selector columns")
set(SECURITY_PARAMETER_LAMBDA 9 CACHE INT "Number of FRI queries")
set(SECURITY_PARAMETER_GRINDING_BITS 0 CACHE INT "Number of FRI grinding bits")

add_definitions(-DRECURSIVE_WITNESS_COLUMNS=${WITNESS_COLUMNS})
add_definitions(-DRECURSIVE_PUBLIC_INPUT_COLUMNS=${PUBLIC_INPUT_COLUMNS})
add_definitions(-DRECURSIVE_COMPONENT_CONSTANT_COLUMNS=${COMPONENT_CONSTANT_COLUMNS})
add_definitions(-DRECURSIVE_LOOKUP_CONSTANT_COLUMNS=${LOOKUP_CONSTANT_COLUMNS})
add_definitions(-DRECURSIVE_COMPONENT_SELECTOR_COLUMNS=${COMPONENT_SELECTOR_COLUMNS})
add_definitions(-DRECURSIVE_LOOKUP_SELECTOR_COLUMNS=${LOOKUP_SELECTOR_COLUMNS})
add_definitions(-DRECURSIVE_LAMBDA=${SECURITY_PARAMETER_LAMBDA})
add_definitions(-DRECURSIVE_GRINDING_BITS=${SECURITY_PARAMETER_GRINDING_BITS})

#Hash is hard-coded poseidon

# get header files; only needed by CMake generators,
# expr.g., for creating proper Xcode projects
set(${CURRENT_PROJECT_NAME}_HEADERS)

# list cpp files excluding platform-dependent files
list(APPEND ${CURRENT_PROJECT_NAME}_SOURCES
src/main.cpp)

add_executable(${CURRENT_PROJECT_NAME}
${${CURRENT_PROJECT_NAME}_HEADERS}
${${CURRENT_PROJECT_NAME}_SOURCES})

set_target_properties(${CURRENT_PROJECT_NAME} PROPERTIES
LINKER_LANGUAGE CXX
EXPORT_NAME ${CURRENT_PROJECT_NAME}
CXX_STANDARD 17
CXX_STANDARD_REQUIRED TRUE)

target_link_libraries(${CURRENT_PROJECT_NAME}
crypto3::algebra
crypto3::block
crypto3::blueprint
crypto3::codec
crypto3::math
crypto3::multiprecision
crypto3::pkpad
crypto3::pubkey
crypto3::random
crypto3::zk

crypto3::assigner
crypto3::transpiler

marshalling::core
marshalling::crypto3_algebra
marshalling::crypto3_multiprecision
marshalling::crypto3_zk

${Boost_LIBRARIES})

target_include_directories(${CURRENT_PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
${CMAKE_CURRENT_SOURCE_DIR}/../../libs/circifier/llvm/include
${CMAKE_CURRENT_SOURCE_DIR}/../../libs/circifier/utils/bazel/llvm-project-overlay/llvm/include
${CMAKE_BINARY_DIR}/libs/circifier/llvm/include

$<$<BOOL:${Boost_FOUND}>:${Boost_INCLUDE_DIRS}>)

if(APPLE OR NOT ${CMAKE_TARGET_ARCHITECTURE} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR})
set_target_properties(${CURRENT_PROJECT_NAME} PROPERTIES
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "${APPLE_CODE_SIGN_IDENTITY}"
XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "${CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM}")
elseif(CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
set_target_properties(${CURRENT_PROJECT_NAME} PROPERTIES
COMPILE_FLAGS "-s USE_BOOST_HEADERS=1 -s EXPORTED_FUNCTIONS=_proof_gen,_main -s EXPORTED_RUNTIME_METHODS=ccall,cwrap"
LINK_FLAGS "-s USE_BOOST_HEADERS=1 -s EXPORTED_FUNCTIONS=_proof_gen,_main -s EXPORTED_RUNTIME_METHODS=ccall,cwrap"
LINK_DIRECTORIES "${CMAKE_BINARY_DIR}/libs/boost/src/boost/stage/lib")
endif()

add_dependencies(${CURRENT_PROJECT_NAME} boost)
endif()
Loading

0 comments on commit 11544ac

Please sign in to comment.