Skip to main content

kimchi/circuits/witness/
index_cell.rs

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