Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 2d53cd3

Browse files
committed
Structures for partial placeholder proof.
1 parent ed03698 commit 2d53cd3

File tree

4 files changed

+82
-48
lines changed

4 files changed

+82
-48
lines changed

libs/marshalling/zk/include/nil/crypto3/marshalling/zk/types/placeholder/proof.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

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

4647
namespace nil {
4748
namespace crypto3 {
@@ -150,8 +151,8 @@ namespace nil {
150151
auto batch_info = proof.eval_proof.eval_proof.z.get_batch_info();
151152

152153
std::size_t cur = 0;
153-
for( const auto &it:batch_info ){
154-
if( it.first == Proof::FIXED_VALUES_BATCH ) continue;
154+
for (const auto &it : batch_info) {
155+
if (it.first == zk::snark::FIXED_VALUES_BATCH) continue;
155156
proof.commitments[it.first] = make_commitment<Endianness, typename Proof::commitment_scheme_type>(
156157
std::get<0>(filled_proof.value()).value()[cur++]
157158
);

libs/marshalling/zk/test/placeholder_proof.cpp

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,7 @@ struct placeholder_kzg_test_fixture_v2 : public test_tools::random_test_initiali
12111211
};
12121212

12131213

1214-
BOOST_AUTO_TEST_SUITE(placeholder_circuit2_kzg_v2)
1214+
/*BOOST_AUTO_TEST_SUITE(placeholder_circuit2_kzg_v2)
12151215
12161216
using TestFixtures = boost::mpl::list<
12171217
placeholder_kzg_test_fixture_v2<
@@ -1224,18 +1224,16 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit2_kzg_v2)
12241224
selector_columns_t,
12251225
usable_rows_t,
12261226
true>
1227-
/*
1228-
, placeholder_kzg_test_fixture<
1229-
algebra::curves::alt_bn128_254,
1230-
hashes::keccak_1600<256>,
1231-
hashes::keccak_1600<256>,
1232-
witness_columns_t,
1233-
public_columns_t,
1234-
constant_columns_t,
1235-
selector_columns_t,
1236-
usable_rows_t,
1237-
4, true>
1238-
*/
1227+
// , placeholder_kzg_test_fixture<
1228+
// algebra::curves::alt_bn128_254,
1229+
// hashes::keccak_1600<256>,
1230+
// hashes::keccak_1600<256>,
1231+
// witness_columns_t,
1232+
// public_columns_t,
1233+
// constant_columns_t,
1234+
// selector_columns_t,
1235+
// usable_rows_t,
1236+
// 4, true>
12391237
, placeholder_kzg_test_fixture_v2<
12401238
algebra::curves::mnt4_298,
12411239
hashes::keccak_1600<256>,
@@ -1256,24 +1254,23 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit2_kzg_v2)
12561254
selector_columns_t,
12571255
usable_rows_t,
12581256
true>
1259-
/*, -- Not yet implemented
1260-
placeholder_kzg_test_fixture<
1261-
algebra::curves::mnt6_298,
1262-
hashes::poseidon<nil::crypto3::hashes::detail::mina_poseidon_policy<algebra::curves::mnt6_298>>,
1263-
hashes::poseidon<nil::crypto3::hashes::detail::mina_poseidon_policy<algebra::curves::mnt6_298>>,
1264-
witness_columns_t,
1265-
public_columns_t,
1266-
constant_columns_t,
1267-
selector_columns_t,
1268-
usable_rows_t,
1269-
4,
1270-
true>
1271-
*/
1257+
// , -- Not yet implemented
1258+
// placeholder_kzg_test_fixture<
1259+
// algebra::curves::mnt6_298,
1260+
// hashes::poseidon<nil::crypto3::hashes::detail::mina_poseidon_policy<algebra::curves::mnt6_298>>,
1261+
// hashes::poseidon<nil::crypto3::hashes::detail::mina_poseidon_policy<algebra::curves::mnt6_298>>,
1262+
// witness_columns_t,
1263+
// public_columns_t,
1264+
// constant_columns_t,
1265+
// selector_columns_t,
1266+
// usable_rows_t,
1267+
// 4,
1268+
// true>
12721269
>;
12731270
12741271
BOOST_AUTO_TEST_CASE_TEMPLATE(prover_test, F, TestFixtures) {
12751272
F fixture;
12761273
BOOST_CHECK(fixture.run_test());
12771274
}
12781275
1279-
BOOST_AUTO_TEST_SUITE_END()
1276+
BOOST_AUTO_TEST_SUITE_END()*/

libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/proof.hpp

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,55 @@
2525
// SOFTWARE.
2626
//---------------------------------------------------------------------------//
2727

28-
#ifndef CRYPTO3_ZK_PLONK_PLACEHOLDER_PROOF_HPP
29-
#define CRYPTO3_ZK_PLONK_PLACEHOLDER_PROOF_HPP
28+
#pragma once
3029

3130
#include <map>
3231

3332
namespace nil {
3433
namespace crypto3 {
3534
namespace zk {
3635
namespace snark {
37-
constexpr std::size_t FIXED_VALUES_BATCH = 0;
38-
constexpr std::size_t VARIABLE_VALUES_BATCH = 1;
39-
constexpr std::size_t PERMUTATION_BATCH =2;
40-
constexpr std::size_t QUOTIENT_BATCH = 3;
41-
constexpr std::size_t LOOKUP_BATCH = 4;
36+
static constexpr std::size_t FIXED_VALUES_BATCH = 0;
37+
static constexpr std::size_t VARIABLE_VALUES_BATCH = 1;
38+
static constexpr std::size_t PERMUTATION_BATCH = 2;
39+
static constexpr std::size_t QUOTIENT_BATCH = 3;
40+
static constexpr std::size_t LOOKUP_BATCH = 4;
41+
42+
template<typename FieldType, typename ParamsType>
43+
struct partial_placeholder_proof {
44+
45+
typedef FieldType field_type;
46+
typedef ParamsType params_type;
47+
48+
using circuit_params_type = typename ParamsType::circuit_params_type;
49+
using commitment_scheme_type = typename ParamsType::commitment_scheme_type;
50+
using commitment_type = typename commitment_scheme_type::commitment_type;
51+
52+
struct partial_evaluation_proof {
53+
typename commitment_scheme_type::partial_proof_type partial_eval_proof;
54+
55+
bool operator==(const partial_evaluation_proof &rhs) const {
56+
return partial_eval_proof == rhs.partial_eval_proof;
57+
}
58+
bool operator!=(const partial_evaluation_proof &rhs) const {
59+
return !(rhs == *this);
60+
}
61+
};
62+
63+
partial_placeholder_proof() = default;
64+
65+
std::map<std::size_t, commitment_type> commitments;
66+
partial_evaluation_proof partial_eval_proof;
67+
68+
bool operator==(const partial_placeholder_proof &rhs) const {
69+
return
70+
commitments == rhs.commitments &&
71+
partial_eval_proof == rhs.partial_eval_proof;
72+
}
73+
bool operator!=(const partial_placeholder_proof &rhs) const {
74+
return !(rhs == *this);
75+
}
76+
};
4277

4378
/**
4479
* A proof for the Placeholder scheme.
@@ -49,12 +84,6 @@ namespace nil {
4984
*/
5085
template<typename FieldType, typename ParamsType>
5186
struct placeholder_proof {
52-
static constexpr std::size_t FIXED_VALUES_BATCH = 0;
53-
static constexpr std::size_t VARIABLE_VALUES_BATCH = 1;
54-
static constexpr std::size_t PERMUTATION_BATCH =2;
55-
static constexpr std::size_t QUOTIENT_BATCH = 3;
56-
static constexpr std::size_t LOOKUP_BATCH = 4;
57-
5887
typedef FieldType field_type;
5988
typedef ParamsType params_type;
6089

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

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

69100
typename commitment_scheme_type::proof_type eval_proof;
@@ -76,8 +107,13 @@ namespace nil {
76107
}
77108
};
78109

79-
placeholder_proof() {
80-
}
110+
placeholder_proof() = default;
111+
placeholder_proof(
112+
const partial_placeholder_proof<FieldType, ParamsType> &partial_proof,
113+
const evaluation_proof &full_eval_proof
114+
) : commitments(partial_proof.commitments),
115+
eval_proof(full_eval_proof)
116+
{}
81117

82118
std::map<std::size_t, commitment_type> commitments;
83119
evaluation_proof eval_proof;
@@ -95,5 +131,3 @@ namespace nil {
95131
} // namespace zk
96132
} // namespace crypto3
97133
} // namespace nil
98-
99-
#endif // CRYPTO3_ZK_PLONK_PLACEHOLDER_PROOF_HPP

libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/verifier.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,9 @@ namespace nil {
377377
transcript(proof.commitments.at(QUOTIENT_BATCH));
378378

379379
auto challenge = transcript.template challenge<FieldType>();
380-
BOOST_ASSERT(challenge == proof.eval_proof.challenge);
380+
if (challenge != proof.eval_proof.challenge) {
381+
return false;
382+
}
381383

382384
commitment_scheme.set_batch_size(VARIABLE_VALUES_BATCH,
383385
proof.eval_proof.eval_proof.z.get_batch_size(VARIABLE_VALUES_BATCH));

0 commit comments

Comments
 (0)