From 97b43fb4a690474cd1483d3fe2811c610328b0c6 Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 5 Sep 2023 22:27:26 +1000 Subject: [PATCH] Format subtree roots in little-endian order (#7466) --- zebra-chain/src/orchard/tree.rs | 7 ++----- zebra-chain/src/sapling/tree.rs | 9 +++------ 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/zebra-chain/src/orchard/tree.rs b/zebra-chain/src/orchard/tree.rs index e6848ecc0..205493ca6 100644 --- a/zebra-chain/src/orchard/tree.rs +++ b/zebra-chain/src/orchard/tree.rs @@ -182,12 +182,9 @@ impl Node { /// Return the node bytes in big-endian byte-order suitable for printing out byte by byte. /// - /// Zebra displays note commitment tree nodes in big-endian byte-order, - /// following the u256 convention set by Bitcoin and zcashd. + /// `zcashd`'s `z_getsubtreesbyindex` does not reverse the byte order of subtree roots. pub fn bytes_in_display_order(&self) -> [u8; 32] { - let mut reversed_bytes = self.0.to_repr(); - reversed_bytes.reverse(); - reversed_bytes + self.to_repr() } } diff --git a/zebra-chain/src/sapling/tree.rs b/zebra-chain/src/sapling/tree.rs index 2c6606cfc..698596216 100644 --- a/zebra-chain/src/sapling/tree.rs +++ b/zebra-chain/src/sapling/tree.rs @@ -190,14 +190,11 @@ impl fmt::Debug for Node { } impl Node { - /// Return the node bytes in big-endian byte-order suitable for printing out byte by byte. + /// Return the node bytes in little-endian byte order suitable for printing out byte by byte. /// - /// Zebra displays note commitment tree nodes in big-endian byte-order, - /// following the u256 convention set by Bitcoin and zcashd. + /// `zcashd`'s `z_getsubtreesbyindex` does not reverse the byte order of subtree roots. pub fn bytes_in_display_order(&self) -> [u8; 32] { - let mut reversed_bytes = self.0; - reversed_bytes.reverse(); - reversed_bytes + self.0 } }