Skip to content

Commit

Permalink
Merge with master #95
Browse files Browse the repository at this point in the history
  • Loading branch information
ETatuzova committed Nov 1, 2024

Verified

This commit was signed with the committer’s verified signature.
SimonBrandner Šimon Brandner
2 parents 2af82c5 + 6b494a1 commit 3810fcc
Showing 563 changed files with 4,670 additions and 85,483 deletions.
54 changes: 19 additions & 35 deletions .github/workflows/check-proof-producer.yml
Original file line number Diff line number Diff line change
@@ -158,7 +158,7 @@ jobs:
- name: List artifacts
working-directory: ${{ steps.strings.outputs.artifact-dir }}
run: find .
run: find . -printf '%t %p\n'

- name: Make proofs for pairs
working-directory: ${{ steps.strings.outputs.artifact-dir }}
@@ -169,41 +169,25 @@ jobs:
fi
targets_str=$(echo "${{ needs.prepare-targets.outputs.prover-targets }}" | awk '{$1=$1};1' | sed '/^$/d' | tr '\n' ' ' | sed 's/ $//')
echo "targets from input: ${targets_str}"
${{ github.workspace }}/proof-producer/tests/make_proof_for_pairs.sh --use-nix ${extra_args} ${targets_str}
- name: Download transpiler output artifact
id: download-to-artifact
uses: dawidd6/action-download-artifact@v3
with:
repo: NilFoundation/zkLLVM
name: ${{ env.TO_ARTIFACT_NAME }}
path: ${{ steps.strings.outputs.artifact-dir }}
run_id: ${{ needs.get-zkllvm-run.outputs.run-id }}
github_token: ${{ secrets.GITHUB_TOKEN }}
targets_arr=($targets_str)
new_targets_str=""
for artifact in "${targets_arr[@]}"; do
new_artifact_name=transpiler_output_"$artifact"
mv "$artifact" "$new_artifact_name"
new_targets_str="$new_targets_str $new_artifact_name"
done
echo "targets for output: ${new_targets_str}"
${{ github.workspace }}/proof-producer/tests/make_proof_for_pairs.sh --use-nix ${extra_args} ${new_targets_str}
# Leave only relevant transpiler_output_* folders
rm -rf ${RUNNER_TEMP}/transpiler_output/
mkdir -p ${RUNNER_TEMP}/transpiler_output/
mv transpiler_output_* ${RUNNER_TEMP}/transpiler_output/
rm -rf *
mv ${RUNNER_TEMP}/transpiler_output/* .
- name: Merge proofs into transpiler output
- name: List artifacts
working-directory: ${{ steps.strings.outputs.artifact-dir }}
run: |
copy_failed=0
while read dir; do
base_name=${dir#./transpiler_output_}
if [[ -d "$base_name" ]]; then
if ! cp "${base_name}/proof.bin" "${dir}/"; then
# fails if artifact contains dirs targets we didn't produce proofs for
echo "Failed to copy proof.bin to ${dir}" >&2
copy_failed=1
else
echo "proof.bin added to ${dir}"
fi
else
echo "Error: No matching directory found for ${dir}" >&2
fi
done < <(find . -type d -name "transpiler_output_*")
if [ $copy_failed -eq 1 ]; then
echo "One or more copy operations failed." >&2
fi
run: find . -printf '%t %p\n'

- name: Set aritfact name
id: artifact-name
@@ -215,7 +199,7 @@ jobs:
with:
name: ${{ steps.artifact-name.outputs.merged }}
path: |
${{ steps.strings.outputs.artifact-dir }}/transpiler_output_*
${{ steps.strings.outputs.artifact-dir }}
# TODO: add package derivation to nix, upload its result
# - name: Upload .deb package
13 changes: 9 additions & 4 deletions .github/workflows/clang-linux-nix-check.yml
Original file line number Diff line number Diff line change
@@ -17,15 +17,20 @@ jobs:
with:
fetch-depth: 0

- name: Run checks
- name: Run checks for crypto3
run: |
nix build -L .?#checks.x86_64-linux.all-clang
mkdir results
cp result/test-logs/*_test.xml results/
nix build -L .?#checks.x86_64-linux.crypto3-clang
env:
NIX_CONFIG: |
cores = 4
- name: Run all checks
# This includes cached crypto3 check from previous step. We don't limit cores in this part
run: |
nix build -L .?#checks.x86_64-linux.all-clang
mkdir results
cp result/test-logs/*_test.xml results/
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action/linux@v2
with:
12 changes: 10 additions & 2 deletions .github/workflows/gcc-linux-nix-check.yml
Original file line number Diff line number Diff line change
@@ -17,14 +17,22 @@ jobs:
with:
fetch-depth: 0

- name: Run checks
- name: Run checks for crypto3
run: |
nix build -L .?#checks.x86_64-linux.crypto3-gcc
env:
NIX_CONFIG: |
cores = 4
- name: Run all checks
# This includes cached crypto3 check from previous step. We don't limit cores in this part
run: |
nix build -L .?#checks.x86_64-linux.all-gcc
mkdir results
cp result/test-logs/*_test.xml results/
env:
NIX_CONFIG: |
cores = 4
cores = 16
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action/linux@v2
2 changes: 1 addition & 1 deletion .github/workflows/verify-circuit-proof.yml
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Configure
run: cd crypto3 && mkdir build && cd build && cmake ../ -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=TRUE -G Ninja
run: cd crypto3 && mkdir build && cd build && cmake ../ -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=TRUE -DBUILD_CRYPTO3_TESTS=TRUE -G Ninja
shell: nix develop .#crypto3-tests --command bash -e {0}
- name: Build
run: cd crypto3/build && ninja transpiler_evm_test
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -24,10 +24,6 @@ add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/crypto3")
if ((${PARALLEL_CRYPTO3_ENABLE}) OR (${PROOF_PRODUCER_ENABLE}) OR (${ZKEVM_FRAMEWORK_ENABLE}))
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/parallel-crypto3")
endif()
if (${ZKEVM_FRAMEWORK_ENABLE})
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/evm-assigner")
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/zkevm-framework")
endif()
if ((${PROOF_PRODUCER_ENABLE}) OR (${ZKEVM_FRAMEWORK_ENABLE}))
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/proof-producer")
endif()
2 changes: 1 addition & 1 deletion crypto3.nix
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ in stdenv.mkDerivation {

cmakeFlags =
[
(if runTests then "-DBUILD_TESTS=TRUE" else "-DBUILD_TESTS=False")
(if runTests then "-DBUILD_CRYPTO3_TESTS=TRUE" else "-DBUILD_CRYPTO3_TESTS=False")
(if enableDebug then "-DCMAKE_BUILD_TYPE=Debug" else "-DCMAKE_BUILD_TYPE=Release")
(if sanitize then "-DSANITIZE=ON" else "-DSANITIZE=OFF")
"-G Ninja"
19 changes: 16 additions & 3 deletions crypto3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -18,8 +18,9 @@ cm_setup_version(VERSION 0.3.0 PREFIX ${CMAKE_WORKSPACE_NAME})

option(BUILD_SHARED_LIBS "Build shared library" FALSE) # TODO: it makes no sense for header-only lib, remove
option(Boost_USE_STATIC_LIBS "Use static libraries for Boost" OFF)
option(CMAKE_ENABLE_TESTS "Enable tests" FALSE) # used by CMTest module
option(BUILD_BENCH_TESTS "Build performance benchmark tests" FALSE)
option(BUILD_TESTS "Enable tests" TRUE) # used by CMTest module; If set to false, tests are removed from crypto3::all target. User still can build individual ones.
option(BUILD_CRYPTO3_TESTS "Enable tests" FALSE)
option(BUILD_CRYPTO3_BENCH_TESTS "Build performance benchmark tests" FALSE)
option(BUILD_DOCS "Build with configuring Doxygen documentation compiler" FALSE)

# The file compile_commands.json is generated in build directory, so LSP could
@@ -31,6 +32,12 @@ if(CMAKE_EXPORT_COMPILE_COMMANDS)
${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
endif()

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options (-fdiagnostics-color=always)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options (-fcolor-diagnostics)
endif ()

set(BUILD_WITH_TARGET_ARCHITECTURE "" CACHE STRING "Target build architecture") # TODO: check if we can do cross-compilation
set(DOXYGEN_OUTPUT_DIR "${CMAKE_CURRENT_LIST_DIR}/docs" CACHE STRING "Specify doxygen output directory")

@@ -44,6 +51,12 @@ endif()

find_package(Boost REQUIRED COMPONENTS container random filesystem log log_setup program_options thread system unit_test_framework timer)

function(add_tests)
if (${BUILD_CRYPTO3_TESTS})
add_subdirectory(test)
endif ()
endfunction(add_tests)

add_subdirectories("${CMAKE_CURRENT_LIST_DIR}/libs/")
add_subdirectories("${CMAKE_CURRENT_LIST_DIR}/libs/marshalling/")

@@ -80,7 +93,7 @@ target_link_libraries(${CMAKE_WORKSPACE_NAME}_common INTERFACE
crypto3::random
)

if(BUILD_BENCH_TESTS)
if(BUILD_CRYPTO3_BENCH_TESTS)
add_subdirectory(benchmarks)
endif()

2 changes: 1 addition & 1 deletion crypto3/libs/algebra/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ target_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
${CMAKE_WORKSPACE_NAME}::multiprecision)

include(CMTest)
cm_add_test_subdirectory(test)
add_tests(test)

if(BUILD_EXAMPLES)
add_subdirectory(example)
Original file line number Diff line number Diff line change
@@ -28,32 +28,12 @@

#include <nil/crypto3/algebra/pairing/pairing_policy.hpp>

#include <optional>

namespace nil {
namespace crypto3 {
namespace algebra {

// template<typename PairingCurveType>
// typename PairingCurveType::pairing::affine_ate_g1_precomp
// affine_ate_precompute_g1(const typename PairingCurveType::pairing::g1_type::value_type &P) {

// return PairingCurveType::pairing::affine_ate_precompute_g1(P);
// }

// template<typename PairingCurveType>
// typename PairingCurveType::pairing::affine_ate_g2_precomp
// affine_ate_precompute_g2(const typename PairingCurveType::pairing::g2_type::value_type &P) {

// return PairingCurveType::pairing::affine_ate_precompute_g2(P);
// }

// template<typename PairingCurveType>
// typename PairingCurveType::pairing::gt_type::value_type
// affine_ate_miller_loop(const typename PairingCurveType::pairing::affine_ate_g1_precomp &prec_P,
// const typename PairingCurveType::pairing::affine_ate_g2_precomp &prec_Q) {

// return PairingCurveType::pairing::affine_ate_miller_loop(prec_P, prec_Q);
// }

template<typename PairingCurveType, typename PairingPolicy = pairing::pairing_policy<PairingCurveType>>
typename PairingPolicy::g1_precomputed_type
precompute_g1(const typename PairingCurveType::template g1_type<>::value_type &P) {
@@ -89,7 +69,7 @@ namespace nil {
#endif

template<typename PairingCurveType, typename PairingPolicy = pairing::pairing_policy<PairingCurveType>>
typename PairingCurveType::gt_type::value_type
std::optional<typename PairingCurveType::gt_type::value_type>
pair_reduced(const typename PairingCurveType::template g1_type<>::value_type &v1,
const typename PairingCurveType::template g2_type<>::value_type &v2) {

@@ -111,7 +91,7 @@ namespace nil {
}

template<typename PairingCurveType, typename PairingPolicy = pairing::pairing_policy<PairingCurveType>>
typename PairingCurveType::gt_type::value_type
std::optional<typename PairingCurveType::gt_type::value_type>
final_exponentiation(const typename PairingCurveType::gt_type::value_type &elt) {

return PairingPolicy::final_exponentiation::process(elt);
Original file line number Diff line number Diff line change
@@ -43,12 +43,11 @@ namespace nil {
using base_field_type = typename alt_bn128_types<254>::base_field_type;
using scalar_field_type = typename alt_bn128_types<254>::scalar_field_type;

constexpr static const typename alt_bn128_types<254>::integral_type a =
typename alt_bn128_types<254>::integral_type(
0x00); ///< coefficient of short Weierstrass curve $y^2=x^3+a*x+b$
constexpr static const typename alt_bn128_types<254>::integral_type b =
typename alt_bn128_types<254>::integral_type(
0x03); ///< coefficient of short Weierstrass curve $y^2=x^3+a*x+b$
///< coefficients of short Weierstrass curve $y^2=x^3+a*x+b$
constexpr static const typename alt_bn128_types<254>::base_field_type::value_type
a = 0x00;
constexpr static const typename alt_bn128_types<254>::base_field_type::value_type
b = 0x03;
};

template<>
@@ -104,9 +103,9 @@ namespace nil {
0x90689D0585FF075EC9E99AD690C3395BC4B313370B38EF355ACDADCD122975B_cppui_modular254)};
};

constexpr typename alt_bn128_types<254>::integral_type const
constexpr typename alt_bn128_types<254>::base_field_type::value_type const
alt_bn128_params<254, forms::short_weierstrass>::a;
constexpr typename alt_bn128_types<254>::integral_type const
constexpr typename alt_bn128_types<254>::base_field_type::value_type const
alt_bn128_params<254, forms::short_weierstrass>::b;

constexpr std::array<
Original file line number Diff line number Diff line change
@@ -42,35 +42,35 @@ namespace nil {
using scalar_field_type = typename babyjubjub_types::scalar_field_type;

// Edwards representation constants a and d
constexpr static const typename babyjubjub_types::integral_type
constexpr static const typename babyjubjub_types::base_field_type::value_type
a = ///< twisted Edwards elliptic curve
0x292FC_cppui_modular18; ///< described by equation ax^2 + y^2 = 1 + dx^2y^2
constexpr static const typename babyjubjub_types::integral_type
constexpr static const typename babyjubjub_types::base_field_type::value_type
d = ///< twisted Edwards elliptic curve
0x292F8_cppui_modular18; ///< described by equation ax^2 + y^2 = 1 + dx^2y^2
};

constexpr
typename babyjubjub_types::integral_type const babyjubjub_params<forms::twisted_edwards>::a;
typename babyjubjub_types::base_field_type::value_type const babyjubjub_params<forms::twisted_edwards>::a;
constexpr
typename babyjubjub_types::integral_type const babyjubjub_params<forms::twisted_edwards>::d;
typename babyjubjub_types::base_field_type::value_type const babyjubjub_params<forms::twisted_edwards>::d;

template<>
struct babyjubjub_params<forms::montgomery> {
using base_field_type = typename babyjubjub_types::base_field_type;
using scalar_field_type = typename babyjubjub_types::scalar_field_type;

// Montgomery representation constants A and B
constexpr static const typename babyjubjub_types::integral_type
constexpr static const typename babyjubjub_types::base_field_type::value_type
A = ///< Montgomery elliptic curve
0x292FA_cppui_modular18; ///< described by equation b*y^2 = x^3 + a*x^2 + x
constexpr static const typename babyjubjub_types::integral_type
constexpr static const typename babyjubjub_types::base_field_type::value_type
B = ///< Montgomery elliptic curve
0x01; ///< described by equation b*y^2 = x^3 + a*x^2 + x
};

constexpr typename babyjubjub_types::integral_type const babyjubjub_params<forms::montgomery>::A;
constexpr typename babyjubjub_types::integral_type const babyjubjub_params<forms::montgomery>::B;
constexpr typename babyjubjub_types::base_field_type::value_type const babyjubjub_params<forms::montgomery>::A;
constexpr typename babyjubjub_types::base_field_type::value_type const babyjubjub_params<forms::montgomery>::B;

template<>
struct babyjubjub_g1_params<forms::twisted_edwards>
Original file line number Diff line number Diff line change
@@ -43,12 +43,11 @@ namespace nil {
using base_field_type = typename bls12_types<377>::base_field_type;
using scalar_field_type = typename bls12_types<377>::scalar_field_type;

constexpr static const typename bls12_types<377>::integral_type a =
typename bls12_types<377>::integral_type(
0x00); ///< coefficient of short Weierstrass curve $y^2=x^3+a*x+b$
constexpr static const typename bls12_types<377>::integral_type b =
typename bls12_types<377>::integral_type(
0x01); ///< coefficient of short Weierstrass curve $y^2=x^3+a*x+b$
///< coefficients of short Weierstrass curve $y^2=x^3+a*x+b$
constexpr static const typename bls12_types<377>::base_field_type::value_type
a = 0x00;
constexpr static const typename bls12_types<377>::base_field_type::value_type
b = 0x01;
};

template<>
@@ -109,9 +108,9 @@ namespace nil {
};

constexpr
typename bls12_types<377>::integral_type const bls12_params<377, forms::short_weierstrass>::a;
typename bls12_types<377>::base_field_type::value_type const bls12_params<377, forms::short_weierstrass>::a;
constexpr
typename bls12_types<377>::integral_type const bls12_params<377, forms::short_weierstrass>::b;
typename bls12_types<377>::base_field_type::value_type const bls12_params<377, forms::short_weierstrass>::b;

constexpr std::array<
typename bls12_g1_params<377, forms::short_weierstrass>::field_type::value_type,
Original file line number Diff line number Diff line change
@@ -43,12 +43,11 @@ namespace nil {
using base_field_type = typename bls12_types<381>::base_field_type;
using scalar_field_type = typename bls12_types<381>::scalar_field_type;

constexpr static const typename bls12_types<381>::integral_type a =
typename bls12_types<381>::integral_type(
0x00); ///< coefficient of short Weierstrass curve $y^2=x^3+a*x+b$
constexpr static const typename bls12_types<381>::integral_type b =
typename bls12_types<381>::integral_type(
0x04); ///< coefficient of short Weierstrass curve $y^2=x^3+a*x+b$
///< coefficients of short Weierstrass curve $y^2=x^3+a*x+b$
constexpr static const typename bls12_types<381>::base_field_type::value_type
a = 0x00;
constexpr static const typename bls12_types<381>::base_field_type::value_type
b = 0x04;
};

template<>
@@ -109,9 +108,9 @@ namespace nil {
};

constexpr
typename bls12_types<381>::integral_type const bls12_params<381, forms::short_weierstrass>::a;
typename bls12_types<381>::base_field_type::value_type const bls12_params<381, forms::short_weierstrass>::a;
constexpr
typename bls12_types<381>::integral_type const bls12_params<381, forms::short_weierstrass>::b;
typename bls12_types<381>::base_field_type::value_type const bls12_params<381, forms::short_weierstrass>::b;

constexpr typename bls12_g2_params<381, forms::short_weierstrass>::field_type::value_type const
bls12_g2_params<381, forms::short_weierstrass>::b;
Loading

0 comments on commit 3810fcc

Please sign in to comment.