Skip to content

Commit 2f74d12

Browse files
Autoparallellonerapier
authored andcommitted
stack height 12 is under 2**18
1 parent 10c8fd4 commit 2f74d12

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

builds/target_512b/json_extraction_512b.circom

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ pragma circom 2.1.9;
22

33
include "../../circuits/json/extraction.circom";
44

5-
component main { public [step_in] } = JSONExtraction(512, 10, 11);
5+
component main { public [step_in] } = JSONExtraction(512, 12, 11);

circuits/json/hash_machine.circom

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -362,32 +362,34 @@ template RewriteStack(n) {
362362
//--------------------------------------------------------------------------------------------//
363363
// Hash the next_* states to produce hash we need
364364
// TODO: This could be optimized -- we don't really need to do the index selector, we can just accumulate elsewhere
365-
component stateHash[2];
366-
stateHash[0] = IndexSelector(n);
367-
stateHash[0].index <== pointer - 1;
368-
stateHash[1] = IndexSelector(n);
369-
stateHash[1].index <== pointer - 1;
365+
signal stateHash[2][n+1];
366+
stateHash[0][0] <== 0;
367+
stateHash[1][0] <== 0;
368+
// stateHash[0] = IndexSelector(n);
369+
// stateHash[0].index <== pointer - 1;
370+
// stateHash[1] = IndexSelector(n);
371+
// stateHash[1].index <== pointer - 1;
370372
for(var i = 0 ; i < n ; i++) {
371-
stateHash[0].in[i] <== tree_hash[i][0];
372-
stateHash[1].in[i] <== tree_hash[i][1];
373+
stateHash[0][i+1] <== stateHash[0][i] + tree_hash_indicator[i] * tree_hash[i][0];
374+
stateHash[1][i+1] <== stateHash[1][i] + tree_hash_indicator[i] * tree_hash[i][1];
373375
}
374376

375377
signal is_object_key <== IsEqualArray(2)([current_value,[1,0]]);
376378
signal is_object_value <== IsEqualArray(2)([current_value,[1,1]]);
377379
signal is_array <== IsEqual()([current_value[0], 2]);
378380

379381
signal not_to_hash <== IsZero()(parsing_string * next_parsing_string + next_parsing_primitive);
380-
signal hash_0 <== is_object_key * stateHash[0].out; // TODO: I think these may not be needed
381-
signal hash_1 <== (is_object_value + is_array) * stateHash[1].out; // TODO: I think these may not be needed
382+
signal hash_0 <== is_object_key * stateHash[0][n]; // TODO: I think these may not be needed
383+
signal hash_1 <== (is_object_value + is_array) * stateHash[1][n]; // TODO: I think these may not be needed
382384

383385
signal monomial_is_zero <== IsZero()(monomial);
384386
signal increased_power <== monomial * polynomial_input;
385387
next_monomial <== (1 - not_to_hash) * (monomial_is_zero + increased_power); // if monomial is zero and to_hash, then this treats monomial as if it is 1, else we increment the monomial
386388
signal option_hash <== hash_0 + hash_1 + byte * next_monomial;
387389

388390
signal next_state_hash[2];
389-
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];
390-
next_state_hash[1] <== not_to_hash * (stateHash[1].out - option_hash) + option_hash;
391+
next_state_hash[0] <== not_to_hash * (stateHash[0][n] - option_hash) + option_hash; // same as: (1 - not_to_hash[i]) * option_hash[i] + not_to_hash[i] * hash[i];
392+
next_state_hash[1] <== not_to_hash * (stateHash[1][n] - option_hash) + option_hash;
391393
// ^^^^ next_state_hash is the previous value (state_hash) or it is the newly computed value (option_hash)
392394
//--------------------------------------------------------------------------------------------//
393395

@@ -405,7 +407,7 @@ template RewriteStack(n) {
405407
signal to_change_zeroth <== (1 - is_array) * still_parsing_object_key + end_kv;
406408

407409
signal not_end_char_for_first <== IsZero()(readColonAndNotParsingString + readCommaAndNotParsingString + readQuote + (1-next_parsing_primitive));
408-
signal maintain_zeroth <== is_object_value * stateHash[0].out;
410+
signal maintain_zeroth <== is_object_value * stateHash[0][n];
409411
signal to_change_first <== is_object_value + is_array;
410412
// signal tree_hash_change_value[2] <== [not_array_and_not_object_value_and_not_end_kv * next_state_hash[0], to_change_first * next_state_hash[1]];
411413

0 commit comments

Comments
 (0)