-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: organize circuits and begin HTTP parsing (#65)
* refactor: circuits * add HTTP to Rust witness creation * basic HTTP language file * parse request method * Update README.md * add note on CLRF * Update get_response.http
- Loading branch information
1 parent
4473a8b
commit 9a44739
Showing
34 changed files
with
237 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
pragma circom 2.1.9; | ||
|
||
// All the possible request methods: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods | ||
|
||
template Syntax() { | ||
//-Delimeters---------------------------------------------------------------------------------// | ||
// - ASCII char `:` | ||
signal output COLON <== 58; | ||
// - ASCII char `;` | ||
signal output SEMICOLON <== 59; | ||
// - ASCII char `,` | ||
signal output COMMA <== 44; | ||
// - ASCII char `"` | ||
signal output QUOTE <== 34; | ||
//-White_space--------------------------------------------------------------------------------// | ||
// - ASCII pair: `\r\n` | ||
signal output CLRF <== [13, 10]; // https://www.rfc-editor.org/rfc/rfc2616#section-2.2 | ||
// https://www.rfc-editor.org/rfc/rfc7230#section-3.5 | ||
// - ASCII char: ` ` | ||
signal output SPACE <== 32; | ||
//-Escape-------------------------------------------------------------------------------------// | ||
// - ASCII char: `\` | ||
signal output ESCAPE <== 92; | ||
} | ||
|
||
template RequestMethod() { | ||
signal output GET[3] <== [71, 69, 84]; | ||
// signal output HEAD[4] <== [72, 69, 65, 68]; | ||
signal output POST[4] <== [80, 79, 83, 84]; | ||
// signal output PUT <== 3; | ||
// signal output DELETE <== 4; | ||
// signal output CONNECT <== 5; | ||
// signal output OPTIONS <== 6; | ||
// signal output TRACE <== 7; | ||
// signal output PATCH <== 8; | ||
} | ||
|
||
// NOTE: Starting at 1 to avoid a false positive with a 0. | ||
template RequestMethodTag() { | ||
signal output GET <== 1; | ||
// signal output HEAD <== 2; | ||
signal output POST <== 3; | ||
// signal output PUT <== 4; | ||
// signal output DELETE <== 5; | ||
// signal output CONNECT <== 6; | ||
// signal output OPTIONS <== 7; | ||
// signal output TRACE <== 8; | ||
// signal output PATCH <== 9; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
pragma circom 2.1.9; | ||
|
||
include "language.circom"; | ||
include "../utils/array.circom"; | ||
|
||
template ParseMethod() { | ||
signal input bytes[7]; | ||
signal output MethodTag; | ||
|
||
component RequestMethod = RequestMethod(); | ||
component RequestMethodTag = RequestMethodTag(); | ||
|
||
component IsGet = IsEqualArray(3); | ||
for(var byte_idx = 0; byte_idx < 3; byte_idx++) { | ||
IsGet.in[0][byte_idx] <== bytes[byte_idx]; | ||
IsGet.in[1][byte_idx] <== RequestMethod.GET[byte_idx]; | ||
} | ||
signal TagGet <== IsGet.out * RequestMethodTag.GET; | ||
|
||
component IsPost = IsEqualArray(4); | ||
for(var byte_idx = 0; byte_idx < 4; byte_idx++) { | ||
IsPost.in[0][byte_idx] <== bytes[byte_idx]; | ||
IsPost.in[1][byte_idx] <== RequestMethod.POST[byte_idx]; | ||
} | ||
signal TagPost <== IsPost.out * RequestMethodTag.POST; | ||
|
||
MethodTag <== TagGet + TagPost; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
pragma circom 2.1.9; | ||
|
||
include "../utils/bytes.circom"; | ||
include "machine.circom"; | ||
|
||
|
||
template Parser(DATA_BYTES) { | ||
signal input data[DATA_BYTES]; | ||
|
||
signal output Method; | ||
|
||
//--------------------------------------------------------------------------------------------// | ||
//-CONSTRAINTS--------------------------------------------------------------------------------// | ||
//--------------------------------------------------------------------------------------------// | ||
component dataASCII = ASCII(DATA_BYTES); | ||
dataASCII.in <== data; | ||
//--------------------------------------------------------------------------------------------// | ||
|
||
component ParseMethod = ParseMethod(); | ||
for(var byte_idx = 0; byte_idx < 7; byte_idx++) { | ||
ParseMethod.bytes[byte_idx] <== data[byte_idx]; | ||
} | ||
log("MethodTag: ", ParseMethod.MethodTag); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
GET /objectserver/restapi/alerts/status HTTP/1.1 | ||
Accept: application/json | ||
Authorization: Basic dGVzdHVzZXIwMTpuZXRjb29s | ||
Host: localhost | ||
Connection: keep-alive |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
HTTP/1.1 200 OK | ||
Content-Type: application/json | ||
Content-Length: 19 | ||
|
||
{"success":"true"} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.