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 5 commits 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.

builds/target_1024b/aes_gctr_nivc_1024b.circom Outdated Show resolved Hide resolved
builds/target_512b/aes_gctr_nivc_512b.circom Outdated Show resolved Hide resolved
circuits/chacha20/chacha20.circom Outdated Show resolved Hide resolved
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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. I don't know, perhaps it's worth looking into if this circuits performance becomes a problem.

// 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes thats exactly correct. this circuit is entirely symmetric.

circuits/test/chacha20/chacha20-nivc.test.ts Outdated Show resolved Hide resolved
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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So what should we use in the full test AES or ChaCha?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually just put them both back in the full test for now which seems best.

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

package.json Outdated Show resolved Hide resolved
@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