@layerzerolabs/lz-evm-protocol-v2 2.0.13 → 2.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/artifacts/contracts/EndpointV2.sol/EndpointV2.json +82 -92
- package/artifacts/contracts/EndpointV2Alt.sol/EndpointV2Alt.json +84 -94
- package/artifacts/contracts/EndpointV2View.sol/EndpointV2View.json +209 -0
- package/artifacts/contracts/EndpointV2ViewUpgradeable.sol/EndpointV2ViewUpgradeable.json +196 -0
- package/artifacts/contracts/MessageLibManager.sol/MessageLibManager.json +12 -12
- package/artifacts/contracts/MessagingChannel.sol/MessagingChannel.json +2 -2
- package/artifacts/contracts/MessagingComposer.sol/MessagingComposer.json +2 -2
- package/artifacts/contracts/interfaces/ILayerZeroEndpointV2.sol/ILayerZeroEndpointV2.json +99 -51
- package/artifacts/contracts/interfaces/IMessageLibManager.sol/IMessageLibManager.json +29 -0
- package/artifacts/contracts/interfaces/IMessagingChannel.sol/IMessagingChannel.json +29 -0
- package/artifacts/contracts/libs/AddressCast.sol/AddressCast.json +14 -3
- package/artifacts/contracts/libs/Errors.sol/Errors.json +30 -45
- package/artifacts/contracts/libs/GUID.sol/GUID.json +2 -2
- package/artifacts/contracts/libs/Transfer.sol/Transfer.json +8 -8
- package/artifacts/contracts/messagelib/BlockedMessageLib.sol/BlockedMessageLib.json +3 -3
- package/artifacts/contracts/messagelib/SimpleMessageLib.sol/SimpleMessageLib.json +10 -10
- package/artifacts/contracts/messagelib/libs/ExecutorOptions.sol/ExecutorOptions.json +5 -5
- package/artifacts/contracts/messagelib/libs/PacketV1Codec.sol/PacketV1Codec.json +2 -2
- package/contracts/EndpointV2.sol +13 -49
- package/contracts/EndpointV2Alt.sol +4 -2
- package/contracts/EndpointV2View.sol +12 -0
- package/contracts/EndpointV2ViewUpgradeable.sol +86 -0
- package/contracts/MessageLibManager.sol +17 -17
- package/contracts/MessagingChannel.sol +8 -8
- package/contracts/MessagingComposer.sol +2 -2
- package/contracts/MessagingContext.sol +1 -1
- package/contracts/interfaces/ILayerZeroEndpointV2.sol +2 -13
- package/contracts/interfaces/ILayerZeroReceiver.sol +0 -1
- package/contracts/interfaces/IMessageLibManager.sol +2 -0
- package/contracts/interfaces/IMessagingChannel.sol +2 -0
- package/contracts/libs/AddressCast.sol +6 -5
- package/contracts/libs/Errors.sol +28 -31
- package/contracts/libs/Transfer.sol +5 -5
- package/contracts/messagelib/BlockedMessageLib.sol +1 -1
- package/contracts/messagelib/SimpleMessageLib.sol +1 -1
- package/contracts/messagelib/libs/ExecutorOptions.sol +6 -6
- package/package.json +3 -1
|
@@ -41,7 +41,7 @@ abstract contract MessagingChannel is IMessagingChannel {
|
|
|
41
41
|
uint64 _nonce,
|
|
42
42
|
bytes32 _payloadHash
|
|
43
43
|
) internal {
|
|
44
|
-
if (_payloadHash == EMPTY_PAYLOAD_HASH) revert Errors.
|
|
44
|
+
if (_payloadHash == EMPTY_PAYLOAD_HASH) revert Errors.LZ_InvalidPayloadHash();
|
|
45
45
|
inboundPayloadHash[_receiver][_srcEid][_sender][_nonce] = _payloadHash;
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -82,7 +82,7 @@ abstract contract MessagingChannel is IMessagingChannel {
|
|
|
82
82
|
function skip(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce) external {
|
|
83
83
|
_assertAuthorized(_oapp);
|
|
84
84
|
|
|
85
|
-
if (_nonce != inboundNonce(_oapp, _srcEid, _sender) + 1) revert Errors.
|
|
85
|
+
if (_nonce != inboundNonce(_oapp, _srcEid, _sender) + 1) revert Errors.LZ_InvalidNonce(_nonce);
|
|
86
86
|
lazyInboundNonce[_oapp][_srcEid][_sender] = _nonce;
|
|
87
87
|
emit InboundNonceSkipped(_srcEid, _sender, _oapp, _nonce);
|
|
88
88
|
}
|
|
@@ -96,9 +96,9 @@ abstract contract MessagingChannel is IMessagingChannel {
|
|
|
96
96
|
_assertAuthorized(_oapp);
|
|
97
97
|
|
|
98
98
|
bytes32 curPayloadHash = inboundPayloadHash[_oapp][_srcEid][_sender][_nonce];
|
|
99
|
-
if (curPayloadHash != _payloadHash) revert Errors.
|
|
99
|
+
if (curPayloadHash != _payloadHash) revert Errors.LZ_PayloadHashNotFound(curPayloadHash, _payloadHash);
|
|
100
100
|
if (_nonce <= lazyInboundNonce[_oapp][_srcEid][_sender] && curPayloadHash == EMPTY_PAYLOAD_HASH)
|
|
101
|
-
revert Errors.
|
|
101
|
+
revert Errors.LZ_InvalidNonce(_nonce);
|
|
102
102
|
// set it to nil
|
|
103
103
|
inboundPayloadHash[_oapp][_srcEid][_sender][_nonce] = NIL_PAYLOAD_HASH;
|
|
104
104
|
emit PacketNilified(_srcEid, _sender, _oapp, _nonce, _payloadHash);
|
|
@@ -113,9 +113,9 @@ abstract contract MessagingChannel is IMessagingChannel {
|
|
|
113
113
|
_assertAuthorized(_oapp);
|
|
114
114
|
|
|
115
115
|
bytes32 curPayloadHash = inboundPayloadHash[_oapp][_srcEid][_sender][_nonce];
|
|
116
|
-
if (curPayloadHash != _payloadHash) revert Errors.
|
|
116
|
+
if (curPayloadHash != _payloadHash) revert Errors.LZ_PayloadHashNotFound(curPayloadHash, _payloadHash);
|
|
117
117
|
if (curPayloadHash == EMPTY_PAYLOAD_HASH || _nonce > lazyInboundNonce[_oapp][_srcEid][_sender])
|
|
118
|
-
revert Errors.
|
|
118
|
+
revert Errors.LZ_InvalidNonce(_nonce);
|
|
119
119
|
delete inboundPayloadHash[_oapp][_srcEid][_sender][_nonce];
|
|
120
120
|
emit PacketBurnt(_srcEid, _sender, _oapp, _nonce, _payloadHash);
|
|
121
121
|
}
|
|
@@ -135,7 +135,7 @@ abstract contract MessagingChannel is IMessagingChannel {
|
|
|
135
135
|
unchecked {
|
|
136
136
|
// try to lazily update the inboundNonce till the _nonce
|
|
137
137
|
for (uint64 i = currentNonce + 1; i <= _nonce; ++i) {
|
|
138
|
-
if (!_hasPayloadHash(_receiver, _srcEid, _sender, i)) revert Errors.
|
|
138
|
+
if (!_hasPayloadHash(_receiver, _srcEid, _sender, i)) revert Errors.LZ_InvalidNonce(i);
|
|
139
139
|
}
|
|
140
140
|
lazyInboundNonce[_receiver][_srcEid][_sender] = _nonce;
|
|
141
141
|
}
|
|
@@ -144,7 +144,7 @@ abstract contract MessagingChannel is IMessagingChannel {
|
|
|
144
144
|
// check the hash of the payload to verify the executor has given the proper payload that has been verified
|
|
145
145
|
actualHash = keccak256(_payload);
|
|
146
146
|
bytes32 expectedHash = inboundPayloadHash[_receiver][_srcEid][_sender][_nonce];
|
|
147
|
-
if (expectedHash != actualHash) revert Errors.
|
|
147
|
+
if (expectedHash != actualHash) revert Errors.LZ_PayloadHashNotFound(expectedHash, actualHash);
|
|
148
148
|
|
|
149
149
|
// remove it from the storage
|
|
150
150
|
delete inboundPayloadHash[_receiver][_srcEid][_sender][_nonce];
|
|
@@ -22,7 +22,7 @@ abstract contract MessagingComposer is IMessagingComposer {
|
|
|
22
22
|
/// @param _message the message
|
|
23
23
|
function sendCompose(address _to, bytes32 _guid, uint16 _index, bytes calldata _message) external {
|
|
24
24
|
// must have not been sent before
|
|
25
|
-
if (composeQueue[msg.sender][_to][_guid][_index] != NO_MESSAGE_HASH) revert Errors.
|
|
25
|
+
if (composeQueue[msg.sender][_to][_guid][_index] != NO_MESSAGE_HASH) revert Errors.LZ_ComposeExists();
|
|
26
26
|
composeQueue[msg.sender][_to][_guid][_index] = keccak256(_message);
|
|
27
27
|
emit ComposeSent(msg.sender, _to, _guid, _index, _message);
|
|
28
28
|
}
|
|
@@ -47,7 +47,7 @@ abstract contract MessagingComposer is IMessagingComposer {
|
|
|
47
47
|
// assert the validity
|
|
48
48
|
bytes32 expectedHash = composeQueue[_from][_to][_guid][_index];
|
|
49
49
|
bytes32 actualHash = keccak256(_message);
|
|
50
|
-
if (expectedHash != actualHash) revert Errors.
|
|
50
|
+
if (expectedHash != actualHash) revert Errors.LZ_ComposeNotFound(expectedHash, actualHash);
|
|
51
51
|
|
|
52
52
|
// marks the message as received to prevent reentrancy
|
|
53
53
|
// cannot just delete the value, otherwise the message can be sent again and could result in some undefined behaviour
|
|
@@ -14,7 +14,7 @@ abstract contract MessagingContext is IMessagingContext {
|
|
|
14
14
|
|
|
15
15
|
/// @dev the sendContext is set to 8 bytes 0s + 4 bytes eid + 20 bytes sender
|
|
16
16
|
modifier sendContext(uint32 _dstEid, address _sender) {
|
|
17
|
-
if (_sendContext != NOT_ENTERED) revert Errors.
|
|
17
|
+
if (_sendContext != NOT_ENTERED) revert Errors.LZ_SendReentrancy();
|
|
18
18
|
_sendContext = (uint256(_dstEid) << 160) | uint160(_sender);
|
|
19
19
|
_;
|
|
20
20
|
_sendContext = NOT_ENTERED;
|
|
@@ -32,12 +32,6 @@ struct Origin {
|
|
|
32
32
|
uint64 nonce;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
enum ExecutionState {
|
|
36
|
-
NotExecutable,
|
|
37
|
-
Executable,
|
|
38
|
-
Executed
|
|
39
|
-
}
|
|
40
|
-
|
|
41
35
|
interface ILayerZeroEndpointV2 is IMessageLibManager, IMessagingComposer, IMessagingChannel, IMessagingContext {
|
|
42
36
|
event PacketSent(bytes encodedPayload, bytes options, address sendLibrary);
|
|
43
37
|
|
|
@@ -70,14 +64,9 @@ interface ILayerZeroEndpointV2 is IMessageLibManager, IMessagingComposer, IMessa
|
|
|
70
64
|
|
|
71
65
|
function verify(Origin calldata _origin, address _receiver, bytes32 _payloadHash) external;
|
|
72
66
|
|
|
73
|
-
function verifiable(
|
|
74
|
-
Origin calldata _origin,
|
|
75
|
-
address _receiver,
|
|
76
|
-
address _receiveLib,
|
|
77
|
-
bytes32 _payloadHash
|
|
78
|
-
) external view returns (bool);
|
|
67
|
+
function verifiable(Origin calldata _origin, address _receiver) external view returns (bool);
|
|
79
68
|
|
|
80
|
-
function
|
|
69
|
+
function initializable(Origin calldata _origin, address _receiver) external view returns (bool);
|
|
81
70
|
|
|
82
71
|
function lzReceive(
|
|
83
72
|
Origin calldata _origin,
|
|
@@ -7,7 +7,6 @@ import { Origin } from "./ILayerZeroEndpointV2.sol";
|
|
|
7
7
|
interface ILayerZeroReceiver {
|
|
8
8
|
function allowInitializePath(Origin calldata _origin) external view returns (bool);
|
|
9
9
|
|
|
10
|
-
// todo: move to OAppReceiver? it is just convention for executor. we may can change it in a new Receiver version
|
|
11
10
|
function nextNonce(uint32 _eid, bytes32 _sender) external view returns (uint64);
|
|
12
11
|
|
|
13
12
|
function lzReceive(
|
|
@@ -42,6 +42,8 @@ interface IMessageLibManager {
|
|
|
42
42
|
|
|
43
43
|
function isSupportedEid(uint32 _eid) external view returns (bool);
|
|
44
44
|
|
|
45
|
+
function isValidReceiveLibrary(address _receiver, uint32 _eid, address _lib) external view returns (bool);
|
|
46
|
+
|
|
45
47
|
/// ------------------- OApp interfaces -------------------
|
|
46
48
|
function setSendLibrary(address _oapp, uint32 _eid, address _newLib) external;
|
|
47
49
|
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
pragma solidity ^0.8.20;
|
|
4
4
|
|
|
5
|
-
import { Errors } from "./Errors.sol";
|
|
6
|
-
|
|
7
5
|
library AddressCast {
|
|
6
|
+
error AddressCast_InvalidSizeForAddress();
|
|
7
|
+
error AddressCast_InvalidAddress();
|
|
8
|
+
|
|
8
9
|
function toBytes32(bytes calldata _addressBytes) internal pure returns (bytes32 result) {
|
|
9
|
-
if (_addressBytes.length > 32) revert
|
|
10
|
+
if (_addressBytes.length > 32) revert AddressCast_InvalidAddress();
|
|
10
11
|
result = bytes32(_addressBytes);
|
|
11
12
|
unchecked {
|
|
12
13
|
uint256 offset = 32 - _addressBytes.length;
|
|
@@ -19,7 +20,7 @@ library AddressCast {
|
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
function toBytes(bytes32 _addressBytes32, uint256 _size) internal pure returns (bytes memory result) {
|
|
22
|
-
if (_size == 0 || _size > 32) revert
|
|
23
|
+
if (_size == 0 || _size > 32) revert AddressCast_InvalidSizeForAddress();
|
|
23
24
|
result = new bytes(_size);
|
|
24
25
|
unchecked {
|
|
25
26
|
uint256 offset = 256 - _size * 8;
|
|
@@ -34,7 +35,7 @@ library AddressCast {
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
function toAddress(bytes calldata _addressBytes) internal pure returns (address result) {
|
|
37
|
-
if (_addressBytes.length != 20) revert
|
|
38
|
+
if (_addressBytes.length != 20) revert AddressCast_InvalidAddress();
|
|
38
39
|
result = address(bytes20(_addressBytes));
|
|
39
40
|
}
|
|
40
41
|
}
|
|
@@ -3,40 +3,37 @@
|
|
|
3
3
|
pragma solidity ^0.8.20;
|
|
4
4
|
|
|
5
5
|
library Errors {
|
|
6
|
-
error
|
|
7
|
-
error
|
|
8
|
-
error
|
|
9
|
-
error
|
|
10
|
-
error
|
|
11
|
-
error
|
|
12
|
-
error
|
|
13
|
-
error
|
|
14
|
-
error
|
|
15
|
-
error
|
|
16
|
-
error
|
|
17
|
-
error
|
|
18
|
-
error
|
|
19
|
-
error
|
|
20
|
-
error
|
|
21
|
-
error
|
|
22
|
-
error
|
|
23
|
-
error
|
|
24
|
-
error
|
|
25
|
-
error
|
|
26
|
-
error
|
|
27
|
-
error
|
|
28
|
-
error
|
|
29
|
-
error
|
|
30
|
-
error
|
|
31
|
-
error
|
|
32
|
-
error
|
|
33
|
-
error InvalidAddress();
|
|
34
|
-
error InvalidSizeForAddress();
|
|
35
|
-
error InsufficientFee(
|
|
6
|
+
error LZ_LzTokenUnavailable();
|
|
7
|
+
error LZ_InvalidReceiveLibrary();
|
|
8
|
+
error LZ_InvalidNonce(uint64 nonce);
|
|
9
|
+
error LZ_InvalidArgument();
|
|
10
|
+
error LZ_InvalidExpiry();
|
|
11
|
+
error LZ_InvalidAmount(uint256 required, uint256 supplied);
|
|
12
|
+
error LZ_OnlyRegisteredOrDefaultLib();
|
|
13
|
+
error LZ_OnlyRegisteredLib();
|
|
14
|
+
error LZ_OnlyNonDefaultLib();
|
|
15
|
+
error LZ_Unauthorized();
|
|
16
|
+
error LZ_DefaultSendLibUnavailable();
|
|
17
|
+
error LZ_DefaultReceiveLibUnavailable();
|
|
18
|
+
error LZ_PathNotInitializable();
|
|
19
|
+
error LZ_PathNotVerifiable();
|
|
20
|
+
error LZ_OnlySendLib();
|
|
21
|
+
error LZ_OnlyReceiveLib();
|
|
22
|
+
error LZ_UnsupportedEid();
|
|
23
|
+
error LZ_UnsupportedInterface();
|
|
24
|
+
error LZ_AlreadyRegistered();
|
|
25
|
+
error LZ_SameValue();
|
|
26
|
+
error LZ_InvalidPayloadHash();
|
|
27
|
+
error LZ_PayloadHashNotFound(bytes32 expected, bytes32 actual);
|
|
28
|
+
error LZ_ComposeNotFound(bytes32 expected, bytes32 actual);
|
|
29
|
+
error LZ_ComposeExists();
|
|
30
|
+
error LZ_SendReentrancy();
|
|
31
|
+
error LZ_NotImplemented();
|
|
32
|
+
error LZ_InsufficientFee(
|
|
36
33
|
uint256 requiredNative,
|
|
37
34
|
uint256 suppliedNative,
|
|
38
35
|
uint256 requiredLzToken,
|
|
39
36
|
uint256 suppliedLzToken
|
|
40
37
|
);
|
|
41
|
-
error
|
|
38
|
+
error LZ_ZeroLzTokenFee();
|
|
42
39
|
}
|
|
@@ -10,17 +10,17 @@ library Transfer {
|
|
|
10
10
|
|
|
11
11
|
address internal constant ADDRESS_ZERO = address(0);
|
|
12
12
|
|
|
13
|
-
error
|
|
14
|
-
error
|
|
13
|
+
error Transfer_NativeFailed(address _to, uint256 _value);
|
|
14
|
+
error Transfer_ToAddressIsZero();
|
|
15
15
|
|
|
16
16
|
function native(address _to, uint256 _value) internal {
|
|
17
|
-
if (_to == ADDRESS_ZERO) revert
|
|
17
|
+
if (_to == ADDRESS_ZERO) revert Transfer_ToAddressIsZero();
|
|
18
18
|
(bool success, ) = _to.call{ value: _value }("");
|
|
19
|
-
if (!success) revert
|
|
19
|
+
if (!success) revert Transfer_NativeFailed(_to, _value);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
function token(address _token, address _to, uint256 _value) internal {
|
|
23
|
-
if (_to == ADDRESS_ZERO) revert
|
|
23
|
+
if (_to == ADDRESS_ZERO) revert Transfer_ToAddressIsZero();
|
|
24
24
|
IERC20(_token).safeTransfer(_to, _value);
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -142,7 +142,7 @@ contract SimpleMessageLib is Ownable, ERC165 {
|
|
|
142
142
|
function _handleMessagingParamsHook(bytes memory _encodedPacket, bytes memory _options) internal virtual {}
|
|
143
143
|
|
|
144
144
|
fallback() external payable {
|
|
145
|
-
revert Errors.
|
|
145
|
+
revert Errors.LZ_NotImplemented();
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
receive() external payable {}
|
|
@@ -14,9 +14,9 @@ library ExecutorOptions {
|
|
|
14
14
|
uint8 internal constant OPTION_TYPE_LZCOMPOSE = 3;
|
|
15
15
|
uint8 internal constant OPTION_TYPE_ORDERED_EXECUTION = 4;
|
|
16
16
|
|
|
17
|
-
error
|
|
18
|
-
error
|
|
19
|
-
error
|
|
17
|
+
error Executor_InvalidLzReceiveOption();
|
|
18
|
+
error Executor_InvalidNativeDropOption();
|
|
19
|
+
error Executor_InvalidLzComposeOption();
|
|
20
20
|
|
|
21
21
|
/// @dev decode the next executor option from the options starting from the specified cursor
|
|
22
22
|
/// @param _options [executor_id][executor_option][executor_id][executor_option]...
|
|
@@ -51,13 +51,13 @@ library ExecutorOptions {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
function decodeLzReceiveOption(bytes calldata _option) internal pure returns (uint128 gas, uint128 value) {
|
|
54
|
-
if (_option.length != 16 && _option.length != 32) revert
|
|
54
|
+
if (_option.length != 16 && _option.length != 32) revert Executor_InvalidLzReceiveOption();
|
|
55
55
|
gas = _option.toU128(0);
|
|
56
56
|
value = _option.length == 32 ? _option.toU128(16) : 0;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
function decodeNativeDropOption(bytes calldata _option) internal pure returns (uint128 amount, bytes32 receiver) {
|
|
60
|
-
if (_option.length != 48) revert
|
|
60
|
+
if (_option.length != 48) revert Executor_InvalidNativeDropOption();
|
|
61
61
|
amount = _option.toU128(0);
|
|
62
62
|
receiver = _option.toB32(16);
|
|
63
63
|
}
|
|
@@ -65,7 +65,7 @@ library ExecutorOptions {
|
|
|
65
65
|
function decodeLzComposeOption(
|
|
66
66
|
bytes calldata _option
|
|
67
67
|
) internal pure returns (uint16 index, uint128 gas, uint128 value) {
|
|
68
|
-
if (_option.length != 18 && _option.length != 34) revert
|
|
68
|
+
if (_option.length != 18 && _option.length != 34) revert Executor_InvalidLzComposeOption();
|
|
69
69
|
index = _option.toU16(0);
|
|
70
70
|
gas = _option.toU128(2);
|
|
71
71
|
value = _option.length == 34 ? _option.toU128(18) : 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@layerzerolabs/lz-evm-protocol-v2",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.15",
|
|
4
4
|
"license": "LZBL-1.2",
|
|
5
5
|
"files": [
|
|
6
6
|
"artifacts/contracts/**/!(*.dbg).json",
|
|
@@ -12,12 +12,14 @@
|
|
|
12
12
|
"dependencies": {},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@openzeppelin/contracts": "^4.8.1",
|
|
15
|
+
"@openzeppelin/contracts-upgradeable": "^4.8.1",
|
|
15
16
|
"hardhat-deploy": "^0.11.44",
|
|
16
17
|
"hardhat-deploy-ethers": "^0.3.0-beta.13",
|
|
17
18
|
"solidity-bytes-utils": "^0.8.0"
|
|
18
19
|
},
|
|
19
20
|
"peerDependencies": {
|
|
20
21
|
"@openzeppelin/contracts": "^4.8.1",
|
|
22
|
+
"@openzeppelin/contracts-upgradeable": "^4.8.1",
|
|
21
23
|
"hardhat-deploy": "^0.11.44",
|
|
22
24
|
"solidity-bytes-utils": "^0.8.0"
|
|
23
25
|
},
|