|
| 1 | +use crate::{utils::Matrix, PCCommitment, PCCommitmentState}; |
| 2 | +use ark_crypto_primitives::{ |
| 3 | + crh::CRHScheme, |
| 4 | + merkle_tree::{Config, LeafParam, Path, TwoToOneParam}, |
| 5 | +}; |
| 6 | +use ark_ff::PrimeField; |
| 7 | +use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; |
| 8 | +#[cfg(not(feature = "std"))] |
| 9 | +use ark_std::vec::Vec; |
| 10 | +use ark_std::{marker::PhantomData, rand::RngCore}; |
| 11 | + |
| 12 | +#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)] |
| 13 | +#[derivative(Clone(bound = ""), Debug(bound = ""))] |
| 14 | +/// The public parameters for Ligero PCS. |
| 15 | +pub struct LigeroPCParams<F: PrimeField, C: Config, H: CRHScheme> { |
| 16 | + pub(crate) _field: PhantomData<F>, |
| 17 | + /// The security parameter |
| 18 | + pub(crate) sec_param: usize, |
| 19 | + /// The inverse of the code rate. |
| 20 | + pub(crate) rho_inv: usize, |
| 21 | + /// This is a flag which determines if the random linear combination is done. |
| 22 | + pub(crate) check_well_formedness: bool, |
| 23 | + /// Parameters for hash function of Merkle tree leaves |
| 24 | + #[derivative(Debug = "ignore")] |
| 25 | + pub(crate) leaf_hash_param: LeafParam<C>, |
| 26 | + /// Parameters for hash function of Merke tree combining two nodes into one |
| 27 | + #[derivative(Debug = "ignore")] |
| 28 | + pub(crate) two_to_one_hash_param: TwoToOneParam<C>, |
| 29 | + // Parameters for obtaining leaf digest from leaf value. |
| 30 | + #[derivative(Debug = "ignore")] |
| 31 | + pub(crate) col_hash_params: H::Parameters, |
| 32 | +} |
| 33 | + |
| 34 | +#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)] |
| 35 | +#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))] |
| 36 | +pub(crate) struct Metadata { |
| 37 | + pub(crate) n_rows: usize, |
| 38 | + pub(crate) n_cols: usize, |
| 39 | + pub(crate) n_ext_cols: usize, |
| 40 | +} |
| 41 | + |
| 42 | +/// The commitment to a polynomial is a root of the merkle tree, |
| 43 | +/// where each node is a hash of the column of the encoded coefficient matrix U. |
| 44 | +#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)] |
| 45 | +#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))] |
| 46 | +pub struct LinCodePCCommitment<C: Config> { |
| 47 | + // number of rows resp. columns of the square matrix containing the coefficients of the polynomial |
| 48 | + pub(crate) metadata: Metadata, |
| 49 | + pub(crate) root: C::InnerDigest, |
| 50 | +} |
| 51 | + |
| 52 | +impl<C: Config> PCCommitment for LinCodePCCommitment<C> { |
| 53 | + fn empty() -> Self { |
| 54 | + LinCodePCCommitment::default() |
| 55 | + } |
| 56 | + |
| 57 | + fn has_degree_bound(&self) -> bool { |
| 58 | + false |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)] |
| 63 | +#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))] |
| 64 | +pub struct LinCodePCCommitmentState<F, H> |
| 65 | +where |
| 66 | + F: PrimeField, |
| 67 | + H: CRHScheme, |
| 68 | +{ |
| 69 | + pub(crate) mat: Matrix<F>, |
| 70 | + pub(crate) ext_mat: Matrix<F>, |
| 71 | + pub(crate) leaves: Vec<H::Output>, |
| 72 | +} |
| 73 | + |
| 74 | +impl<F, H> PCCommitmentState for LinCodePCCommitmentState<F, H> |
| 75 | +where |
| 76 | + F: PrimeField, |
| 77 | + H: CRHScheme, |
| 78 | +{ |
| 79 | + type Randomness = (); |
| 80 | + fn empty() -> Self { |
| 81 | + unimplemented!() |
| 82 | + } |
| 83 | + |
| 84 | + fn rand<R: RngCore>( |
| 85 | + _num_queries: usize, |
| 86 | + _has_degree_bound: bool, |
| 87 | + _num_vars: Option<usize>, |
| 88 | + _rng: &mut R, |
| 89 | + ) -> Self::Randomness { |
| 90 | + unimplemented!() |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +/// Proof of an individual linear code well-formedness check or opening |
| 95 | +#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)] |
| 96 | +#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))] |
| 97 | +pub(crate) struct LinCodePCProofSingle<F, C> |
| 98 | +where |
| 99 | + F: PrimeField, |
| 100 | + C: Config, |
| 101 | +{ |
| 102 | + /// For each of the indices in q, `paths` contains the path from the root of the merkle tree to the leaf |
| 103 | + pub(crate) paths: Vec<Path<C>>, |
| 104 | + |
| 105 | + /// v, s.t. E(v) = w |
| 106 | + pub(crate) v: Vec<F>, |
| 107 | + |
| 108 | + pub(crate) columns: Vec<Vec<F>>, |
| 109 | +} |
| 110 | + |
| 111 | +/// The Proof type for linear code PCS, which amounts to an array of individual proofs |
| 112 | +#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)] |
| 113 | +#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))] |
| 114 | +pub struct LinCodePCProof<F, C> |
| 115 | +where |
| 116 | + F: PrimeField, |
| 117 | + C: Config, |
| 118 | +{ |
| 119 | + pub(crate) opening: LinCodePCProofSingle<F, C>, |
| 120 | + pub(crate) well_formedness: Option<Vec<F>>, |
| 121 | +} |
| 122 | + |
| 123 | +// Multiple poly at one point |
| 124 | +pub(crate) type LPCPArray<F, C> = Vec<LinCodePCProof<F, C>>; |
0 commit comments