Skip to content

Commit 1570241

Browse files
RahulMaganti47Rahul Maganti
and
Rahul Maganti
authored
evm: natspec changes and additions (#249)
* evm: natspec changes and additions * evm: add natspec for ITransceiver.sol * evm: modify natspec indentation for INttManager.sol * evm: add natspec to transceiver registry * evm: add natspec to WormholeTransceiver.sol * evm: add author tags * evm: fix errors * evm: fix indentation + spelling * evm: reword bytes -> bits --------- Co-authored-by: Rahul Maganti <rahulmaganti@rahuls-mbp.mynetworksettings.com>
1 parent 51dd6fe commit 1570241

10 files changed

+237
-29
lines changed

evm/src/NttManager/NttManager.sol

+17
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,23 @@ import "../interfaces/ITransceiver.sol";
1717

1818
import {NttManagerState} from "./NttManagerState.sol";
1919

20+
/// @title NttManager
21+
/// @author Wormhole Project Contributors.
22+
/// @notice The NttManager contract is responsible for managing the token
23+
/// and associated transceivers.
24+
///
25+
/// @dev Each NttManager contract is associated with a single token but
26+
/// can be responsible for multiple transceivers.
27+
///
28+
/// @dev When transferring tokens, the NttManager contract will either
29+
/// lock the tokens or burn them, depending on the mode.
30+
///
31+
/// @dev To initiate a transfer, the user calls the transfer function with:
32+
/// - the amount
33+
/// - the recipient chain
34+
/// - the recipient address
35+
/// - (optional) a flag to indicate whether the transfer should be queued
36+
/// if the rate limit is exceeded
2037
contract NttManager is INttManager, NttManagerState {
2138
using BytesParsing for bytes;
2239
using SafeERC20 for IERC20;

evm/src/NttManager/TransceiverRegistry.sol

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
// SPDX-License-Identifier: Apache 2
22
pragma solidity >=0.8.8 <0.9.0;
33

4-
/// @dev This contract is responsible for handling the registration of Transceivers.
4+
/// @title TransceiverRegistry
5+
/// @author Wormhole Project Contributors.
6+
/// @notice This contract is responsible for handling the registration of Transceivers.
7+
/// @dev This contract checks that a few critical invariants hold when transceivers are added or removed,
8+
/// including:
9+
/// 1. If a transceiver is not registered, it should be enabled.
10+
/// 2. The value set in the bitmap of trannsceivers
11+
/// should directly correspond to the whether the transceiver is enabled
512
abstract contract TransceiverRegistry {
613
constructor() {
714
_checkTransceiversInvariants();
@@ -33,11 +40,33 @@ abstract contract TransceiverRegistry {
3340

3441
uint8 constant MAX_TRANSCEIVERS = 64;
3542

43+
/// @notice Error when the caller is not the transceiver.
44+
/// @dev Selector 0xa0ae911d.
45+
/// @param caller The address of the caller.
3646
error CallerNotTransceiver(address caller);
47+
48+
/// @notice Error when the transceiver is the zero address.
49+
/// @dev Selector 0x2f44bd77.
3750
error InvalidTransceiverZeroAddress();
51+
52+
/// @notice Error when the transceiver is disabled.
53+
/// @dev Selector 0x1f61ba44.
3854
error DisabledTransceiver(address transceiver);
55+
56+
/// @notice Error when the number of registered transceivers
57+
/// exceeeds (MAX_TRANSCEIVERS = 64).
58+
/// @dev Selector 0x891684c3.
3959
error TooManyTransceivers();
60+
61+
/// @notice Error when attempting to remove a transceiver
62+
/// that is not registered.
63+
/// @dev Selector 0xd583f470.
64+
/// @param transceiver The address of the transceiver.
4065
error NonRegisteredTransceiver(address transceiver);
66+
67+
/// @notice Error when attempting to enable a transceiver that is already enabled.
68+
/// @dev Selector 0x8d68f84d.
69+
/// @param transceiver The address of the transceiver.
4170
error TransceiverAlreadyEnabled(address transceiver);
4271

4372
modifier onlyTransceiver() {

evm/src/Transceiver/Transceiver.sol

+9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ import "../libraries/Implementation.sol";
1111
import "../interfaces/INttManager.sol";
1212
import "../interfaces/ITransceiver.sol";
1313

14+
/// @title Transceiver
15+
/// @author Wormhole Project Contributors.
16+
/// @notice This contract is a base contract for Transceivers.
17+
/// @dev The Transceiver provides basic functionality for transmitting / receiving NTT messages.
18+
/// The contract supports pausing via an admin or owner and is upgradable.
19+
///
20+
/// @dev The interface for receiving messages is not enforced by this contract.
21+
/// Instead, inheriting contracts should implement their own receiving logic,
22+
/// based on the verification model and serde logic associated with message handling.
1423
abstract contract Transceiver is
1524
ITransceiver,
1625
PausableOwnable,

evm/src/Transceiver/WormholeTransceiver/WormholeTransceiver.sol

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ import "../../interfaces/INttManager.sol";
1414

1515
import "./WormholeTransceiverState.sol";
1616

17+
/// @title WormholeTransceiver
18+
/// @author Wormhole Project Contributors.
19+
/// @notice Transceiver implementation for Wormhole.
20+
///
21+
/// @dev This contract is responsible for sending and receiving NTT messages
22+
/// that are authenticated through Wormhole Core.
23+
///
24+
/// @dev Messages can be delivered either via standard relaying or special relaying, or
25+
/// manually via the core layer.
26+
///
27+
/// @dev Once a message is received, it is delivered to its corresponding
28+
/// NttManager contract.
1729
contract WormholeTransceiver is
1830
IWormholeTransceiver,
1931
IWormholeReceiver,

evm/src/interfaces/INttManager.sol

+52-17
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,22 @@ import "../libraries/TransceiverStructs.sol";
77
import "./INttManagerState.sol";
88

99
interface INttManager is INttManagerState {
10+
/// @notice The mode is either LOCKING or BURNING. In LOCKING mode, the NttManager locks the
11+
/// tokens of the sender and mints an equivalent amount on the target chain. In BURNING
12+
/// mode, the NttManager burns the tokens of the sender and mints an equivalent amount
13+
/// on the target chain.LOCKING mode preserves the total supply of the tokens.
1014
enum Mode {
1115
LOCKING,
1216
BURNING
1317
}
1418

15-
// @dev Information about attestations for a given message.
19+
/// @notice Information about attestations for a given message.
20+
/// @dev The fields are as follows:
21+
/// - executed: whether the message has been executed.
22+
/// - attested: bitmap of transceivers that have attested to this message.
23+
/// (NOTE: might contain disabled transceivers)
1624
struct AttestationInfo {
17-
// whether this message has been executed
1825
bool executed;
19-
// bitmap of transceivers that have attested to this message (NOTE: might contain disabled transceivers)
2026
uint64 attestedTransceivers;
2127
}
2228

@@ -34,27 +40,56 @@ interface INttManager is INttManagerState {
3440
error DeliveryPaymentTooLow(uint256 requiredPayment, uint256 providedPayment);
3541

3642
//// @notice The transfer has some dust.
37-
//// @dev This is a security measure to prevent users from losing funds.
38-
//// This is the result of trimming the amount and then untrimming it.
43+
//// @dev This is a security measure to prevent users from losing funds.
44+
//// This is the result of trimming the amount and then untrimming it.
3945
//// @param amount The amount to transfer.
4046
error TransferAmountHasDust(uint256 amount, uint256 dust);
4147

4248
/// @notice The mode is invalid. It is neither in LOCKING or BURNING mode.
4349
/// @param mode The mode.
4450
error InvalidMode(uint8 mode);
4551

52+
/// @notice Error when the refund to the sender fails.
53+
/// @dev Selector 0x2ca23714.
54+
/// @param refundAmount The refund amount.
4655
error RefundFailed(uint256 refundAmount);
56+
57+
/// @notice Error when the tranceiver already attested to the message.
58+
/// To ensure the client does not continue to initiate calls to the attestationReceived function.
59+
/// @dev Selector 0x2113894.
60+
/// @param nttManagerMessageHash The hash of the message.
4761
error TransceiverAlreadyAttestedToMessage(bytes32 nttManagerMessageHash);
62+
63+
/// @notice Error when the message is not approved.
64+
/// @dev Selector 0x451c4fb0.
65+
/// @param msgHash The hash of the message.
4866
error MessageNotApproved(bytes32 msgHash);
67+
68+
/// @notice Error when trying to execute a message on an unintended target chain.
69+
/// @dev Selector 0x3dcb204a.
70+
/// @param targetChain The target chain.
71+
/// @param thisChain The current chain.
4972
error InvalidTargetChain(uint16 targetChain, uint16 thisChain);
73+
74+
/// @notice Error when the transfer amount is zero.
75+
/// @dev Selector 0x9993626a.
5076
error ZeroAmount();
77+
78+
/// @notice Error when the recipient is invalid.
79+
/// @dev Selector 0x9c8d2cd2.
5180
error InvalidRecipient();
81+
82+
/// @notice Error when the amount burned is different than the balance difference,
83+
/// since NTT does not support burn fees.
84+
/// @dev Selector 0x02156a8f.
85+
/// @param burnAmount The amount burned.
86+
/// @param balanceDiff The balance after burning.
5287
error BurnAmountDifferentThanBalanceDiff(uint256 burnAmount, uint256 balanceDiff);
5388

5489
/// @notice Transfer a given amount to a recipient on a given chain. This function is called
55-
/// by the user to send the token cross-chain. This function will either lock or burn the
56-
/// sender's tokens. Finally, this function will call into registered `Endpoint` contracts
57-
/// to send a message with the incrementing sequence number and the token transfer payload.
90+
/// by the user to send the token cross-chain. This function will either lock or burn the
91+
/// sender's tokens. Finally, this function will call into registered `Endpoint` contracts
92+
/// to send a message with the incrementing sequence number and the token transfer payload.
5893
/// @param amount The amount to transfer.
5994
/// @param recipientChain The chain ID for the destination.
6095
/// @param recipient The recipient address.
@@ -65,9 +100,9 @@ interface INttManager is INttManagerState {
65100
) external payable returns (uint64 msgId);
66101

67102
/// @notice Transfer a given amount to a recipient on a given chain. This function is called
68-
/// by the user to send the token cross-chain. This function will either lock or burn the
69-
/// sender's tokens. Finally, this function will call into registered `Endpoint` contracts
70-
/// to send a message with the incrementing sequence number and the token transfer payload.
103+
/// by the user to send the token cross-chain. This function will either lock or burn the
104+
/// sender's tokens. Finally, this function will call into registered `Endpoint` contracts
105+
/// to send a message with the incrementing sequence number and the token transfer payload.
71106
/// @dev Transfers are queued if the outbound limit is hit and must be completed by the client.
72107
/// @param amount The amount to transfer.
73108
/// @param recipientChain The chain ID for the destination.
@@ -106,8 +141,8 @@ interface INttManager is INttManagerState {
106141

107142
/// @notice Called by an Endpoint contract to deliver a verified attestation.
108143
/// @dev This function enforces attestation threshold and replay logic for messages. Once all
109-
/// validations are complete, this function calls `executeMsg` to execute the command specified
110-
/// by the message.
144+
/// validations are complete, this function calls `executeMsg` to execute the command specified
145+
/// by the message.
111146
/// @param sourceChainId The chain id of the sender.
112147
/// @param sourceNttManagerAddress The address of the sender's nttManager contract.
113148
/// @param payload The VAA payload.
@@ -117,11 +152,11 @@ interface INttManager is INttManagerState {
117152
TransceiverStructs.NttManagerMessage memory payload
118153
) external;
119154

120-
/// @notice Called after a message has been sufficiently verified to execute the command in the message.
121-
/// This function will decode the payload as an NttManagerMessage to extract the sequence, msgType,
122-
/// and other parameters.
155+
/// @notice Called after a message has been sufficiently verified to execute
156+
/// the command in the message. This function will decode the payload
157+
/// as an NttManagerMessage to extract the sequence, msgType, and other parameters.
123158
/// @dev This function is exposed as a fallback for when an `Transceiver` is deregistered
124-
/// when a message is in flight.
159+
/// when a message is in flight.
125160
/// @param sourceChainId The chain id of the sender.
126161
/// @param sourceNttManagerAddress The address of the sender's nttManager contract.
127162
/// @param message The message to execute.

evm/src/interfaces/ITransceiver.sol

+26-2
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,44 @@ import "../libraries/TransceiverStructs.sol";
55

66
interface ITransceiver {
77
/// @notice The caller is not the deployer.
8+
/// @dev Selector: 0xc68a0e42.
9+
/// @param deployer The address of the deployer.
10+
/// @param caller The address of the caller.
811
error UnexpectedDeployer(address deployer, address caller);
12+
13+
/// @notice The caller is not the NttManager.
14+
/// @dev Selector: 0xc5aa6153.
15+
/// @param caller The address of the caller.
916
error CallerNotNttManager(address caller);
17+
18+
/// @notice Error when trying renounce transceiver ownership.
19+
/// Ensures the owner of the transceiver is in sync with
20+
/// the owner of the NttManager.
21+
/// @dev Selector: 0x66791dd6.
22+
/// @param currentOwner he current owner of the transceiver.
1023
error CannotRenounceTransceiverOwnership(address currentOwner);
24+
25+
/// @notice Error when trying to transfer transceiver ownership.
26+
/// @dev Selector: 0x306239eb.
27+
/// @param currentOwner The current owner of the transceiver.
28+
/// @param newOwner The new owner of the transceiver.
1129
error CannotTransferTransceiverOwnership(address currentOwner, address newOwner);
30+
31+
/// @notice Error when the recipient NttManager address is not the
32+
/// corresponding manager of the transceiver.
33+
/// @dev Selector: 0x73bdd322.
34+
/// @param recipientNttManagerAddress The address of the recipient NttManager.
35+
/// @param expectedRecipientNttManagerAddress The expected address of the recipient NttManager.
1236
error UnexpectedRecipientNttManagerAddress(
1337
bytes32 recipientNttManagerAddress, bytes32 expectedRecipientNttManagerAddress
1438
);
1539

1640
/// @notice Fetch the delivery price for a given recipient chain transfer.
1741
/// @param recipientChain The Wormhole chain ID of the target chain.
1842
/// @param instruction An additional Instruction provided by the Transceiver to be
19-
/// executed on the recipient chain.
43+
/// executed on the recipient chain.
2044
/// @return deliveryPrice The cost of delivering a message to the recipient chain,
21-
/// in this chain's native token.
45+
/// in this chain's native token.
2246
function quoteDeliveryPrice(
2347
uint16 recipientChain,
2448
TransceiverStructs.TransceiverInstruction memory instruction

evm/src/interfaces/IWormholeTransceiver.sol

+39-4
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,64 @@ import "../libraries/TransceiverStructs.sol";
66
import "./IWormholeTransceiverState.sol";
77

88
interface IWormholeTransceiver is IWormholeTransceiverState {
9+
/// @notice The instruction for the WormholeTransceiver contract
10+
/// to skip delivery via the relayer.
911
struct WormholeTransceiverInstruction {
1012
bool shouldSkipRelayerSend;
1113
}
1214

15+
/// @notice Emitted when a relayed message is received.
16+
/// @dev Topic0
17+
/// 0xf557dbbb087662f52c815f6c7ee350628a37a51eae9608ff840d996b65f87475
18+
/// @param digest The digest of the message.
19+
/// @param emitterChainId The chain ID of the emitter.
20+
/// @param emitterAddress The address of the emitter.
1321
event ReceivedRelayedMessage(bytes32 digest, uint16 emitterChainId, bytes32 emitterAddress);
22+
23+
/// @notice Emitted when a message is received.
24+
/// @dev Topic0
25+
/// 0xf6fc529540981400dc64edf649eb5e2e0eb5812a27f8c81bac2c1d317e71a5f0.
26+
/// @param digest The digest of the message.
27+
/// @param emitterChainId The chain ID of the emitter.
28+
/// @param emitterAddress The address of the emitter.
29+
/// @param sequence The sequence of the message.
1430
event ReceivedMessage(
1531
bytes32 digest, uint16 emitterChainId, bytes32 emitterAddress, uint64 sequence
1632
);
33+
34+
/// @notice Emitted when a message is sent from the transceiver.
35+
/// @dev Topic0
36+
/// 0x53b3e029c5ead7bffc739118953883859d30b1aaa086e0dca4d0a1c99cd9c3f5.
37+
/// @param recipientChain The chain ID of the recipient.
38+
/// @param message The message.
1739
event SendTransceiverMessage(
1840
uint16 recipientChain, TransceiverStructs.TransceiverMessage message
1941
);
2042

43+
/// @notice Error when the relaying configuration is invalid. (e.g. chainId is not registered)
44+
/// @dev Selector: 0x9449a36c.
45+
/// @param chainId The chain ID that is invalid.
2146
error InvalidRelayingConfig(uint16 chainId);
47+
48+
/// @notice Error when the peer transceiver is invalid.
49+
/// @dev Selector: 0x79b1ce56.
50+
/// @param chainId The chain ID of the peer.
51+
/// @param peerAddress The address of the invalid peer.
2252
error InvalidWormholePeer(uint16 chainId, bytes32 peerAddress);
53+
54+
/// @notice Error when the VAA has already been consumed.
55+
/// @dev Selector: 0x406e719e.
56+
/// @param vaaHash The hash of the VAA.
2357
error TransferAlreadyCompleted(bytes32 vaaHash);
2458

25-
/// @notice Receive an attested message from the verification layer. This function should verify
26-
/// the `encodedVm` and then deliver the attestation to the transceiver NttManager contract.
59+
/// @notice Receive an attested message from the verification layer.
60+
/// This function should verify the `encodedVm` and then deliver the attestation
61+
/// to the transceiver NttManager contract.
2762
/// @param encodedMessage The attested message.
2863
function receiveMessage(bytes memory encodedMessage) external;
2964

30-
/// @notice Parses the encoded instruction and returns the instruction struct. This instruction
31-
/// is specific to the WormholeTransceiver contract.
65+
/// @notice Parses the encoded instruction and returns the instruction struct.
66+
/// This instruction is specific to the WormholeTransceiver contract.
3267
/// @param encoded The encoded instruction.
3368
/// @return instruction The parsed `WormholeTransceiverInstruction`.
3469
function parseWormholeTransceiverInstruction(bytes memory encoded)

0 commit comments

Comments
 (0)