Skip to content

Commit 36ecc82

Browse files
authored
fix: avoid inserting unused witnesses into circuit (#20965)
This PR avoids returning extra values from unconstrained to constrained code just to drop them immediately
2 parents 94f596f + 90a2fab commit 36ecc82

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/accumulated_data/assert_sorted_padded_transformed_array.nr

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ where
7979
unconstrained fn get_num_padded_items<Value, let N: u32>(
8080
padded_items: [Value; N],
8181
original_array_length: u32,
82-
CappedSize: u32,
82+
capped_size: u32,
8383
) -> u32
8484
where
8585
Value: Ordered,
8686
{
8787
let mut num_padded_items = 0;
88-
for i in original_array_length..CappedSize {
88+
for i in original_array_length..capped_size {
8989
if padded_items[i].counter() == MAX_U32_VALUE {
9090
// Only padding items have this counter.
9191
num_padded_items += 1;
@@ -109,7 +109,7 @@ where
109109
{
110110
// Safety: The hints are constrained by `assert_sorted_padded_transformed_i_array_capped_size_with_hints`.
111111
let (sorted_index_hints, num_padded_items_hint) = unsafe {
112-
let sorted_indexes = get_order_hints(original_array.array).sorted_indexes;
112+
let sorted_indexes = get_sorted_indexes(original_array.array);
113113
let num_padded_items =
114114
get_num_padded_items(padded_items, original_array.length, CappedSize);
115115
(sorted_indexes, num_padded_items)
@@ -125,6 +125,13 @@ where
125125
)
126126
}
127127

128+
unconstrained fn get_sorted_indexes<T, let N: u32>(original_array: [T; N]) -> [u32; N]
129+
where
130+
T: Ordered + Empty,
131+
{
132+
get_order_hints(original_array).sorted_indexes
133+
}
134+
128135
/// @param original_array - is technically the so-called `kept_` array that's already been through squashing; it's "original" from
129136
/// the perspective of this function and the transformations it will apply.
130137
/// @param CappedSize - is a comptime constant for the number of siloing iterations this variant of the circuit supports.

0 commit comments

Comments
 (0)