Skip to content

Commit aef1fde

Browse files
committed
merge
2 parents 4494e16 + 44c7dc5 commit aef1fde

File tree

11 files changed

+302
-335
lines changed

11 files changed

+302
-335
lines changed

.github/workflows/benchmark.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Install Nargo
1818
uses: noir-lang/[email protected]
1919
with:
20-
toolchain: 1.0.0-beta.6
20+
toolchain: 1.0.0-beta.12
2121

2222
- name: Install bb
2323
run: |

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
env:
1010
CARGO_TERM_COLOR: always
11-
MINIMUM_NOIR_VERSION: v1.0.0-beta.1
11+
MINIMUM_NOIR_VERSION: 1.0.0-beta.12
1212

1313
jobs:
1414
noir-version-list:

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ For numbers larger than 64 bits, the method `get_value` will work, which will re
104104

105105
### Fine-grained maximum parameter control
106106

107-
If the predefined JSON types are not sufficient for your use case, you can define a JSON object with a custom parametrisation:
107+
If the predefined JSON types are not sufficient for your use case, you can define a JSON object with a custom parameterization:
108108

109-
The JSON struct in `dep::json_parser::json::JSON` is parametrised with the following parameters:
109+
The JSON struct in `dep::json_parser::json::JSON` is parameterized with the following parameters:
110110

111111
`struct JSON<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let MaxNumValues: u32, let MaxKeyFields: u32>`
112112

@@ -116,11 +116,11 @@ The JSON struct in `dep::json_parser::json::JSON` is parametrised with the follo
116116
- `MaxNumValues`: the maximum number of values in the json blob _plus one_
117117
- `MaxKeyFields`: the largest size a key can take (in bytes) equals `MaxKeyFields * 31`
118118

119-
e.g. to take the existing 1kb JSON paramters, but also support 124-byte keys, use `JSON<1024, 37, 128, 65, 4>`
119+
e.g. to take the existing 1kb JSON parameters, but also support 124-byte keys, use `JSON<1024, 37, 128, 65, 4>`
120120

121121
### Making queries with keys of unknown length
122122

123-
If you are deriving a key to look up in-circuit and you do not know the maximum length of the key, all query methods have a version with a `_var` suffix (e.g. `JSON::get_string_var`), which accepts the key as a `BoundedVec`
123+
If you are deriving a key to look up in-circuit and you do not know the maximum length of the key, all query methods accept the key as a `BoundedVec`
124124

125125
# Architecture
126126
### Overview

src/_string_tools/slice_packed_field.nr

Lines changed: 123 additions & 88 deletions
Large diffs are not rendered by default.

