Skip to content

Commit 2047b71

Browse files
committed
Add comments to clarify the order of struct parsing
The 'wire format' of the Transceiver messages encodes/decodes the fields of the struct in reverse order to how they are declared in the Solidity and Rust structs. This is done safely, and we have unit tests to verify that the encoding/decoding process is consistent on both sides. However, it's not clear that this is intentional when reading through the code. This comment should help with readability and hopefully will stop reviewers from falling down rabbit holes.
1 parent f0f087c commit 2047b71

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

evm/src/libraries/TransceiverStructs.sol

+2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ library TransceiverStructs {
127127
revert IncorrectPrefix(prefix);
128128
}
129129

130+
// The `amount` and `decimals` fields are parsed in reverse order compared to how they are declared in the
131+
// `TrimmedAMount` struct. This is consistent with the Rust NTT implementation.
130132
uint8 numDecimals;
131133
(numDecimals, offset) = encoded.asUint8Unchecked(offset);
132134
uint64 amount;

solana/modules/ntt-messages/src/trimmed_amount.rs

+4
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ impl Readable for TrimmedAmount {
9696
Self: Sized,
9797
R: io::Read,
9898
{
99+
// The fields of this struct are intentionally read in reverse order. This is consistent
100+
// with the equivalent code in the EVM implementation of NTT serialization.
99101
let decimals = Readable::read(reader)?;
100102
let amount = Readable::read(reader)?;
101103
Ok(Self { amount, decimals })
@@ -108,6 +110,8 @@ impl Writeable for TrimmedAmount {
108110
W: io::Write,
109111
{
110112
let TrimmedAmount { amount, decimals } = self;
113+
// The fields of this struct are intentionally written in reverse order. This is consistent
114+
// with the equivalent code in the EVM implementation of NTT serialization.
111115
decimals.write(writer)?;
112116
amount.write(writer)?;
113117

0 commit comments

Comments
 (0)