Skip to content

Commit

Permalink
Redshift compilation updates. #20
Browse files Browse the repository at this point in the history
  • Loading branch information
nkaskov committed Dec 13, 2021
1 parent b8e6017 commit a335176
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 24 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ target_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
${CMAKE_WORKSPACE_NAME}::math
${CMAKE_WORKSPACE_NAME}::hash
${CMAKE_WORKSPACE_NAME}::multiprecision
${CMAKE_WORKSPACE_NAME}::containers
)

cm_deploy(TARGETS ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
#ifndef CRYPTO3_ZK_FRI_COMMITMENT_SCHEME_HPP
#define CRYPTO3_ZK_FRI_COMMITMENT_SCHEME_HPP

#include <nil/crypto3/zk/snark/commitments/commitment.hpp>
#include <nil/crypto3/math/polynomial/polynom.hpp>
#include <nil/crypto3/zk/snark/transcript/fiat_shamir.hpp>

#include <nil/crypto3/merkle/tree.hpp>
#include <nil/crypto3/merkle/proof.hpp>

namespace nil {
namespace crypto3 {
Expand All @@ -50,41 +54,42 @@ namespace nil {
std::size_t r, std::size_t m=2>
class list_polynomial_commitment_scheme {

typedef typename merkletree::MerkleTree<Hash> merkle_tree_type;
typedef typename merkletree::MerkleProof<Hash> merkle_proof_type;
typedef Hash transcript_hash_type;

typedef merkle_tree<Hash, 2> merkle_tree_type;
typedef merkle_proof<Hash, 2> merkle_proof_type;

constexpr static const math::polynomial::polynom<typename FieldType::value_type>
q = {0, 0, 1};

struct transcript_round_manifest {
enum challenges_ids {x, y};
}
};
public:

using openning_type = merkle_proof_type;
using commitment_type = typename merkle_tree_type::root_type;
using commitment_type = typename merkle_tree_type::value_type;

struct proof_type {
std::array<merkle_proof_type, k> z_openings;
std::array<std::array<merkle_proof_type, m * r>, lamda> alpha_openings;
std::array<std::array<merkle_proof_type, r>, lamda> f_y_openings;
std::array<std::array<merkle_proof_type, m * r>, lambda> alpha_openings;
std::array<std::array<merkle_proof_type, r>, lambda> f_y_openings;

std::array<std::array<commitment_type, r - 1>, lamda> f_commitments;
std::array<std::array<commitment_type, r - 1>, lambda> f_commitments;

std::array<std::array<typename FieldType::value_type>, lambda>
std::array<std::vector<typename FieldType::value_type>, lambda>
f_ip1_coefficients;
}
};

// The result of this function is not commitment_type (as it would expected),
// but the built Merkle tree. This is done so, because we often need to reuse
// the built Merkle tree
// After this function
// result.root();
// should be called
template <...>
static merkle_tree_type commit (const math::polynomial::polynom<
typename FieldType::value_type> &f,
const std::vector<...> &D){
const std::vector<typename FieldType::value_type> &D){

std::vector<typename FieldType::value_type> y;
for (typename FieldType::value_type H : D){
Expand All @@ -94,12 +99,11 @@ namespace nil {
return merkle_tree_type(y);
}

template <...>
static proof_type proof_eval (
std::array<typename FieldType::value_type, k> evaluation_points,
const merkle_tree_type &T,
const math::polynomial::polynom<typename FieldType::value_type> &f,
const std::vector<...> &D){
const std::vector<typename FieldType::value_type> &D){

proof_type proof;

Expand Down Expand Up @@ -184,13 +188,11 @@ namespace nil {

return proof;
}
};

template <...>
static bool verify_eval (std::array<typename FieldType::value_type, k> evaluation_points,
commitment_type root,
proof_type proof,
const std::vector<...> &D){
const std::vector<typename FieldType::value_type> &D){

fiat_shamir_heuristic<transcript_round_manifest, transcript_hash_type> transcript;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#include <nil/crypto3/math/polynomial/polynom.hpp>

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

#include <nil/crypto3/zk/snark/commitments/list_polynomial_commitment.hpp>
#include <nil/crypto3/zk/snark/transcript/fiat_shamir.hpp>
#include <nil/crypto3/zk/snark/systems/plonk/redshift/types.hpp>
Expand Down
17 changes: 10 additions & 7 deletions include/nil/crypto3/zk/snark/transcript/fiat_shamir.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#ifndef CRYPTO3_ZK_TRANSCRIPT_FIAT_SHAMIR_HEURISTIC_HPP
#define CRYPTO3_ZK_TRANSCRIPT_FIAT_SHAMIR_HEURISTIC_HPP

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

namespace nil {
namespace crypto3 {
namespace zk {
Expand Down Expand Up @@ -53,31 +56,31 @@ namespace nil {
* }
* };
*/
template<enum TChallenges, typename Hash = hashes::sha2>
template<typename TChallenges, typename Hash = hashes::sha2<256>>
class fiat_shamir_heuristic {

accumulators::accumulator_set<Hash> acc;
accumulator_set<Hash> acc;
public:

fiat_shamir_heuristic() {
acc();
}

template <typename TAny>
operator (TAny data){
void operator() (TAny data){
acc(data);
}

template <challenges_ids ChallengeId>
template <typename TChallenges::challenges_ids ChallengeId>
typename Hash::digest_type get_challenge(){
acc(ChallengeId);
return extract::hash<hash_t>(acc);
return accumulators::extract::hash<Hash>(acc);
}

template <challenges_ids ChallengeId, std::size_t Index>
template <typename TChallenges::challenges_ids ChallengeId, std::size_t Index>
typename Hash::digest_type get_challenge(){
acc(ChallengeId + Index);
return extract::hash<hash_t>(acc);
return accumulators::extract::hash<Hash>(acc);
}
};
} // namespace snark
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ set(TESTS_NAMES
"relations/numeric/ssp"

"systems/plonk/pickles"
"systems/plonk/redshift"

"systems/pcd/r1cs_pcd/r1cs_mp_ppzkpcd/r1cs_mp_ppzkpcd"
"systems/pcd/r1cs_pcd/r1cs_sp_ppzkpcd/r1cs_sp_ppzkpcd"
Expand Down
44 changes: 44 additions & 0 deletions test/systems/plonk/redshift.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2021 Mikhail Komarov <nemo@nil.foundation>
// Copyright (c) 2021 Nikita Kaskov <nbering@nil.foundation>
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//---------------------------------------------------------------------------//

#define BOOST_TEST_MODULE redshift_test

#include <string>

#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <boost/test/data/monomorphic.hpp>

#include <nil/crypto3/zk/snark/systems/plonk/redshift/prover.hpp>

using namespace nil::crypto3;

BOOST_AUTO_TEST_SUITE(redshift_prover_test_suite)

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE(redshift_proveron_test_suite)

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit a335176

Please sign in to comment.