diff --git a/noir-projects/aztec-nr/aztec/src/hash.nr b/noir-projects/aztec-nr/aztec/src/hash.nr index d2c065c9da6..f6980f78c2c 100644 --- a/noir-projects/aztec-nr/aztec/src/hash.nr +++ b/noir-projects/aztec-nr/aztec/src/hash.nr @@ -89,21 +89,24 @@ pub fn hash_args(args: [Field]) -> Field { if args.len() == 0 { 0 } else { + assert(args.len() < ARGS_HASH_CHUNK_COUNT * ARGS_HASH_CHUNK_LENGTH); let mut chunks_hashes = [0; ARGS_HASH_CHUNK_COUNT]; - for i in 0..ARGS_HASH_CHUNK_COUNT { - let mut chunk_hash = 0; - let start_chunk_index = i * ARGS_HASH_CHUNK_LENGTH; - if start_chunk_index < args.len() { - let mut chunk_args = [0; ARGS_HASH_CHUNK_LENGTH]; - for j in 0..ARGS_HASH_CHUNK_LENGTH { - let item_index = i * ARGS_HASH_CHUNK_LENGTH + j; - if item_index < args.len() { - chunk_args[j] = args[item_index]; - } - } - chunk_hash = pedersen_hash(chunk_args, GENERATOR_INDEX__FUNCTION_ARGS); + let mut current_chunk_values = [0; ARGS_HASH_CHUNK_LENGTH]; + + let mut current_chunk_index = 0; + let mut index_inside_current_chunk = 0; + for i in 0..args.len() { + current_chunk_values[index_inside_current_chunk] = args[i]; + index_inside_current_chunk+=1; + if index_inside_current_chunk == ARGS_HASH_CHUNK_LENGTH { + chunks_hashes[current_chunk_index] = pedersen_hash(current_chunk_values, GENERATOR_INDEX__FUNCTION_ARGS); + current_chunk_values = [0; ARGS_HASH_CHUNK_LENGTH]; + current_chunk_index+=1; + index_inside_current_chunk = 0; } - chunks_hashes[i] = chunk_hash; + } + if index_inside_current_chunk > 0 { + chunks_hashes[current_chunk_index] = pedersen_hash(current_chunk_values, GENERATOR_INDEX__FUNCTION_ARGS); } pedersen_hash(chunks_hashes, GENERATOR_INDEX__FUNCTION_ARGS) } diff --git a/noir/noir-repo/compiler/noirc_evaluator/src/ssa/opt/unrolling.rs b/noir/noir-repo/compiler/noirc_evaluator/src/ssa/opt/unrolling.rs index c6bf7923fa8..6cf155f85ab 100644 --- a/noir/noir-repo/compiler/noirc_evaluator/src/ssa/opt/unrolling.rs +++ b/noir/noir-repo/compiler/noirc_evaluator/src/ssa/opt/unrolling.rs @@ -151,7 +151,10 @@ impl Loops { if next_loop.blocks.iter().any(|block| self.modified_blocks.contains(block)) { let mut new_context = find_all_loops(function); new_context.failed_to_unroll = self.failed_to_unroll; - return new_context.unroll_each_loop(function); + return unroll_errors + .into_iter() + .chain(new_context.unroll_each_loop(function)) + .collect(); } // Don't try to unroll the loop again if it is known to fail