Skip to content

Commit afa807c

Browse files
authored
Revert: Add parameter validation to allbridge lf 14440 [GenericErrors v1.0.2,AllBridgeFacet v2.0.0,ChainflipFacet v1.0.0,RelayFacet v1.0.0,SwapperV2 v1.0.0,LibAsset v2.1.0,ReceiverChainflip v1.0.0] (#1280)
* Revert "Add parameter validation to allbridge lf 14440 (#1275)" This reverts commit efa7976. * fake-bump GenericErrors version for git action to pass
1 parent efa7976 commit afa807c

File tree

15 files changed

+71
-358
lines changed

15 files changed

+71
-358
lines changed

conventions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ Follow the folder structure to locate resources and generate or modify code in a
201201
);
202202
}
203203
```
204-
- When a non-EVM address is used, the `bridgeData.receiver` must contain `NON_EVM_ADDRESS` (found in src/Helpers/LiFiData.sol), ensuring proper handling:
204+
- When a non-EVM address is used, the `bridgeData.receiver` must contain `LibAsset.NON_EVM_ADDRESS`, ensuring proper handling:
205205
```
206206
if (
207-
bridgeData.receiver != NON_EVM_ADDRESS
207+
bridgeData.receiver != LibAsset.NON_EVM_ADDRESS
208208
) {
209209
revert InvalidCallData();
210210
}

