From fc708205fec53a3a61b05383fbf1912327f1cc05 Mon Sep 17 00:00:00 2001 From: Brawn Date: Mon, 1 Sep 2025 13:05:47 +0300 Subject: [PATCH] fix: handle variable-size buffer for U256 --- utils/src/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/utils/src/lib.rs b/utils/src/lib.rs index aa16ad61b38..161c7c9ee35 100644 --- a/utils/src/lib.rs +++ b/utils/src/lib.rs @@ -55,14 +55,16 @@ pub async fn wait_for_rpc( /// converting a keccak256-based structured commitment (32 bytes) into type `U256` pub fn commitment_to_u256(comm: Commitment) -> U256 { - let mut buf = vec![]; - comm.serialize_uncompressed(&mut buf).unwrap(); + let mut buf = [0u8; 32]; + let mut cursor = &mut buf[..]; + comm.serialize_uncompressed(&mut cursor).unwrap(); U256::from_le_slice(&buf) } /// converting a `U256` value into a keccak256-based structured commitment (32 bytes) pub fn u256_to_commitment(comm: U256) -> Result, SerializationError> { - Commitment::deserialize_uncompressed_unchecked(&*comm.to_le_bytes_vec()) + let bytes = comm.to_le_bytes_vec(); + Commitment::deserialize_uncompressed_unchecked(&bytes) } /// Implement `to_fixed_bytes` for wrapped types