Skip to main content

zip_plus/
code.rs

1pub mod iprs;
2pub mod raa;
3pub mod raa_sign_flip;
4
5use crate::pcs::structs::ZipTypes;
6use crypto_primitives::FromPrimitiveWithConfig;
7use std::fmt::Debug;
8use zinc_utils::from_ref::FromRef;
9
10pub trait LinearCode<Zt: ZipTypes>: Debug + Clone + Eq + Sync + Send {
11    /// Repetition factor, a.k.a. inverse rate, the ratio of codeword length to
12    /// input row length. Has to be at a power of 2.
13    ///
14    /// Note: Ideally, this should be a generic constant, but due to the fact
15    /// that generic parameters may not be used in const operations, this
16    /// makes using it too much of a hassle.
17    const REPETITION_FACTOR: usize;
18
19    /// Length of each input row before encoding
20    fn row_len(&self) -> usize;
21
22    /// Length of each encoded codeword (output length after encoding)
23    fn codeword_len(&self) -> usize;
24
25    /// String representation of the parameters of this linear code, used for
26    /// benchmarks. Should start with "row_len=X".
27    fn params_string(&self) -> String;
28
29    /// Encodes a row of cryptographic integers using this linear encoding
30    /// scheme.
31    ///
32    /// This function is optimized for the prover's context where we work with
33    /// cryptographic integers. It's more efficient than `encode_f` as it
34    /// avoids field conversions.
35    ///
36    /// # Parameters
37    /// - `row`: Slice of cryptographic integers to encode
38    ///
39    /// # Returns
40    /// A vector of cryptographic integers representing the encoded row
41    fn encode(&self, row: &[Zt::Eval]) -> Vec<Zt::Cw>;
42
43    /// Encodes a row of cryptographic integers using this linear encoding
44    /// scheme.
45    ///
46    /// This function is optimized for the prover's context where we work with
47    /// cryptographic integers. It's more efficient than `encode_f` as it
48    /// avoids field conversions.
49    ///
50    /// # Parameters
51    /// - `row`: Slice of cryptographic integers to encode
52    ///
53    /// # Returns
54    /// A vector of cryptographic integers representing the encoded row
55    fn encode_wide(&self, row: &[Zt::CombR]) -> Vec<Zt::CombR>;
56
57    /// Encodes a row of field elements using this linear encoding scheme.
58    ///
59    /// This function is used when working with field elements directly and
60    /// performs the encoding by first converting the sparse matrices to
61    /// field elements.
62    ///
63    /// # Parameters
64    /// - `row`: Slice of field elements to encode
65    /// - `field`: Field configuration for the conversion
66    ///
67    /// # Returns
68    /// A vector of field elements representing the encoded row
69    fn encode_f<F>(&self, row: &[F]) -> Vec<F>
70    where
71        F: FromPrimitiveWithConfig + FromRef<F>;
72}