@ -18,11 +18,8 @@ pub struct Evaluations {
pub struct UniversalParams < E : PairingEngine > {
/// prover parameters
pub prover_param : ProverParam < E > ,
/// g^randomness: g^t1, g^t2, ...
#[ cfg(not(feature = " group-switched " )) ]
pub g_mask : Vec < E ::G1Affine > ,
#[ cfg(feature = " group-switched " ) ]
pub g_mask : Vec < E ::G2Affine > ,
/// h^randomness: h^t1, h^t2, ..., **h^{t_nv}**
pub h_mask : Vec < E ::G2Affine > ,
}
/// Prover Parameters
@ -32,26 +29,11 @@ pub struct ProverParam {
pub num_vars : usize ,
/// `pp_{num_vars}`, `pp_{num_vars - 1}`, `pp_{num_vars - 2}`, ..., defined
/// by XZZPD19
#[ cfg(not(feature = " group-switched " )) ]
pub powers_of_g : Vec < Evaluations < E ::G1Affine > > ,
#[ cfg(feature = " group-switched " ) ]
pub powers_of_g : Vec < Evaluations < E ::G2Affine > > ,
/// `pp_{num_vars}`, `pp_{num_vars - 1}`, `pp_{num_vars - 2}`, ..., defined
/// by XZZPD19
#[ cfg(not(feature = " group-switched " )) ]
pub powers_of_h : Vec < Evaluations < E ::G2Affine > > ,
#[ cfg(feature = " group-switched " ) ]
pub powers_of_h : Vec < Evaluations < E ::G1Affine > > ,
/// generator for G1
#[ cfg(not(feature = " group-switched " )) ]
pub g : E ::G1Affine ,
#[ cfg(feature = " group-switched " ) ]
pub g : E ::G2Affine ,
/// generator for G2
#[ cfg(not(feature = " group-switched " )) ]
pub h : E ::G2Affine ,
#[ cfg(feature = " group-switched " ) ]
pub h : E ::G1Affine ,
}
/// Verifier Parameters
@ -61,22 +43,13 @@ pub struct VerifierParam {
pub num_vars : usize ,
/// generator of G1
#[ cfg(not(feature = " group-switched " )) ]
pub g : E ::G1Affine ,
#[ cfg(feature = " group-switched " ) ]
pub g : E ::G2Affine ,
/// generator of G2
#[ cfg(not(feature = " group-switched " )) ]
pub h : E ::G2Affine ,
#[ cfg(feature = " group-switched " ) ]
pub h : E ::G1Affine ,
/// g^t1, g^t2, ...
#[ cfg(not(feature = " group-switched " )) ]
pub g_mask : Vec < E ::G1Affine > ,
#[ cfg(feature = " group-switched " ) ]
pub g_mask : Vec < E ::G2Affine > ,
/// h^randomness: h^t1, h^t2, ..., **h^{t_nv}**
pub h_mask : Vec < E ::G2Affine > ,
}
impl < E : PairingEngine > UniversalParams < E > {
@ -91,7 +64,7 @@ impl UniversalParams {
num_vars : self . prover_param . num_vars ,
g : self . prover_param . g ,
h : self . prover_param . h ,
g_mask : self . g _mask. clone ( ) ,
h_mask : self . h _mask. clone ( ) ,
}
}
@ -112,7 +85,6 @@ impl UniversalParams {
let to_reduce = self . prover_param . num_vars - supported_num_vars ;
let ck = ProverParam {
powers_of_h : self . prover_param . powers_of_h [ to_reduce . . ] . to_vec ( ) ,
powers_of_g : self . prover_param . powers_of_g [ to_reduce . . ] . to_vec ( ) ,
g : self . prover_param . g ,
h : self . prover_param . h ,
@ -122,7 +94,7 @@ impl UniversalParams {
num_vars : supported_num_vars ,
g : self . prover_param . g ,
h : self . prover_param . h ,
g_mask : self . g _mask[ to_reduce . . ] . to_vec ( ) ,
h_mask : self . h _mask[ to_reduce . . ] . to_vec ( ) ,
} ;
Ok ( ( ck , vk ) )
}
@ -144,18 +116,11 @@ impl UniversalParams {
let pp_generation_timer = start_timer ! ( | | "Prover Param generation" ) ;
#[ cfg(not(feature = " group-switched " )) ]
let g = E ::G1Projective ::rand ( rng ) ;
#[ cfg(feature = " group-switched " ) ]
let g = E ::G2Projective ::rand ( rng ) ;
#[ cfg(not(feature = " group-switched " )) ]
let h = E ::G2Projective ::rand ( rng ) ;
#[ cfg(feature = " group-switched " ) ]
let h = E ::G1Projective ::rand ( rng ) ;
let mut powers_of_g = Vec ::new ( ) ;
let mut powers_of_h = Vec ::new ( ) ;
let t : Vec < _ > = ( 0 . . num_vars ) . map ( | _ | E ::Fr ::rand ( rng ) ) . collect ( ) ;
let scalar_bits = E ::Fr ::size_in_bits ( ) ;
@ -186,35 +151,18 @@ impl UniversalParams {
}
let window_size = FixedBaseMSM ::get_mul_window_size ( total_scalars ) ;
let g_table = FixedBaseMSM ::get_window_table ( scalar_bits , window_size , g ) ;
let h_table = FixedBaseMSM ::get_window_table ( scalar_bits , window_size , h ) ;
#[ cfg(not(feature = " group-switched " )) ]
let pp_g = E ::G1Projective ::batch_normalization_into_affine (
& FixedBaseMSM ::multi_scalar_mul ( scalar_bits , window_size , & g_table , & pp_powers ) ,
) ;
#[ cfg(feature = " group-switched " ) ]
let pp_g = E ::G2Projective ::batch_normalization_into_affine (
& FixedBaseMSM ::multi_scalar_mul ( scalar_bits , window_size , & g_table , & pp_powers ) ,
) ;
#[ cfg(not(feature = " group-switched " )) ]
let pp_h = E ::G2Projective ::batch_normalization_into_affine (
& FixedBaseMSM ::multi_scalar_mul ( scalar_bits , window_size , & h_table , & pp_powers ) ,
) ;
#[ cfg(feature = " group-switched " ) ]
let pp_h = E ::G1Projective ::batch_normalization_into_affine (
& FixedBaseMSM ::multi_scalar_mul ( scalar_bits , window_size , & h_table , & pp_powers ) ,
) ;
let mut start = 0 ;
for i in 0 . . num_vars {
let size = 1 < < ( num_vars - i ) ;
let pp_k_g = Evaluations {
evals : pp_g [ start . . ( start + size ) ] . to_vec ( ) ,
} ;
let pp_k_h = Evaluations {
evals : pp_h [ start . . ( start + size ) ] . to_vec ( ) ,
} ;
powers_of_g . push ( pp_k_g ) ;
powers_of_h . push ( pp_k_h ) ;
start + = size ;
}
@ -223,32 +171,26 @@ impl UniversalParams {
g : g . into_affine ( ) ,
h : h . into_affine ( ) ,
powers_of_g ,
powers_of_h ,
} ;
end_timer ! ( pp_generation_timer ) ;
let vp_generation_timer = start_timer ! ( | | "VP generation" ) ;
let g _mask = {
let h _mask = {
let window_size = FixedBaseMSM ::get_mul_window_size ( num_vars ) ;
let g_table = FixedBaseMSM ::get_window_table ( scalar_bits , window_size , g ) ;
#[ cfg(not(feature = " group-switched " )) ]
let res = E ::G1Projective ::batch_normalization_into_affine (
& FixedBaseMSM ::multi_scalar_mul ( scalar_bits , window_size , & g_table , & t ) ,
) ;
#[ cfg(feature = " group-switched " ) ]
let res = E ::G2Projective ::batch_normalization_into_affine (
& FixedBaseMSM ::multi_scalar_mul ( scalar_bits , window_size , & g_table , & t ) ,
) ;
res
let h_table = FixedBaseMSM ::get_window_table ( scalar_bits , window_size , h ) ;
E ::G2Projective ::batch_normalization_into_affine ( & FixedBaseMSM ::multi_scalar_mul (
scalar_bits ,
window_size ,
& h_table ,
& t ,
) )
} ;
end_timer ! ( vp_generation_timer ) ;
end_timer ! ( total_timer ) ;
Ok ( Self {
prover_param : pp ,
g _mask,
h _mask,
} )
}
}