-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: isolate validation of the bridge params
- Loading branch information
1 parent
c50042a
commit 9fb4461
Showing
1 changed file
with
31 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,24 +137,10 @@ contract FastBridgeV2 is Admin, IFastBridgeV2, IFastBridgeV2Errors { | |
} | ||
|
||
/// @inheritdoc IFastBridgeV2 | ||
// TODO: reduce cyclomatic complexity alongside arbitrary call | ||
// solhint-disable-next-line code-complexity | ||
function bridge(BridgeParams memory params, BridgeParamsV2 memory paramsV2) public payable { | ||
// check bridge params | ||
if (params.dstChainId == block.chainid) revert ChainIncorrect(); | ||
if (params.originAmount == 0 || params.destAmount == 0) revert AmountIncorrect(); | ||
if (params.sender == address(0) || params.to == address(0)) revert ZeroAddress(); | ||
if (params.originToken == address(0) || params.destToken == address(0)) revert ZeroAddress(); | ||
if (params.deadline < block.timestamp + MIN_DEADLINE_PERIOD) revert DeadlineTooShort(); | ||
if (paramsV2.callParams.length > MAX_CALL_PARAMS_LENGTH) revert CallParamsLengthAboveMax(); | ||
if (paramsV2.callValue != 0 && params.destToken == UniversalTokenLib.ETH_ADDRESS) { | ||
revert NativeTokenCallValueNotSupported(); | ||
} | ||
int256 exclusivityEndTime = int256(block.timestamp) + paramsV2.quoteExclusivitySeconds; | ||
// exclusivityEndTime must be in range (0 .. params.deadline] | ||
if (exclusivityEndTime <= 0 || exclusivityEndTime > int256(params.deadline)) { | ||
revert ExclusivityParamsIncorrect(); | ||
} | ||
_validateBridgeParams(params, paramsV2, exclusivityEndTime); | ||
|
||
// transfer tokens to bridge contract | ||
/// @dev use returned originAmount in request in case of transfer fees | ||
uint256 originAmount = _pullToken(params.originToken, params.originAmount); | ||
|
@@ -373,6 +359,35 @@ contract FastBridgeV2 is Admin, IFastBridgeV2, IFastBridgeV2Errors { | |
} | ||
} | ||
|
||
/// @notice Performs all the necessary checks for a bridge to happen. | ||
/// @dev There's no good way to refactor this function to reduce cyclomatic complexity due to | ||
/// the number of checks that need to be performed, so we skip the code-complexity rule here. | ||
// solhint-disable-next-line code-complexity | ||
function _validateBridgeParams( | ||
BridgeParams memory params, | ||
BridgeParamsV2 memory paramsV2, | ||
int256 exclusivityEndTime | ||
) | ||
internal | ||
view | ||
{ | ||
// Check V1 (legacy) params | ||
if (params.dstChainId == block.chainid) revert ChainIncorrect(); | ||
if (params.originAmount == 0 || params.destAmount == 0) revert AmountIncorrect(); | ||
if (params.sender == address(0) || params.to == address(0)) revert ZeroAddress(); | ||
if (params.originToken == address(0) || params.destToken == address(0)) revert ZeroAddress(); | ||
if (params.deadline < block.timestamp + MIN_DEADLINE_PERIOD) revert DeadlineTooShort(); | ||
// Check V2 params | ||
if (paramsV2.callParams.length > MAX_CALL_PARAMS_LENGTH) revert CallParamsLengthAboveMax(); | ||
if (paramsV2.callValue != 0 && params.destToken == UniversalTokenLib.ETH_ADDRESS) { | ||
revert NativeTokenCallValueNotSupported(); | ||
} | ||
// exclusivityEndTime must be in range (0 .. params.deadline] | ||
if (exclusivityEndTime <= 0 || exclusivityEndTime > int256(params.deadline)) { | ||
revert ExclusivityParamsIncorrect(); | ||
} | ||
} | ||
Check notice Code scanning / Slither Block timestamp Low
FastBridgeV2._validateBridgeParams(IFastBridge.BridgeParams,IFastBridgeV2.BridgeParamsV2,int256) uses timestamp for comparisons
Dangerous comparisons: - params.deadline < block.timestamp + MIN_DEADLINE_PERIOD - exclusivityEndTime <= 0 || exclusivityEndTime > int256(params.deadline) |
||
|
||
/// @notice Performs all the necessary checks for a relay to happen. | ||
function _validateRelayParams( | ||
BridgeTransactionV2 memory transaction, | ||
|