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