Skip to content

Commit

Permalink
fix: aes-gctr-nivc (#43)
Browse files Browse the repository at this point in the history
* fix: broken input length

* bump: package version

* fix: `HttpNIVC` equal checks

* move final extract value to be multiple of 16

---------

Co-authored-by: lonerapier <lonerapier@proton.me>
  • Loading branch information
Autoparallel and lonerapier authored Nov 13, 2024
1 parent 7f4cdc1 commit 73260ab
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion builds/target_512b/json_extract_value_512b.circom
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ pragma circom 2.1.9;

include "../../circuits/json/nivc/extractor.circom";

component main { public [step_in] } = MaskExtractFinal(512, 50);
component main { public [step_in] } = MaskExtractFinal(512, 48);
8 changes: 7 additions & 1 deletion circuits/aes-gcm/nivc/aes-gctr-nivc.circom
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ template AESGCTRFOLD() {
aes.plainText <== plainText;
aes.lastCounter <== ctr;

aes.cipherText === cipherText;
signal ciphertext_equal_check[16];
for(var i = 0 ; i < 16 ; i++) {
ciphertext_equal_check[i] <== IsEqual()([aes.cipherText[i], cipherText[i]]);
ciphertext_equal_check[i] === 1;
}


var packedPlaintext = 0;
for(var i = 0 ; i < 16 ; i++) {
packedPlaintext += plainText[i] * 2**(8*i);
Expand Down
12 changes: 9 additions & 3 deletions circuits/http/nivc/http_nivc.circom
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ template HttpNIVC(DATA_BYTES, MAX_NUMBER_OF_HEADERS) {
start_line[i] <== data[i] * (1 - not_start_line_mask[i]);
}
signal inner_start_line_hash <== DataHasher(DATA_BYTES)(start_line);
inner_start_line_hash === start_line_hash;
signal start_line_hash_equal_check <== IsEqual()([inner_start_line_hash, start_line_hash]);
start_line_hash_equal_check === 1;

// Get the header shit
signal header[MAX_NUMBER_OF_HEADERS][DATA_BYTES];
Expand All @@ -60,10 +61,12 @@ template HttpNIVC(DATA_BYTES, MAX_NUMBER_OF_HEADERS) {
}
signal inner_header_hashes[MAX_NUMBER_OF_HEADERS];
signal header_is_unused[MAX_NUMBER_OF_HEADERS]; // If a header hash is passed in as 0, it is not used (no way to compute preimage of 0)
signal header_hashes_equal_check[MAX_NUMBER_OF_HEADERS];
for(var i = 0 ; i < MAX_NUMBER_OF_HEADERS ; i++) {
header_is_unused[i] <== IsZero()(header_hashes[i]);
inner_header_hashes[i] <== DataHasher(DATA_BYTES)(header[i]);
(1 - header_is_unused[i]) * inner_header_hashes[i] === header_hashes[i];
header_hashes_equal_check[i] <== IsEqual()([(1 - header_is_unused[i]) * inner_header_hashes[i], header_hashes[i]]);
header_hashes_equal_check[i] === 1;
}

// Get the body shit
Expand All @@ -72,6 +75,9 @@ template HttpNIVC(DATA_BYTES, MAX_NUMBER_OF_HEADERS) {
body[i] <== data[i] * State[i].parsing_body;
}
signal inner_body_hash <== DataHasher(DATA_BYTES)(body);
inner_body_hash === body_hash;
signal body_hash_equal_check <== IsEqual()([inner_body_hash, body_hash]);
body_hash_equal_check === 1;


step_out[0] <== inner_body_hash;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "web-prover-circuits",
"description": "ZK Circuits for WebProofs",
"version": "0.5.1",
"version": "0.5.2",
"license": "Apache-2.0",
"repository": {
"type": "git",
Expand Down

0 comments on commit 73260ab

Please sign in to comment.