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