From 021b3d7881558d2e496fcceca1209db01fab4515 Mon Sep 17 00:00:00 2001 From: Waylon Jepsen Date: Fri, 1 Nov 2024 15:35:02 +0700 Subject: [PATCH] Revert "compose web_proof.circom" This reverts commit 69c6129472e2b5af118c0685dad636d5814c6a54. --- circuits/aes-gctr-nivc.circom | 6 + circuits/extract_value.circom | 5 + circuits/http_body_mask.circom | 6 + circuits/http_lock_header.circom | 7 + .../http_parse_and_lock_start_line.circom | 5 + circuits/json_mask_array_index.circom | 5 + circuits/json_mask_object.circom | 5 + circuits/json_parse.circom | 6 + circuits/web_proof.circom | 121 ------------------ 9 files changed, 45 insertions(+), 121 deletions(-) create mode 100644 circuits/aes-gctr-nivc.circom create mode 100644 circuits/extract_value.circom create mode 100644 circuits/http_body_mask.circom create mode 100644 circuits/http_lock_header.circom create mode 100644 circuits/http_parse_and_lock_start_line.circom create mode 100644 circuits/json_mask_array_index.circom create mode 100644 circuits/json_mask_object.circom create mode 100644 circuits/json_parse.circom delete mode 100644 circuits/web_proof.circom diff --git a/circuits/aes-gctr-nivc.circom b/circuits/aes-gctr-nivc.circom new file mode 100644 index 0000000..2ec7580 --- /dev/null +++ b/circuits/aes-gctr-nivc.circom @@ -0,0 +1,6 @@ +pragma circom 2.1.9; + +include "aes-gcm/nivc/aes-gctr-nivc.circom"; + +// the circomkit tests become unhappy when there is a main. +component main { public [step_in] } = AESGCTRFOLD(48); \ No newline at end of file diff --git a/circuits/extract_value.circom b/circuits/extract_value.circom new file mode 100644 index 0000000..8e3906b --- /dev/null +++ b/circuits/extract_value.circom @@ -0,0 +1,5 @@ +pragma circom 2.1.9; + +include "json/nivc/extractor.circom"; + +component main { public [step_in] } = MaskExtractFinal(49, 32, 32); \ No newline at end of file diff --git a/circuits/http_body_mask.circom b/circuits/http_body_mask.circom new file mode 100644 index 0000000..de2a95c --- /dev/null +++ b/circuits/http_body_mask.circom @@ -0,0 +1,6 @@ +pragma circom 2.1.9; + +include "http/nivc/body_mask.circom"; + +component main { public [step_in] } = HTTPMaskBodyNIVC(4160, 320); + diff --git a/circuits/http_lock_header.circom b/circuits/http_lock_header.circom new file mode 100644 index 0000000..c81aa82 --- /dev/null +++ b/circuits/http_lock_header.circom @@ -0,0 +1,7 @@ +pragma circom 2.1.9; + +include "http/nivc/lock_header.circom"; + +component main { public [step_in] } = LockHeader(48, 16, 12, 16); +// this one took about + diff --git a/circuits/http_parse_and_lock_start_line.circom b/circuits/http_parse_and_lock_start_line.circom new file mode 100644 index 0000000..f0ba8a5 --- /dev/null +++ b/circuits/http_parse_and_lock_start_line.circom @@ -0,0 +1,5 @@ +pragma circom 2.1.9; + +include "http/nivc/parse_and_lock_start_line.circom"; + +component main { public [step_in] } = ParseAndLockStartLine(48, 16, 8, 3, 2); \ No newline at end of file diff --git a/circuits/json_mask_array_index.circom b/circuits/json_mask_array_index.circom new file mode 100644 index 0000000..dfe2334 --- /dev/null +++ b/circuits/json_mask_array_index.circom @@ -0,0 +1,5 @@ +pragma circom 2.1.9; + +include "json/nivc/masker.circom"; + +component main { public [step_in] } = JsonMaskArrayIndexNIVC(48, 16); \ No newline at end of file diff --git a/circuits/json_mask_object.circom b/circuits/json_mask_object.circom new file mode 100644 index 0000000..5f49944 --- /dev/null +++ b/circuits/json_mask_object.circom @@ -0,0 +1,5 @@ +pragma circom 2.1.9; + +include "json/nivc/masker.circom"; + +component main { public [step_in] } = JsonMaskObjectNIVC(48, 16, 5); diff --git a/circuits/json_parse.circom b/circuits/json_parse.circom new file mode 100644 index 0000000..3204dff --- /dev/null +++ b/circuits/json_parse.circom @@ -0,0 +1,6 @@ +pragma circom 2.1.9; + +include "json/nivc/parse.circom"; + +component main { public [step_in] } = JsonParseNIVC(48, 16); + diff --git a/circuits/web_proof.circom b/circuits/web_proof.circom deleted file mode 100644 index ec2ca1b..0000000 --- a/circuits/web_proof.circom +++ /dev/null @@ -1,121 +0,0 @@ -pragma circom 2.1.9; - -include "aes-gcm/nivc/aes-gctr-nivc.circom"; -include "http/nivc/parse_and_lock_start_line.circom"; -include "http/nivc/lock_header.circom"; -include "http/nivc/body_mask.circom"; -include "json/nivc/parse.circom"; -include "json/nivc/masker.circom"; -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 -// DATA_BYTES = length of block * 2 + 4 -// e.g. 36 = 16 * 2 + 4 for a single block -template WEPPROOF( - DATA_BYTES, - MAX_STACK_HEIGHT, - MAX_BEGINNING_LENGTH, - MAX_MIDDLE_LENGTH, - MAX_FINAL_LENGTH, - MAX_HEADER_NAME_LENGTH, - MAX_HEADER_VALUE_LENGTH, - MAX_KEY_LENGTH, - MAX_VALUE_LENGTH) { - - var TOTAL_BYTES_ACROSS_NIVC = DATA_BYTES * 2 + 4; - signal input step_in[TOTAL_BYTES_ACROSS_NIVC]; - signal output step_out[TOTAL_BYTES_ACROSS_NIVC]; - - // AES - signal input key[16]; - signal input iv[12]; - signal input aad[16]; - signal input plainText[16]; - component aes_gctr_nivc = AESGCTRFOLD(DATA_BYTES); - aes_gctr_nivc.key <== key; - aes_gctr_nivc.iv <== iv; - aes_gctr_nivc.aad <== aad; - aes_gctr_nivc.plainText <== plainText; - aes_gctr_nivc.step_in <== step_in; - - // Parse and lock - component http_parse = ParseAndLockStartLine(DATA_BYTES, - MAX_STACK_HEIGHT, - MAX_BEGINNING_LENGTH, - MAX_MIDDLE_LENGTH, - MAX_FINAL_LENGTH); - - signal input beginning[MAX_BEGINNING_LENGTH]; - signal input beginning_length; - signal input middle[MAX_MIDDLE_LENGTH]; - signal input middle_length; - signal input final[MAX_FINAL_LENGTH]; - signal input final_length; - - http_parse.step_in <== aes_gctr_nivc.step_out; - http_parse.beginning <== beginning; - http_parse.beginning_length <== beginning_length; - http_parse.middle <== middle; - http_parse.middle_length <== middle_length; - http_parse.final <== final; - http_parse.final_length <== final_length; - - // Lock header - component http_lock_header = LockHeader(DATA_BYTES, - MAX_STACK_HEIGHT, - MAX_HEADER_NAME_LENGTH, - MAX_HEADER_VALUE_LENGTH); - - signal input header[MAX_HEADER_NAME_LENGTH]; - signal input headerNameLength; - signal input value[MAX_HEADER_VALUE_LENGTH]; - signal input headerValueLength; - - http_lock_header.step_in <== http_parse.step_out; - http_lock_header.header <== header; - http_lock_header.headerNameLength <== headerNameLength; - http_lock_header.value <== value; - http_lock_header.headerValueLength <== headerValueLength; - - // HTTP body mask - component http_body_mask = HTTPMaskBodyNIVC(DATA_BYTES, MAX_STACK_HEIGHT); - http_body_mask.step_in <== http_lock_header.step_out; - - // JSON parse - component json_parse = JsonParseNIVC(DATA_BYTES, MAX_STACK_HEIGHT); - json_parse.step_in <== http_body_mask.step_out; - - // Note: picked Array over object for now - // TODO(WJ 2024-11-01): add conditional logic via a mux - // template JsonMaskObjectNIVC(DATA_BYTES, MAX_STACK_HEIGHT, MAX_KEY_LENGTH) - // component json_mask_object = JsonMaskObjectNIVC(DATA_BYTES, MAX_STACK_HEIGHT, MAX_KEY_LENGTH); - - // JSON array - component json_mask_array = JsonMaskArrayIndexNIVC(DATA_BYTES, MAX_STACK_HEIGHT); - json_mask_array.step_in <== json_parse.step_out; - - // Final Extraction - component extract_value = MaskExtractFinal(DATA_BYTES, MAX_STACK_HEIGHT, MAX_VALUE_LENGTH); -} - -/// Note, DATA_BYTES > MAX_BEGINNING_LENGTH and MAX_MIDDLE_LENGTH and MAX_FINAL_LENGTH -component main = WEPPROOF( - 64, // DATA_BYTES - 5, // MAX_STACK_HEIGHT - 10, // MAX_BEGINNING_LENGTH - 50, // MAX_MIDDLE_LENGTH - 10, // MAX_FINAL_LENGTH - 12, // MAX_HEADER_NAME_LENGTH - 16, // MAX_HEADER_VALUE_LENGTH - 8, // MAX_KEY_LENGTH - 16 // MAX_VALUE_LENGTH - ); - - // 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 MAX_BEGINNING_LENGTH = 10; - // const MAX_MIDDLE_LENGTH = 50; - // const MAX_FINAL_LENGTH = 10; \ No newline at end of file