Skip to content

Commit

Permalink
Interpreter: add bitmask to extract bits from foreign field limbs
Browse files Browse the repository at this point in the history
  • Loading branch information
dannywillems committed Feb 28, 2024
1 parent f9d19e3 commit 4c87d1b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions msm/src/serialization/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ pub trait InterpreterEnv {
// TODO
}

/// Extract the bits from the variable `x` between `highest_bit` and `lowest_bit`, and store
/// the result in `position`.
/// `lowest_bit` becomes the least-significant bit of the resulting value.
fn bitmask(
&mut self,
x: &Self::Variable,
highest_bit: u128,
lowest_bit: u128,
position: Self::Position,
) -> Self::Variable;

/// Deserialize the next field element given as input
fn deserialize_field_element(&mut self);

Expand Down
15 changes: 15 additions & 0 deletions msm/src/serialization/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ impl<const N: usize, Fp: Field> InterpreterEnv for Env<N, Fp> {
fn deserialize_field_element(&mut self) {
// TODO
}

/// Returns the bits between [highest_bit, lowest_bit] of the variable `x`,
/// and copy the result in the column `position`.
fn bitmask(
&mut self,
x: &Self::Variable,
highest_bit: u128,
lowest_bit: u128,
position: Self::Position,
) -> Self::Variable {
let x: u128 = *x;
let res = (x >> lowest_bit) & ((1 << (highest_bit - lowest_bit)) - 1);
self.write_column(position, res);
res
}
}

impl<const N: usize, Fp: Field> Env<N, Fp> {
Expand Down

0 comments on commit 4c87d1b

Please sign in to comment.