-
Notifications
You must be signed in to change notification settings - Fork 523
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
Removes window_num_bits
< 8 in decompose_word
#631
base: refactor-decompose-gadget
Are you sure you want to change the base?
Removes window_num_bits
< 8 in decompose_word
#631
Conversation
@@ -186,8 +186,6 @@ pub fn decompose_word<F: PrimeFieldBits>( | |||
word_num_bits: usize, | |||
window_num_bits: usize, | |||
) -> Vec<u8> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're returning Vec<u8>
, I think we would have to at least check that window_num_bits <= (1 << 8)
. However, in future I would like this function to return
) -> Vec<u8> { | |
) -> Vec<[bool; K]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure how to do this since array lengths don't support generics.
Shall we add the following assert statement for now
assert(window_num_bits <= (1 << 8))
Or should we try making it generic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add a const generic to
decompose_word<F: PrimeFieldBits, const K: usize>(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So something like the following? -
pub fn decompose_word<F: PrimeFieldBits, const K: usize>(
word: &F,
word_num_bits: usize,
) -> Vec<[bool; K]> {
// Pad bits to multiple of window_num_bits
let padding = (K - (word_num_bits % K)) % K;
let bits: Vec<bool> = word
.to_le_bits()
.into_iter()
.take(word_num_bits)
.chain(std::iter::repeat(false).take(padding))
.collect();
assert_eq!(bits.len(), word_num_bits + padding);
bits.chunks_exact(K)
.map(|x| {
let chunks = [false; K];
chunks.copy_from_slice(x);
chunks
})
.collect()
}
221fc45
to
5bf60e0
Compare
c9daeca
to
c334934
Compare
No description provided.