You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -134,7 +134,7 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
134
134
}
135
135
136
136
letold_transcript = self.transcript[i];
137
-
// only change is set the token to be KEY_TOKEN
137
+
// The only difference between old_transcript and new_transcript is that the token is set to KEY_TOKEN
138
138
letnew_transcript = TranscriptEntry::to_field(
139
139
TranscriptEntry {
140
140
token: KEY_TOKENasField,
@@ -228,40 +228,6 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
228
228
assert(depth == 0, "validate_tokens: unclosed objects or arrays");
229
229
}
230
230
231
-
/// Parses [`Self::transcript`] to populate [`Self::json_entries_packed`] and [`Self::key_data`]
232
-
/// Given a processed transcript of json tokens, compute a list of json entries that describes the values within the JSON blob
233
-
///
234
-
/// [`Self::json_entries_packed`] is a [JSONEntry] struct whose members have been packed into a single Field element.
235
-
///
236
-
/// A 'value' here is either an Object, Array, String, Numeric or Literal.
237
-
/// e.g. "[ 1, 2, 3 ]" contains 4 values (3 Numeric types and the Array that contains them)
238
-
///
239
-
/// To avoid branches and if statements, we construct a state transition function out of the lookup table TOKEN_FLAGS_TABLE
240
-
/// This table takes as an input the following:
241
-
/// 1. The token value of an element in the transcript
242
-
/// 2. The layer type the previous token is located in (i.e. are we in an array or an object?)
243
-
/// The table outputs the following data:
244
-
/// 1. Should we create a new json entry? (i.e. is the token a STRING_TOKEN, LITERAL_TOKEN, NUMERIC_TOKEN, END_ARRAY_TOKEN, END_OBJECT_TOKEN)
245
-
/// 2. Is the token `}` or `]`?
246
-
/// 3. Is the token `{` or `[`?
247
-
/// 4. Given the current layer type and the token being queried, what should the new layer type be?
248
-
/// 5. Is the token `KEY_TOKEN`?
249
-
/// 6. Is the token a `STRING_TOKEN`, `NUMERIC_TOKEN` OR `VALUE_TOKEN`?
250
-
/// 7. Is the token one that we should skip over? `,` or `:`
251
-
///
252
-
/// ## explanation of `parent_context_stack`
253
-
/// When recording a JSONEntry, we need to understand how many children (if any) a JSONEntry has,
254
-
/// as well as a way of accessing children given the parent JSONEntry object
255
-
/// Note: OBJECT_TOKEN and ARRAY_TOKEN have children. single values (NUMERIC_TOKEN, LITERAL_TOKEN, STRING_TOKEN) do not.
256
-
/// We define a "context stack" via `parent_context_stack` to track this data.
257
-
/// The front of `parent_context_stack` contains a JSONContextStackEntry (packed into a single Field for the purposes of efficient lookups) for the current parent
258
-
/// If we parse a token that creates a new parent (BEGIN_OBJECT_TOKEN or BEGIN_ARRAY_TOKEN), we push a new parent onto the stack
259
-
/// If we reach the end of an object or array (END_OBJECT_TOKEN, END_ARRAY_TOKEN) we pop the current parent off of the stack
260
-
/// Note: "stack" is used loosely here. We have a fixed-size array of packed JSONContextStackEntry vals and a pointer to the head of the stack.
261
-
/// (the array size defines the maximum number of entities the stack can contain, currently set at 32)
262
-
/// Note: the size param `32` is a magic number we should replace with a defined const global variable
263
-
/// To push: we increment the pointer by 1 and write a new entry at the pointer value
264
-
/// To pop: we decrement the pointer by 1 (we don't need to delete data because new data is written every time the pointer is incremented)
265
231
/// Parses [`Self::transcript`] to populate [`Self::json_entries_packed`] and [`Self::key_data`]
266
232
/// Given a processed transcript of json tokens, compute a list of json entries that describes the values within the JSON blob
267
233
///
@@ -303,11 +269,8 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
303
269
// Note: parent_context_stack[0] = the root JSON object
304
270
letmut depth: Field = 1;
305
271
// how many children does the current parent have?
306
-
// how many children does the current parent have?
307
272
letmut num_entries_at_current_depth: Field = 0;
308
273
309
-
// current_identity_value = unique identifier for all JSON objects/arrays we create
310
-
311
274
// current_identity_value = unique identifier for all JSON objects/arrays we create
312
275
letmut current_identity_value: Field = 0;
313
276
// next_identity_value = smallest integer that we've not yet assigned as a unique identifier to the JSON objects/arrays we create
@@ -316,11 +279,6 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
316
279
// context: 0 for object, 1 for array
317
280
letmut context = OBJECT_LAYER;
318
281
319
-
// current_key_index_and_length encodes 2 bits of data in a single Field element (to save some gates)
320
-
// note: would be more readable if we had a custom struct that wrapped a Field element with defined update methods
321
-
// 1. what is the key index? (index = unique identifier, starts at 0)
322
-
// 2. what is the size of the key in bytes?
323
-
// current_key_index_and_length = index + length * 0x10000 (assumes index does not exceed 2^16. I don't think we check for this, there is an assumption that the size of the circuit would be too large to compile/run if the JSON blob has over 2^16 unique keys)
324
282
// current_key_index_and_length encodes 2 bits of data in a single Field element (to save some gates)
325
283
// note: would be more readable if we had a custom struct that wrapped a Field element with defined update methods
326
284
// 1. what is the key index? (index = unique identifier, starts at 0)
@@ -352,33 +310,19 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
@@ -699,8 +606,7 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
699
606
// 2 gates
700
607
letraw: Field = raw_transcript[cast_num_to_u32(transcript_ptr)];
701
608
702
-
// TODO: document this
703
-
// TODO: why are we comparing a derived quantity against `raw_transcript` instead of constructing `raw_transcript` directly (faster)
609
+
// Compare a derived quantity against `raw_transcript` instead of constructing `raw_transcript` directly to avoid writing to arrays in a constrained function
0 commit comments