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: adaptable foldable AES circuit #47

Merged
merged 5 commits into from
Nov 20, 2024

Conversation

Autoparallel
Copy link
Contributor

@Autoparallel Autoparallel commented Nov 14, 2024

Idea

Basically, we want to be able to provide a padded plaintext input to our NIVC chain. There may be 242 bytes of plaintext, but we will pad to 512.

With previous work (a-la #45), we were able to run the AES circuit 16 times and not actually the full 32 needed to consume the padded ciphertext because when we hash plaintext data, we are doing so by ignoring full 16 byte chunks that are zero (as these indicate padding). Real plaintext won't have that (unless I'm mistaken -- in which case we should pad with -1 or 256 since real plaintext absolutely, certainly, cannot have that).

Now, what we also want to be able to do is potentially do 2 or more AES encryption chunks per fold. However, there is potentially some oddity that would happen in a case where the plaintext was, say 239 bytes and we were folding 2 AES encryption chunks at a time. Namely, it would encrypt the bytes 240-256 as a chunk, even those these are actually all zeros and only appear due to padding and trying to encrypt more than we need.

This PR

This PR solves this problem. We will default to checking that the encryption of plaintext in circuit matches the ciphertext private input chunk by chunk UNLESS both the plaintext and ciphertext chunks input at that point were zero. In that case, it bypasses this check and continues forward.

Furthermore, we selectively only hash the nonzero chunks just like the new DataHasher circuit from #45.

Reviewing

PLEASE BE CAREFUL REVIEWING THIS! This is a potential optimization we can use, but this does need some time to be carefully reviewed before I feel comfortable shipping it.


Closes #46

ciphertext_input_was_zero_chunk[i] <== IsZero()(packedCiphertext[i]);
both_input_chunks_were_zero[i] <== plaintext_input_was_zero_chunk[i] * ciphertext_input_was_zero_chunk[i];
ciphertext_option[i] <== (1 - both_input_chunks_were_zero[i]) * packedComputedCiphertext[i];
ciphertext_equal_check[i] <== IsEqual()([packedCiphertext[i], ciphertext_option[i]]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice okay i see whats going on here. This is clever. Do we know how much perf it gives us? How many changes will this require downstream in the web-prover? Is it worth spending time on performance for aes when we know chacha20 is more performant over all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is about allowing for doing less folds with AES which should boost performance especially in WASM. Every fold adds time, every fold adds memory pressure, and every fold makes compression slower.

Yes, we will likely move to chacha20, but it is never a bad idea to have a backup!

Copy link
Contributor

@0xJepsen 0xJepsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this approach is fine if you want to move forward with it. I wonder if it's a sunk cost now that we know chacha20 is the more performant approach, but i am fine moving forward with this if it seems like the fastest way forward.

@Autoparallel
Copy link
Contributor Author

I think this approach is fine if you want to move forward with it. I wonder if it's a sunk cost now that we know chacha20 is the more performant approach, but i am fine moving forward with this if it seems like the fastest way forward.

I don't believe it is sunk cost -- the PR is mostly done. It just needs a bit more review. Spending <1h or so of total review isn't asking much to get something that gives us flexibility.

Likely won't be as high impact as ChaCha20, but it is not clear if we will have the TLS changes made in web-prover at the same rate. Time will tell.

@0xJepsen 0xJepsen merged commit ed6b61f into main Nov 20, 2024
3 checks passed
@lonerapier lonerapier deleted the feat/ignore-zero-chunks-aes-hash branch December 12, 2024 04:25
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.

feat: do selective hashing in generic chunked AES
2 participants