kimchi/circuits/witness/
index_cell.rs

1use super::{variables::Variables, WitnessCell};
2use ark_ff::Field;
3
4/// Witness cell assigned from an indexable variable
5/// See [Variables] for more details
6pub struct IndexCell<'a> {
7    name: &'a str,
8    length: usize,
9}
10
11impl<'a> IndexCell<'a> {
12    /// Create witness cell assigned from a variable name a length
13    pub fn create(name: &'a str, from: usize, to: usize) -> Box<IndexCell<'a>> {
14        Box::new(IndexCell {
15            name,
16            length: to - from,
17        })
18    }
19}
20
21impl<'a, F: Field, const W: usize> WitnessCell<F, Vec<F>, W> for IndexCell<'a> {
22    fn value(&self, _witness: &mut [Vec<F>; W], variables: &Variables<Vec<F>>, index: usize) -> F {
23        assert!(index < self.length, "index out of bounds of `IndexCell`");
24        variables[self.name][index]
25    }
26    fn length(&self) -> usize {
27        self.length
28    }
29}