Skip to content

Commit 7337f24

Browse files
committed
readme: add Solana message lifecycle
Signed-off-by: bingyuyap <bingyu.yap.21@gmail.com>
1 parent 1470fc6 commit 7337f24

File tree

1 file changed

+101
-10
lines changed

1 file changed

+101
-10
lines changed

README.md

+101-10
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
Wormhole’s Native Token Transfers (NTT) is an open, flexible, and composable framework for transferring tokens across blockchains without liquidity pools. Integrators have full control over how their Natively Transferred Tokens (NTTs) behave on each chain, including the token standard and metadata. For existing token deployments, the framework can be used in “locking” mode which preserves the original token supply on a single chain. Otherwise, the framework can be used in “burning” mode to deploy natively multichain tokens with supply distributed among multiple chains.
66

77
### Design
8-
- Transceiver - This contract module is responsible for sending Ntt transfers forwarded through the NTTManager on the source chain and delivered to a corresponding peer NTTManager on the recipient chain. Transceivers should follow the ITransceiver interface. Transceivers can be instantiated without use of the Wormhole core contracts for message authentication.
98

10-
- NttManager: The NttManager contract is responsible for managing the token and the transceivers. It also handles the rate limiting and the message attestation logic. Note that each NTTManager corresponds to a single token. However, a single NTTManager can manager can control multiple transceivers.
9+
- Transceiver - This contract module is responsible for sending Ntt transfers forwarded through the NTTManager on the source chain and delivered to a corresponding peer NTTManager on the recipient chain. Transceivers should follow the ITransceiver interface. Transceivers can be instantiated without use of the Wormhole core contracts for message authentication.
10+
11+
- NttManager: The NttManager contract is responsible for managing the token and the transceivers. It also handles the rate limiting and the message attestation logic. Note that each NTTManager corresponds to a single token. However, a single NTTManager can manager can control multiple transceivers.
1112

1213
### Amount trimming
1314

@@ -21,49 +22,138 @@ The payload includes the trimmed amount, together with the decimals that trimmed
2122
### NTT Message Lifecycle
2223

2324
### EVM
25+
2426
1. **Sending**: A client calls on [`transfer`] to initiate an NTT transfer. The client must specify at minimum, the amount of the transfer, the recipient chain, and the recipient address on the recipient chain. [`transfer`] also supports a flag to specify whether the NTTManager should queue transfers if they are rate-limited. Clients can also include additional instructions to forward along to its peer NTT Manager on the recipient chain to execute. Depending on the mode, transfers are either "locked" or "burned". Once the transfer has been forwarded to the Transceiver, the NTTManager emits the following event:
2527

26-
``` solidity
28+
```solidity
2729
emit TransferSent(recipient, _nttDenormalize(amount), recipientChain, seq);
2830
```
31+
2932
2. **Rate Limiting**: NTT supports rate-limiting of tranfers based on a 24-hr sliding window. This is intended to be a defense-in-depth security measure to mitigate and localize risk. This is a security feature intended to protect large unintended transfers. If a transfer sent from the source chain is rate-limited, it is added to a queue of transfers. The following event is emitted:
30-
``` solidity
33+
34+
```solidity
3135
emit OutboundTransferRateLimited(msg.sender, sequence, amount, getCurrentOutboundCapacity());
3236
```
37+
3338
A transfer can be released from the queue in 2 ways: (1) the capacity available exceeds the transfer amount; (2) the 24 hr period is up. In both cases, the client can call the [`completeOutboundQueuedTransfer`] function to release the transfer from the queue. The client should specify the gas amount here again to ensure that the delivery does not revert.
3439

3540
3. Transmit
3641

3742
Once the NttManager forwards the message to the Transceiver the message is transmitted via the [`sendMessage`] method. The method signature if enforced by the [`Transceiver`] but transceivers are free to determine their own implementation for transmitting messages.
3843
(e.g A message routed through the Wormhole Transceiver can be sent via automatic relaying (AR), via a specialized or custom relayer, or via the core bridge).The following event is emitted once the message has been transmitted.
39-
``` solidity
44+
45+
```solidity
4046
emit SendTransceiverMessage(recipientChain, endpointMessage);
4147
```
48+
4249
4. Receive
4350

4451
Once a message has been transmitted across the wire, an off-chain process (e.g. a relayer) will forward the message to the corresponding Transceiver on the recipient chain. The relayer interacts with the transceiver via an entrypoint for receiving messages (e.g. Wormhole messages are received through the [`receiveWormholeMessages`] method, which performs the messages verification along with replay protection)
4552
The following event is emitted during this process:
46-
``` solidity
53+
54+
```solidity
4755
emit ReceivedRelayedMessage(deliveryHash, sourceChain, sourceAddress);
4856
```
57+
4958
This method should also forward the message to the NttManager on the recipient chain.
5059
NOTE: The Transceiver interface does not enforce the method signature abstractly because receiving messages may be specific to the way in which a transceiver consumes messages.
5160

52-
``` solidity
61+
```solidity
5362
emit ReceivedMessage(vm.hash, vm.emitterChainId, vm.emitterAddress, vm.sequence);
5463
```
5564

5665
5. Attestation
5766

58-
``` solidity
67+
```solidity
5968
emit MessageAttestedTo(digest, endpoint, _getEndpointInfosStorage()[endpoint].index);
6069
emit MessageAlreadyExecuted(sourceManagerAddress, digest);
6170
```
6271

