3
3
// Copyright (c) 2020-2021 Nikita Kaskov <[email protected] >
4
4
// Copyright (c) 2020-2021 Ilias Khairullin <[email protected] >
5
5
// Copyright (c) 2022 Ekaterina Chukavina <[email protected] >
6
+ // Copyright (c) 2024 Vasiliy Olekhov <[email protected] >
6
7
//
7
8
// MIT License
8
9
//
@@ -217,6 +218,9 @@ namespace nil {
217
218
typename PolynomialType = math::polynomial_dfs<typename CurveType::scalar_field_type::value_type>
218
219
>
219
220
struct batched_kzg {
221
+
222
+ constexpr static bool is_kzg = true ;
223
+
220
224
typedef CurveType curve_type;
221
225
typedef TranscriptHashType transcript_hash_type;
222
226
typedef typename curve_type::gt_type::value_type gt_value_type;
@@ -235,8 +239,10 @@ namespace nil {
235
239
236
240
using commitment_type = std::vector<std::uint8_t >; // Used in placeholder because it's easy to push it into transcript
237
241
242
+ using eval_storage_type = eval_storage<field_type>;
243
+
238
244
struct proof_type {
239
- eval_storage<field_type> z;
245
+ eval_storage_type z;
240
246
single_commitment_type kzg_proof;
241
247
};
242
248
@@ -605,8 +611,12 @@ namespace nil {
605
611
606
612
namespace commitments {
607
613
// 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> {
610
620
public:
611
621
using curve_type = typename KZGScheme::curve_type;
612
622
using field_type = typename KZGScheme::field_type;
@@ -616,7 +626,7 @@ namespace nil {
616
626
using commitment_type = typename KZGScheme::commitment_type;
617
627
using transcript_type = typename KZGScheme::transcript_type;
618
628
using transcript_hash_type = typename KZGScheme::transcript_hash_type;
619
- using poly_type = PolynomialType ;
629
+ using poly_type = typename KZGScheme::poly_type ;
620
630
using proof_type = typename KZGScheme::proof_type;
621
631
using endianness = nil::marshalling::option::big_endian;
622
632
private:
@@ -832,9 +842,15 @@ namespace nil {
832
842
* Dan Boneh, Justin Drake, Ben Fisch,
833
843
* <https://eprint.iacr.org/2020/081.pdf>
834
844
*/
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> {
837
851
public:
852
+ constexpr static bool is_kzg_commitment_scheme_v2 = true ;
853
+
838
854
using curve_type = typename KZGScheme::curve_type;
839
855
using field_type = typename KZGScheme::field_type;
840
856
using params_type = typename KZGScheme::params_type;
@@ -844,10 +860,20 @@ namespace nil {
844
860
using verification_key_type = typename curve_type::template g2_type<>::value_type;
845
861
using transcript_type = typename KZGScheme::transcript_type;
846
862
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
+
848
868
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
+ }
851
877
};
852
878
using endianness = nil::marshalling::option::big_endian;
853
879
private:
@@ -920,7 +946,13 @@ namespace nil {
920
946
void mark_batch_as_fixed (std::size_t index) {
921
947
}
922
948
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
+ }
924
956
925
957
// Differs from static, because we pack the result into byte blob.
926
958
commitment_type commit (std::size_t index){
0 commit comments