Skip to content

Commit

Permalink
reduce HTTP start line public io
Browse files Browse the repository at this point in the history
  • Loading branch information
Autoparallel committed Nov 5, 2024
1 parent 38e9370 commit dfd5721
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
component main { public [step_in] } = ParseAndLockStartLine(1024, 50, 200, 50);
Original file line number Diff line number Diff line change
Expand Up @@ -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);
component main { public [step_in] } = ParseAndLockStartLine(512, 50, 200, 50);
48 changes: 11 additions & 37 deletions circuits/http/nivc/parse_and_lock_start_line.circom
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
}
}
}
6 changes: 2 additions & 4 deletions circuits/test/http/nivc/parse_and_lock_start_line.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
});
Expand Down

0 comments on commit dfd5721

Please sign in to comment.