6372
6. Mint or Unlock
64-
``` solidity
73+
74+
```solidity
6575
emit TransferRedeemed(digest);
6676
```
77+
78+
### Solana
79+
80+
1. Sending
81+
82+
A client calls the [transfer_lock] or [transfer_burn] instruction based on whether the program is in "locking" or "burning" mode. The program mode is set during initialization. When transferring, the client must specify the amount of the transfer, the recipient chain, the recipient address on the recipient chain, and the boolean flag `should_queue` to specify whether the transfer should be queued if it hits the outbound rate limit. If `should_queue` is set to false, the transfer reverts instead of queuing if the rate limit were to be hit.
83+
84+
> Using the wrong transfer instruction, i.e. [`transfer_lock`] for a program that is in "burning" mode, will result in `InvalidMode` error.
85+
86+
Depending on the mode and instruction, the following will be produced in the program logs:
87+
88+
```
89+
Program log: Instruction: TransferLock
90+
Program log: Instruction: TransferBurn
91+
```
92+
93+
Outbound transfers are always added into an Outbox via the `insert_into_outbox` method. This method checks the transfer against the configured outbound rate limit amount to determine whether the transfer should be rate limited. An `OutboxItem` is a Solana Account which holds details of the outbound transfer. If no rate limit is hit, the transfer can be released from the Outbox immediately. If a rate limit is hit, the transfer can only be released from the Outbox after the rate limit delay duration has expired.
94+
95+
2. Rate Limiting
96+
97+
The program checks rate limits via the `consume_or_delay` function during the transfer process. The Solana rate limiting logic is equivalent to the EVM rate limiting logic.
98+
99+
If the transfer amount fits within the current capacity:
100+
101+
- Reduce the current capacity
102+
- Refill the inbound capacity for the destination chain
103+
- Add the transfer to the outbox with `release_timestamp` set to the current timestamp, so it can be released immediately.
104+
105+
If the transfer amount does not fit within the current capacity:
106+
107+
- If `shouldQueue = true`, add the transfer to the outbox with `release_timestamp` set to the current timestamp plus the configured `RATE_LIMIT_DURATION`.
108+
- If `shouldQueue = false`, revert with a `TransferExceedsRateLimit` error
109+
110+
3. Transmit
111+
112+
The caller then needs to request each Transceiver to send messages via the [`release_outbound`] instruction. To execute this instruction, the caller needs to pass the account of the Outbox item to be released. The instruction will then verify that the Transceiver is one of the specified senders for the message. Transceivers then send the messages based on the verification backend they are using.
113+
114+
For example, the Wormhole Transceiver will send by calling [`post_message`] on the Wormhole program, so that the Wormhole Guardians can observe and verify the message.
115+
116+
> When `revert_on_delay` is true, the transaction will revert if the release timestamp has not been reached. When `revert_on_delay` is false, the transaction succeeds, but the outbound release is not performed.
117+
118+
The following will be produced in the program logs:
119+
120+
```
121+
Program log: Instruction: ReleaseOutbound
122+
```
123+
124+
4. Receive
125+
126+
Similar to EVM, Transceivers vary in how they receive messages, since message relaying and verification methods may differ between implementations.
127+
128+
The Wormhole Transceiver receives a verified Wormhole message on Solana via the [`receive_message`] entrypoint instruction. Callers can use the [`receive_wormhole_message`] Anchor library function to execute this instruction. The instruction verifies the Wormhole VAA and stores it in a `VerifiedTransceiverMessage` account.
129+
130+
The following will be produced in the program logs:
131+
132+
```
133+
Program log: Instruction: ReceiveMessage
134+
```
135+
136+
[`redeem`] checks the inbound rate limit and places the message in an Inbox. Logic works the same as the outbound rate limit we mentioned previously.
137+
138+
The following will be produced in the program logs:
139+
140+
```
141+
Program log: Instruction: Redeem
142+
```
143+
144+
5. Mint or Unlock
145+
146+
The inbound transfer is released and the tokens are unlocked or minted to the recipient (depending on the mode) through either [`release_inbound_mint`] (if the mode is `burning`) or [`release_inbound_unlock`] (if the mode is `locking`). Similar to transfer, using the wrong transfer instruction, i.e. [`release_inbound_mint`] for a program that is in "locking" mode, will result in `InvalidMode` error.
147+
148+
> When `revert_on_delay` is true, the transaction will revert if the release timestamp has not been reached. When `revert_on_delay` is false, the transaction succeeds, but the minting/unlocking is not performed.
149+
150+
Depending on the mode and instruction, the following will be produced in the program logs:
151+
152+
```
153+
Program log: Instruction: ReleaseInboundMint
154+
Program log: Instruction: ReleaseInboundUnlock
155+
```
156+
67157
#### Installation
68158

69159
Install [Foundry](https://book.getfoundry.sh/getting-started/installation)
@@ -72,6 +162,7 @@ Install [Foundry](https://book.getfoundry.sh/getting-started/installation)
72162
TODO: add installation instructions for solana
73163

74164
Install [rust](https://doc.rust-lang.org/book/ch01-01-installation.html)
165+
75166
```
76167
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
77168
```
@@ -90,13 +181,13 @@ _Test_
90181
$ forge test
91182
```
92183

93-
94184
#### Submitting a PR
95185

96186
Before submitting a PR, please run the following commands:
97187

98188
_Test_
99189
EVM Tests:
190+
100191
```
101192
$ make test-evm
102193
```

0 commit comments

Comments
 (0)