From 38e9370f4ba72b007195ff97c7e1ff9800d08184 Mon Sep 17 00:00:00 2001 From: Colin Roberts Date: Tue, 5 Nov 2024 14:50:17 -0700 Subject: [PATCH] reduce AES public io --- builds/target_1024b/aes_gctr_nivc_1024b.circom | 3 +-- builds/target_256b/aes_gctr_nivc_256b.circom | 6 ------ builds/target_256b/http_body_mask_256b.circom | 6 ------ builds/target_256b/http_lock_header_256b.circom | 5 ----- .../http_parse_and_lock_start_line_256b.circom | 5 ----- builds/target_256b/json_extract_value_256b.circom | 5 ----- .../target_256b/json_mask_array_index_256b.circom | 5 ----- builds/target_256b/json_mask_object_256b.circom | 5 ----- builds/target_256b/json_parse_256b.circom | 6 ------ builds/target_512b/aes_gctr_nivc_512b.circom | 3 +-- circuits/aes-gcm/nivc/aes-gctr-nivc.circom | 9 +++------ circuits/test/aes-gcm/nivc/aes-gctr-nivc.test.ts | 14 ++++++-------- package.json | 2 +- 13 files changed, 12 insertions(+), 62 deletions(-) delete mode 100644 builds/target_256b/aes_gctr_nivc_256b.circom delete mode 100644 builds/target_256b/http_body_mask_256b.circom delete mode 100644 builds/target_256b/http_lock_header_256b.circom delete mode 100644 builds/target_256b/http_parse_and_lock_start_line_256b.circom delete mode 100644 builds/target_256b/json_extract_value_256b.circom delete mode 100644 builds/target_256b/json_mask_array_index_256b.circom delete mode 100644 builds/target_256b/json_mask_object_256b.circom delete mode 100644 builds/target_256b/json_parse_256b.circom diff --git a/builds/target_1024b/aes_gctr_nivc_1024b.circom b/builds/target_1024b/aes_gctr_nivc_1024b.circom index ae0ccf2..a48234a 100644 --- a/builds/target_1024b/aes_gctr_nivc_1024b.circom +++ b/builds/target_1024b/aes_gctr_nivc_1024b.circom @@ -2,5 +2,4 @@ pragma circom 2.1.9; include "../../circuits/aes-gcm/nivc/aes-gctr-nivc.circom"; -// the circomkit tests become unhappy when there is a main. -component main { public [step_in] } = AESGCTRFOLD(1024, 10); \ No newline at end of file +component main { public [step_in] } = AESGCTRFOLD(1024); \ No newline at end of file diff --git a/builds/target_256b/aes_gctr_nivc_256b.circom b/builds/target_256b/aes_gctr_nivc_256b.circom deleted file mode 100644 index 478c4b2..0000000 --- a/builds/target_256b/aes_gctr_nivc_256b.circom +++ /dev/null @@ -1,6 +0,0 @@ -pragma circom 2.1.9; - -include "../../circuits/aes-gcm/nivc/aes-gctr-nivc.circom"; - -// the circomkit tests become unhappy when there is a main. -component main { public [step_in] } = AESGCTRFOLD(256, 10); \ No newline at end of file diff --git a/builds/target_256b/http_body_mask_256b.circom b/builds/target_256b/http_body_mask_256b.circom deleted file mode 100644 index cb65ee5..0000000 --- a/builds/target_256b/http_body_mask_256b.circom +++ /dev/null @@ -1,6 +0,0 @@ -pragma circom 2.1.9; - -include "../../circuits/http/nivc/body_mask.circom"; - -component main { public [step_in] } = HTTPMaskBodyNIVC(256, 10); - diff --git a/builds/target_256b/http_lock_header_256b.circom b/builds/target_256b/http_lock_header_256b.circom deleted file mode 100644 index 892e013..0000000 --- a/builds/target_256b/http_lock_header_256b.circom +++ /dev/null @@ -1,5 +0,0 @@ -pragma circom 2.1.9; - -include "../../circuits/http/nivc/lock_header.circom"; - -component main { public [step_in] } = LockHeader(256, 10, 50, 100); \ No newline at end of file diff --git a/builds/target_256b/http_parse_and_lock_start_line_256b.circom b/builds/target_256b/http_parse_and_lock_start_line_256b.circom deleted file mode 100644 index 00411e1..0000000 --- a/builds/target_256b/http_parse_and_lock_start_line_256b.circom +++ /dev/null @@ -1,5 +0,0 @@ -pragma circom 2.1.9; - -include "../../circuits/http/nivc/parse_and_lock_start_line.circom"; - -component main { public [step_in] } = ParseAndLockStartLine(256, 10, 50, 200, 50); \ No newline at end of file diff --git a/builds/target_256b/json_extract_value_256b.circom b/builds/target_256b/json_extract_value_256b.circom deleted file mode 100644 index da8db1f..0000000 --- a/builds/target_256b/json_extract_value_256b.circom +++ /dev/null @@ -1,5 +0,0 @@ -pragma circom 2.1.9; - -include "../../circuits/json/nivc/extractor.circom"; - -component main { public [step_in] } = MaskExtractFinal(256, 10, 50); \ No newline at end of file diff --git a/builds/target_256b/json_mask_array_index_256b.circom b/builds/target_256b/json_mask_array_index_256b.circom deleted file mode 100644 index 83ebb08..0000000 --- a/builds/target_256b/json_mask_array_index_256b.circom +++ /dev/null @@ -1,5 +0,0 @@ -pragma circom 2.1.9; - -include "../../circuits/json/nivc/masker.circom"; - -component main { public [step_in] } = JsonMaskArrayIndexNIVC(256, 10); \ No newline at end of file diff --git a/builds/target_256b/json_mask_object_256b.circom b/builds/target_256b/json_mask_object_256b.circom deleted file mode 100644 index b6bb1ef..0000000 --- a/builds/target_256b/json_mask_object_256b.circom +++ /dev/null @@ -1,5 +0,0 @@ -pragma circom 2.1.9; - -include "../../circuits/json/nivc/masker.circom"; - -component main { public [step_in] } = JsonMaskObjectNIVC(256, 10, 10); diff --git a/builds/target_256b/json_parse_256b.circom b/builds/target_256b/json_parse_256b.circom deleted file mode 100644 index c0f5e8c..0000000 --- a/builds/target_256b/json_parse_256b.circom +++ /dev/null @@ -1,6 +0,0 @@ -pragma circom 2.1.9; - -include "../../circuits/json/nivc/parse.circom"; - -component main { public [step_in] } = JsonParseNIVC(256, 10); - diff --git a/builds/target_512b/aes_gctr_nivc_512b.circom b/builds/target_512b/aes_gctr_nivc_512b.circom index 07939ff..f863572 100644 --- a/builds/target_512b/aes_gctr_nivc_512b.circom +++ b/builds/target_512b/aes_gctr_nivc_512b.circom @@ -2,5 +2,4 @@ pragma circom 2.1.9; include "../../circuits/aes-gcm/nivc/aes-gctr-nivc.circom"; -// the circomkit tests become unhappy when there is a main. -component main { public [step_in] } = AESGCTRFOLD(512, 10); \ No newline at end of file +component main { public [step_in] } = AESGCTRFOLD(512); \ No newline at end of file diff --git a/circuits/aes-gcm/nivc/aes-gctr-nivc.circom b/circuits/aes-gcm/nivc/aes-gctr-nivc.circom index aa866f3..bae0890 100644 --- a/circuits/aes-gcm/nivc/aes-gctr-nivc.circom +++ b/circuits/aes-gcm/nivc/aes-gctr-nivc.circom @@ -5,13 +5,12 @@ include "../../utils/array.circom"; // Compute AES-GCTR -template AESGCTRFOLD(DATA_BYTES, MAX_STACK_HEIGHT) { +template AESGCTRFOLD(DATA_BYTES) { // ------------------------------------------------------------------------------------------------------------------ // // ~~ Set sizes at compile time ~~ assert(DATA_BYTES % 16 == 0); - // Total number of variables in the parser for each byte of data - var PER_ITERATION_DATA_LENGTH = MAX_STACK_HEIGHT * 2 + 2; - var TOTAL_BYTES_ACROSS_NIVC = DATA_BYTES * (PER_ITERATION_DATA_LENGTH + 1) + 1; + // Value for accumulating both plaintext and ciphertext as well as counter + var TOTAL_BYTES_ACROSS_NIVC = 2 * DATA_BYTES + 4; // ------------------------------------------------------------------------------------------------------------------ // @@ -75,8 +74,6 @@ template AESGCTRFOLD(DATA_BYTES, MAX_STACK_HEIGHT) { step_out[i] <== nextTexts.outSecond[i - DATA_BYTES]; } else if(i < 2 * DATA_BYTES + 4) { step_out[i] <== aes.counter[i - (2 * DATA_BYTES)]; - } else { - step_out[i] <== 0; } } } diff --git a/circuits/test/aes-gcm/nivc/aes-gctr-nivc.test.ts b/circuits/test/aes-gcm/nivc/aes-gctr-nivc.test.ts index 6ebd2bb..88e361e 100644 --- a/circuits/test/aes-gcm/nivc/aes-gctr-nivc.test.ts +++ b/circuits/test/aes-gcm/nivc/aes-gctr-nivc.test.ts @@ -2,20 +2,18 @@ import { assert } from "chai"; import { WitnessTester } from "circomkit"; import { circomkit } from "../../common"; -const MAX_STACK_HEIGHT = 0; - describe("aes-gctr-nivc", () => { let circuit_one_block: WitnessTester<["key", "iv", "plainText", "aad", "step_in"], ["step_out"]>; const DATA_BYTES_0 = 16; - const TOTAL_BYTES_ACROSS_NIVC_0 = DATA_BYTES_0 * (MAX_STACK_HEIGHT + 2 + 1) + 1; + const TOTAL_BYTES_ACROSS_NIVC_0 = 2 * DATA_BYTES_0 + 4; it("all correct for self generated single zero pt block case", async () => { circuit_one_block = await circomkit.WitnessTester("aes-gcm-fold", { file: "aes-gcm/nivc/aes-gctr-nivc", template: "AESGCTRFOLD", - params: [DATA_BYTES_0, MAX_STACK_HEIGHT], // input len is 16 bytes + params: [DATA_BYTES_0], // input len is 16 bytes }); let key = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; @@ -40,7 +38,7 @@ describe("aes-gctr-nivc", () => { circuit_one_block = await circomkit.WitnessTester("aes-gcm-fold", { file: "aes-gcm/nivc/aes-gctr-nivc", template: "AESGCTRFOLD", - params: [DATA_BYTES_0, MAX_STACK_HEIGHT], // input len is 16 bytes + params: [DATA_BYTES_0], // input len is 16 bytes }); let key = [0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31]; @@ -63,7 +61,7 @@ describe("aes-gctr-nivc", () => { }); const DATA_BYTES_1 = 32; - const TOTAL_BYTES_ACROSS_NIVC_1 = DATA_BYTES_1 * (MAX_STACK_HEIGHT + 2 + 1) + 1; + const TOTAL_BYTES_ACROSS_NIVC_1 = DATA_BYTES_1 * 2 + 4; let zero_block = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; @@ -79,7 +77,7 @@ describe("aes-gctr-nivc", () => { circuit_one_block = await circomkit.WitnessTester("aes-gcm-fold", { file: "aes-gcm/nivc/aes-gctr-nivc", template: "AESGCTRFOLD", - params: [DATA_BYTES_1, MAX_STACK_HEIGHT], // input len is 32 bytes + params: [DATA_BYTES_1], // input len is 32 bytes }); const counter = [0x00, 0x00, 0x00, 0x01]; @@ -98,7 +96,7 @@ describe("aes-gctr-nivc", () => { circuit_one_block = await circomkit.WitnessTester("aes-gcm-fold", { file: "aes-gcm/nivc/aes-gctr-nivc", template: "AESGCTRFOLD", - params: [DATA_BYTES_1, MAX_STACK_HEIGHT], // input len is 32 bytes + params: [DATA_BYTES_1], // input len is 32 bytes }); const counter = [0x00, 0x00, 0x00, 0x02]; diff --git a/package.json b/package.json index 8834711..13e5752 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "web-prover-circuits", "description": "ZK Circuits for WebProofs", - "version": "0.2.7", + "version": "0.3.0", "license": "Apache-2.0", "repository": { "type": "git",