From 3fbefc6d788c0c5ecaa7bd255c14384677c87148 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Fri, 27 Feb 2026 17:29:47 +0000 Subject: [PATCH] fix: avoid inserting unused witnesses into circuit --- .../assert_sorted_padded_transformed_array.nr | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/accumulated_data/assert_sorted_padded_transformed_array.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/accumulated_data/assert_sorted_padded_transformed_array.nr index a6f3a31e4ae2..bd2a1c6ab752 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/accumulated_data/assert_sorted_padded_transformed_array.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/accumulated_data/assert_sorted_padded_transformed_array.nr @@ -79,13 +79,13 @@ where unconstrained fn get_num_padded_items( padded_items: [Value; N], original_array_length: u32, - CappedSize: u32, + capped_size: u32, ) -> u32 where Value: Ordered, { let mut num_padded_items = 0; - for i in original_array_length..CappedSize { + for i in original_array_length..capped_size { if padded_items[i].counter() == MAX_U32_VALUE { // Only padding items have this counter. num_padded_items += 1; @@ -109,7 +109,7 @@ where { // Safety: The hints are constrained by `assert_sorted_padded_transformed_i_array_capped_size_with_hints`. let (sorted_index_hints, num_padded_items_hint) = unsafe { - let sorted_indexes = get_order_hints(original_array.array).sorted_indexes; + let sorted_indexes = get_sorted_indexes(original_array.array); let num_padded_items = get_num_padded_items(padded_items, original_array.length, CappedSize); (sorted_indexes, num_padded_items) @@ -125,6 +125,13 @@ where ) } +unconstrained fn get_sorted_indexes(original_array: [T; N]) -> [u32; N] +where + T: Ordered + Empty, +{ + get_order_hints(original_array).sorted_indexes +} + /// @param original_array - is technically the so-called `kept_` array that's already been through squashing; it's "original" from /// the perspective of this function and the transformations it will apply. /// @param CappedSize - is a comptime constant for the number of siloing iterations this variant of the circuit supports.