Skip to content

Commit

Permalink
Structures for partial placeholder proof.
Browse files Browse the repository at this point in the history
  • Loading branch information
Iluvmagick committed Sep 9, 2024
1 parent ed03698 commit 2d53cd3
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

#include <nil/crypto3/marshalling/algebra/types/field_element.hpp>
#include <nil/crypto3/marshalling/zk/types/commitments/eval_storage.hpp>
#include <nil/crypto3/zk/snark/systems/plonk/placeholder/proof.hpp>

namespace nil {
namespace crypto3 {
Expand Down Expand Up @@ -150,8 +151,8 @@ namespace nil {
auto batch_info = proof.eval_proof.eval_proof.z.get_batch_info();

std::size_t cur = 0;
for( const auto &it:batch_info ){
if( it.first == Proof::FIXED_VALUES_BATCH ) continue;
for (const auto &it : batch_info) {
if (it.first == zk::snark::FIXED_VALUES_BATCH) continue;
proof.commitments[it.first] = make_commitment<Endianness, typename Proof::commitment_scheme_type>(
std::get<0>(filled_proof.value()).value()[cur++]
);
Expand Down
51 changes: 24 additions & 27 deletions libs/marshalling/zk/test/placeholder_proof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ struct placeholder_kzg_test_fixture_v2 : public test_tools::random_test_initiali
};


BOOST_AUTO_TEST_SUITE(placeholder_circuit2_kzg_v2)
/*BOOST_AUTO_TEST_SUITE(placeholder_circuit2_kzg_v2)
using TestFixtures = boost::mpl::list<
placeholder_kzg_test_fixture_v2<
Expand All @@ -1224,18 +1224,16 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit2_kzg_v2)
selector_columns_t,
usable_rows_t,
true>
/*
, placeholder_kzg_test_fixture<
algebra::curves::alt_bn128_254,
hashes::keccak_1600<256>,
hashes::keccak_1600<256>,
witness_columns_t,
public_columns_t,
constant_columns_t,
selector_columns_t,
usable_rows_t,
4, true>
*/
// , placeholder_kzg_test_fixture<
// algebra::curves::alt_bn128_254,
// hashes::keccak_1600<256>,
// hashes::keccak_1600<256>,
// witness_columns_t,
// public_columns_t,
// constant_columns_t,
// selector_columns_t,
// usable_rows_t,
// 4, true>
, placeholder_kzg_test_fixture_v2<
algebra::curves::mnt4_298,
hashes::keccak_1600<256>,
Expand All @@ -1256,24 +1254,23 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit2_kzg_v2)
selector_columns_t,
usable_rows_t,
true>
/*, -- Not yet implemented
placeholder_kzg_test_fixture<
algebra::curves::mnt6_298,
hashes::poseidon<nil::crypto3::hashes::detail::mina_poseidon_policy<algebra::curves::mnt6_298>>,
hashes::poseidon<nil::crypto3::hashes::detail::mina_poseidon_policy<algebra::curves::mnt6_298>>,
witness_columns_t,
public_columns_t,
constant_columns_t,
selector_columns_t,
usable_rows_t,
4,
true>
*/
// , -- Not yet implemented
// placeholder_kzg_test_fixture<
// algebra::curves::mnt6_298,
// hashes::poseidon<nil::crypto3::hashes::detail::mina_poseidon_policy<algebra::curves::mnt6_298>>,
// hashes::poseidon<nil::crypto3::hashes::detail::mina_poseidon_policy<algebra::curves::mnt6_298>>,
// witness_columns_t,
// public_columns_t,
// constant_columns_t,
// selector_columns_t,
// usable_rows_t,
// 4,
// true>
>;
BOOST_AUTO_TEST_CASE_TEMPLATE(prover_test, F, TestFixtures) {
F fixture;
BOOST_CHECK(fixture.run_test());
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()*/
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,55 @@
// SOFTWARE.
//---------------------------------------------------------------------------//

#ifndef CRYPTO3_ZK_PLONK_PLACEHOLDER_PROOF_HPP
#define CRYPTO3_ZK_PLONK_PLACEHOLDER_PROOF_HPP
#pragma once

#include <map>

namespace nil {
namespace crypto3 {
namespace zk {
namespace snark {
constexpr std::size_t FIXED_VALUES_BATCH = 0;
constexpr std::size_t VARIABLE_VALUES_BATCH = 1;
constexpr std::size_t PERMUTATION_BATCH =2;
constexpr std::size_t QUOTIENT_BATCH = 3;
constexpr std::size_t LOOKUP_BATCH = 4;
static constexpr std::size_t FIXED_VALUES_BATCH = 0;
static constexpr std::size_t VARIABLE_VALUES_BATCH = 1;
static constexpr std::size_t PERMUTATION_BATCH = 2;
static constexpr std::size_t QUOTIENT_BATCH = 3;
static constexpr std::size_t LOOKUP_BATCH = 4;

template<typename FieldType, typename ParamsType>
struct partial_placeholder_proof {

typedef FieldType field_type;
typedef ParamsType params_type;

using circuit_params_type = typename ParamsType::circuit_params_type;
using commitment_scheme_type = typename ParamsType::commitment_scheme_type;
using commitment_type = typename commitment_scheme_type::commitment_type;

struct partial_evaluation_proof {
typename commitment_scheme_type::partial_proof_type partial_eval_proof;

bool operator==(const partial_evaluation_proof &rhs) const {
return partial_eval_proof == rhs.partial_eval_proof;
}
bool operator!=(const partial_evaluation_proof &rhs) const {
return !(rhs == *this);
}
};

partial_placeholder_proof() = default;

std::map<std::size_t, commitment_type> commitments;
partial_evaluation_proof partial_eval_proof;

bool operator==(const partial_placeholder_proof &rhs) const {
return
commitments == rhs.commitments &&
partial_eval_proof == rhs.partial_eval_proof;
}
bool operator!=(const partial_placeholder_proof &rhs) const {
return !(rhs == *this);
}
};

/**
* A proof for the Placeholder scheme.
Expand All @@ -49,12 +84,6 @@ namespace nil {
*/
template<typename FieldType, typename ParamsType>
struct placeholder_proof {
static constexpr std::size_t FIXED_VALUES_BATCH = 0;
static constexpr std::size_t VARIABLE_VALUES_BATCH = 1;
static constexpr std::size_t PERMUTATION_BATCH =2;
static constexpr std::size_t QUOTIENT_BATCH = 3;
static constexpr std::size_t LOOKUP_BATCH = 4;

typedef FieldType field_type;
typedef ParamsType params_type;

Expand All @@ -63,7 +92,9 @@ namespace nil {
using commitment_type = typename commitment_scheme_type::commitment_type;

struct evaluation_proof {
// TODO: remove it!
// TODO: remove it?
// This is difficult to achieve in the current architecture.
// We might be fine with just checking that the challenge matches the expected one.
typename FieldType::value_type challenge;

typename commitment_scheme_type::proof_type eval_proof;
Expand All @@ -76,8 +107,13 @@ namespace nil {
}
};

placeholder_proof() {
}
placeholder_proof() = default;
placeholder_proof(
const partial_placeholder_proof<FieldType, ParamsType> &partial_proof,
const evaluation_proof &full_eval_proof
) : commitments(partial_proof.commitments),
eval_proof(full_eval_proof)
{}

std::map<std::size_t, commitment_type> commitments;
evaluation_proof eval_proof;
Expand All @@ -95,5 +131,3 @@ namespace nil {
} // namespace zk
} // namespace crypto3
} // namespace nil

#endif // CRYPTO3_ZK_PLONK_PLACEHOLDER_PROOF_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,9 @@ namespace nil {
transcript(proof.commitments.at(QUOTIENT_BATCH));

auto challenge = transcript.template challenge<FieldType>();
BOOST_ASSERT(challenge == proof.eval_proof.challenge);
if (challenge != proof.eval_proof.challenge) {
return false;
}

commitment_scheme.set_batch_size(VARIABLE_VALUES_BATCH,
proof.eval_proof.eval_proof.z.get_batch_size(VARIABLE_VALUES_BATCH));
Expand Down

0 comments on commit 2d53cd3

Please sign in to comment.