Skip to content

Commit

Permalink
Merge branch 'witness/index-cell' into zkvm/keccak/indexcell
Browse files Browse the repository at this point in the history
  • Loading branch information
querolita committed Oct 23, 2023
2 parents f65c1cf + 1491b17 commit be7e77d
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions kimchi/src/circuits/witness/constant_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ impl<F: Field> ConstantCell<F> {
}
}

impl<const N: usize, F: Field> WitnessCell<N, F, F> for ConstantCell<F> {
fn value(&self, _witness: &mut [Vec<F>; N], _variables: &Variables<F>, _index: usize) -> F {
impl<const W: usize, F: Field> WitnessCell<W, F, F> for ConstantCell<F> {
fn value(&self, _witness: &mut [Vec<F>; W], _variables: &Variables<F>, _index: usize) -> F {
self.value
}
}
4 changes: 2 additions & 2 deletions kimchi/src/circuits/witness/copy_bits_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ impl CopyBitsCell {
}
}

impl<const N: usize, F: Field> WitnessCell<N, F, F> for CopyBitsCell {
fn value(&self, witness: &mut [Vec<F>; N], _variables: &Variables<F>, _index: usize) -> F {
impl<const W: usize, F: Field> WitnessCell<W, F, F> for CopyBitsCell {
fn value(&self, witness: &mut [Vec<F>; W], _variables: &Variables<F>, _index: usize) -> F {
F::from_bits(&witness[self.col][self.row].to_bits()[self.start..self.end])
.expect("failed to deserialize field bits for copy bits cell")
}
Expand Down
4 changes: 2 additions & 2 deletions kimchi/src/circuits/witness/copy_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ impl CopyCell {
}
}

impl<const N: usize, F: Field> WitnessCell<N, F, F> for CopyCell {
fn value(&self, witness: &mut [Vec<F>; N], _variables: &Variables<F>, _index: usize) -> F {
impl<const W: usize, F: Field> WitnessCell<W, F, F> for CopyCell {
fn value(&self, witness: &mut [Vec<F>; W], _variables: &Variables<F>, _index: usize) -> F {
witness[self.col][self.row]
}
}
4 changes: 2 additions & 2 deletions kimchi/src/circuits/witness/copy_shift_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ impl CopyShiftCell {
}
}

impl<const N: usize, F: Field> WitnessCell<N, F, F> for CopyShiftCell {
fn value(&self, witness: &mut [Vec<F>; N], _variables: &Variables<F>, _index: usize) -> F {
impl<const W: usize, F: Field> WitnessCell<W, F, F> for CopyShiftCell {
fn value(&self, witness: &mut [Vec<F>; W], _variables: &Variables<F>, _index: usize) -> F {
F::from(2u32).pow([self.shift]) * witness[self.col][self.row]
}
}
4 changes: 2 additions & 2 deletions kimchi/src/circuits/witness/index_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ impl<'a> IndexCell<'a> {
}
}

impl<'a, const N: usize, F: Field> WitnessCell<N, F, Vec<F>> for IndexCell<'a> {
fn value(&self, _witness: &mut [Vec<F>; N], variables: &Variables<Vec<F>>, index: usize) -> F {
impl<'a, const W: usize, F: Field> WitnessCell<W, F, Vec<F>> for IndexCell<'a> {
fn value(&self, _witness: &mut [Vec<F>; W], variables: &Variables<Vec<F>>, index: usize) -> F {
assert!(index < self.length, "index out of bounds of `IndexCell`");
variables[self.name][index]
}
Expand Down
22 changes: 11 additions & 11 deletions kimchi/src/circuits/witness/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ pub use self::{
};

/// Witness cell interface
pub trait WitnessCell<const N: usize, F: Field, T> {
fn value(&self, witness: &mut [Vec<F>; N], variables: &Variables<T>, index: usize) -> F;
pub trait WitnessCell<const W: usize, F: Field, T> {
fn value(&self, witness: &mut [Vec<F>; W], variables: &Variables<T>, index: usize) -> F;

fn length(&self) -> usize {
1
Expand All @@ -40,25 +40,25 @@ pub trait WitnessCell<const N: usize, F: Field, T> {
/// - layout: the partial layout to initialize from
/// - variables: the hashmap of variables to get the values from
#[allow(clippy::too_many_arguments)]
pub fn init_cell<const N: usize, F: PrimeField, T>(
witness: &mut [Vec<F>; N],
pub fn init_cell<const W: usize, F: PrimeField, T>(
witness: &mut [Vec<F>; W],
offset: usize,
row: usize,
col: usize,
cell: usize,
index: usize,
layout: &[Vec<Box<dyn WitnessCell<N, F, T>>>],
layout: &[Vec<Box<dyn WitnessCell<W, F, T>>>],
variables: &Variables<T>,
) {
witness[col][row + offset] = layout[row][cell].value(witness, variables, index);
}

/// Initialize a witness row based on layout and computed variables
pub fn init_row<const N: usize, F: PrimeField, T>(
witness: &mut [Vec<F>; N],
pub fn init_row<const W: usize, F: PrimeField, T>(
witness: &mut [Vec<F>; W],
offset: usize,
row: usize,
layout: &[Vec<Box<dyn WitnessCell<N, F, T>>>],
layout: &[Vec<Box<dyn WitnessCell<W, F, T>>>],
variables: &Variables<T>,
) {
let mut col = 0;
Expand All @@ -72,10 +72,10 @@ pub fn init_row<const N: usize, F: PrimeField, T>(
}

/// Initialize a witness based on layout and computed variables
pub fn init<const N: usize, F: PrimeField, T>(
witness: &mut [Vec<F>; N],
pub fn init<const W: usize, F: PrimeField, T>(
witness: &mut [Vec<F>; W],
offset: usize,
layout: &[Vec<Box<dyn WitnessCell<N, F, T>>>],
layout: &[Vec<Box<dyn WitnessCell<W, F, T>>>],
variables: &Variables<T>,
) {
for row in 0..layout.len() {
Expand Down
4 changes: 2 additions & 2 deletions kimchi/src/circuits/witness/variable_bits_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ impl<'a> VariableBitsCell<'a> {
}
}

impl<'a, const N: usize, F: Field> WitnessCell<N, F, F> for VariableBitsCell<'a> {
fn value(&self, _witness: &mut [Vec<F>; N], variables: &Variables<F>, _index: usize) -> F {
impl<'a, const W: usize, F: Field> WitnessCell<W, F, F> 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 {
Expand Down
4 changes: 2 additions & 2 deletions kimchi/src/circuits/witness/variable_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ impl<'a> VariableCell<'a> {
}
}

impl<'a, const N: usize, F: Field> WitnessCell<N, F, F> for VariableCell<'a> {
fn value(&self, _witness: &mut [Vec<F>; N], variables: &Variables<F>, _index: usize) -> F {
impl<'a, const W: usize, F: Field> WitnessCell<W, F, F> for VariableCell<'a> {
fn value(&self, _witness: &mut [Vec<F>; W], variables: &Variables<F>, _index: usize) -> F {
variables[self.name]
}
}

0 comments on commit be7e77d

Please sign in to comment.