use super::{variables::Variables, WitnessCell};
use ark_ff::Field;
use o1_utils::FieldHelpers;
pub struct VariableBitsCell<'a> {
name: &'a str,
start: usize, end: Option<usize>, }
impl<'a> VariableBitsCell<'a> {
pub fn create(name: &'a str, start: usize, end: Option<usize>) -> Box<VariableBitsCell<'a>> {
Box::new(VariableBitsCell { name, start, end })
}
}
impl<'a, F: Field, const W: usize> WitnessCell<F, F, W> for VariableBitsCell<'a> {
fn value(&self, _witness: &mut [Vec<F>; W], variables: &Variables<F>, _index: usize) -> F {
let bits = if let Some(end) = self.end {
F::from_bits(&variables[self.name].to_bits()[self.start..end])
} else {
F::from_bits(&variables[self.name].to_bits()[self.start..])
};
bits.expect("failed to deserialize field bits for variable bits cell")
}
}