Skip to content

Commit

Permalink
zkevm-framework: enable partial proof in assigner
Browse files Browse the repository at this point in the history
  • Loading branch information
akokoshn committed Sep 23, 2024
1 parent dc8911c commit d645d96
Show file tree
Hide file tree
Showing 13 changed files with 550 additions and 117 deletions.
12 changes: 12 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,27 @@
enableDebug = false;
crypto3 = crypto3;
evm-assigner = evm-assigner;
transpiler = transpiler;
proof-producer = proof-producer;
parallel-crypto3 = parallel-crypto3;
});
zkevm-framework-tests = (pkgs.callPackage ./zkevm-framework/zkevm-framework.nix {
runTests = true;
enableDebug = false;
crypto3 = crypto3;
evm-assigner = evm-assigner;
transpiler = transpiler;
proof-producer = proof-producer;
parallel-crypto3 = parallel-crypto3;
});
zkevm-framework-debug-tests = (pkgs.callPackage ./zkevm-framework/zkevm-framework.nix {
enableDebug = true;
runTests = true;
crypto3 = crypto3;
evm-assigner = evm-assigner;
transpiler = transpiler;
proof-producer = proof-producer;
parallel-crypto3 = parallel-crypto3;
});

transpiler = (pkgs.callPackage ./transpiler/transpiler.nix {
Expand Down Expand Up @@ -186,6 +195,9 @@
enableDebug = false;
crypto3 = packages.crypto3;
evm-assigner = evm-assigner-gcc;
transpiler = packages.transpiler;
proof-producer = proof-producer-gcc;
parallel-crypto3 = packages.parallel-crypto3;
});

transpiler-gcc = (pkgs.callPackage ./transpiler/transpiler.nix {
Expand Down
19 changes: 19 additions & 0 deletions proof-producer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,22 @@ set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/bin/proof-producer")

include(CPack)

# INSTALL

set(CONFIG_PATH ${CMAKE_INSTALL_LIBDIR}/cmake/proof-producer)
set(TARGET_NAMESPACE crypto3::)
install(EXPORT proof-producerTargets NAMESPACE ${TARGET_NAMESPACE} DESTINATION ${CONFIG_PATH})

include(CMakePackageConfigHelpers)
configure_package_config_file(
cmake/Config.cmake.in
proof-producer-config.cmake
INSTALL_DESTINATION ${CONFIG_PATH}
)

install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/proof-producer-config.cmake
DESTINATION ${CONFIG_PATH}
)
26 changes: 26 additions & 0 deletions proof-producer/bin/proof-producer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ function(setup_proof_generator_target)
src/main.cpp
)

add_library(${ARG_TARGET_NAME}-lib INTERFACE)

# Make sure to add these dependencies before the others, since for multi-threaded version dependency on
# actor-zk must come first.
if(ARG_ADDITIONAL_DEPENDENCIES)
foreach(lib IN LISTS ARG_ADDITIONAL_DEPENDENCIES)
target_link_libraries(${ARG_TARGET_NAME} ${lib})
target_link_libraries(${ARG_TARGET_NAME}-lib INTERFACE ${lib})
endforeach()
endif()

Expand All @@ -65,6 +68,11 @@ function(setup_proof_generator_target)
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