src/get_array.nr

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::_comparison_tools::lt::lt_field_16_bit;
22
use crate::enums::Layer::ARRAY_LAYER;
33
use crate::enums::Token::END_ARRAY_TOKEN;
4+
use crate::getters::KeyHashable;
45
use crate::json::JSON;
56
use crate::json::JSONValue;
67
use crate::json_entry::JSONEntry;
@@ -26,20 +27,11 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
2627
/// if the root JSON is an object, extract an array given by `key`
2728
///
2829
/// returns an Option<JSON> where, if the array exists, the JSON object will have the requested array as its root value
29-
pub fn get_array<let KeyBytes: u32>(self, key: [u8; KeyBytes]) -> Option<Self> {
30-
self.get_array_var(BoundedVec::from_parts_unchecked(key, KeyBytes))
31-
}
32-
33-
/// if the root JSON is an object, extract an array given by `key`
34-
///
35-
/// will revert if the array does not exist
36-
pub fn get_array_unchecked<let KeyBytes: u32>(self, key: [u8; KeyBytes]) -> Self {
37-
self.get_array_unchecked_var(BoundedVec::from_parts_unchecked(key, KeyBytes))
38-
}
39-
40-
/// same as `get_array` for where the key length may be less than KeyBytes
41-
pub fn get_array_var<let KeyBytes: u32>(self, key: BoundedVec<u8, KeyBytes>) -> Option<Self> {
42-
let (exists, entry, key_index) = self.get_json_entry_var(key);
30+
pub(crate) fn get_array<K>(self, key: K) -> Option<Self>
31+
where
32+
K: KeyHashable,
33+
{
34+
let (exists, entry, key_index) = self.get_json_entry(key);
4335
if !exists {
4436
assert_eq(
4537
entry.entry_type,
@@ -57,11 +49,16 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
5749
}
5850
}
5951

60-
/// same as `get_array_unchecked` for where the key length may be less than KeyBytes
61-
pub fn get_array_unchecked_var<let KeyBytes: u32>(self, key: BoundedVec<u8, KeyBytes>) -> Self {
52+
/// if the root JSON is an object, extract an array given by `key`
53+
///
54+
/// will revert if the array does not exist
55+
pub(crate) fn get_array_unchecked<K>(self, key: K) -> Self
56+
where
57+
K: KeyHashable,
58+
{
6259
assert(self.layer_type_of_root != ARRAY_LAYER, "cannot extract array elements via a key");
6360

64-
let (entry, key_index) = self.get_json_entry_unchecked_with_key_index_var(key);
61+
let (entry, key_index) = self.get_json_entry_unchecked_with_key_index(key);
6562
assert(entry.entry_type == END_ARRAY_TOKEN as Field, "key does not describe an object");
6663

6764
self.update_json_array(entry, key_index)

src/get_literal.nr

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::enums::Token::LITERAL_TOKEN;
2+
use crate::getters::KeyHashable;
23
use crate::json::JSON;
34
use crate::utils::cast_num_to_u32;
45

@@ -63,26 +64,14 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
6364
/// if the root JSON is an object, extract a literal value given by `key`
6465
///
6566
/// returns an Option<JSONLiteral> which will be null if the literal does not exist
66-
pub fn get_literal<let KeyBytes: u32>(self, key: [u8; KeyBytes]) -> Option<JSONLiteral> {
67-
self.get_literal_var(BoundedVec::from_parts_unchecked(key, KeyBytes))
68-
}
69-
70-
/// if the root JSON is an object, extract a literal value given by `key`
71-
///
72-
/// will revert if the literal does not exist
73-
pub fn get_literal_unchecked<let KeyBytes: u32>(self, key: [u8; KeyBytes]) -> JSONLiteral {
74-
self.get_literal_unchecked_var(BoundedVec::from_parts_unchecked(key, KeyBytes))
75-
}
76-
77-
/// same as `get_literal` for where the key length may be less than KeyBytes
78-
pub fn get_literal_var<let KeyBytes: u32>(
79-
self,
80-
key: BoundedVec<u8, KeyBytes>,
81-
) -> Option<JSONLiteral> {
82-
let (exists, entry, _) = self.get_json_entry_var(key);
67+
pub(crate) fn get_literal<K>(self, key: K) -> Option<JSONLiteral>
68+
where
69+
K: KeyHashable,
70+
{
71+
let (exists, entry, _) = self.get_json_entry(key);
8372
assert(
8473
(entry.entry_type - LITERAL_TOKEN as Field) * exists as Field == 0,
85-
"get_literal_var: entry exists but is not a literal!",
74+
"get_literal: entry exists but is not a literal!",
8675
);
8776
let mut parsed_string: [u8; MAX_LITERAL_LENGTH_AS_STRING] =
8877
self.extract_string_entry(entry);
@@ -94,15 +83,17 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
9483
}
9584
}
9685

97-
/// same as `get_literal_unchecked` for where the key length may be less than KeyBytes
98-
pub fn get_literal_unchecked_var<let KeyBytes: u32>(
99-
self,
100-
key: BoundedVec<u8, KeyBytes>,
101-
) -> JSONLiteral {
102-
let entry = self.get_json_entry_unchecked_var(key);
86+
/// if the root JSON is an object, extract a literal value given by `key`
87+
///
88+
/// will revert if the literal does not exist
89+
pub(crate) fn get_literal_unchecked<K>(self, key: K) -> JSONLiteral
90+
where
91+
K: KeyHashable,
92+
{
93+
let entry = self.get_json_entry_unchecked(key);
10394
assert(
10495
entry.entry_type == LITERAL_TOKEN as Field,
105-
"get_literal_unchecked_var: entry exists but is not a literal!",
96+
"get_literal_unchecked: entry exists but is not a literal!",
10697
);
10798
let mut parsed_string: [u8; MAX_LITERAL_LENGTH_AS_STRING] =
10899
self.extract_string_entry(entry);

src/get_number.nr

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::enums::Token::NUMERIC_TOKEN;
2+
use crate::getters::KeyHashable;
23
use crate::json::JSON;
34
use crate::json_tables::ASCII_TO_NUMBER;
45
use crate::utils::cast_num_to_u32;
@@ -49,20 +50,11 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
4950
/// if the root JSON is an object, extract a numeric value given by `key`
5051
///
5152
/// returns an Option<u64> which will be null if the key does not exist
52-
pub fn get_number<let KeyBytes: u32>(self, key: [u8; KeyBytes]) -> Option<u64> {
53-
self.get_number_var(BoundedVec::from_parts_unchecked(key, KeyBytes))
54-
}
55-
56-
/// if the root JSON is an object, extract a u64 value given by `key`
57-
///
58-
/// will revert if the number does not exist
59-
pub fn get_number_unchecked<let KeyBytes: u32>(self, key: [u8; KeyBytes]) -> u64 {
60-
self.get_number_unchecked_var(BoundedVec::from_parts_unchecked(key, KeyBytes))
61-
}
62-
63-
/// same as `get_number` for where the key length may be less than KeyBytes
64-
pub fn get_number_var<let KeyBytes: u32>(self, key: BoundedVec<u8, KeyBytes>) -> Option<u64> {
65-
let (exists, entry, _) = self.get_json_entry_var(key);
53+
pub(crate) fn get_number<K>(self, key: K) -> Option<u64>
54+
where
55+
K: KeyHashable,
56+
{
57+
let (exists, entry, _) = self.get_json_entry(key);
6658
assert(
6759
(entry.entry_type - NUMERIC_TOKEN as Field) * exists as Field == 0,
6860
"get_number: entry exists but is not a number!",
@@ -76,9 +68,14 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
7668
}
7769
}
7870

79-
/// same as `get_number_unchecked` for where the key length may be less than KeyBytes
80-
pub fn get_number_unchecked_var<let KeyBytes: u32>(self, key: BoundedVec<u8, KeyBytes>) -> u64 {
81-
let entry = self.get_json_entry_unchecked_var(key);
71+
/// if the root JSON is an object, extract a u64 value given by `key`
72+
///
73+
/// will revert if the number does not exist
74+
pub(crate) fn get_number_unchecked<K>(self, key: K) -> u64
75+
where
76+
K: KeyHashable,
77+
{
78+
let entry = self.get_json_entry_unchecked(key);
8279
assert(
8380
entry.entry_type == NUMERIC_TOKEN as Field,
8481
"get_number_unchecked: entry exists but is not a number!",

src/get_object.nr

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::enums::Layer::{ARRAY_LAYER, OBJECT_LAYER};
22
use crate::enums::Token::END_OBJECT_TOKEN;
3+
use crate::getters::KeyHashable;
34
use crate::json::JSON;
45
use crate::json_entry::JSONEntry;
56

@@ -16,20 +17,11 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
1617
/// if the root JSON is an object, extract a child object given by `key`
1718
///
1819
/// returns an Option<JSON> where, if the object exists, the JSON object will have the requested object as its root value
19-
pub fn get_object<let KeyBytes: u32>(self, key: [u8; KeyBytes]) -> Option<Self> {
20-
self.get_object_var(BoundedVec::from_parts_unchecked(key, KeyBytes))
21-
}
22-
23-
/// if the root JSON is an object, extract a child object given by `key`
24-
///
25-
/// will revert if the requested object does not exist
26-
pub fn get_object_unchecked<let KeyBytes: u32>(self, key: [u8; KeyBytes]) -> Self {
27-
self.get_object_unchecked_var(BoundedVec::from_parts_unchecked(key, KeyBytes))
28-
}
29-
30-
/// same as `get_object` for where the key length may be less than KeyBytes
31-
pub fn get_object_var<let KeyBytes: u32>(self, key: BoundedVec<u8, KeyBytes>) -> Option<Self> {
32-
let (exists, entry, key_index) = self.get_json_entry_var(key);
20+
pub(crate) fn get_object<K>(self, key: K) -> Option<Self>
21+
where
22+
K: KeyHashable,
23+
{
24+
let (exists, entry, key_index) = self.get_json_entry(key);
3325
if exists {
3426
assert_eq(
3527
entry.entry_type,
@@ -47,13 +39,15 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
4739
}
4840
}
4941

50-
/// same as `get_object_unchecked` for where the key length may be less than KeyBytes
51-
pub fn get_object_unchecked_var<let KeyBytes: u32>(
52-
self,
53-
key: BoundedVec<u8, KeyBytes>,
54-
) -> Self {
42+
// if the root JSON is an object, extract a child object given by `key`
43+
///
44+
/// will revert if the requested object does not exist
45+
pub(crate) fn get_object_unchecked<K>(self, key: K) -> Self
46+
where
47+
K: KeyHashable,
48+
{
5549
assert(self.layer_type_of_root != ARRAY_LAYER, "cannot extract array elements via a key");
56-
let (entry, key_index) = self.get_json_entry_unchecked_with_key_index_var(key);
50+
let (entry, key_index) = self.get_json_entry_unchecked_with_key_index(key);
5751
let entry: JSONEntry = self.json_entries_packed[key_index].into();
5852
assert_eq(
5953
entry.entry_type,
@@ -117,19 +111,19 @@ fn test_object() {
117111
let not_real = B.get_object("bartholomew tony Harrison IV".as_bytes());
118112
assert(not_real.is_some() == false);
119113

120-
let C = B.get_object_unchecked_var(BoundedVec::from_parts_unchecked(
114+
let C = B.get_object_unchecked(BoundedVec::from_parts_unchecked(
121115
"bartholomew tony Harrison III".as_bytes(),
122116
29,
123117
));
124118
assert_eq(JSONEntry::from(C.json_entries_packed[C.root_index_in_transcript]).num_children, 1);
125119

126-
let C = B.get_object_var(BoundedVec::from_parts_unchecked(
120+
let C = B.get_object(BoundedVec::from_parts_unchecked(
127121
"bartholomew tony Harrison III".as_bytes(),
128122
28,
129123
));
130124
assert(C.is_some() == false);
131125

132-
let C = B.get_object_var(BoundedVec::from_parts_unchecked(
126+
let C = B.get_object(BoundedVec::from_parts_unchecked(
133127
"bartholomew tony Harrison IIIekurfgaeoiurh".as_bytes(),
134128
29,
135129
));

0 commit comments

Comments
 (0)