kimchi/circuits/witness/
copy_bits_cell.rs

1use ark_ff::Field;
2use o1_utils::FieldHelpers;
3
4use super::{variables::Variables, WitnessCell};
5
6/// Witness cell copied from bits of another witness cell
7pub struct CopyBitsCell {
8    row: usize,
9    col: usize,
10    start: usize, // inclusive
11    end: usize,   // exclusive
12}
13
14impl CopyBitsCell {
15    /// Create witness cell copied from bits [start, end) of the witness cell at position (row, col)
16    pub fn create(row: usize, col: usize, start: usize, end: usize) -> Box<CopyBitsCell> {
17        Box::new(CopyBitsCell {
18            row,
19            col,
20            start,
21            end,
22        })
23    }
24}
25
26impl<F: Field, const W: usize> WitnessCell<F, F, W> for CopyBitsCell {
27    fn value(&self, witness: &mut [Vec<F>; W], _variables: &Variables<F>, _index: usize) -> F {
28        F::from_bits(&witness[self.col][self.row].to_bits()[self.start..self.end])
29            .expect("failed to deserialize field bits for copy bits cell")
30    }
31}