Skip to content

Commit

Permalink
wip: brain hurty
Browse files Browse the repository at this point in the history
left a note to myself
  • Loading branch information
Autoparallel committed Nov 22, 2024
1 parent 7075dc1 commit d41b22f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
4 changes: 4 additions & 0 deletions circuits/json/parser/hash_machine.circom
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,12 @@ template RewriteStack(n) {
signal hash_0 <== is_object_key * stateHash[0].out;
signal hash_1 <== (is_object_value + is_array) * stateHash[1].out;
signal option_hash;
log("hash_0 + hash_1 = ", hash_0 + hash_1);
option_hash <== PoseidonChainer()([hash_0 + hash_1, byte]); // TODO: Trying this now so we just hash the byte stream of KVs
// option_hash <== PoseidonChainer()([stateHash[1].out, byte]); // TODO: Now we are double hashing, we certainly don't need to do this, so should optimize this out
log("to_hash: ", (1-not_to_hash));
signal next_state_hash[2];
log("option_hash = ", option_hash);
next_state_hash[0] <== not_to_hash * (stateHash[0].out - option_hash) + option_hash; // same as: (1 - not_to_hash[i]) * option_hash[i] + not_to_hash[i] * hash[i];
next_state_hash[1] <== not_to_hash * (stateHash[1].out - option_hash) + option_hash;
// ^^^^ next_state_hash is the previous value (state_hash) or it is the newly computed value (option_hash)
Expand All @@ -383,6 +385,8 @@ template RewriteStack(n) {
signal to_change_first <== (not_end_char_for_first + still_parsing_string) * (is_object_value + is_array);
signal tree_hash_change_value[2] <== [to_change_zeroth * next_state_hash[0], to_change_first * next_state_hash[1]];


// TODO (autoparallel): Okay, this isn't clearing off the previous hash value and is instead adding them to each other. I suppose this isn't wrong, but it's not what is intended. I really need to refactor this shit.
for(var i = 0; i < n; i++) {
next_stack[i][0] <== stack[i][0] + indicator[i] * stack_change_value[0];
second_index_clear[i] <== stack[i][1] * (readEndBrace + readEndBracket); // Checking if we read some end char
Expand Down
52 changes: 26 additions & 26 deletions circuits/test/json/parser/hash_machine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import { PoseidonModular } from "../../common/poseidon";
describe("hash_machine", () => {
let circuit: WitnessTester<["data"]>;

it(`array_only_input`, async () => {
let filename = "array_only";
let [input, keyUnicode, output] = readJSONInputFile(`${filename}.json`, [0]);
// it(`array_only_input`, async () => {
// let filename = "array_only";
// let [input, keyUnicode, output] = readJSONInputFile(`${filename}.json`, [0]);

circuit = await circomkit.WitnessTester(`Parser`, {
file: "json/parser/hash_parser",
template: "ParserHasher",
params: [input.length, 3],
});
console.log("#constraints:", await circuit.getConstraintCount());
// circuit = await circomkit.WitnessTester(`Parser`, {
// file: "json/parser/hash_parser",
// template: "ParserHasher",
// params: [input.length, 3],
// });
// console.log("#constraints:", await circuit.getConstraintCount());

await circuit.expectPass({
data: input
});
});
// await circuit.expectPass({
// data: input
// });
// });

// Numbers for the 42 read in 0th index
console.log("[0,\"4\"] hash: ", PoseidonModular([0, 52]));
Expand Down Expand Up @@ -56,19 +56,19 @@ describe("hash_machine", () => {
// });


// it(`spotify_input`, async () => {
// let filename = "spotify";
// let [input, keyUnicode, output] = readJSONInputFile(`${filename}.json`, ["data"]);
it(`spotify_input`, async () => {
let filename = "spotify";
let [input, keyUnicode, output] = readJSONInputFile(`${filename}.json`, ["data"]);

// circuit = await circomkit.WitnessTester(`Parser`, {
// file: "json/parser/hash_parser",
// template: "ParserHasher",
// params: [input.length, 7],
// });
// console.log("#constraints:", await circuit.getConstraintCount());
circuit = await circomkit.WitnessTester(`Parser`, {
file: "json/parser/hash_parser",
template: "ParserHasher",
params: [input.length, 7],
});
console.log("#constraints:", await circuit.getConstraintCount());

// await circuit.expectPass({
// data: input
// });
// });
await circuit.expectPass({
data: input
});
});
})

0 comments on commit d41b22f

Please sign in to comment.