kimchi/circuits/witness/
index_cell.rs1use super::{variables::Variables, WitnessCell};
2use ark_ff::Field;
3
4pub struct IndexCell<'a> {
7    name: &'a str,
8    length: usize,
9}
10
11impl<'a> IndexCell<'a> {
12    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}