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

Removes window_num_bits < 8 in decompose_word #631

Open
wants to merge 6 commits into
base: refactor-decompose-gadget
Choose a base branch
from

Conversation

Janmajayamall
Copy link

No description provided.

@@ -186,8 +186,6 @@ pub fn decompose_word<F: PrimeFieldBits>(
word_num_bits: usize,
window_num_bits: usize,
) -> Vec<u8> {
Copy link
Collaborator

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

Suggested change
) -> Vec<u8> {
) -> Vec<[bool; K]> {

Copy link
Author

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?

Copy link
Collaborator

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>(

Copy link
Author

@Janmajayamall Janmajayamall Jul 13, 2022

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()
}

@therealyingtong therealyingtong force-pushed the refactor-decompose-gadget branch from 221fc45 to 5bf60e0 Compare October 24, 2022 22:18
@therealyingtong therealyingtong force-pushed the refactor-decompose-gadget branch 2 times, most recently from c9daeca to c334934 Compare January 22, 2023 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants