Skip to content

Commit 3c26548

Browse files
committed
remove single layer
1 parent e4a779b commit 3c26548

File tree

5 files changed

+30
-67
lines changed

5 files changed

+30
-67
lines changed

src/_string_tools/slice_packed_field.nr

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -763,11 +763,12 @@ pub fn slice_fields<let InputFields: u32, let OutputFields: u32>(
763763
let mut path: [Field; OutputFields] = [0; OutputFields];
764764
path[0] = (1 - path_valid_output[0] as Field);
765765
for i in 1..OutputFields {
766-
path[i] = path_valid_output[i - 1] as Field - path_valid_output[i] as Field * path_valid_output[i - 1] as Field;
766+
path[i] = path_valid_output[i - 1] as Field
767+
- path_valid_output[i] as Field * path_valid_output[i - 1] as Field;
767768
}
768769

769770
for i in 0..OutputFields {
770-
result[i] = (last_limb - result[i]) * path[i]+ result[i];
771+
result[i] = (last_limb - result[i]) * path[i] + result[i];
771772
}
772773
result
773774
}
@@ -856,7 +857,7 @@ mod test {
856857
for j in 0..18 {
857858
let start_byte: u32 = text.len() - num_bytes - byte_positions[j];
858859
let mut expected_slices: [Field; 3] =
859-
// Safety: this is a test
860+
// Safety: this is a test
860861
unsafe { build_slices_for_test(text, start_byte, num_bytes) };
861862
let result_slices: [Field; 3] =
862863
slice_fields(slices, start_byte as Field, num_bytes as Field);

src/_table_generation/make_tables.nr

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Contains methods used to generate tables in `json_tables.nr`. These table generation methods shouldn't be used inside of actual circuits.
22
use crate::enums::CaptureMode::STRING_CAPTURE;
3-
use crate::enums::Layer::{ARRAY_LAYER, OBJECT_LAYER, SINGLE_VALUE_LAYER};
3+
use crate::enums::Layer::{ARRAY_LAYER, OBJECT_LAYER};
44
use crate::enums::Token::{
55
BEGIN_ARRAY_TOKEN, BEGIN_OBJECT_TOKEN, END_ARRAY_TOKEN, END_OBJECT_TOKEN, KEY_SEPARATOR_TOKEN,
66
KEY_TOKEN, LITERAL_TOKEN, NO_TOKEN, NUM_TOKENS, NUMERIC_TOKEN, STRING_TOKEN,
@@ -60,10 +60,10 @@ unconstrained fn make_ascii_to_token_table() -> [Field; 1024] {
6060
result
6161
}
6262

63-
unconstrained fn make_token_validation_table() -> [Field; NUM_TOKENS * NUM_TOKENS * 3] {
63+
unconstrained fn make_token_validation_table() -> [Field; NUM_TOKENS * NUM_TOKENS * 2] {
6464
// index = layer type, current token and next token
6565
// output is layer type
66-
// 11 tokens , 3 layers = 11 * 11 * 3 = 121 * 3 = 343
66+
// 11 tokens , 2 layers = 11 * 11 * 2 = 121 * 2 = 242
6767
// object contexts
6868
let no_change = ValidationFlags { push_layer: 0, push_layer_type_of_root: 0, pop_layer: 0 };
6969
let error_flags =
@@ -153,9 +153,6 @@ unconstrained fn make_token_validation_table() -> [Field; NUM_TOKENS * NUM_TOKEN
153153

154154
let mut object_layer_flags: [[Field; NUM_TOKENS]; NUM_TOKENS] = [[0; NUM_TOKENS]; NUM_TOKENS];
155155
let mut array_layer_flags: [[Field; NUM_TOKENS]; NUM_TOKENS] = [[0; NUM_TOKENS]; NUM_TOKENS];
156-
let mut single_value_layer_flags: [[Field; NUM_TOKENS]; NUM_TOKENS] =
157-
[[0; NUM_TOKENS]; NUM_TOKENS];
158-
159156
let no_token_outcomes: [Field; NUM_TOKENS] = token_ids.map(|token| {
160157
let mut result = error_flags.to_field();
161158
if (token == NO_TOKEN) {
@@ -264,36 +261,13 @@ unconstrained fn make_token_validation_table() -> [Field; NUM_TOKENS * NUM_TOKEN
264261
array_layer_flags[NUMERIC_TOKEN] = array_layer_value_token_outcomes;
265262
array_layer_flags[LITERAL_TOKEN] = array_layer_value_token_outcomes;
266263
array_layer_flags[KEY_TOKEN] = error_token_outcomes;
267-
268-
let single_value_layer_value_token_outcomes: [Field; NUM_TOKENS] = token_ids.map(|token| {
269-
let mut result = error_flags.to_field();
270-
// we have reached the end of json
271-
if (token == NO_TOKEN) {
272-
result = no_change.to_field();
273-
}
274-
result
275-
});
276-
single_value_layer_flags[NO_TOKEN] = no_token_outcomes;
277-
single_value_layer_flags[BEGIN_OBJECT_TOKEN] = error_token_outcomes;
278-
single_value_layer_flags[END_OBJECT_TOKEN] = single_value_layer_value_token_outcomes;
279-
single_value_layer_flags[BEGIN_ARRAY_TOKEN] = error_token_outcomes;
280-
single_value_layer_flags[END_ARRAY_TOKEN] = single_value_layer_value_token_outcomes;
281-
single_value_layer_flags[KEY_SEPARATOR_TOKEN] = object_layer_key_separator_token_outcomes;
282-
single_value_layer_flags[VALUE_SEPARATOR_TOKEN] = error_token_outcomes;
283-
single_value_layer_flags[STRING_TOKEN] = single_value_layer_value_token_outcomes;
284-
single_value_layer_flags[NUMERIC_TOKEN] = single_value_layer_value_token_outcomes;
285-
single_value_layer_flags[LITERAL_TOKEN] = single_value_layer_value_token_outcomes;
286-
single_value_layer_flags[KEY_TOKEN] = no_token_outcomes;
287-
288-
let mut flattened_flags: [Field; NUM_TOKENS * NUM_TOKENS * 3] =
289-
[0; NUM_TOKENS * NUM_TOKENS * 3];
264+
let mut flattened_flags: [Field; NUM_TOKENS * NUM_TOKENS * 2] =
265+
[0; NUM_TOKENS * NUM_TOKENS * 2];
290266
let NN = (NUM_TOKENS * NUM_TOKENS);
291267
for j in 0..NUM_TOKENS {
292268
for k in 0..NUM_TOKENS {
293269
flattened_flags[OBJECT_LAYER * NN + j * NUM_TOKENS + k] = object_layer_flags[j][k];
294270
flattened_flags[ARRAY_LAYER * NN + j * NUM_TOKENS + k] = array_layer_flags[j][k];
295-
flattened_flags[SINGLE_VALUE_LAYER * NN + j * NUM_TOKENS + k] =
296-
single_value_layer_flags[j][k];
297271
}
298272
}
299273
flattened_flags

src/enums.nr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,4 @@ pub(crate) mod Token {
2525
pub(crate) mod Layer {
2626
pub(crate) global OBJECT_LAYER: u32 = 0;
2727
pub(crate) global ARRAY_LAYER: u32 = 1;
28-
pub(crate) global SINGLE_VALUE_LAYER: u32 = 2;
2928
}

src/json.nr

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::_comparison_tools::bounds_checker::get_validity_flags;
22
use crate::enums::CaptureMode::GRAMMAR_CAPTURE;
3-
use crate::enums::Layer::{ARRAY_LAYER, OBJECT_LAYER, SINGLE_VALUE_LAYER};
3+
use crate::enums::Layer::{ARRAY_LAYER, OBJECT_LAYER};
44
use crate::enums::Token::{
55
BEGIN_ARRAY_TOKEN, BEGIN_OBJECT_TOKEN, KEY_SEPARATOR_TOKEN, KEY_TOKEN, LITERAL_TOKEN,
66
NUM_TOKENS, NUMERIC_TOKEN, STRING_TOKEN,
@@ -52,7 +52,7 @@ pub struct JSON<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u
5252
pub(crate) key_hashes: [Field; MaxNumValues], // a sorted list of key hashes
5353
pub(crate) unsorted_json_entries_packed: [JSONEntryPacked; MaxNumValues], // a list of all the processed json values (objects, arrays, numerics, literals, strings)
5454
pub(crate) json_entries_packed: [JSONEntryPacked; MaxNumValues], // a sorted list of all the processed json values (objects, arrays, numerics, literals, strings)
55-
pub(crate) layer_type_of_root: u32, // is the root an OBJECT_LAYER, ARRAY_LAYER or SINGLE_VALUE_LAYER?
55+
pub(crate) layer_type_of_root: u32, // is the root an OBJECT_LAYER, ARRAY_LAYER
5656
pub(crate) root_id: Field, // the unique identifier of the root (if an object or array)
5757
pub(crate) root_index_in_transcript: u32, // location in json_entries_packed of the root
5858
}
@@ -267,13 +267,14 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
267267
tokens[i] = token;
268268
// 13 gates
269269
let TokenFlags {
270-
create_json_entry,
271-
is_end_of_object_or_array,
272-
is_start_of_object_or_array,
273-
new_context,
274-
is_key_token: update_key,
275-
is_value_token,
276-
preserve_num_entries,} = TokenFlags::from_field(
270+
create_json_entry,
271+
is_end_of_object_or_array,
272+
is_start_of_object_or_array,
273+
new_context,
274+
is_key_token: update_key,
275+
is_value_token,
276+
preserve_num_entries,
277+
} = TokenFlags::from_field(
277278
TOKEN_FLAGS_TABLE[cast_num_to_u32(token) + context * NUM_TOKENS],
278279
);
279280

@@ -455,8 +456,12 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
455456
// 2 gates
456457
let capture_flags = JSON_CAPTURE_TABLE[cast_num_to_u32(encoded_ascii)];
457458
// 5 gates
458-
let ScanData { scan_token, push_transcript, increase_length, is_potential_escape_sequence } =
459-
ScanData::from_field(capture_flags);
459+
let ScanData {
460+
scan_token,
461+
push_transcript,
462+
increase_length,
463+
is_potential_escape_sequence,
464+
} = ScanData::from_field(capture_flags);
460465

461466
// 2 gates
462467
let raw = raw_transcript[cast_num_to_u32(transcript_ptr)];
@@ -591,8 +596,6 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
591596
OBJECT_LAYER
592597
} else if (first.token == BEGIN_ARRAY_TOKEN as Field) {
593598
ARRAY_LAYER
594-
} else if (first.token == STRING_TOKEN as Field) {
595-
SINGLE_VALUE_LAYER
596599
} else {
597600
self.layer_type_of_root
598601
};
@@ -671,8 +674,8 @@ unconstrained fn __build_transcript<let NumBytes: u32, let MaxNumTokens: u32>(
671674
let encoded_ascii = previous_was_potential_escape_sequence as Field * 1024
672675
+ scan_mode * 256
673676
+ ascii as Field;
674-
let ScanData { scan_token, push_transcript, increase_length, is_potential_escape_sequence } =
675-
ScanData::from_field(JSON_CAPTURE_TABLE[cast_num_to_u32(encoded_ascii)]);
677+
let ScanData { scan_token, push_transcript, increase_length, is_potential_escape_sequence }
678+
= ScanData::from_field(JSON_CAPTURE_TABLE[cast_num_to_u32(encoded_ascii)]);
676679

677680
if push_transcript {
678681
let new_entry = RawTranscriptEntry::to_field(

src/json_tables.nr

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,7 +2215,8 @@ pub(crate) global JSON_CAPTURE_TABLE: [Field; 2048] = [
22152215
0x0100000000,
22162216
0x0100000000,
22172217
];
2218-
pub(crate) global TOKEN_VALIDATION_TABLE: [Field; 363] = [
2218+
2219+
pub(crate) global TOKEN_VALIDATION_TABLE: [Field; 242] = [
22192220
0x00, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000,
22202221
0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x010000, 0x01000000, 0x01000000,
22212222
0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x00, 0x00, 0x01000000, 0x010000,
@@ -2245,22 +2246,7 @@ pub(crate) global TOKEN_VALIDATION_TABLE: [Field; 363] = [
22452246
0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000,
22462247
0x010000, 0x01000000, 0x00, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000,
22472248
0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000,
2248-
0x01000000, 0x01000000, 0x00, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000,
2249-
0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000,
2250-
0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000,
2251-
0x00, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000,
2252-
0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000,
2253-
0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x00, 0x01000000,
2254-
0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000,
2255-
0x01000000, 0x01000000, 0x01, 0x01000000, 0x0101, 0x01000000, 0x01000000, 0x01000000, 0x00,
2256-
0x00, 0x00, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000,
2257-
0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x00, 0x01000000, 0x01000000,
2258-
0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000,
2259-
0x00, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000,
2260-
0x01000000, 0x01000000, 0x01000000, 0x00, 0x01000000, 0x01000000, 0x01000000, 0x01000000,
2261-
0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x00, 0x01000000,
2262-
0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000, 0x01000000,
2263-
0x01000000,
2249+
0x01000000, 0x01000000,
22642250
];
22652251

22662252
pub(crate) global ASCII_TO_NUMBER: [u8; 128] = [

0 commit comments

Comments
 (0)