From 118d4cb2d12bfb7cc0b30b60dfad9f78c71d8fb7 Mon Sep 17 00:00:00 2001 From: Waylon Jepsen Date: Fri, 1 Nov 2024 11:55:33 +0700 Subject: [PATCH] change aes input to data bytes --- circuits/aes-gcm/nivc/aes-gctr-nivc.circom | 6 ++-- .../test/aes-gcm/nivc/aes-gctr-nivc.test.ts | 8 ++--- circuits/web_proof.circom | 30 +++++++++++-------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/circuits/aes-gcm/nivc/aes-gctr-nivc.circom b/circuits/aes-gcm/nivc/aes-gctr-nivc.circom index 689da97..995fe9e 100644 --- a/circuits/aes-gcm/nivc/aes-gctr-nivc.circom +++ b/circuits/aes-gcm/nivc/aes-gctr-nivc.circom @@ -5,9 +5,11 @@ include "../../utils/array.circom"; // Compute AES-GCTR -template AESGCTRFOLD(INPUT_LEN) { +template AESGCTRFOLD(DATA_BYTES) { + // Length of plaintext + var INPUT_LEN = (DATA_BYTES - 4) / 2; assert(INPUT_LEN % 16 == 0); - var DATA_BYTES = (INPUT_LEN * 2) + 4; + signal input key[16]; signal input iv[12]; signal input aad[16]; 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 4b63918..75de5dd 100644 --- a/circuits/test/aes-gcm/nivc/aes-gctr-nivc.test.ts +++ b/circuits/test/aes-gcm/nivc/aes-gctr-nivc.test.ts @@ -9,7 +9,7 @@ describe("aes-gctr-nivc", () => { circuit_one_block = await circomkit.WitnessTester("aes-gcm-fold", { file: "aes-gcm/nivc/aes-gctr-nivc", template: "AESGCTRFOLD", - params: [16], // input len is 16 bytes + params: [36], // input len is 16 bytes }); let key = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; @@ -30,7 +30,7 @@ describe("aes-gctr-nivc", () => { circuit_one_block = await circomkit.WitnessTester("aes-gcm-fold", { file: "aes-gcm/nivc/aes-gctr-nivc", template: "AESGCTRFOLD", - params: [16], // input len is 16 bytes + params: [36], // input len is 16 bytes }); let key = [0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31]; @@ -54,7 +54,7 @@ describe("aes-gctr-nivc", () => { circuit_one_block = await circomkit.WitnessTester("aes-gcm-fold", { file: "aes-gcm/nivc/aes-gctr-nivc", template: "AESGCTRFOLD", - params: [32], // input len is 32 bytes + params: [68], // input len is 32 bytes }); let zero_block = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; @@ -78,7 +78,7 @@ describe("aes-gctr-nivc", () => { circuit_one_block = await circomkit.WitnessTester("aes-gcm-fold", { file: "aes-gcm/nivc/aes-gctr-nivc", template: "AESGCTRFOLD", - params: [32], // input len is 32 bytes + params: [68], // input len is 32 bytes }); let zero_block = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; diff --git a/circuits/web_proof.circom b/circuits/web_proof.circom index ecd2c5c..19ccaf9 100644 --- a/circuits/web_proof.circom +++ b/circuits/web_proof.circom @@ -10,32 +10,36 @@ include "json/nivc/masker.circom"; include "json/nivc/extractor.circom"; // AES -> HTTP Parse -> http lock header -> http body mask -> json parse -> json_mask_object/json_mask_array -> extract value -template WEPPROOF { +// DATA_BYTES = length of block * 2 + 4 +// e.g. 36 = 16 * 2 + 4 for a single block +template WEPPROOF(DATA_BYTES) { - // template AESGCTRFOLD(INPUT_LEN) - component aes_gctr_nivc = AESGCTRFOLD(48); + // template AESGCTRFOLD(DATA) + component aes_gctr_nivc = AESGCTRFOLD(DATA_BYTES); // template ParseAndLockStartLine(DATA_BYTES, MAX_STACK_HEIGHT, MAX_BEGINNING_LENGTH, MAX_MIDDLE_LENGTH, MAX_FINAL_LENGTH) - component http_parse = ParseAndLockStartLine(48, 16, 8, 3, 2); + component http_parse = ParseAndLockStartLine(DATA_BYTES, 16, 8, 3, 2); // template LockHeader(DATA_BYTES, MAX_STACK_HEIGHT, MAX_HEADER_NAME_LENGTH, MAX_HEADER_VALUE_LENGTH) - component http_lock_header = LockHeader(48, 16, 12, 16); + component http_lock_header = LockHeader(DATA_BYTES, 16, 12, 16); // template HTTPMaskBodyNIVC(DATA_BYTES, MAX_STACK_HEIGHT) - component http_body_mask = HTTPMaskBodyNIVC(48, 16); + component http_body_mask = HTTPMaskBodyNIVC(DATA_BYTES, 16); // JsonParseNIVC(DATA_BYTES, MAX_STACK_HEIGHT) - component json_parse = JsonParseNIVC(48, 16); + component json_parse = JsonParseNIVC(DATA_BYTES, 16); // need logic to specif which json type // object or array + // template JsonMaskObjectNIVC(DATA_BYTES, MAX_STACK_HEIGHT, MAX_KEY_LENGTH) + component json_mask_object = JsonMaskObjectNIVC(DATA_BYTES, 16, 4); - component json_mask_object = JsonMaskObjectNIVC(48, 16, 4); - component json_mask_array = JsonMaskArrayIndexNIVC(48, 16); - // extract value - component extract_value = MaskExtractFinal(49, 32, 32); + // template JsonMaskArrayIndexNIVC(DATA_BYTES, MAX_STACK_HEIGHT) + component json_mask_array = JsonMaskArrayIndexNIVC(DATA_BYTES, 16); + + // template MaskExtractFinal(DATA_BYTES, MAX_STACK_HEIGHT, MAX_VALUE_LENGTH) + component extract_value = MaskExtractFinal(DATA_BYTES, 32, 32); } -// = AESGCTRFOLD(48); -component main = WEPPROOF(); +component main = WEPPROOF(36);