Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bn): check_fits_in_bits -> decompose_in_bits #82

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/gadgets/nonnative/bn/big_uint_mul_mod_chip/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,8 @@ impl<F: ff::PrimeField> BigUintMulModChip<F> {
let target_base: F = big_uint::nat_to_f(&target_base_bn).expect("TODO");

let mut accumulated_extra = BigUintRaw::zero();
let carry_bits = calc_carry_bits(&max_word_bn, self.limb_width)?;
debug!("carry_bits {carry_bits}");
let carry_bits_len = calc_carry_bits(&max_word_bn, self.limb_width)?;
debug!("carry_bits {carry_bits_len}");

let lhs_column = &self.config().state[0];
let lhs_selector = &self.config().q_1[0];
Expand Down Expand Up @@ -700,7 +700,9 @@ impl<F: ff::PrimeField> BigUintMulModChip<F> {
if limb_index != max_cells_len - 1 {
prev_carry_cell = Some({
ctx.next();
self.check_fits_in_bits(ctx, carry_cell, carry_bits)?
self.decompose_in_bits(ctx, carry_cell.clone(), carry_bits_len)?;

carry_cell
});
} else {
prev_carry_cell = Some(carry_cell);
Expand Down Expand Up @@ -822,12 +824,12 @@ impl<F: ff::PrimeField> BigUintMulModChip<F> {
/// ```
///
/// At the end, a constraint is made that the incoming cell is equal to the new counted cell.
fn check_fits_in_bits(
pub fn decompose_in_bits(
&self,
ctx: &mut RegionCtx<'_, F>,
cell: AssignedCell<F, F>,
expected_bits_count: NonZeroUsize,
) -> Result<AssignedCell<F, F>, Error> {
) -> Result<Vec<AssignedCell<F, F>>, Error> {
let value_repr = cell
.value()
.map(|v| v.to_repr())
Expand Down Expand Up @@ -906,7 +908,7 @@ impl<F: ff::PrimeField> BigUintMulModChip<F> {

ctx.constrain_equal(final_sum_cell.cell(), cell.cell())?;

Ok(final_sum_cell)
Ok(bits_cells)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/gadgets/nonnative/bn/big_uint_mul_mod_chip/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ mod components_tests {
)
.unwrap();

chip.check_fits_in_bits(
chip.decompose_in_bits(
&mut region,
number,
NonZeroUsize::new(mem::size_of::<u32>() * 8).unwrap(),
Expand Down
Loading