From dfd572141cccda089671a22d6ccadbf139c65930 Mon Sep 17 00:00:00 2001 From: Colin Roberts Date: Tue, 5 Nov 2024 14:59:56 -0700 Subject: [PATCH] reduce HTTP start line public io --- ...ttp_parse_and_lock_start_line_1024b.circom | 2 +- ...http_parse_and_lock_start_line_512b.circom | 2 +- .../nivc/parse_and_lock_start_line.circom | 48 +++++-------------- .../nivc/parse_and_lock_start_line.test.ts | 6 +-- 4 files changed, 15 insertions(+), 43 deletions(-) diff --git a/builds/target_1024b/http_parse_and_lock_start_line_1024b.circom b/builds/target_1024b/http_parse_and_lock_start_line_1024b.circom index d55f32c..b70daa1 100644 --- a/builds/target_1024b/http_parse_and_lock_start_line_1024b.circom +++ b/builds/target_1024b/http_parse_and_lock_start_line_1024b.circom @@ -2,4 +2,4 @@ pragma circom 2.1.9; include "../../circuits/http/nivc/parse_and_lock_start_line.circom"; -component main { public [step_in] } = ParseAndLockStartLine(1024, 10, 50, 200, 50); \ No newline at end of file +component main { public [step_in] } = ParseAndLockStartLine(1024, 50, 200, 50); \ No newline at end of file diff --git a/builds/target_512b/http_parse_and_lock_start_line_512b.circom b/builds/target_512b/http_parse_and_lock_start_line_512b.circom index f88d411..6463e4c 100644 --- a/builds/target_512b/http_parse_and_lock_start_line_512b.circom +++ b/builds/target_512b/http_parse_and_lock_start_line_512b.circom @@ -2,4 +2,4 @@ pragma circom 2.1.9; include "../../circuits/http/nivc/parse_and_lock_start_line.circom"; -component main { public [step_in] } = ParseAndLockStartLine(512, 10, 50, 200, 50); \ No newline at end of file +component main { public [step_in] } = ParseAndLockStartLine(512, 50, 200, 50); \ No newline at end of file diff --git a/circuits/http/nivc/parse_and_lock_start_line.circom b/circuits/http/nivc/parse_and_lock_start_line.circom index f1c1c53..afa1d3a 100644 --- a/circuits/http/nivc/parse_and_lock_start_line.circom +++ b/circuits/http/nivc/parse_and_lock_start_line.circom @@ -6,40 +6,22 @@ include "../../utils/bytes.circom"; // TODO: Note that TOTAL_BYTES will match what we have for AESGCMFOLD step_out // I have not gone through to double check the sizes of everything yet. -template ParseAndLockStartLine(DATA_BYTES, MAX_STACK_HEIGHT, MAX_BEGINNING_LENGTH, MAX_MIDDLE_LENGTH, MAX_FINAL_LENGTH) { +template ParseAndLockStartLine(DATA_BYTES, MAX_BEGINNING_LENGTH, MAX_MIDDLE_LENGTH, MAX_FINAL_LENGTH) { // ------------------------------------------------------------------------------------------------------------------ // // ~~ Set sizes at compile time ~~ - // Total number of variables in the parser for each byte of data - // var AES_BYTES = DATA_BYTES + 50; // TODO: Might be wrong, but good enough for now - /* 5 is for the variables: - next_parsing_start - next_parsing_header - next_parsing_field_name - next_parsing_field_value - State[i].next_parsing_body - */ - var TOTAL_BYTES_HTTP_STATE = DATA_BYTES * (5 + 1); // data + parser vars - var PER_ITERATION_DATA_LENGTH = MAX_STACK_HEIGHT * 2 + 2; - var TOTAL_BYTES_ACROSS_NIVC = DATA_BYTES * (PER_ITERATION_DATA_LENGTH + 1) + 1; + var TOTAL_BYTES_ACROSS_NIVC = DATA_BYTES * 2 + 4; // AES ct/pt + ctr // ------------------------------------------------------------------------------------------------------------------ // // ------------------------------------------------------------------------------------------------------------------ // - // ~ Unravel from previous NIVC step ~ - // Read in from previous NIVC step (JsonParseNIVC) signal input step_in[TOTAL_BYTES_ACROSS_NIVC]; signal output step_out[TOTAL_BYTES_ACROSS_NIVC]; + // Get the plaintext signal data[DATA_BYTES]; for (var i = 0 ; i < DATA_BYTES ; i++) { - // data[i] <== step_in[50 + i]; // THIS WAS OFFSET FOR AES, WHICH WE NEED TO TAKE INTO ACCOUNT data[i] <== step_in[i]; } - // // TODO: check if these needs to here or not - // DON'T THINK WE NEED THIS SINCE AES SHOULD OUTPUT ASCII OR FAIL - // component dataASCII = ASCII(DATA_BYTES); - // dataASCII.in <== data; - signal input beginning[MAX_BEGINNING_LENGTH]; signal input beginning_length; signal input middle[MAX_MIDDLE_LENGTH]; @@ -114,21 +96,13 @@ template ParseAndLockStartLine(DATA_BYTES, MAX_STACK_HEIGHT, MAX_BEGINNING_LENGT final_length === final_end_counter - middle_end_counter - 2; // ------------------------------------------------------------------------------------------------------------------ // - // ~ Write out to next NIVC step (Lock Header) - for (var i = 0 ; i < DATA_BYTES ; i++) { - // add plaintext http input to step_out - // step_out[i] <== step_in[50 + i]; // AGAIN, NEED TO ACCOUNT FOR AES VARIABLES POSSIBLY - step_out[i] <== step_in[i]; - - // add parser state - step_out[DATA_BYTES + i * 5] <== State[i].next_parsing_start; - step_out[DATA_BYTES + i * 5 + 1] <== State[i].next_parsing_header; - step_out[DATA_BYTES + i * 5 + 2] <== State[i].next_parsing_field_name; - step_out[DATA_BYTES + i * 5 + 3] <== State[i].next_parsing_field_value; - step_out[DATA_BYTES + i * 5 + 4] <== State[i].next_parsing_body; - } - // Pad remaining with zeros - for (var i = TOTAL_BYTES_HTTP_STATE ; i < TOTAL_BYTES_ACROSS_NIVC ; i++ ) { - step_out[i] <== 0; + // write out the pt again + for (var i = 0 ; i < TOTAL_BYTES_ACROSS_NIVC ; i++) { + // add plaintext http input to step_out and ignore the ciphertext + if(i < DATA_BYTES) { + step_out[i] <== step_in[i]; + } else { + step_out[i] <== 0; + } } } diff --git a/circuits/test/http/nivc/parse_and_lock_start_line.test.ts b/circuits/test/http/nivc/parse_and_lock_start_line.test.ts index c52000a..c843c6d 100644 --- a/circuits/test/http/nivc/parse_and_lock_start_line.test.ts +++ b/circuits/test/http/nivc/parse_and_lock_start_line.test.ts @@ -5,9 +5,7 @@ describe("HTTPParseAndLockStartLine", async () => { let httpParseAndLockStartLineCircuit: WitnessTester<["step_in", "beginning", "beginning_length", "middle", "middle_length", "final", "final_length"], ["step_out"]>; const DATA_BYTES = 320; - const MAX_STACK_HEIGHT = 5; - const PER_ITERATION_DATA_LENGTH = MAX_STACK_HEIGHT * 2 + 2; - const TOTAL_BYTES_ACROSS_NIVC = DATA_BYTES * (PER_ITERATION_DATA_LENGTH + 1) + 1; + const TOTAL_BYTES_ACROSS_NIVC = DATA_BYTES * 2 + 4; const MAX_BEGINNING_LENGTH = 10; const MAX_MIDDLE_LENGTH = 50; @@ -17,7 +15,7 @@ describe("HTTPParseAndLockStartLine", async () => { httpParseAndLockStartLineCircuit = await circomkit.WitnessTester(`ParseAndLockStartLine`, { file: "http/nivc/parse_and_lock_start_line", template: "ParseAndLockStartLine", - params: [DATA_BYTES, MAX_STACK_HEIGHT, MAX_BEGINNING_LENGTH, MAX_MIDDLE_LENGTH, MAX_FINAL_LENGTH], + params: [DATA_BYTES, MAX_BEGINNING_LENGTH, MAX_MIDDLE_LENGTH, MAX_FINAL_LENGTH], }); console.log("#constraints:", await httpParseAndLockStartLineCircuit.getConstraintCount()); });