From 6f5a203d1abe160fa9129adfd108f813499ebae9 Mon Sep 17 00:00:00 2001 From: Colin Roberts Date: Wed, 14 Aug 2024 13:20:05 -0600 Subject: [PATCH] good state! --- circuits/language.circom | 4 ++-- circuits/parser.circom | 24 ++++++++++++------------ json_examples/test/example_json.md | 3 --- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/circuits/language.circom b/circuits/language.circom index dbaaad4..f9ba54f 100644 --- a/circuits/language.circom +++ b/circuits/language.circom @@ -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 `,` diff --git a/circuits/parser.circom b/circuits/parser.circom index 2dcd468..c484968 100644 --- a/circuits/parser.circom +++ b/circuits/parser.circom @@ -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 @@ -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; } @@ -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 @@ -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 } diff --git a/json_examples/test/example_json.md b/json_examples/test/example_json.md index bd11903..a398ff8 100644 --- a/json_examples/test/example_json.md +++ b/json_examples/test/example_json.md @@ -1,6 +1,3 @@ -# Notes on this JSON for reference - - { "a": // 7 { "b": "c", // 19 "d": { // 25