Skip to content

Commit

Permalink
Merge branch 'v0.7' into feat/hi_lo
Browse files Browse the repository at this point in the history
  • Loading branch information
z2trillion authored Oct 31, 2023
2 parents eb9e910 + 6232ff4 commit 24830b3
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/gadgets/canonical_representation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,42 @@ impl CanonicalRepresentationConfig {
offset += 1
}
}

let expected_offset = Self::n_rows_required(values);
debug_assert!(
offset == expected_offset,
"assign used {offset} rows but {expected_offset} rows expected from `n_rows_required`",
);

let n_padding_values = n_rows / 32 - values.len();
for _ in 0..n_padding_values {
for (index, modulus_byte) in modulus_bytes.iter().enumerate() {
self.modulus_byte
.assign(region, offset, u64::from(*modulus_byte));

self.index
.assign(region, offset, u64::try_from(index).unwrap());
if index.is_zero() {
self.index_is_zero.enable(region, offset);
} else if index == 31 {
self.index_is_31.enable(region, offset);
}

let difference = Fr::from(u64::from(*modulus_byte));
self.difference.assign(region, offset, difference);
self.difference_is_zero.assign(region, offset, difference);

self.differences_are_zero_so_far
.assign(region, offset, index == 0);

offset += 1
}
}
}

pub fn n_rows_required(values: &[Fr]) -> usize {
// +1 because assigment starts on offset = 1 instead of offset = 0.
values.len() * 32 + 1
}

pub fn n_rows_required(values: &[Fr]) -> usize {
Expand Down

0 comments on commit 24830b3

Please sign in to comment.