diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6ffba86..d8ab990 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,7 @@ jobs: strategy: fail-fast: false matrix: - toolchain: [nightly, 0.32.0] + toolchain: [nightly, 0.34.0] steps: - name: Checkout sources uses: actions/checkout@v4 @@ -38,7 +38,7 @@ jobs: - name: Install Nargo uses: noir-lang/noirup@v0.1.3 with: - toolchain: 0.32.0 + toolchain: 0.34.0 - name: Run formatter run: nargo fmt --check diff --git a/Nargo.toml b/Nargo.toml index 19c6baf..16b6578 100644 --- a/Nargo.toml +++ b/Nargo.toml @@ -2,7 +2,7 @@ name = "json_parser" type = "lib" authors = [""] -compiler_version = ">=0.32.0" +compiler_version = ">=0.34.0" [dependencies] noir_sort = {tag = "v0.1.0", git = "https://github.com/noir-lang/noir_sort"} \ No newline at end of file diff --git a/src/_string_tools/slice_field.nr b/src/_string_tools/slice_field.nr index ebbc47e..eac3be1 100644 --- a/src/_string_tools/slice_field.nr +++ b/src/_string_tools/slice_field.nr @@ -8,7 +8,7 @@ struct Slice200 { hihi: u64, // 7 bytes hilo: u64, // 7 bytes lohi: u64, // 7 bytes - lolo: u32 // 4 bytes + lolo: u32 // 4 bytes } global PHI_54: u64 = 0x30644E72E131A0; global PLO_200: Slice200 = Slice200 { @@ -19,7 +19,7 @@ global PLO_200: Slice200 = Slice200 { }; unconstrained fn __slice_200_bits_from_field(f: Field) -> (Field, Field, bool) { - let b = f.to_be_bytes(32); + let b: [u8; 32] = f.to_be_bytes(); let mut res200: Slice200 = Slice200 { hihi: 0, hilo: 0, lohi: 0, lolo: 0 }; let mut res54: u64 = 0; @@ -74,4 +74,3 @@ pub fn slice_200_bits_from_field(f: Field) -> Field { hi_diff.assert_max_bit_size(56); lo } - diff --git a/src/_string_tools/slice_packed_field.nr b/src/_string_tools/slice_packed_field.nr index 6eba030..688bb6a 100644 --- a/src/_string_tools/slice_packed_field.nr +++ b/src/_string_tools/slice_packed_field.nr @@ -371,7 +371,7 @@ global PATH_LOOKUP: [[bool; 5]; 32] = [ **/ unconstrained fn __slice_field(f: Field, num_bytes: Field) -> [Field; 5] { let head_path = PATH_LOOKUP[num_bytes]; - let bytes = f.to_be_bytes(32); + let bytes: [u8; 32] = f.to_be_bytes(); let bytes = bytes.map(|b: u8| b as Field); let mut chunks: [Field; 5] = [0; 5]; @@ -401,14 +401,14 @@ unconstrained fn __slice_field(f: Field, num_bytes: Field) -> [Field; 5] { tail_ptr += 4; } if head_path[3] { - chunks[3] = + chunks[3] = bytes[head_ptr] * 0x100000000000000 + bytes[head_ptr + 1] * 0x1000000000000 + bytes[head_ptr + 2] * 0x10000000000 + bytes[head_ptr + 3] * 0x100000000 + bytes[head_ptr + 4] * 0x1000000 + bytes[head_ptr + 5] * 0x10000 + bytes[head_ptr + 6] * 0x100 + bytes[head_ptr + 7]; head_ptr += 8; } else { - chunks[3] = + chunks[3] = bytes[tail_ptr] * 0x100000000000000 + bytes[tail_ptr + 1] * 0x1000000000000 + bytes[tail_ptr + 2] * 0x10000000000 + bytes[tail_ptr + 3] * 0x100000000 + bytes[tail_ptr + 4] * 0x1000000 + bytes[tail_ptr + 5] * 0x10000 @@ -416,7 +416,7 @@ unconstrained fn __slice_field(f: Field, num_bytes: Field) -> [Field; 5] { tail_ptr += 8; } if head_path[4] { - chunks[4] = + chunks[4] = bytes[head_ptr] * 0x1000000000000000000000000000000 + bytes[head_ptr + 1] * 0x10000000000000000000000000000 + bytes[head_ptr + 2] * 0x100000000000000000000000000 + bytes[head_ptr + 3] * 0x1000000000000000000000000 + bytes[head_ptr + 4] * 0x10000000000000000000000 + bytes[head_ptr + 5] * 0x100000000000000000000 @@ -426,7 +426,7 @@ unconstrained fn __slice_field(f: Field, num_bytes: Field) -> [Field; 5] { + bytes[head_ptr + 12] * 0x1000000 + bytes[head_ptr + 13] * 0x10000 + bytes[head_ptr + 14] * 0x100 + bytes[head_ptr + 15]; } else { - chunks[4] = + chunks[4] = bytes[tail_ptr] * 0x1000000000000000000000000000000 + bytes[tail_ptr + 1] * 0x10000000000000000000000000000 + bytes[tail_ptr + 2] * 0x100000000000000000000000000 + bytes[tail_ptr + 3] * 0x1000000000000000000000000 + bytes[tail_ptr + 4] * 0x10000000000000000000000 + bytes[tail_ptr + 5] * 0x100000000000000000000 @@ -548,7 +548,7 @@ pub fn slice_field(f: Field, num_bytes: Field) -> (Field, Field) { /** * @brief Given an array of fields that pack 31 bytes, return an array that slices the packed byte array at a given index for a given number of bytes - * @description Some serious dark black magic nonsense going on here. TODO: document + * @description Some serious dark black magic nonsense going on here. TODO: document **/ pub fn slice_fields( data: [Field; InputFields], @@ -783,7 +783,7 @@ fn test_slice_fields() { fn test_slice_field() { let input = 0xffeebbccbbaa99887766554433221100112233445566778899aabbccddeeff; - let input_bytes: [u8; 32] = input.to_be_bytes(32).as_array(); + let input_bytes: [u8; 32] = input.to_be_bytes(); for i in 0..32 { println(f"i = {i}"); diff --git a/src/_string_tools/string_chopper.nr b/src/_string_tools/string_chopper.nr index 7119b79..58cdda7 100644 --- a/src/_string_tools/string_chopper.nr +++ b/src/_string_tools/string_chopper.nr @@ -13,7 +13,7 @@ impl StringChopper { let sliced: [Field; NeedlePackedFields] = slice_fields(haystack, start_bytes, num_bytes); - let sliced_bytes = sliced.map(|x: Field| { let r: [u8; 31] = x.to_be_bytes(31).as_array(); r }); + let sliced_bytes = sliced.map(|x: Field| { let r: [u8; 31] = x.to_be_bytes(); r }); let num_slices = StringBytes / 31; let overflow = StringBytes % 31; @@ -28,4 +28,3 @@ impl StringChopper { parsed_string } } - diff --git a/src/_table_generation/make_tables.nr b/src/_table_generation/make_tables.nr index 88486b4..2066750 100644 --- a/src/_table_generation/make_tables.nr +++ b/src/_table_generation/make_tables.nr @@ -1,6 +1,4 @@ -/** - * @file Contains methods used to generate tables in `json_tables.nr`. These table generation methods shouldn't be used inside of actual circuits. - **/ +//! Contains methods used to generate tables in `json_tables.nr`. These table generation methods shouldn't be used inside of actual circuits. mod CaptureMode { global GRAMMAR_CAPTURE = 0; diff --git a/src/getters.nr b/src/getters.nr index 702d77a..b75392f 100644 --- a/src/getters.nr +++ b/src/getters.nr @@ -27,7 +27,7 @@ impl which will be null if the entry does not exist + * @description returns an Option which will be null if the entry does not exist **/ fn get_json_entry(self, key: [u8; KeyBytes]) -> (bool, JSONEntry) { // let key_index = self.find_key_in_map(keyhash); @@ -251,7 +251,7 @@ impl KeySearchResult { let mut found_index: Field = 0; @@ -322,7 +322,7 @@ impl last entry - case 3: entry A > keyhash > entryB + case 3: entry A > keyhash > entryB */ let hasher: ByteHasher = ByteHasher {}; @@ -380,7 +380,7 @@ impl last entry - case 3: entry A > keyhash > entryB + case 3: entry A > keyhash > entryB */ let hasher: ByteHasher = ByteHasher {}; @@ -424,7 +424,7 @@ impl(self) -> BoundedVec { + unconstrained fn __get_keys_at_root(self) -> BoundedVec { let mut result: BoundedVec = BoundedVec { len: 0, storage: [0; MaxNumKeys] }; let root_object: JSONEntry = JSONEntry::from(self.json_entries_packed[self.root_index_in_transcript]); diff --git a/src/json.nr b/src/json.nr index 235409d..e7e5e96 100644 --- a/src/json.nr +++ b/src/json.nr @@ -61,16 +61,18 @@ struct JSON std::cmp::Eq for JSON { fn eq(self, other: Self) -> bool { - (self.json == other.json) & (self.raw_transcript == other.raw_transcript) - & (self.transcript == other.transcript) - & (self.transcript_length == other.transcript_length) - & (self.key_data == other.key_data) - & (self.key_hashes == other.key_hashes) - & (self.layer_type_of_root == other.layer_type_of_root) - & (self.root_id == other.root_id) - & (self.root_index_in_transcript == other.root_index_in_transcript) - & (self.json_entries_packed == other.json_entries_packed) - & (self.json_packed == other.json_packed) + (self.json == other.json) + & (self.raw_transcript == other.raw_transcript) + & (self.transcript == other.transcript) + & (self.transcript_length == other.transcript_length) + & (self.key_data == other.key_data) + & (self.key_hashes == other.key_hashes) + & (self.layer_type_of_root == other.layer_type_of_root) + & (self.root_id == other.root_id) + & (self.root_index_in_transcript + == other.root_index_in_transcript) + & (self.json_entries_packed == other.json_entries_packed) + & (self.json_packed == other.json_packed) } } diff --git a/src/json_entry.nr b/src/json_entry.nr index 56a6e26..5c3f462 100644 --- a/src/json_entry.nr +++ b/src/json_entry.nr @@ -10,7 +10,7 @@ struct JSONContextStackEntry { } impl JSONContextStackEntry { unconstrained fn __from_field(f: Field) -> Self { - let bytes = f.to_be_bytes(11); + let bytes: [u8; 11] = f.to_be_bytes(); let context = bytes[0] as Field; let num_entries = bytes[1] as Field * 0x100 + bytes[2] as Field; let current_key_length = bytes[3] as Field * 0x100 + bytes[4] as Field; @@ -59,7 +59,7 @@ struct JSONEntry { entry_type: Field, // is this an OBJECT_TOKEN, ARRAY_TOKEN, STRING_TOKEN, NUMERIC_TOKEN or LITERAL_TOKEN? id: Field, // if this is an object or array, describes the unique identifier assigned to this item parent_index: Field, // if parent is an object or array, describes the unique identifier assigned to our parent - array_pointer: Field, // if parent is an array, where in the array are we? + array_pointer: Field, // if parent is an array, where in the array are we? child_pointer: Field, // if this is an object or array, points to the location in `json_entries_packed` of this item's first child num_children: Field, // if this is an object or array, how many child elements do we contain? json_pointer: Field, // points to the json that describes the first byte of this entry @@ -145,7 +145,7 @@ impl JSONEntry { parent_index } unconstrained fn __from_field(f: Field) -> Self { - let bytes: [u8; 20] = f.to_be_bytes(20).as_array(); // 10.5 gates + let bytes: [u8; 20] = f.to_be_bytes(); // 10.5 gates let entry_type = bytes[0] as Field; @@ -230,6 +230,7 @@ impl std::cmp::Eq for JSONEntryPacked { } impl std::default::Default for JSONEntryPacked { - fn default() -> Self { JSONEntryPacked{ value: 0 }} + fn default() -> Self { + JSONEntryPacked { value: 0 } + } } - diff --git a/src/keymap.nr b/src/keymap.nr index d9ab7cd..938d873 100644 --- a/src/keymap.nr +++ b/src/keymap.nr @@ -26,7 +26,7 @@ impl KeyIndexData { } unconstrained fn __from_field(packed: Field) -> Self { - let unpacked = packed.to_be_bytes(8); + let unpacked: [u8; 8] = packed.to_be_bytes(); let array_index: Field = unpacked[1] as Field + unpacked[0] as Field * 0x100; let json_length: Field = unpacked[3] as Field + unpacked[2] as Field * 0x100; let json_index: Field = unpacked[5] as Field + unpacked[4] as Field * 0x100; diff --git a/src/lib.nr b/src/lib.nr index 1613561..b89bf3b 100644 --- a/src/lib.nr +++ b/src/lib.nr @@ -196,8 +196,10 @@ mod JSON512b { fn get_string_from_array_unchecked(self, array_index: Field) -> BoundedVec { self.inner.get_string_from_array_unchecked(array_index) } - fn get_string_from_path(self, keys: [BoundedVec; PathDepth]) -> Option> - { + fn get_string_from_path( + self, + keys: [BoundedVec; PathDepth] + ) -> Option> { self.inner.get_string_from_path(keys) } fn get_value(self, key: [u8; KeyBytes]) -> Option> { @@ -218,11 +220,13 @@ mod JSON512b { fn get_value_from_array_unchecked(self, array_index: Field) -> crate::JSONValue { self.inner.get_value_from_array_unchecked(array_index) } - fn get_value_from_path(self, keys: [BoundedVec; PathDepth]) -> Option> - { + fn get_value_from_path( + self, + keys: [BoundedVec; PathDepth] + ) -> Option> { self.inner.get_value_from_path(keys) } - + fn key_exists(self, key: BoundedVec) -> bool { self.inner.key_exists(key) } @@ -355,8 +359,10 @@ mod JSON1kb { fn get_string_from_array_unchecked(self, array_index: Field) -> BoundedVec { self.inner.get_string_from_array_unchecked(array_index) } - fn get_string_from_path(self, keys: [BoundedVec; PathDepth]) -> Option> - { + fn get_string_from_path( + self, + keys: [BoundedVec; PathDepth] + ) -> Option> { self.inner.get_string_from_path(keys) } fn get_value(self, key: [u8; KeyBytes]) -> Option> { @@ -377,8 +383,10 @@ mod JSON1kb { fn get_value_from_array_unchecked(self, array_index: Field) -> crate::JSONValue { self.inner.get_value_from_array_unchecked(array_index) } - fn get_value_from_path(self, keys: [BoundedVec; PathDepth]) -> Option> - { + fn get_value_from_path( + self, + keys: [BoundedVec; PathDepth] + ) -> Option> { self.inner.get_value_from_path(keys) } fn key_exists(self, key: BoundedVec) -> bool { @@ -513,8 +521,10 @@ mod JSON2kb { fn get_string_from_array_unchecked(self, array_index: Field) -> BoundedVec { self.inner.get_string_from_array_unchecked(array_index) } - fn get_string_from_path(self, keys: [BoundedVec; PathDepth]) -> Option> - { + fn get_string_from_path( + self, + keys: [BoundedVec; PathDepth] + ) -> Option> { self.inner.get_string_from_path(keys) } fn get_value(self, key: [u8; KeyBytes]) -> Option> { @@ -535,8 +545,10 @@ mod JSON2kb { fn get_value_from_array_unchecked(self, array_index: Field) -> crate::JSONValue { self.inner.get_value_from_array_unchecked(array_index) } - fn get_value_from_path(self, keys: [BoundedVec; PathDepth]) -> Option> - { + fn get_value_from_path( + self, + keys: [BoundedVec; PathDepth] + ) -> Option> { self.inner.get_value_from_path(keys) } fn key_exists(self, key: BoundedVec) -> bool { @@ -671,8 +683,10 @@ mod JSON4kb { fn get_string_from_array_unchecked(self, array_index: Field) -> BoundedVec { self.inner.get_string_from_array_unchecked(array_index) } - fn get_string_from_path(self, keys: [BoundedVec; PathDepth]) -> Option> - { + fn get_string_from_path( + self, + keys: [BoundedVec; PathDepth] + ) -> Option> { self.inner.get_string_from_path(keys) } fn get_value(self, key: [u8; KeyBytes]) -> Option> { @@ -693,8 +707,10 @@ mod JSON4kb { fn get_value_from_array_unchecked(self, array_index: Field) -> crate::JSONValue { self.inner.get_value_from_array_unchecked(array_index) } - fn get_value_from_path(self, keys: [BoundedVec; PathDepth]) -> Option> - { + fn get_value_from_path( + self, + keys: [BoundedVec; PathDepth] + ) -> Option> { self.inner.get_value_from_path(keys) } fn key_exists(self, key: BoundedVec) -> bool { @@ -829,8 +845,10 @@ mod JSON8kb { fn get_string_from_array_unchecked(self, array_index: Field) -> BoundedVec { self.inner.get_string_from_array_unchecked(array_index) } - fn get_string_from_path(self, keys: [BoundedVec; PathDepth]) -> Option> - { + fn get_string_from_path( + self, + keys: [BoundedVec; PathDepth] + ) -> Option> { self.inner.get_string_from_path(keys) } fn get_value(self, key: [u8; KeyBytes]) -> Option> { @@ -851,8 +869,10 @@ mod JSON8kb { fn get_value_from_array_unchecked(self, array_index: Field) -> crate::JSONValue { self.inner.get_value_from_array_unchecked(array_index) } - fn get_value_from_path(self, keys: [BoundedVec; PathDepth]) -> Option> - { + fn get_value_from_path( + self, + keys: [BoundedVec; PathDepth] + ) -> Option> { self.inner.get_value_from_path(keys) } fn key_exists(self, key: BoundedVec) -> bool { @@ -987,8 +1007,10 @@ mod JSON16kb { fn get_string_from_array_unchecked(self, array_index: Field) -> BoundedVec { self.inner.get_string_from_array_unchecked(array_index) } - fn get_string_from_path(self, keys: [BoundedVec; PathDepth]) -> Option> - { + fn get_string_from_path( + self, + keys: [BoundedVec; PathDepth] + ) -> Option> { self.inner.get_string_from_path(keys) } fn get_value(self, key: [u8; KeyBytes]) -> Option> { @@ -1009,8 +1031,10 @@ mod JSON16kb { fn get_value_from_array_unchecked(self, array_index: Field) -> crate::JSONValue { self.inner.get_value_from_array_unchecked(array_index) } - fn get_value_from_path(self, keys: [BoundedVec; PathDepth]) -> Option> - { + fn get_value_from_path( + self, + keys: [BoundedVec; PathDepth] + ) -> Option> { self.inner.get_value_from_path(keys) } fn key_exists(self, key: BoundedVec) -> bool { diff --git a/src/token_flags.nr b/src/token_flags.nr index 3f5b04d..1fb1c3a 100644 --- a/src/token_flags.nr +++ b/src/token_flags.nr @@ -11,7 +11,7 @@ struct TokenFlags { impl TokenFlags { unconstrained fn __from_field(f: Field) -> Self { - let bytes = f.to_be_bytes(7); + let bytes: [u8; 7] = f.to_be_bytes(); let create_json_entry = bytes[0] as Field; let is_end_of_object_or_array = bytes[1] as Field; let is_start_of_object_or_array = bytes[2] as Field; diff --git a/src/transcript_entry.nr b/src/transcript_entry.nr index 61b02a0..7c8ba2e 100644 --- a/src/transcript_entry.nr +++ b/src/transcript_entry.nr @@ -13,7 +13,7 @@ impl ValidationFlags { } unconstrained fn __from_field(f: Field) -> Self { - let bytes = f.to_be_bytes(4); + let bytes: [u8; 4] = f.to_be_bytes(); let mut push_layer= bytes[3] as Field; let push_layer_type_of_root = bytes[2] as Field; let pop_layer = bytes[1] as Field; @@ -57,7 +57,7 @@ impl RawTranscriptEntry { } unconstrained fn __from_field(felt: Field) -> Self { - let slices = felt.to_be_bytes(6); // 2 gates + 1.25 + 2 = 5.25 + let slices: [u8; 6] = felt.to_be_bytes(); // 2 gates + 1.25 + 2 = 5.25 let length = slices[1] as Field + slices[0] as Field * 0x100; let index = slices[3] as Field + slices[2] as Field * 0x100; let encoded_ascii = slices[5] as Field + slices[4] as Field * 0x100; @@ -107,7 +107,7 @@ struct ScanData { impl ScanData { unconstrained fn __from_field(f: Field) -> Self { - let bytes = f.to_le_bytes(6); + let bytes : [u8; 6]= f.to_le_bytes(); let mut scan_token = bytes[0] as Field; let push_transcript = bytes[1] as Field; @@ -140,13 +140,13 @@ impl ScanData { } struct PostProcessScanData { - token: Field, + token: Field, new_grammar: Field, scan_token: Field, } impl PostProcessScanData { fn from_field(f: Field) -> Self { - let bytes = f.to_be_bytes(3); + let bytes: [u8; 3] = f.to_be_bytes(); let token = bytes[2] as Field; let new_grammar = bytes[1] as Field; let scan_token = bytes[0] as Field; @@ -161,7 +161,7 @@ impl TranscriptEntry { self.token + self.index * 0x100 + self.length * (0x1000000) } unconstrained fn __from_field(felt: Field) -> Self { - let slices = felt.to_be_bytes(5); // 2 gates + 1.25 + 2 = 5.25 + let slices: [u8; 5] = felt.to_be_bytes(); // 2 gates + 1.25 + 2 = 5.25 let length = slices[1] as Field + slices[0] as Field * 256; let index = slices[3] as Field + slices[2] as Field * 256; let token = slices[4] as Field;