Skip to content

Commit

Permalink
good state!
Browse files Browse the repository at this point in the history
  • Loading branch information
Autoparallel committed Aug 14, 2024
1 parent a79fd4e commit 6f5a203
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
4 changes: 2 additions & 2 deletions circuits/language.circom
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ template Command() {
// STATE = [pushpop, stack_val, parsing_string, parsing_number]
signal output NOTHING[4] <== [0, 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[4] <== [1, 1, 0, 0 ]; // Command returned by switch if we hit a start brace `{`
signal output END_BRACE[4] <== [-1, 1, 0, -1 ]; // Command returned by switch if we hit a end brace `}`
signal output END_BRACE[4] <== [-1, -1, 0, -1 ]; // Command returned by switch if we hit a end brace `}`
signal output START_BRACKET[4] <== [1, 2, 0, 0 ]; // TODO: Might want `in_value` to toggle. Command returned by switch if we hit a start bracket `[` (TODO: could likely be combined with end bracket)
signal output END_BRACKET[4] <== [-1, 2, 0, -1 ]; // Command returned by switch if we hit a start bracket `]`
signal output END_BRACKET[4] <== [-1, -2, 0, -1 ]; // Command returned by switch if we hit a start bracket `]`
signal output QUOTE[4] <== [0, 0, 1, 0 ]; // TODO: Mightn ot want this to toglle `parsing_array`. Command returned by switch if we hit a quote `"`
signal output COLON[4] <== [1, 3, 0, 0 ]; // Command returned by switch if we hit a colon `:`
signal output COMMA[4] <== [-1, 4, 0, -1 ]; // Command returned by switch if we hit a comma `,`
Expand Down
24 changes: 12 additions & 12 deletions circuits/parser.circom
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ template StateUpdate(MAX_STACK_HEIGHT) {
component numeral_range_check = InRange(8);
numeral_range_check.in <== byte;
numeral_range_check.range <== [48, 57]; // ASCII NUMERALS
log("isNumeral:", numeral_range_check.out);
// log("isNumeral:", numeral_range_check.out);
signal IS_NUMBER <== numeral_range_check.out * Syntax.NUMBER;
matcher.case <== (1 - numeral_range_check.out) * byte + IS_NUMBER; // IF (NOT is_number) THEN byte ELSE 256

Expand Down Expand Up @@ -125,17 +125,17 @@ template StateToMask(n) {
component toParseNumber = Switch(16);
// TODO: Could combine this into something that returns arrays so that we can set the mask more easily.
toParseNumber.branches <== [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
toParseNumber.vals <== [1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0];
toParseNumber.vals <== [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0];
component stateToNum = Bits2Num(4);
stateToNum.in <== [isParsingString.out, isParsingNumber.out, isNumber.out, isDelimeter.out];
// 1 2 4 8
toParseNumber.case <== stateToNum.out;
log("isNumber: ", isNumber.out);
log("isParsingString: ", isParsingString.out);
log("isParsingNumber: ", isParsingNumber.out);
log("isDelimeter: ", isDelimeter.out);
log("stateToNum: ", stateToNum.out);
log("toParseNumber: ", toParseNumber.out);
// log("isNumber: ", isNumber.out);
// log("isParsingString: ", isParsingString.out);
// log("isParsingNumber: ", isParsingNumber.out);
// log("isDelimeter: ", isDelimeter.out);
// log("stateToNum: ", stateToNum.out);
// log("toParseNumber: ", toParseNumber.out);

out[3] <== toParseNumber.out;
}
Expand Down Expand Up @@ -219,10 +219,10 @@ template RewriteStack(n) {
signal isPushAt[n];

component readEndChar = IsZero();
readEndChar.in <== (stack_val - 1) * (stack_val - 2);
readEndChar.in <== (stack_val + 1) * (stack_val + 2);

signal NOT_READ_COMMA <== (1 - readComma.out) * stack_val;
signal READ_COMMA <== readComma.out * ((1-isArray.out) * (3) + isArray.out * (2));
signal READ_COMMA <== readComma.out * ((1-isArray.out) * (-3) + isArray.out * (-2));
signal corrected_stack_val <== READ_COMMA + NOT_READ_COMMA;

// top of stack is a 3, then we need to pop off 3, and check the value underneath
Expand Down Expand Up @@ -259,10 +259,10 @@ template RewriteStack(n) {

// Leave the stack alone except for where we indicate change
second_pop_val[i] <== isPopAtPrev[i] * corrected_stack_val;
temp_val[i] <== corrected_stack_val + (1 + corrected_stack_val) * isDoublePop;
temp_val[i] <== corrected_stack_val - (3 + corrected_stack_val) * isDoublePop;
first_pop_val[i] <== isPopAt[i] * temp_val[i]; // = isPopAt[i] * (corrected_stack_val * (1 - isDoublePop) - 3 * isDoublePop)

next_stack[i] <== stack[i] + isPushAt[i] * corrected_stack_val - first_pop_val[i] - second_pop_val[i];
next_stack[i] <== stack[i] + isPushAt[i] * corrected_stack_val + first_pop_val[i] + second_pop_val[i];

// TODO: Constrain next_stack entries to be 0,1,2,3
}
Expand Down
3 changes: 0 additions & 3 deletions json_examples/test/example_json.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Notes on this JSON for reference


{ "a": // 7
{ "b": "c", // 19
"d": { // 25
Expand Down

0 comments on commit 6f5a203

Please sign in to comment.