Skip to content

Commit 6b3a70a

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 6b3a70a

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-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 implementation of the Rust NTT implementation.
130132
uint8 numDecimals;
131133
(numDecimals, offset) = encoded.asUint8Unchecked(offset);
132134
uint64 amount;

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

+2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ impl Writeable for TrimmedAmount {
108108
W: io::Write,
109109
{
110110
let TrimmedAmount { amount, decimals } = self;
111+
// The fields of this struct are intentionally written in reverse order. This is consistent
112+
// with the equivalent code in the EVM implementation of NTT serialization.
111113
decimals.write(writer)?;
112114
amount.write(writer)?;
113115

0 commit comments

Comments
 (0)