docs/ChainflipFacet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct ChainflipData {
3232
}
3333
```
3434

35-
For non-EVM destinations (i.e. Solana, Bitcoin), set the `receiver` in `BridgeData` to `NON_EVM_ADDRESS` (inherit from src/Helpers/LiFiData.sol) and provide the destination address in `nonEVMReceiver`.
35+
For non-EVM destinations (i.e. Solana, Bitcoin), set the `receiver` in `BridgeData` to `LibAsset.NON_EVM_ADDRESS` and provide the destination address in `nonEVMReceiver`.
3636

3737
## Supported Chains
3838

src/Errors/GenericErrors.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ error InvalidConfig();
1919
error InvalidContract();
2020
error InvalidDestinationChain();
2121
error InvalidFallbackAddress();
22-
error InvalidNonEVMReceiver();
2322
error InvalidReceiver();
2423
error InvalidSendingToken();
2524
error NativeAssetNotSupported();

src/Facets/AllBridgeFacet.sol

Lines changed: 10 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,27 @@ import { SwapperV2 } from "../Helpers/SwapperV2.sol";
88
import { ReentrancyGuard } from "../Helpers/ReentrancyGuard.sol";
99
import { Validatable } from "../Helpers/Validatable.sol";
1010
import { LibSwap } from "../Libraries/LibSwap.sol";
11-
import { InvalidConfig, InvalidCallData, InvalidNonEVMReceiver, InvalidReceiver } from "../Errors/GenericErrors.sol";
12-
import { LiFiData } from "../Helpers/LiFiData.sol";
1311

1412
/// @title Allbridge Facet
15-
/// @author LI.FI (https://li.fi)
13+
/// @author Li.Finance (https://li.finance)
1614
/// @notice Provides functionality for bridging through AllBridge
17-
/// @custom:version 2.1.0
18-
contract AllBridgeFacet is
19-
ILiFi,
20-
ReentrancyGuard,
21-
SwapperV2,
22-
Validatable,
23-
LiFiData
24-
{
25-
uint32 private constant ALLBRIDGE_ID_ETHEREUM = 1;
26-
uint32 private constant ALLBRIDGE_ID_BSC = 2;
27-
uint32 private constant ALLBRIDGE_ID_TRON = 3;
28-
uint32 private constant ALLBRIDGE_ID_SOLANA = 4;
29-
uint32 private constant ALLBRIDGE_ID_POLYGON = 5;
30-
uint32 private constant ALLBRIDGE_ID_ARBITRUM = 6;
31-
uint32 private constant ALLBRIDGE_ID_AVALANCHE = 8;
32-
uint32 private constant ALLBRIDGE_ID_BASE = 9;
33-
uint32 private constant ALLBRIDGE_ID_OPTIMISM = 10;
34-
uint32 private constant ALLBRIDGE_ID_CELO = 11;
35-
uint32 private constant ALLBRIDGE_ID_SUI = 13;
36-
uint256 internal constant LIFI_CHAIN_ID_ARBITRUM = 42161;
37-
uint256 internal constant LIFI_CHAIN_ID_AVALANCHE = 43114;
38-
uint256 internal constant LIFI_CHAIN_ID_BASE = 8453;
39-
uint256 internal constant LIFI_CHAIN_ID_BSC = 56;
40-
uint256 internal constant LIFI_CHAIN_ID_CELO = 42220;
41-
uint256 internal constant LIFI_CHAIN_ID_POLYGON = 137;
42-
43-
error UnsupportedAllBridgeChainId();
44-
15+
/// @custom:version 2.0.0
16+
contract AllBridgeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable {
4517
/// @notice The contract address of the AllBridge router on the source chain.
4618
// solhint-disable-next-line immutable-vars-naming
47-
IAllBridge private immutable ALLBRIDGE;
19+
IAllBridge private immutable allBridge;
4820

4921
/// @notice The struct for the AllBridge data.
50-
/// @param recipient The address of the token receiver after bridging.
5122
/// @param fees The amount of token to pay the messenger and the bridge
23+
/// @param recipient The address of the token receiver after bridging.
5224
/// @param destinationChainId The destination chain id.
5325
/// @param receiveToken The token to receive on the destination chain.
5426
/// @param nonce A random nonce to associate with the tx.
5527
/// @param messenger The messenger protocol enum
5628
/// @param payFeeWithSendingAsset Whether to pay the relayer fee with the sending asset or not
5729
struct AllBridgeData {
58-
bytes32 recipient;
5930
uint256 fees;
31+
bytes32 recipient;
6032
uint256 destinationChainId;
6133
bytes32 receiveToken;
6234
uint256 nonce;
@@ -67,9 +39,7 @@ contract AllBridgeFacet is
6739
/// @notice Initializes the AllBridge contract
6840
/// @param _allBridge The address of the AllBridge contract
6941
constructor(IAllBridge _allBridge) {
70-
if (address(_allBridge) == address(0)) revert InvalidConfig();
71-
72-
ALLBRIDGE = _allBridge;
42+
allBridge = _allBridge;
7343
}
7444

7545
/// @notice Bridge tokens to another chain via AllBridge
@@ -126,38 +96,14 @@ contract AllBridgeFacet is
12696
ILiFi.BridgeData memory _bridgeData,
12797
AllBridgeData calldata _allBridgeData
12898
) internal {
129-
// make sure destinationChainId matches in bridgeData and allBridgeData
130-
if (
131-
_allBridgeData.destinationChainId !=
132-
_getAllBridgeChainId(_bridgeData.destinationChainId)
133-
) revert InvalidCallData();
134-
135-
// validate receiver address
136-
if (_bridgeData.receiver == NON_EVM_ADDRESS) {
137-
// destination chain is non-EVM
138-
// make sure it's non-zero (we cannot validate further)
139-
if (_allBridgeData.recipient == bytes32(0))
140-
revert InvalidNonEVMReceiver();
141-
} else {
142-
// destination chain is EVM
143-
// make sure that bridgeData and allBridgeData receiver addresses match
144-
if (
145-
_bridgeData.receiver !=
146-
address(uint160(uint256(_allBridgeData.recipient)))
147-
) revert InvalidReceiver();
148-
}
149-
150-
// set max approval to allBridge, if current allowance is insufficient
15199
LibAsset.maxApproveERC20(
152100
IERC20(_bridgeData.sendingAssetId),
153-
address(ALLBRIDGE),
101+
address(allBridge),
154102
_bridgeData.minAmount
155103
);
156104

157-
// check if bridge fee should be paid with sending or native asset
158105
if (_allBridgeData.payFeeWithSendingAsset) {
159-
// pay fee with sending asset
160-
ALLBRIDGE.swapAndBridge(
106+
allBridge.swapAndBridge(
161107
bytes32(uint256(uint160(_bridgeData.sendingAssetId))),
162108
_bridgeData.minAmount,
163109
_allBridgeData.recipient,
@@ -168,8 +114,7 @@ contract AllBridgeFacet is
168114
_allBridgeData.fees
169115
);
170116
} else {
171-
// pay fee with native asset
172-
ALLBRIDGE.swapAndBridge{ value: _allBridgeData.fees }(
117+
allBridge.swapAndBridge{ value: _allBridgeData.fees }(
173118
bytes32(uint256(uint160(_bridgeData.sendingAssetId))),
174119
_bridgeData.minAmount,
175120
_allBridgeData.recipient,
@@ -183,41 +128,4 @@ contract AllBridgeFacet is
183128

184129
emit LiFiTransferStarted(_bridgeData);
185130
}
186-
187-
/// @notice Converts LiFi internal chain IDs to AllBridge chain IDs
188-
/// @param _destinationChainId The LiFi chain ID to convert
189-
/// @return The corresponding Chainflip chain ID
190-
/// @dev Reverts if the destination chain is not supported
191-
function _getAllBridgeChainId(
192-
uint256 _destinationChainId
193-
) internal pure returns (uint256) {
194-
// split possible values in half for more efficient search/matching
195-
196-
// first try to match cases where chainId is the same and does not need to be mapped
197-
if (
198-
_destinationChainId == ALLBRIDGE_ID_ETHEREUM ||
199-
_destinationChainId == ALLBRIDGE_ID_OPTIMISM
200-
) return _destinationChainId;
201-
// all others have custom chainIds
202-
else if (_destinationChainId == LIFI_CHAIN_ID_BSC)
203-
return ALLBRIDGE_ID_BSC;
204-
else if (_destinationChainId == LIFI_CHAIN_ID_TRON)
205-
return ALLBRIDGE_ID_TRON;
206-
else if (_destinationChainId == LIFI_CHAIN_ID_SOLANA)
207-
return ALLBRIDGE_ID_SOLANA;
208-
else if (_destinationChainId == LIFI_CHAIN_ID_POLYGON)
209-
return ALLBRIDGE_ID_POLYGON;
210-
else if (_destinationChainId == LIFI_CHAIN_ID_ARBITRUM)
211-
return ALLBRIDGE_ID_ARBITRUM;
212-
else if (_destinationChainId == LIFI_CHAIN_ID_AVALANCHE)
213-
return ALLBRIDGE_ID_AVALANCHE;
214-
else if (_destinationChainId == LIFI_CHAIN_ID_BASE)
215-
return ALLBRIDGE_ID_BASE;
216-
else if (_destinationChainId == LIFI_CHAIN_ID_CELO)
217-
return ALLBRIDGE_ID_CELO;
218-
else if (_destinationChainId == LIFI_CHAIN_ID_SUI)
219-
return ALLBRIDGE_ID_SUI;
220-
// revert if no match found
221-
else revert UnsupportedAllBridgeChainId();
222-
}
223131
}

src/Facets/ChainflipFacet.sol

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,12 @@ import { Validatable } from "../Helpers/Validatable.sol";
1010
import { IChainflipVault } from "../Interfaces/IChainflip.sol";
1111
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
1212
import { InformationMismatch, InvalidConfig, InvalidReceiver } from "../Errors/GenericErrors.sol";
13-
import { LiFiData } from "../Helpers/LiFiData.sol";
1413

15-
/// @title ChainflipFacet
14+
/// @title Chainflip Facet
1615
/// @author LI.FI (https://li.fi)
1716
/// @notice Allows bridging assets via Chainflip
18-
/// @custom:version 1.0.1
19-
contract ChainflipFacet is
20-
ILiFi,
21-
ReentrancyGuard,
22-
SwapperV2,
23-
Validatable,
24-
LiFiData
25-
{
17+
/// @custom:version 1.0.0
18+
contract ChainflipFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable {
2619
/// Events ///
2720
event BridgeToNonEVMChain(
2821
bytes32 indexed transactionId,
@@ -141,7 +134,7 @@ contract ChainflipFacet is
141134

142135
// Handle address encoding based on destination chain type
143136
bytes memory encodedDstAddress;
144-
if (_bridgeData.receiver == NON_EVM_ADDRESS) {
137+
if (_bridgeData.receiver == LibAsset.NON_EVM_ADDRESS) {
145138
if (_chainflipData.nonEVMReceiver.length == 0) {
146139
revert EmptyNonEvmAddress();
147140
}

src/Facets/RelayFacet.sol

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,12 @@ import { ReentrancyGuard } from "../Helpers/ReentrancyGuard.sol";
99
import { SwapperV2 } from "../Helpers/SwapperV2.sol";
1010
import { Validatable } from "../Helpers/Validatable.sol";
1111
import { ECDSA } from "solady/utils/ECDSA.sol";
12-
import { LiFiData } from "../Helpers/LiFiData.sol";
13-
import { InvalidConfig } from "../Errors/GenericErrors.sol";
1412

15-
/// @title RelayFacet
13+
/// @title Relay Facet
1614
/// @author LI.FI (https://li.fi)
1715
/// @notice Provides functionality for bridging through Relay Protocol
18-
/// @custom:version 1.0.1
19-
contract RelayFacet is
20-
ILiFi,
21-
ReentrancyGuard,
22-
SwapperV2,
23-
Validatable,
24-
LiFiData
25-
{
16+
/// @custom:version 1.0.0
17+
contract RelayFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable {
2618
// Receiver for native transfers
2719
// solhint-disable-next-line immutable-vars-naming
2820
address public immutable relayReceiver;
@@ -75,7 +67,7 @@ contract RelayFacet is
7567

7668
// Ensure nonEVMAddress is not empty
7769
if (
78-
_bridgeData.receiver == NON_EVM_ADDRESS &&
70+
_bridgeData.receiver == LibAsset.NON_EVM_ADDRESS &&
7971
_relayData.nonEVMReceiver == bytes32(0)
8072
) {
8173
revert InvalidQuote();
@@ -92,7 +84,7 @@ contract RelayFacet is
9284
bytes32(uint256(uint160(address(this)))),
9385
bytes32(uint256(uint160(_bridgeData.sendingAssetId))),
9486
_getMappedChainId(_bridgeData.destinationChainId),
95-
_bridgeData.receiver == NON_EVM_ADDRESS
87+
_bridgeData.receiver == LibAsset.NON_EVM_ADDRESS
9688
? _relayData.nonEVMReceiver
9789
: bytes32(uint256(uint160(_bridgeData.receiver))),
9890
_relayData.receivingAssetId
@@ -111,10 +103,6 @@ contract RelayFacet is
111103
/// @param _relayReceiver The receiver for native transfers
112104
/// @param _relaySolver The relayer wallet for ERC20 transfers
113105
constructor(address _relayReceiver, address _relaySolver) {
114-
if (_relayReceiver == address(0) || _relaySolver == address(0)) {
115-
revert InvalidConfig();
116-
}
117-
118106
relayReceiver = _relayReceiver;
119107
relaySolver = _relaySolver;
120108
}
@@ -215,7 +203,7 @@ contract RelayFacet is
215203
consumedIds[_relayData.requestId] = true;
216204

217205
// Emit special event if bridging to non-EVM chain
218-
if (_bridgeData.receiver == NON_EVM_ADDRESS) {
206+
if (_bridgeData.receiver == LibAsset.NON_EVM_ADDRESS) {
219207
emit BridgeToNonEVMChain(
220208
_bridgeData.transactionId,
221209
_getMappedChainId(_bridgeData.destinationChainId),

src/Helpers/LiFiData.sol

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/Helpers/SwapperV2.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// SPDX-License-Identifier: LGPL-3.0-only
2+
/// @custom:version 1.0.0
23
pragma solidity ^0.8.17;
34

45
import { ILiFi } from "../Interfaces/ILiFi.sol";
@@ -7,10 +8,9 @@ import { LibAsset } from "../Libraries/LibAsset.sol";
78
import { LibAllowList } from "../Libraries/LibAllowList.sol";
89
import { ContractCallNotAllowed, NoSwapDataProvided, CumulativeSlippageTooHigh } from "../Errors/GenericErrors.sol";
910

10-
/// @title SwapperV2
11+
/// @title Swapper
1112
/// @author LI.FI (https://li.fi)
1213
/// @notice Abstract contract to provide swap functionality
13-
/// @custom:version 1.0.1
1414
contract SwapperV2 is ILiFi {
1515
/// Types ///
1616

@@ -119,7 +119,7 @@ contract SwapperV2 is ILiFi {
119119

120120
if (finalBalance > initialBalance) {
121121
LibAsset.transferAsset(
122-
LibAsset.NULL_ADDRESS,
122+
LibAsset.NATIVE_ASSETID,
123123
_refundReceiver,
124124
finalBalance - initialBalance
125125
);

src/Libraries/LibAsset.sol

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,23 @@ import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol";
77
import { InvalidReceiver, NullAddrIsNotAValidSpender, InvalidAmount, NullAddrIsNotAnERC20Token } from "../Errors/GenericErrors.sol";
88

99
/// @title LibAsset
10-
/// @custom:version 2.1.1
10+
/// @custom:version 2.1.0
1111
/// @notice This library contains helpers for dealing with onchain transfers
1212
/// of assets, including accounting for the native asset `assetId`
1313
/// conventions and any noncompliant ERC20 transfers
1414
library LibAsset {
1515
using SafeTransferLib for address;
1616
using SafeTransferLib for address payable;
1717

18+
address internal constant NULL_ADDRESS = address(0);
19+
20+
address internal constant NON_EVM_ADDRESS =
21+
0x11f111f111f111F111f111f111F111f111f111F1;
22+
1823
/// @dev All native assets use the empty address for their asset id
1924
/// by convention
20-
address internal constant NULL_ADDRESS = address(0);
25+
26+
address internal constant NATIVE_ASSETID = NULL_ADDRESS;
2127

2228
/// @dev EIP-7702 delegation designator prefix for Account Abstraction
2329
bytes3 internal constant DELEGATION_DESIGNATOR = 0xef0100;
@@ -185,7 +191,7 @@ library LibAsset {
185191
/// @param assetId The asset identifier to evaluate
186192
/// @return Boolean indicating if the asset is the native asset
187193
function isNativeAsset(address assetId) internal pure returns (bool) {
188-
return assetId == NULL_ADDRESS;
194+
return assetId == NATIVE_ASSETID;
189195
}
190196

191197
/// @notice Checks if the given address is a contract

src/Periphery/ReceiverChainflip.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { InvalidConfig } from "../Errors/GenericErrors.sol";
1212
/// @title ReceiverChainflip
1313
/// @author LI.FI (https://li.fi)
1414
/// @notice Receiver contract for Chainflip cross-chain swaps and message passing
15-
/// @custom:version 1.0.1
15+
/// @custom:version 1.0.0
1616
contract ReceiverChainflip is ILiFi, WithdrawablePeriphery {
1717
using SafeTransferLib for address;
1818
using SafeTransferLib for address payable;
@@ -114,7 +114,7 @@ contract ReceiverChainflip is ILiFi, WithdrawablePeriphery {
114114
) private {
115115
// Group address conversion and store in memory to avoid multiple storage reads
116116
address actualAssetId = assetId == CHAINFLIP_NATIVE_ADDRESS
117-
? LibAsset.NULL_ADDRESS
117+
? LibAsset.NATIVE_ASSETID
118118
: assetId;
119119
bool isNative = LibAsset.isNativeAsset(actualAssetId);
120120

0 commit comments

Comments
 (0)