From 06b84e8dca597ef5707dec6213d46f8457fe5ffe Mon Sep 17 00:00:00 2001 From: arnaucube Date: Mon, 14 Jul 2025 15:27:58 +0200 Subject: [PATCH] change Hash (and RawValue) hex-string representation to show the least-significant field element as big-endian hex string (#338) * change Hash (and RawValue) hex-string representation to show the least-significant field element as big-endian hex string The motivation is that since some commits ago, the hex representation was changed from little-endian to big-endian, and when cropping the long strings of hex (hex representation of byte-arrays), the small values (224 bits or less) were being represented by `0x00000000...`, which is indistinguishable from the `0` value. This commit updates this cropped representation to print the last characters of the string (the less signifcant bytes of the big-endian representation), so that for example for the integer `5` the representation would be `0x...00000005`. --- src/middleware/basetypes.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/middleware/basetypes.rs b/src/middleware/basetypes.rs index fa9e8e8..e187a30 100644 --- a/src/middleware/basetypes.rs +++ b/src/middleware/basetypes.rs @@ -236,13 +236,13 @@ impl fmt::Display for Hash { if f.alternate() { write!(f, "0x{}", self.encode_hex::()) } else { - // display first hex digit in big endian - write!(f, "0x")?; - let v3 = self.0[3].to_canonical_u64(); - for i in 0..4 { - write!(f, "{:02x}", (v3 >> ((7 - i) * 8)) & 0xff)?; + // display the least significant field element in big endian + write!(f, "0x…")?; + let v0 = self.0[0].to_canonical_u64(); + for i in (0..4).rev() { + write!(f, "{:02x}", (v0 >> (i * 8)) & 0xff)?; } - write!(f, "…") + Ok(()) } } }