Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: value extractor #37

Merged
merged 134 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 133 commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
d2be624
add: `reddit_response.json`
Autoparallel Aug 7, 2024
6d4b7c3
refactor tests + add failing case
Autoparallel Aug 8, 2024
afcacda
easier fix
Autoparallel Aug 8, 2024
99e0e5c
test: parse to key
Autoparallel Aug 8, 2024
3a20a47
tests: key parsing
Autoparallel Aug 8, 2024
98a3b51
bug: `next_end_of_kv` on read `:`
Autoparallel Aug 8, 2024
44bcc18
fix: `end_of_kv` bug
Autoparallel Aug 8, 2024
fb0fb34
test: find value
Autoparallel Aug 8, 2024
0f82ab0
tests: `inside_value` and `inside_value_to_exit`
Autoparallel Aug 8, 2024
0b166ea
test: parse to NEXT key
Autoparallel Aug 8, 2024
fc81c78
parses JSON with two string keys
Autoparallel Aug 8, 2024
f1ebb51
WIP: value inside value
Autoparallel Aug 8, 2024
07fd671
comment
Autoparallel Aug 8, 2024
a62dd35
refactor (#10)
Autoparallel Aug 8, 2024
63a00d5
feat: 2 key depth 1 json
Autoparallel Aug 8, 2024
9528248
2 kv json and all tests passing
Autoparallel Aug 9, 2024
86bb82d
nested json works!!!
Autoparallel Aug 9, 2024
4142ab0
reduce constraints
Autoparallel Aug 9, 2024
1d425e5
cleanup
Autoparallel Aug 9, 2024
ec6ec0e
rename variables
Autoparallel Aug 9, 2024
ba8888f
more cleaning
Autoparallel Aug 9, 2024
887786a
more cleanup
Autoparallel Aug 9, 2024
621e130
make comments clean
Autoparallel Aug 9, 2024
18c68d8
WAYLON NITPICKING ME LOL
Autoparallel Aug 9, 2024
52fa826
feat: improved CLI for witness
Autoparallel Aug 9, 2024
331f218
gitignore input.json
Autoparallel Aug 9, 2024
7eef73e
Update main.rs
Autoparallel Aug 9, 2024
ca148b5
feat: update rust
Autoparallel Aug 9, 2024
c95b72f
feat: parse with array as value
Autoparallel Aug 9, 2024
5998757
feat; `InRange` template
Autoparallel Aug 9, 2024
e9d8b17
WIP: number parsing
Autoparallel Aug 9, 2024
b8923e7
good stopping point
Autoparallel Aug 10, 2024
c673c1b
compiling again
Autoparallel Aug 10, 2024
5432b17
stack hard
Autoparallel Aug 10, 2024
0e04f42
save progress
Autoparallel Aug 10, 2024
ded3c36
save wip
Autoparallel Aug 10, 2024
a11efb8
getting through tests
Autoparallel Aug 10, 2024
536b661
add optimised
lonerapier Aug 7, 2024
7329f38
resolve random input bug using poseidon hash
lonerapier Aug 8, 2024
4d4f02a
import circomlib and remove circuits
lonerapier Aug 11, 2024
ea1ebf7
add array and hash circuits
lonerapier Aug 11, 2024
c7425eb
add search
lonerapier Aug 11, 2024
8c7f55c
add js poseidon
lonerapier Aug 11, 2024
5b028c5
update tests
lonerapier Aug 11, 2024
fbf32c6
add search tests
lonerapier Aug 11, 2024
ce1bde9
wip: stack
Autoparallel Aug 11, 2024
1e4979d
big ints killing me
Autoparallel Aug 11, 2024
226d691
use strings for tests
Autoparallel Aug 11, 2024
8126615
reduce and fix some tests!
Autoparallel Aug 11, 2024
577152f
refactor tests
lonerapier Aug 12, 2024
a2e0c9a
reduce and fix some tests!
Autoparallel Aug 11, 2024
0652140
moar tests
Autoparallel Aug 12, 2024
982bb6c
Merge branch 'feat/stack-machine' of https://github.com/pluto/extract…
Autoparallel Aug 12, 2024
e2fb192
cosmetics
Autoparallel Aug 12, 2024
40f88c5
continuing with tests
Autoparallel Aug 12, 2024
d08ff4c
save state
Autoparallel Aug 12, 2024
ad2e643
renumbered stack entries
Autoparallel Aug 12, 2024
0884909
wip: handle end of arr/obj
Autoparallel Aug 12, 2024
780e8c2
maybe progress
Autoparallel Aug 12, 2024
f1c674c
save
Autoparallel Aug 12, 2024
cb7fa98
almost!
Autoparallel Aug 12, 2024
59fdcf1
tests passing
Autoparallel Aug 12, 2024
c1ac3ea
cleaning
Autoparallel Aug 12, 2024
b862535
wip: big example
Autoparallel Aug 12, 2024
2b283a8
bug: fails to parse example.json
Autoparallel Aug 12, 2024
762992c
add basic switch template again
Autoparallel Aug 12, 2024
d544d5c
feat: `GetTopOfStack`
Autoparallel Aug 12, 2024
3f38c79
IT"S LIVING
Autoparallel Aug 13, 2024
449ac72
refactor: use `circomlib` directly
Autoparallel Aug 13, 2024
f4fc944
refactor: JSONs
Autoparallel Aug 13, 2024
e4e256b
redo all in `circuits.json`
Autoparallel Aug 13, 2024
ccb86bf
changeable stack height
Autoparallel Aug 13, 2024
43d0a14
save state
Autoparallel Aug 13, 2024
304987f
reorganize tests
Autoparallel Aug 13, 2024
9e4426c
small cleanup
Autoparallel Aug 13, 2024
70688ba
continuing test cleanup
Autoparallel Aug 13, 2024
dbf5c8f
remove antiquated tests
Autoparallel Aug 13, 2024
38683a3
cleanup
Autoparallel Aug 13, 2024
049d45b
refactor: `language.circom`
Autoparallel Aug 13, 2024
e553e04
todo note
Autoparallel Aug 13, 2024
83ad3a1
Merge branch 'feat/substring-matching' into temp-fetcher
lonerapier Aug 14, 2024
a79fd4e
good save state
Autoparallel Aug 14, 2024
6f5a203
good state!
Autoparallel Aug 14, 2024
37c28bf
Update notes.md
Autoparallel Aug 14, 2024
558ba96
2d stack
Autoparallel Aug 14, 2024
e0f8893
basic array tracking
Autoparallel Aug 14, 2024
33fbe23
tests passing
Autoparallel Aug 14, 2024
7a30f8a
small cleanup
Autoparallel Aug 14, 2024
caa4941
almost there!
Autoparallel Aug 14, 2024
17f1105
arrays!
Autoparallel Aug 14, 2024
7294dd5
satisfying!
Autoparallel Aug 14, 2024
2270ac9
another example
Autoparallel Aug 14, 2024
267e913
Update notes.md
Autoparallel Aug 14, 2024
d83e3ab
Merge branch 'feat/stack-machine' into temp-fetcher
lonerapier Aug 15, 2024
ea18b67
save notes
Autoparallel Aug 15, 2024
e84b196
Squashed commit of the following:
Autoparallel Aug 15, 2024
d5c06e1
WIP: remove `pointer` state
Autoparallel Aug 15, 2024
9b94cd9
WIP: cleaning further
Autoparallel Aug 16, 2024
a34f328
WIP: reduced many variables
Autoparallel Aug 16, 2024
afff6a8
all tests pass
Autoparallel Aug 16, 2024
b7bbc74
updated circuits
Autoparallel Aug 16, 2024
6d10e1b
formatting
Autoparallel Aug 16, 2024
c3e8ef3
Merge branch 'feat/stack-machine' into temp-fetcher
lonerapier Aug 16, 2024
c42e2bb
add zkemail
lonerapier Aug 17, 2024
be08e0d
extracting string yayyy!!!!!
lonerapier Aug 17, 2024
cbb657c
add tests for string extractor
lonerapier Aug 17, 2024
631ea57
parse numbers
lonerapier Aug 18, 2024
ea91ba7
convert unicode number array to number
lonerapier Aug 18, 2024
ebba402
extracting array index
lonerapier Aug 20, 2024
8875441
yay!! multi-depth key extraction done. onto more nested structures noww
lonerapier Aug 21, 2024
62a4dfd
extract nested array working
lonerapier Aug 21, 2024
e67e8dc
add nested structure example circuit
lonerapier Aug 21, 2024
e5f68a8
Merge branch 'main' into temp-fetcher
lonerapier Aug 23, 2024
bfcd828
delete utils
lonerapier Aug 23, 2024
ab1b567
move input generation to separate binary
lonerapier Aug 27, 2024
bdc226e
initial codegen
lonerapier Aug 27, 2024
01c2a79
fix: correct hardcoded signals
lonerapier Aug 27, 2024
fa63840
add codegen example
lonerapier Aug 28, 2024
0a4dd57
remove old code and rename to interpreter
lonerapier Aug 28, 2024
5598c2c
codegen changes
lonerapier Aug 28, 2024
7743775
add test files
lonerapier Aug 28, 2024
2e430dc
feat(codegen): add output filename
lonerapier Aug 28, 2024
c84e46a
complete tests
lonerapier Aug 28, 2024
6ea32ce
Merge branch 'main' into temp-fetcher
lonerapier Aug 28, 2024
34a2b6c
chore(tests): remove duplicate
lonerapier Aug 28, 2024
614d184
chore(docs): interpreter
lonerapier Aug 28, 2024
4aff062
tests: add interpreter
lonerapier Aug 28, 2024
f7a49ce
fix(test): add tests failing in parallel
lonerapier Aug 28, 2024
f2b5a4d
fix(codegen): add poseidon hasher
lonerapier Aug 28, 2024
1dbf8d4
Merge branch 'main' into temp-fetcher
lonerapier Aug 28, 2024
26031e3
refactor: code reorganisation
lonerapier Aug 28, 2024
20ef2b4
experiment with mocha parallel tests
lonerapier Aug 28, 2024
8c3e624
review nits
lonerapier Aug 28, 2024
b8f1e30
handle conflicting files
lonerapier Aug 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ jobs:

- name: Download and install Circom
run: |
CIRCOM_VERSION=2.1.9
CIRCOM_VERSION=2.1.9
curl -L https://github.com/iden3/circom/releases/download/v$CIRCOM_VERSION/circom-linux-amd64 -o circom
chmod +x circom
sudo mv circom /usr/local/bin/
circom --version
circom --version

- name: Run tests
run: npx mocha
run: npm run par-test
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,25 @@ npx circomkit clean extract

All of the above should be ran from repository root.

## Rust Example Witness JSON Creation
To generate example input JSON files for the Circom circuits, you can
```
cargo install --path .
```
to install the `witness` binary.
To get the basic idea, run `witness --help`.
It can process and generate JSON files to be used for the circuits.
For example, if we have a given JSON file we want to parse such as `examples/json/test/example.json` for the `extract` circuit (see `circuits.json`), then we can:
```
witness json --input-file examples/json/test/example.json --output-dir inputs/extract --output-filename input.json
```

For an HTTP request/response, you can generate a JSON input via:
```
witness http --input-file examples/http/get_request.http --output-dir inputs/get_request --output-filename input.json
```
Afterwards, you can run `circomkit compile get_request` then `circomkit witness get_request input`.

## Testing
To test, you can just run
```
Expand Down
37 changes: 21 additions & 16 deletions circuits.json
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
{
"extract": {
"file": "extract",
"template": "Extract",
"file": "parser_json/parser",
"template": "Parser",
"params": [
157,
13
]
},
"value_string": {
"file": "extract",
"template": "Extract",
"file": "parser_json/parser",
"template": "Parser",
"params": [
12,
1
]
},
"value_number": {
"file": "extract",
"template": "Extract",
"file": "parser_json/parser",
"template": "Parser",
"params": [
12,
2
]
},
"value_array": {
"file": "extract",
"template": "Extract",
"file": "parser_json/parser",
"template": "Parser",
"params": [
18,
2
]
},
"value_array_nested": {
"file": "extract",
"template": "Extract",
"file": "parser_json/parser",
"template": "Parser",
"params": [
24,
4
]
},
"value_array_object": {
"file": "extract",
"template": "Extract",
"file": "parser_json/parser",
"template": "Parser",
"params": [
25,
4
]
},
"value_array_object_array": {
"file": "extract",
"template": "Extract",
"file": "parser_json/parser",
"template": "Parser",
"params": [
31,
5
]
},
"value_object": {
"file": "extract",
"template": "Extract",
"file": "parser_json/parser",
"template": "Parser",
"params": [
21,
3
Expand All @@ -70,5 +70,10 @@
787,
10
]
},
"get_request": {
"file": "parser_http_request/parser",
"template": "Parser",
"params": [158]
}
}
49 changes: 49 additions & 0 deletions circuits/http/parser_request/language.circom
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;
}
28 changes: 28 additions & 0 deletions circuits/http/parser_request/machine.circom
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;
}
24 changes: 24 additions & 0 deletions circuits/http/parser_request/parser.circom
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);
}
Loading