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: foldable chacha20 #51

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

0xJepsen
Copy link
Contributor

Reverts #50

This one is reopen so now you can review

@0xJepsen 0xJepsen requested review from lonerapier and Autoparallel and removed request for lonerapier November 19, 2024 16:05
@Autoparallel
Copy link
Contributor

lol the name here

@Autoparallel Autoparallel changed the title Revert "Revert "Chacha20"" feat: foldable chacha20 Nov 19, 2024
Copy link
Contributor

@Autoparallel Autoparallel left a comment

Choose a reason for hiding this comment

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

Some changes requested here. Mostly to not remove AES.

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't remove this please! No harm in keeping it in here for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't remove this either.

Copy link
Contributor

Choose a reason for hiding this comment

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

Comment for the future:

I think we may be able to byte pack all of this. Expanding 32 field elements for 32 bits is likely not necessary. We can fit that amount of data into 2 field elements!

I'm not sure if this would help given we have to do bitwise XOR, but I do think there are probably tricks to do bitwise XOR on bytes or, say, 128bit numbers. Maybe not. Food for thought!

This circuit already seems wildly more efficient, so I'm not really worried about it.

Copy link
Contributor

Choose a reason for hiding this comment

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

This also goes for all the chacha circuits we use.

var tmp[4][32] = in;

// a += b
component add1 = AddBits(32);
Copy link
Contributor

Choose a reason for hiding this comment

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

Like surely we can do this 32 bit add more efficiently, right?

// counter => 32-bit word to apply w nonce
signal input counter[32];

// the below can be both ciphertext or plaintext depending on the direction
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't quite get this. Is this to say that the encryption algorithm is exactly the same as decryption?



describe("chacha20-nivc", () => {
describe("2 block test", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
describe("2 block test", () => {
describe("16 block test", () => {

Is this really testing two blocks? It looks like it is doing 16 at once. Maybe i misunderstand the naming between block/words.

Comment on lines +16 to +19
// Test case from RCF https://www.rfc-editor.org/rfc/rfc7539.html#section-2.4.2
// the input encoding here is not the most intuitive. inputs are serialized as little endian.
// i.e. "e4e7f110" is serialized as "10 f1 e7 e4". So the way i am reading in inputs is
// to ensure that every 32 bit word is byte reversed before being turned into bits.
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -212,7 +206,7 @@ const json_key3_mask = [
const json_key3_mask_hash = DataHasher(json_key3_mask);

describe("NIVC_FULL", async () => {
let aesCircuit: WitnessTester<["key", "iv", "aad", "ctr", "plainText", "cipherText", "step_in"], ["step_out"]>;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a fan of deleting a whole test case. We may want to come back to AES. We don't know yet, but I don't want to remove this circuit and its test in this PR.

In general, PRs should do one thing -- this one adds fodlable ChaCha20. It should not remove AES-GCTR. This is the main reason this got reverted.

signal input in[BITS];
signal output out[BITS];
for (var i = 0; i < BITS; i++) {
out[i] <== in[(i + L) % BITS];
Copy link
Contributor

Choose a reason for hiding this comment

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

modular arithmetic is the best thing

@@ -1,7 +1,7 @@
{
"name": "web-prover-circuits",
"description": "ZK Circuits for WebProofs",
"version": "0.5.4",
"version": "0.6.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm partial to putting this as v0.5.5 as this does not break an API here. It introduces an extended API.

This is less important to me though. I could go either way.

@Autoparallel Autoparallel added the performance ⚡️ This will not be worked on label Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance ⚡️ This will not be worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants