kimchi/circuits/witness/
variable_bits_cell.rs1use super::{variables::Variables, WitnessCell};
2use alloc::{boxed::Box, vec::Vec};
3use ark_ff::Field;
4use o1_utils::FieldHelpers;
5
6pub struct VariableBitsCell<'a> {
9 name: &'a str,
10 start: usize, end: Option<usize>, }
13
14impl<'a> VariableBitsCell<'a> {
15 pub fn create(name: &'a str, start: usize, end: Option<usize>) -> Box<VariableBitsCell<'a>> {
18 Box::new(VariableBitsCell { name, start, end })
19 }
20}
21
22impl<'a, F: Field, const W: usize> WitnessCell<F, F, W> for VariableBitsCell<'a> {
23 fn value(&self, _witness: &mut [Vec<F>; W], variables: &Variables<F>, _index: usize) -> F {
24 let bits = if let Some(end) = self.end {
25 F::from_bits(&variables[self.name].to_bits()[self.start..end])
26 } else {
27 F::from_bits(&variables[self.name].to_bits()[self.start..])
28 };
29 bits.expect("failed to deserialize field bits for variable bits cell")
30 }
31}