Skip to content

Commit

Permalink
feat: optimize for loops in duplex challenger
Browse files Browse the repository at this point in the history
  • Loading branch information
yi-sun committed Jan 10, 2025
1 parent 2d5a26e commit 7d8670b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions extensions/native/recursion/src/challenger/duplex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,12 @@ impl<C: Config> DuplexChallengerVariable<C> {
pub fn check_witness(&mut self, builder: &mut Builder<C>, nb_bits: usize, witness: Felt<C::F>) {
self.observe(builder, witness);
let element_bits = self.sample_bits(builder, RVar::from(nb_bits));
builder.range(0, nb_bits).for_each(|i, builder| {
let element = builder.get(&element_bits, i);
builder.assert_var_eq(element, C::N::ZERO);
});
let element_bits_truncated = element_bits.slice(builder, 0, nb_bits);
builder
.iter(&element_bits_truncated)
.for_each(|element, builder| {
builder.assert_var_eq(element, C::N::ZERO);
});
}
}

Expand All @@ -158,8 +160,7 @@ impl<C: Config> CanObserveVariable<C, Felt<C::F>> for DuplexChallengerVariable<C
}

fn observe_slice(&mut self, builder: &mut Builder<C>, values: Array<C, Felt<C::F>>) {
builder.range(0, values.len()).for_each(|i, builder| {
let element = builder.get(&values, i);
builder.iter(&values).for_each(|element, builder| {
self.observe(builder, element);
});
}
Expand Down

0 comments on commit 7d8670b

Please sign in to comment.