From 60d43fd689c5c7a1d290c95c7eda520bd976dc49 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Mon, 6 Jan 2025 13:22:30 +0000 Subject: [PATCH] feat: more efficient `compute_l2_to_l1_hash` (#11036) This avoids unnecessary tracking of the length of the `BoundedVec`. --- .../noir-protocol-circuits/crates/types/src/hash.nr | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr b/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr index 1ffc5782024..2e73769fe24 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr @@ -138,19 +138,19 @@ pub fn compute_l2_to_l1_hash( rollup_version_id: Field, chain_id: Field, ) -> Field { - let mut bytes: BoundedVec = BoundedVec::new(); + let mut bytes: [u8; 160] = std::mem::zeroed(); let inputs = [contract_address.to_field(), rollup_version_id, recipient.to_field(), chain_id, content]; - for i in 0..inputs.len() { + for i in 0..5 { // TODO are bytes be in fr.to_buffer() ? let item_bytes: [u8; 32] = inputs[i].to_be_bytes(); for j in 0..32 { - bytes.push(item_bytes[j]); + bytes[32 * i + j] = item_bytes[j]; } } - sha256_to_field(bytes.storage()) + sha256_to_field(bytes) } pub fn silo_l2_to_l1_message(