Skip to main content

kimchi/circuits/witness/
copy_bits_cell.rs

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