ark_poly_commit/linear_codes/univariate_ligero/
mod.rs1use crate::{
2 linear_codes::{utils::reed_solomon, LigeroPCParams, LinearEncode},
3 Error,
4};
5use ark_crypto_primitives::{
6 crh::{CRHScheme, TwoToOneCRHScheme},
7 merkle_tree::Config,
8};
9use ark_ff::PrimeField;
10use ark_poly::DenseUVPolynomial;
11use ark_std::marker::PhantomData;
12#[cfg(not(feature = "std"))]
13use ark_std::vec::Vec;
14
15mod tests;
16
17pub struct UnivariateLigero<F: PrimeField, C: Config, P: DenseUVPolynomial<F>, H: CRHScheme> {
24 _phantom: PhantomData<(F, C, P, H)>,
25}
26
27impl<F, C, P, H> LinearEncode<F, C, P, H> for UnivariateLigero<F, C, P, H>
28where
29 F: PrimeField,
30 C: Config,
31 P: DenseUVPolynomial<F>,
32 P::Point: Into<F>,
33 H: CRHScheme,
34{
35 type LinCodePCParams = LigeroPCParams<F, C, H>;
36
37 fn setup<R>(
38 _max_degree: usize,
39 _num_vars: Option<usize>,
40 _rng: &mut R,
41 leaf_hash_param: <<C as Config>::LeafHash as CRHScheme>::Parameters,
42 two_to_one_hash_param: <<C as Config>::TwoToOneHash as TwoToOneCRHScheme>::Parameters,
43 col_hash_params: H::Parameters,
44 ) -> Self::LinCodePCParams {
45 Self::LinCodePCParams::new(
46 128,
47 4,
48 true,
49 leaf_hash_param,
50 two_to_one_hash_param,
51 col_hash_params,
52 )
53 }
54
55 fn encode(msg: &[F], param: &Self::LinCodePCParams) -> Result<Vec<F>, Error> {
56 Ok(reed_solomon(msg, param.rho_inv))
57 }
58
59 fn poly_to_vec(polynomial: &P) -> Vec<F> {
61 polynomial.coeffs().to_vec()
62 }
63
64 fn point_to_vec(point: P::Point) -> Vec<F> {
65 vec![point]
66 }
67
68 fn tensor(z: &F, left: usize, right: usize) -> (Vec<F>, Vec<F>) {
71 let mut left_out = Vec::with_capacity(left);
72 let mut pow_a = F::one();
73 for _ in 0..left {
74 left_out.push(pow_a);
75 pow_a *= z;
76 }
77
78 let mut right_out = Vec::with_capacity(right);
79 let mut pow_b = F::one();
80 for _ in 0..right {
81 right_out.push(pow_b);
82 pow_b *= pow_a;
83 }
84
85 (left_out, right_out)
86 }
87}