@@ -125,13 +125,12 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
125
125
for i in 0 ..MaxNumTokens - 1 {
126
126
next = TranscriptEntry ::from_field (self .transcript [i + 1 ]);
127
127
128
- let next_is_key = ( next .token == KEY_SEPARATOR_TOKEN as Field ) as Field ;
128
+ let next_is_key = next .token == KEY_SEPARATOR_TOKEN as Field ;
129
129
130
130
let valid_token = TOKEN_IS_STRING [cast_num_to_u32 (current .token )];
131
- assert (
132
- (valid_token * next_is_key ) + (1 - next_is_key ) == 1 ,
133
- "Cannot find key/value straddling KEY_DELIMITER_TOKEN" ,
134
- );
131
+ if !valid_token {
132
+ assert (!next_is_key , "Cannot find key/value straddling KEY_DELIMITER_TOKEN" );
133
+ }
135
134
136
135
let old_transcript = self .transcript [i ];
137
136
let new_transcript = TranscriptEntry ::to_field (
@@ -141,9 +140,11 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
141
140
length : current .length ,
142
141
},
143
142
);
144
- let updated_transcript =
145
- (new_transcript - old_transcript ) * next_is_key + old_transcript ;
146
- self .transcript [i ] = updated_transcript ;
143
+ self .transcript [i ] = if next_is_key {
144
+ new_transcript
145
+ } else {
146
+ old_transcript
147
+ };
147
148
148
149
current = next ;
149
150
}
@@ -183,7 +184,7 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
183
184
parent_layer_stack [0 ] =
184
185
is_object as Field * OBJECT_LAYER as Field + is_array as Field * ARRAY_LAYER as Field ;
185
186
assert (
186
- TOKEN_IS_ARRAY_OBJECT_OR_VALUE [cast_num_to_u32 (previous_token )] == 1 ,
187
+ TOKEN_IS_ARRAY_OBJECT_OR_VALUE [cast_num_to_u32 (previous_token )],
187
188
"first json token does not describe an object, array or key" ,
188
189
);
189
190
@@ -206,7 +207,7 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
206
207
207
208
// 1 gate
208
209
// we encode an error flag into `push_layer` by making its value such that `depth` will exceed the size of `parent_layer_stack`
209
- depth = depth + push_layer - pop_layer ;
210
+ depth += push_layer - pop_layer ;
210
211
std:: as_witness (depth );
211
212
212
213
// 6.5 gates
@@ -675,13 +676,15 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
675
676
676
677
// TODO we could make this more efficient...probably not a big deal though
677
678
let first = TranscriptEntry ::from_field (self .transcript [0 ]);
678
- if (first .token == BEGIN_OBJECT_TOKEN as Field ) {
679
- self . layer_type_of_root = OBJECT_LAYER ;
679
+ self . layer_type_of_root = if (first .token == BEGIN_OBJECT_TOKEN as Field ) {
680
+ OBJECT_LAYER
680
681
} else if (first .token == BEGIN_ARRAY_TOKEN as Field ) {
681
- self . layer_type_of_root = ARRAY_LAYER ;
682
+ ARRAY_LAYER
682
683
} else if (first .token == STRING_TOKEN as Field ) {
683
- self .layer_type_of_root = SINGLE_VALUE_LAYER ;
684
- }
684
+ SINGLE_VALUE_LAYER
685
+ } else {
686
+ self .layer_type_of_root
687
+ };
685
688
}
686
689
687
690
fn parse_json <let StringBytes : u32 >(stringbytes : [u8 ; StringBytes ]) -> Self {
0 commit comments