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: stack machine #18

Merged
merged 101 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 97 commits
Commits
Show all changes
101 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
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
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
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
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
2cd22ce
cut down on constraints
Autoparallel Aug 16, 2024
019fcd8
save state
Autoparallel Aug 16, 2024
6cfe96b
lots of cleanup
Autoparallel Aug 16, 2024
65e3a6a
Delete mask.test.ts
Autoparallel Aug 16, 2024
957922a
example test
Autoparallel Aug 16, 2024
2e229c7
Squashed commit of the following:
Autoparallel Aug 20, 2024
8a7d334
docs + refactor: `parser`
Autoparallel Aug 22, 2024
91c3564
redo instruction
Autoparallel Aug 22, 2024
167da25
add documentation
Autoparallel Aug 22, 2024
9c71481
Update parser.circom
Autoparallel Aug 22, 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

node_modules/*

# Circomkit generated
build/*
ptau/*
circuits/test/*.circom
circuits/main/*

# Rust generated
inputs/**/*.json
52 changes: 34 additions & 18 deletions circuits.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,66 @@
{
"test_extract": {
"extract": {
"file": "extract",
"template": "Extract",
"params": [
4,
21
157,
13
]
},
"test_extract_two_key": {
"value_string": {
"file": "extract",
"template": "Extract",
"params": [
4,
40
12,
1
]
},
"test_extract_depth": {
"value_number": {
"file": "extract",
"template": "Extract",
"params": [
4,
64
12,
2
]
},
"test_extract_sambhav": {
"value_array": {
"file": "extract",
"template": "Extract",
"params": [
4,
105
18,
2
]
},
"test_extract_hard": {
"value_array_nested": {
"file": "extract",
"template": "Extract",
"params": [
4,
48
24,
4
]
},
"extract": {
"value_array_object": {
"file": "extract",
"template": "Extract",
"params": [
25,
4
]
},
"value_array_object_array": {
"file": "extract",
"template": "Extract",
"params": [
31,
5
]
},
"value_object": {
"file": "extract",
"template": "Extract",
"params": [
10,
787
21,
3
]
}
}
58 changes: 0 additions & 58 deletions circuits/bytes.circom

This file was deleted.

65 changes: 32 additions & 33 deletions circuits/extract.circom
Original file line number Diff line number Diff line change
@@ -1,54 +1,53 @@
pragma circom 2.1.9;

include "bytes.circom";
include "operators.circom";
include "utils.circom";
include "parser.circom";

template Extract(KEY_BYTES, DATA_BYTES) {
signal input key[KEY_BYTES];
template Extract(DATA_BYTES, MAX_STACK_HEIGHT) {
signal input data[DATA_BYTES];
signal output KeyMatches[DATA_BYTES - KEY_BYTES];

// TODO: Add assertions on the inputs here!

//--------------------------------------------------------------------------------------------//
//-CONSTRAINTS--------------------------------------------------------------------------------//
//--------------------------------------------------------------------------------------------//
// Working with a single key for now to do substring matching
component keyASCII = ASCII(KEY_BYTES);
keyASCII.in <== key;

//--------------------------------------------------------------------------------------------//
component dataASCII = ASCII(DATA_BYTES);
dataASCII.in <== data;
//--------------------------------------------------------------------------------------------//
// Initialze the parser
component State[DATA_BYTES];
State[0] = StateUpdate();
State[0].byte <== data[0];
State[0].tree_depth <== 0;
State[0].parsing_key <== 0;
State[0].inside_key <== 0;
State[0].parsing_value <== 0;
State[0].inside_value <== 0;

for(var data_pointer = 1; data_pointer < DATA_BYTES; data_pointer++) {
State[data_pointer] = StateUpdate();
State[data_pointer].byte <== data[data_pointer];
State[data_pointer].tree_depth <== State[data_pointer - 1].next_tree_depth;
State[data_pointer].parsing_key <== State[data_pointer - 1].next_parsing_key;
State[data_pointer].inside_key <== State[data_pointer - 1].next_inside_key;
State[data_pointer].parsing_value <== State[data_pointer - 1].next_parsing_value;
State[data_pointer].inside_value <== State[data_pointer - 1].next_inside_value;
State[0] = StateUpdate(MAX_STACK_HEIGHT);
State[0].byte <== data[0];
for(var i = 0; i < MAX_STACK_HEIGHT; i++) {
State[0].stack[i] <== [0,0];
}
State[0].parsing_string <== 0;
State[0].parsing_number <== 0;

for(var data_idx = 1; data_idx < DATA_BYTES; data_idx++) {
State[data_idx] = StateUpdate(MAX_STACK_HEIGHT);
State[data_idx].byte <== data[data_idx];
State[data_idx].stack <== State[data_idx - 1].next_stack;
State[data_idx].parsing_string <== State[data_idx - 1].next_parsing_string;
State[data_idx].parsing_number <== State[data_idx - 1].next_parsing_number;

// Debugging
log("State[", data_pointer, "].tree_depth", "= ", State[data_pointer].tree_depth);
log("State[", data_pointer, "].parsing_key", "= ", State[data_pointer].parsing_key);
log("State[", data_pointer, "].inside_key", "= ", State[data_pointer].inside_key);
log("State[", data_pointer, "].parsing_value", "= ", State[data_pointer].parsing_value);
log("State[", data_pointer, "].inside_value", "= ", State[data_pointer].inside_value);
log("---");
for(var i = 0; i<MAX_STACK_HEIGHT; i++) {
log("State[", data_idx, "].stack[", i,"] ", "= [",State[data_idx].stack[i][0], "][", State[data_idx].stack[i][1],"]" );
}
log("State[", data_idx, "].parsing_string", "= ", State[data_idx].parsing_string);
log("State[", data_idx, "].parsing_number", "= ", State[data_idx].parsing_number);
log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
}

// Constrain to have valid JSON (TODO: more is needed)
State[DATA_BYTES - 1].next_tree_depth === 0;
// State[DATA_BYTES - 1].next_tree_depth === 0;

// Debugging
for(var i = 0; i < MAX_STACK_HEIGHT; i++) {
log("State[", DATA_BYTES, "].stack[", i,"] ", "= [",State[DATA_BYTES -1].next_stack[i][0], "][", State[DATA_BYTES - 1].next_stack[i][1],"]" );
}
log("State[", DATA_BYTES, "].parsing_string", "= ", State[DATA_BYTES-1].next_parsing_string);
log("State[", DATA_BYTES, "].parsing_number", "= ", State[DATA_BYTES-1].next_parsing_number);
log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
}
42 changes: 42 additions & 0 deletions circuits/language.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
pragma circom 2.1.9;

template Syntax() {
//-Delimeters---------------------------------------------------------------------------------//
// - ASCII char: `{`
signal output START_BRACE <== 123;
// - ASCII char: `}`
signal output END_BRACE <== 125;
// - ASCII char `[`
signal output START_BRACKET <== 91;
// - ASCII char `]`
signal output END_BRACKET <== 93;
// - ASCII char `"`
signal output QUOTE <== 34;
// - ASCII char `:`
signal output COLON <== 58;
// - ASCII char `,`
signal output COMMA <== 44;
//-White_space--------------------------------------------------------------------------------//
// - ASCII char: `\n`
signal output NEWLINE <== 10;
// - ASCII char: ` `
signal output SPACE <== 32;
//-Escape-------------------------------------------------------------------------------------//
// - ASCII char: `\`
signal output ESCAPE <== 92;
//-Number_Remapping---------------------------------------------------------------------------//
signal output NUMBER <== 256; // past a u8 -- reserved for ANY numerical ASCII (48 - 57)
}

template Command() {
// STATE = [read_write_value, parsing_string, parsing_number]
signal output NOTHING[3] <== [0, 0, -1 ]; // Command returned by switch if we want to do nothing, e.g. read a whitespace char while looking for a key
signal output START_BRACE[3] <== [1, 0, 0 ]; // Command returned by switch if we hit a start brace `{`
signal output END_BRACE[3] <== [-1, 0, -1 ]; // Command returned by switch if we hit a end brace `}`
signal output START_BRACKET[3] <== [2, 0, 0 ]; // Command returned by switch if we hit a start bracket `[`
signal output END_BRACKET[3] <== [-2, 0, -1 ]; // Command returned by switch if we hit a start bracket `]`
signal output QUOTE[3] <== [0, 1, 0 ]; // Command returned by switch if we hit a quote `"`
signal output COLON[3] <== [3, 0, 0 ]; // Command returned by switch if we hit a colon `:`
signal output COMMA[3] <== [4, 0, -1 ]; // Command returned by switch if we hit a comma `,`
signal output NUMBER[3] <== [256, 0, 1 ]; // Command returned by switch if we hit some decimal number (e.g., ASCII 48-57)
}
Loading
Loading