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

Commit af3caeb

Browse files
committed
Work in progress on KZG marshalling #300
1 parent 8b5632c commit af3caeb

File tree

4 files changed

+52
-12
lines changed

4 files changed

+52
-12
lines changed

include/nil/crypto3/zk/commitments/detail/polynomial/basic_fri.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ namespace nil {
7878
struct basic_batched_fri {
7979
BOOST_STATIC_ASSERT_MSG(M == 2, "unsupported m value!");
8080

81+
constexpr static const bool is_fri = true;
82+
8183
constexpr static const std::size_t m = M;
8284
constexpr static const std::size_t lambda = Lambda;
8385

@@ -1014,4 +1016,4 @@ namespace nil {
10141016
} // namespace crypto3
10151017
} // namespace nil
10161018

1017-
#endif // CRYPTO3_ZK_COMMITMENTS_BASIC_FRI_HPP
1019+
#endif // CRYPTO3_ZK_COMMITMENTS_BASIC_FRI_HPP

include/nil/crypto3/zk/commitments/polynomial/kzg.hpp

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Copyright (c) 2020-2021 Nikita Kaskov <[email protected]>
44
// Copyright (c) 2020-2021 Ilias Khairullin <[email protected]>
55
// Copyright (c) 2022 Ekaterina Chukavina <[email protected]>
6+
// Copyright (c) 2024 Vasiliy Olekhov <[email protected]>
67
//
78
// MIT License
89
//
@@ -217,6 +218,9 @@ namespace nil {
217218
typename PolynomialType = math::polynomial_dfs<typename CurveType::scalar_field_type::value_type>
218219
>
219220
struct batched_kzg {
221+
222+
constexpr static bool is_kzg = true;
223+
220224
typedef CurveType curve_type;
221225
typedef TranscriptHashType transcript_hash_type;
222226
typedef typename curve_type::gt_type::value_type gt_value_type;
@@ -235,8 +239,10 @@ namespace nil {
235239

236240
using commitment_type = std::vector<std::uint8_t>; // Used in placeholder because it's easy to push it into transcript
237241

242+
using eval_storage_type = eval_storage<field_type>;
243+
238244
struct proof_type {
239-
eval_storage<field_type> z;
245+
eval_storage_type z;
240246
single_commitment_type kzg_proof;
241247
};
242248

@@ -605,8 +611,12 @@ namespace nil {
605611

606612
namespace commitments{
607613
// Placeholder-friendly class
608-
template<typename KZGScheme, typename PolynomialType = typename math::polynomial_dfs<typename KZGScheme::field_type::value_type>>
609-
class kzg_commitment_scheme : public polys_evaluator<typename KZGScheme::params_type, typename KZGScheme::commitment_type, PolynomialType>{
614+
template<typename KZGScheme>
615+
class kzg_commitment_scheme :
616+
public polys_evaluator<
617+
typename KZGScheme::params_type,
618+
typename KZGScheme::commitment_type,
619+
typename KZGScheme::poly_type> {
610620
public:
611621
using curve_type = typename KZGScheme::curve_type;
612622
using field_type = typename KZGScheme::field_type;
@@ -616,7 +626,7 @@ namespace nil {
616626
using commitment_type = typename KZGScheme::commitment_type;
617627
using transcript_type = typename KZGScheme::transcript_type;
618628
using transcript_hash_type = typename KZGScheme::transcript_hash_type;
619-
using poly_type = PolynomialType;
629+
using poly_type = typename KZGScheme::poly_type;
620630
using proof_type = typename KZGScheme::proof_type;
621631
using endianness = nil::marshalling::option::big_endian;
622632
private:
@@ -832,9 +842,15 @@ namespace nil {
832842
* Dan Boneh, Justin Drake, Ben Fisch,
833843
* <https://eprint.iacr.org/2020/081.pdf>
834844
*/
835-
template<typename KZGScheme, typename PolynomialType = typename math::polynomial_dfs<typename KZGScheme::field_type::value_type>>
836-
class kzg_commitment_scheme_v2 : public polys_evaluator<typename KZGScheme::params_type, typename KZGScheme::commitment_type, PolynomialType>{
845+
template<typename KZGScheme>
846+
class kzg_commitment_scheme_v2 :
847+
public polys_evaluator<
848+
typename KZGScheme::params_type,
849+
typename KZGScheme::commitment_type,
850+
typename KZGScheme::poly_type> {
837851
public:
852+
constexpr static bool is_kzg_commitment_scheme_v2 = true;
853+
838854
using curve_type = typename KZGScheme::curve_type;
839855
using field_type = typename KZGScheme::field_type;
840856
using params_type = typename KZGScheme::params_type;
@@ -844,10 +860,20 @@ namespace nil {
844860
using verification_key_type = typename curve_type::template g2_type<>::value_type;
845861
using transcript_type = typename KZGScheme::transcript_type;
846862
using transcript_hash_type = typename KZGScheme::transcript_hash_type;
847-
using poly_type = PolynomialType;
863+
using poly_type = typename KZGScheme::poly_type;
864+
865+
using eval_storage_type = eval_storage<field_type>;
866+
using single_commitment_type = typename KZGScheme::single_commitment_type;
867+
848868
struct proof_type {
849-
eval_storage<field_type> z;
850-
typename KZGScheme::single_commitment_type pi_1, pi_2;
869+
eval_storage_type z;
870+
single_commitment_type pi_1, pi_2;
871+
bool operator==(proof_type const& other) const {
872+
return (z == other.z) && (pi_1 == other.pi_1) && (pi_2 == other.pi_2);
873+
}
874+
bool operator!=(proof_type const& other) const {
875+
return !(*this == other);
876+
}
851877
};
852878
using endianness = nil::marshalling::option::big_endian;
853879
private:
@@ -920,7 +946,13 @@ namespace nil {
920946
void mark_batch_as_fixed(std::size_t index) {
921947
}
922948

923-
kzg_commitment_scheme_v2(params_type kzg_params) : _params(kzg_params) {}
949+
static params_type create_params(std::size_t d, typename KZGScheme::scalar_value_type alpha) {
950+
return params_type(d, 1, alpha);
951+
}
952+
953+
kzg_commitment_scheme_v2(params_type kzg_params) : _params(kzg_params) {
954+
BOOST_ASSERT( kzg_params.verification_key.size() == 2);
955+
}
924956

925957
// Differs from static, because we pack the result into byte blob.
926958
commitment_type commit(std::size_t index){

include/nil/crypto3/zk/commitments/polynomial/lpc.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ namespace nil {
6767
using eval_storage_type = typename LPCScheme::eval_storage_type;
6868
using preprocessed_data_type = std::map<std::size_t, std::vector<value_type>>;
6969

70+
constexpr static bool is_lpc = true;
71+
7072
private:
7173
std::map<std::size_t, precommitment_type> _trees;
7274
typename fri_type::params_type _fri_params;
@@ -331,6 +333,7 @@ namespace nil {
331333
constexpr static const std::size_t lambda = LPCParams::lambda;
332334
constexpr static const std::size_t m = LPCParams::m;
333335
constexpr static const bool is_const_size = LPCParams::is_const_size;
336+
constexpr static const bool is_batched_list_polynomial_commitment = true;
334337

335338
typedef LPCParams lpc_params;
336339

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
#ifndef CRYPTO3_ZK_PLONK_PLACEHOLDER_PROOF_HPP
2929
#define CRYPTO3_ZK_PLONK_PLACEHOLDER_PROOF_HPP
3030

31+
#include <cstddef>
32+
#include <map>
33+
3134
namespace nil {
3235
namespace crypto3 {
3336
namespace zk {
@@ -67,7 +70,7 @@ namespace nil {
6770
typename commitment_scheme_type::proof_type eval_proof;
6871

6972
bool operator==(const evaluation_proof &rhs) const {
70-
return challenge == rhs.challenge && eval_proof == rhs.eval_proof;
73+
return challenge == rhs.challenge && eval_proof == rhs.eval_proof;
7174
}
7275
bool operator!=(const evaluation_proof &rhs) const {
7376
return !(rhs == *this);

0 commit comments

Comments
 (0)