target_include_directories(${ARG_TARGET_NAME}-lib INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

target_link_libraries(${ARG_TARGET_NAME}
crypto3::all

Expand All @@ -75,14 +83,32 @@ function(setup_proof_generator_target)
Boost::program_options
Boost::thread
)

target_link_libraries(${ARG_TARGET_NAME}-lib INTERFACE
crypto3::all

crypto3::transpiler

Boost::filesystem
Boost::log
Boost::program_options
Boost::thread
)
endfunction()

# Declare single-threaded target
set(SINGLE_THREADED_TARGET "${CURRENT_PROJECT_NAME}-single-threaded")
setup_proof_generator_target(TARGET_NAME ${SINGLE_THREADED_TARGET})


# Declare multi-threaded target
set(MULTI_THREADED_TARGET "${CURRENT_PROJECT_NAME}-multi-threaded")
setup_proof_generator_target(TARGET_NAME ${MULTI_THREADED_TARGET} ADDITIONAL_DEPENDENCIES actor::zk)

install(TARGETS ${SINGLE_THREADED_TARGET} ${MULTI_THREADED_TARGET} RUNTIME DESTINATION bin)

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

# Install library
install(TARGETS ${SINGLE_THREADED_TARGET}-lib ${MULTI_THREADED_TARGET}-lib EXPORT proof-producerTargets DESTINATION ${CMAKE_INSTALL_LIBDIR})
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ namespace nil {
commitment_scheme.state_commited(crypto3::zk::snark::LOOKUP_BATCH);
commitment_scheme.mark_batch_as_fixed(crypto3::zk::snark::FIXED_VALUES_BATCH);

commitment_scheme.set_fixed_polys_values(common_data_->commitment_scheme_data);
commitment_scheme.set_fixed_polys_values(common_data_.has_value() ? common_data_->commitment_scheme_data :
public_preprocessed_data_->common_data.commitment_scheme_data);

std::size_t theta_power = commitment_scheme.compute_theta_power_for_combined_Q();

Expand Down Expand Up @@ -492,6 +493,13 @@ namespace nil {
return true;
}

bool set_circuit(const ConstraintSystem& circuit) {
BOOST_LOG_TRIVIAL(info) << "Set circuit" << std::endl;

constraint_system_.emplace(std::move(circuit));
return true;
}

bool read_assignment_table(const boost::filesystem::path& assignment_table_file_) {
BOOST_LOG_TRIVIAL(info) << "Read assignment table from " << assignment_table_file_;

Expand All @@ -512,6 +520,20 @@ namespace nil {
return true;
}

bool set_assignment_table(const AssignmentTable& assignment_table, std::size_t used_rows_amount) {
BOOST_LOG_TRIVIAL(info) << "Set external assignment table" << std::endl;

table_description_->witness_columns = assignment_table.witnesses_amount();
table_description_->public_input_columns = assignment_table.public_inputs_amount();
table_description_->constant_columns = assignment_table.constants_amount();
table_description_->selector_columns = assignment_table.selectors_amount();
table_description_->usable_rows_amount = used_rows_amount;
table_description_->rows_amount = assignment_table.rows_amount();
assignment_table_.emplace(std::move(assignment_table));
public_inputs_.emplace(assignment_table_->public_inputs());
return true;
}

bool save_assignment_description(const boost::filesystem::path& assignment_description_file) {
BOOST_LOG_TRIVIAL(info) << "Writing assignment description to " << assignment_description_file;

Expand Down
7 changes: 7 additions & 0 deletions proof-producer/cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)
find_dependency(crypto3 REQUIRED)
find_dependency(crypto3_transpiler)

include("${CMAKE_CURRENT_LIST_DIR}/proof-producerTargets.cmake")
24 changes: 24 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
echo "1th circuit partial proof"
./result/bin/assigner --shard-id 1 --block-hash 0x001 --path /root/tmp/out/ --target-circuits add.0 -e pallas --input 326522724692461750427768532537390503835 --input 89059515727727869117346995944635890507 --input 291547819587797372485177713898460727720 --input 194782098816759892662980765881849306481 --log-level debug
echo "2th circuit partial proof"
./result/bin/assigner --shard-id 1 --block-hash 0x001 --path /root/tmp/out/ --target-circuits add.1 -e pallas --input 326522724692461750427768532537390503835 --input 89059515727727869117346995944635890507 --input 291547819587797372485177713898460727720 --input 194782098816759892662980765881849306481 --log-level debug

echo "aggregate challenges"
./result/bin/proof-producer-multi-threaded --stage="generate-aggregated-challenge" --input-challenge-files "/root/tmp/out/challenge.0.1.0x001" "/root/tmp/out/challenge.1.1.0x001" --aggregated-challenge-file="/root/tmp/out/aggregated_challenges.1.0x001"

echo "compute Q 1th circuit"
./result/bin/proof-producer-multi-threaded --stage="compute-combined-Q" --aggregated-challenge-file="/root/tmp/out/aggregated_challenges.1.0x001" --combined-Q-starting-power=0 --commitment-state-file="/root/tmp/out/commitment_state.0.1.0x001" --combined-Q-polynomial-file="/root/tmp/out/combined_Q.0.1.0x001"
echo "compute Q 2th circuit"
./result/bin/proof-producer-multi-threaded --stage="compute-combined-Q" --aggregated-challenge-file="/root/tmp/out/aggregated_challenges.1.0x001" --combined-Q-starting-power=0 --commitment-state-file="/root/tmp/out/commitment_state.1.1.0x001" --combined-Q-polynomial-file="/root/tmp/out/combined_Q.1.1.0x001"

echo "aggregate FRY"
./result/bin/proof-producer-multi-threaded --stage="aggregated-FRI" --assignment-description-file="/root/tmp/out/assignment_table_description.0.1.0x001" --aggregated-challenge-file="/root/tmp/out/aggregated_challenges.1.0x001" --input-combined-Q-polynomial-files "/root/tmp/out/combined_Q.0.1.0x001" "/root/tmp/out/combined_Q.1.1.0x001" --proof="/root/tmp/out/aggregated_FRI_proof.1.0x001" --proof-of-work-file="/root/tmp/out/POW.1.0x001" --consistency-checks-challenges-file="/root/tmp/out/challenges.1.0x001"

echo "consistency check 1th circuit"
./result/bin/proof-producer-multi-threaded --stage="consistency-checks" --commitment-state-file="/root/tmp/out/commitment_state.0.1.0x001" --combined-Q-polynomial-file="/root/tmp/out/combined_Q.0.1.0x001" --consistency-checks-challenges-file="/root/tmp/out/challenges.1.0x001" --proof="/root/tmp/out/LPC_consistency_check_proof.0.1.0x001"
echo "consistency check 2th circuit"
./result/bin/proof-producer-multi-threaded --stage="consistency-checks" --commitment-state-file="/root/tmp/out/commitment_state.1.1.0x001" --combined-Q-polynomial-file="/root/tmp/out/combined_Q.1.1.0x001" --consistency-checks-challenges-file="/root/tmp/out/challenges.1.0x001" --proof="/root/tmp/out/LPC_consistency_check_proof.1.1.0x001"


echo "merge final proof"
./result/bin/proof-producer-multi-threaded --stage merge-proofs --partial-proof "/root/tmp/out/proof.0.1.0x001" "/root/tmp/out/proof.1.1.0x001" --initial-proof "/root/tmp/out/LPC_consistency_check_proof.0.1.0x001" "/root/tmp/out/LPC_consistency_check_proof.1.1.0x001" --aggregated-FRI-proof "/root/tmp/out/aggregated_FRI_proof.1.0x001" --proof "/root/tmp/out/final-proof.1.0x001"
5 changes: 5 additions & 0 deletions zkevm-framework/bin/assigner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@ target_include_directories(${TARGET_NAME}
${CMAKE_CURRENT_SOURCE_DIR}/include
)

find_package(actor_zk REQUIRED)

find_package(proof-producer REQUIRED)

target_link_libraries(${TARGET_NAME}
PRIVATE
zkEVMPreset
zkEVMAssignerRunner
zkEVMJsonHelpers
zkEVMOutputArtifacts
crypto3::proof-producer-multi-threaded-lib
Boost::program_options
Boost::log
Boost::random
Expand Down
Loading

0 comments on commit d645d96

Please sign in to comment.