Skip to content

Commit 9a6c221

Browse files
evm: Adds Transceiver Payload V1 (#316)
1 parent d35c929 commit 9a6c221

File tree

5 files changed

+51
-18
lines changed

5 files changed

+51
-18
lines changed

ci_tests/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

evm/src/Transceiver/WormholeTransceiver/WormholeTransceiver.sol

+46-13
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,9 @@ contract WormholeTransceiver is
182182
TransceiverStructs.TransceiverInstruction memory instruction,
183183
bytes memory nttManagerMessage
184184
) internal override {
185-
(
186-
TransceiverStructs.TransceiverMessage memory transceiverMessage,
187-
bytes memory encodedTransceiverPayload
188-
) = TransceiverStructs.buildAndEncodeTransceiverMessage(
189-
WH_TRANSCEIVER_PAYLOAD_PREFIX,
190-
toWormholeFormat(caller),
191-
recipientNttManagerAddress,
192-
nttManagerMessage,
193-
new bytes(0)
194-
);
185+
TransceiverStructs.TransceiverMessage memory transceiverMessage;
186+
bytes memory encodedTransceiverPayload;
187+
bytes32 wormholeFormattedCaller = toWormholeFormat(caller);
195188

196189
WormholeTransceiverInstruction memory weIns =
197190
parseWormholeTransceiverInstruction(instruction.payload);
@@ -200,6 +193,15 @@ contract WormholeTransceiver is
200193
// NOTE: standard relaying supports refunds. The amount to be refunded will be sent
201194
// to a refundAddress specified by the client on the destination chain.
202195

196+
(transceiverMessage, encodedTransceiverPayload) = TransceiverStructs
197+
.buildAndEncodeTransceiverMessage(
198+
WH_TRANSCEIVER_PAYLOAD_PREFIX,
199+
wormholeFormattedCaller,
200+
recipientNttManagerAddress,
201+
nttManagerMessage,
202+
new bytes(0)
203+
);
204+
203205
// push onto the stack again to avoid stack too deep error
204206
bytes32 refundRecipient = refundAddress;
205207
uint16 destinationChain = recipientChain;
@@ -216,18 +218,49 @@ contract WormholeTransceiver is
216218

217219
emit RelayingInfo(uint8(RelayingType.Standard), refundAddress, deliveryPayment);
218220
} else if (!weIns.shouldSkipRelayerSend && isSpecialRelayingEnabled(recipientChain)) {
221+
// This transceiver payload is used to signal whether the message should be
222+
// picked up by the special relayer or not:
223+
// - It only affects the off-chain special relayer.
224+
// - It is not used by the target NTT Manager contract.
225+
// Transceiver payload is prefixed with 1 byte representing the version of
226+
// the payload. The rest of the bytes are the -actual- payload data. In payload
227+
// v1, the payload data is a boolean representing whether the message should
228+
// be picked up by the special relayer or not.
229+
bytes memory transceiverPayload = abi.encodePacked(uint8(1), true);
230+
(transceiverMessage, encodedTransceiverPayload) = TransceiverStructs
231+
.buildAndEncodeTransceiverMessage(
232+
WH_TRANSCEIVER_PAYLOAD_PREFIX,
233+
wormholeFormattedCaller,
234+
recipientNttManagerAddress,
235+
nttManagerMessage,
236+
transceiverPayload
237+
);
238+
239+
// push onto the stack again to avoid stack too deep error
240+
uint256 deliveryFee = deliveryPayment;
241+
uint16 destinationChain = recipientChain;
242+
219243
uint256 wormholeFee = wormhole.messageFee();
220244
uint64 sequence = wormhole.publishMessage{value: wormholeFee}(
221245
0, encodedTransceiverPayload, consistencyLevel
222246
);
223-
specialRelayer.requestDelivery{value: deliveryPayment - wormholeFee}(
224-
getNttManagerToken(), recipientChain, 0, sequence
247+
specialRelayer.requestDelivery{value: deliveryFee - wormholeFee}(
248+
getNttManagerToken(), destinationChain, 0, sequence
225249
);
226250

227251
// NOTE: specialized relaying does not currently support refunds. The zero address
228252
// is used as a placeholder for the refund address until support is added.
229-
emit RelayingInfo(uint8(RelayingType.Special), bytes32(0), deliveryPayment);
253+
emit RelayingInfo(uint8(RelayingType.Special), bytes32(0), deliveryFee);
230254
} else {
255+
(transceiverMessage, encodedTransceiverPayload) = TransceiverStructs
256+
.buildAndEncodeTransceiverMessage(
257+
WH_TRANSCEIVER_PAYLOAD_PREFIX,
258+
wormholeFormattedCaller,
259+
recipientNttManagerAddress,
260+
nttManagerMessage,
261+
new bytes(0)
262+
);
263+
231264
wormhole.publishMessage{value: deliveryPayment}(
232265
0, encodedTransceiverPayload, consistencyLevel
233266
);

evm/test/TransceiverStructs.t.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ contract TestTransceiverStructs is Test {
9494
sourceNttManagerAddress: hex"042942FAFABE",
9595
recipientNttManagerAddress: hex"042942FABABE",
9696
nttManagerPayload: TransceiverStructs.encodeNttManagerMessage(mm),
97-
transceiverPayload: new bytes(0)
97+
transceiverPayload: hex"0101"
9898
});
9999

100100
bytes memory encodedTransceiverMessage =
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9945ff10042942fafabe0000000000000000000000000000000000000000000000000000042942fababe00000000000000000000000000000000000000000000000000000091128434bafe23430000000000000000000000000000000000ce00aa00000000004667921341234300000000000000000000000000000000000000000000000000004f994e545407000000000012d687beefface00000000000000000000000000000000000000000000000000000000feebcafe0000000000000000000000000000000000000000000000000000000000110000
1+
9945ff10042942fafabe0000000000000000000000000000000000000000000000000000042942fababe00000000000000000000000000000000000000000000000000000091128434bafe23430000000000000000000000000000000000ce00aa00000000004667921341234300000000000000000000000000000000000000000000000000004f994e545407000000000012d687beefface00000000000000000000000000000000000000000000000000000000feebcafe00000000000000000000000000000000000000000000000000000000001100020101

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ mod test {
232232
},
233233
},
234234
},
235-
transceiver_payload: vec![],
235+
transceiver_payload: vec![0x01, 0x01],
236236
};
237237
assert_eq!(message, expected);
238238
assert_eq!(vec.len(), 0);

0 commit comments

Comments
 (0)