Skip to content

Commit

Permalink
fix: avoid huge unrolling in hash_args (#5703)
Browse files Browse the repository at this point in the history
After noir-lang/noir#4736 was fixed, now this
is possible :)

---------

Co-authored-by: Alvaro Rodriguez <sirasistant@MacBook-Pro-de-Alvaro.local>
  • Loading branch information
2 people authored and AztecBot committed Apr 13, 2024
1 parent a0e00e2 commit d199966
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions aztec/src/hash.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit d199966

Please sign in to comment.