1
1
use crate :: {
2
2
fk20:: cosets:: { coset_gens, reverse_bit_order} ,
3
- opening_key :: OpeningKey ,
3
+ verification_key :: VerificationKey ,
4
4
} ;
5
5
use bls12_381:: {
6
6
batch_inversion:: batch_inverse, ff:: Field , g1_batch_normalize, lincomb:: g1_lincomb,
@@ -36,7 +36,7 @@ pub type CommitmentIndex = u64;
36
36
/// - We only use FK20 to create proofs
37
37
#[ derive( Debug ) ]
38
38
pub struct FK20Verifier {
39
- pub opening_key : OpeningKey ,
39
+ pub verification_key : VerificationKey ,
40
40
pub coset_gens_bit_reversed : Vec < Scalar > ,
41
41
coset_domain : Domain ,
42
42
// Pre-computations for the verification algorithm
@@ -52,22 +52,26 @@ pub struct FK20Verifier {
52
52
}
53
53
54
54
impl FK20Verifier {
55
- pub fn new ( opening_key : OpeningKey , num_points_to_open : usize , num_cosets : usize ) -> Self {
55
+ pub fn new (
56
+ verification_key : VerificationKey ,
57
+ num_points_to_open : usize ,
58
+ num_cosets : usize ,
59
+ ) -> Self {
56
60
const BIT_REVERSED : bool = true ;
57
61
let coset_gens = coset_gens ( num_points_to_open, num_cosets, BIT_REVERSED ) ;
58
62
59
63
let coset_size = num_points_to_open / num_cosets;
60
64
assert ! (
61
- opening_key . g2s. len( ) >= coset_size,
65
+ verification_key . g2s. len( ) >= coset_size,
62
66
"need as many g2 points as coset size"
63
67
) ;
64
- let coset_domain = polynomial:: domain:: Domain :: new ( opening_key . coset_size ) ;
68
+ let coset_domain = polynomial:: domain:: Domain :: new ( verification_key . coset_size ) ;
65
69
66
- let n = opening_key . coset_size ;
70
+ let n = verification_key . coset_size ;
67
71
// [s^n]_2
68
- let s_pow_n = G2Prepared :: from ( G2Point :: from ( opening_key . g2s [ n] ) ) ;
72
+ let s_pow_n = G2Prepared :: from ( G2Point :: from ( verification_key . g2s [ n] ) ) ;
69
73
// [-1]_2
70
- let neg_g2_gen = G2Prepared :: from ( -opening_key . g2_gen ( ) ) ;
74
+ let neg_g2_gen = G2Prepared :: from ( -verification_key . g2_gen ( ) ) ;
71
75
72
76
let coset_gens_pow_n = coset_gens
73
77
. iter ( )
@@ -84,7 +88,7 @@ impl FK20Verifier {
84
88
. collect ( ) ;
85
89
86
90
Self {
87
- opening_key ,
91
+ verification_key ,
88
92
coset_gens_bit_reversed : coset_gens,
89
93
coset_domain,
90
94
s_pow_n,
@@ -146,7 +150,7 @@ impl FK20Verifier {
146
150
// We compute one challenge `r` using fiat-shamir and the rest are powers of `r`
147
151
// This is safe because of the Schwartz-Zippel Lemma.
148
152
let r = compute_fiat_shamir_challenge (
149
- & self . opening_key ,
153
+ & self . verification_key ,
150
154
deduplicated_commitments,
151
155
commitment_indices,
152
156
bit_reversed_coset_indices,
@@ -215,8 +219,9 @@ impl FK20Verifier {
215
219
random_sum_interpolation_poly =
216
220
poly_add ( random_sum_interpolation_poly, scaled_interpolation_poly) ;
217
221
}
218
- let comm_random_sum_interpolation_poly =
219
- self . opening_key . commit_g1 ( & random_sum_interpolation_poly) ;
222
+ let comm_random_sum_interpolation_poly = self
223
+ . verification_key
224
+ . commit_g1 ( & random_sum_interpolation_poly) ;
220
225
221
226
let mut weighted_r_powers = Vec :: with_capacity ( batch_size) ;
222
227
for ( coset_index, r_power) in bit_reversed_coset_indices. iter ( ) . zip ( r_powers) {
@@ -255,7 +260,7 @@ impl FK20Verifier {
255
260
/// The matching function in the spec is: https://github.com/ethereum/consensus-specs/blob/13ac373a2c284dc66b48ddd2ef0a10537e4e0de6/specs/_features/eip7594/polynomial-commitments-sampling.md#compute_verify_cell_kzg_proof_batch_challenge
256
261
#[ allow( clippy:: manual_slice_size_calculation) ]
257
262
fn compute_fiat_shamir_challenge (
258
- opening_key : & OpeningKey ,
263
+ verification_key : & VerificationKey ,
259
264
row_commitments : & [ G1Point ] ,
260
265
row_indices : & [ u64 ] ,
261
266
coset_indices : & [ u64 ] ,
@@ -271,14 +276,14 @@ fn compute_fiat_shamir_challenge(
271
276
+ row_commitments. len ( ) * G1Point :: compressed_size ( )
272
277
+ row_indices. len ( ) * size_of :: < u64 > ( )
273
278
+ coset_indices. len ( ) * size_of :: < u64 > ( )
274
- + coset_evals. len ( ) * opening_key . coset_size * size_of :: < Scalar > ( )
279
+ + coset_evals. len ( ) * verification_key . coset_size * size_of :: < Scalar > ( )
275
280
+ proofs. len ( ) * G1Point :: compressed_size ( ) ;
276
281
277
282
let mut hash_input: Vec < u8 > = Vec :: with_capacity ( hash_input_size) ;
278
283
279
284
hash_input. extend ( DOMAIN_SEP . as_bytes ( ) ) ;
280
- hash_input. extend ( ( opening_key . num_coefficients_in_polynomial as u64 ) . to_be_bytes ( ) ) ;
281
- hash_input. extend ( ( opening_key . coset_size as u64 ) . to_be_bytes ( ) ) ;
285
+ hash_input. extend ( ( verification_key . num_coefficients_in_polynomial as u64 ) . to_be_bytes ( ) ) ;
286
+ hash_input. extend ( ( verification_key . coset_size as u64 ) . to_be_bytes ( ) ) ;
282
287
283
288
let num_commitments = row_commitments. len ( ) as u64 ;
284
289
hash_input. extend ( num_commitments. to_be_bytes ( ) ) ;
0 commit comments