Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audit fixes [GasZipFacet v2.0.2] #910

Merged
merged 12 commits into from
Jan 11, 2025
8 changes: 5 additions & 3 deletions src/Facets/GasZipFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ import { InvalidCallData, CannotBridgeToSameNetwork, InvalidAmount } from "lifi/
contract GasZipFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable {
using SafeTransferLib for address;

uint256 internal constant MAX_CHAINID_LENGTH_ALLOWED = 32;

error OnlyNativeAllowed();
error TooManyChainIds();

/// State ///
address public constant NON_EVM_RECEIVER_IDENTIFIER =
address public constant NON_EVM_ADDRESS =
0x11f111f111f111F111f111f111F111f111f111F1;
IGasZip public immutable gasZipRouter;

Expand Down Expand Up @@ -104,7 +106,7 @@ contract GasZipFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable {

// validate that receiverAddress matches with bridgeData in case of EVM target chain
if (
_bridgeData.receiver != NON_EVM_RECEIVER_IDENTIFIER &&
_bridgeData.receiver != NON_EVM_ADDRESS &&
_gasZipData.receiverAddress !=
bytes32(uint256(uint160(_bridgeData.receiver)))
) revert InvalidCallData();
Expand All @@ -130,7 +132,7 @@ contract GasZipFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable {
) external pure returns (uint256 destinationChains) {
uint256 length = _chainIds.length;

if (length > 32) revert TooManyChainIds();
if (length > MAX_CHAINID_LENGTH_ALLOWED) revert TooManyChainIds();

for (uint256 i; i < length; ++i) {
// Shift destinationChains left by 8 bits and add the next chainID
Expand Down
3 changes: 1 addition & 2 deletions src/Libraries/LibAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ library LibAsset {
}

if (assetId.allowance(address(this), spender) < amount) {
SafeERC20.safeApprove(IERC20(assetId), spender, 0);
SafeERC20.safeApprove(IERC20(assetId), spender, MAX_UINT);
SafeERC20.forceApprove(IERC20(assetId), spender, MAX_UINT);
}
}

Expand Down
14 changes: 3 additions & 11 deletions src/Periphery/GasZipPeriphery.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,21 @@ import { IGasZip } from "../Interfaces/IGasZip.sol";
import { LibSwap } from "../Libraries/LibSwap.sol";
import { LibAsset, IERC20 } from "../Libraries/LibAsset.sol";
import { LibUtil } from "../Libraries/LibUtil.sol";
import { ReentrancyGuard } from "../Helpers/ReentrancyGuard.sol";
import { SwapperV2 } from "../Helpers/SwapperV2.sol";
import { WithdrawablePeriphery } from "../Helpers/WithdrawablePeriphery.sol";
import { Validatable } from "../Helpers/Validatable.sol";
import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol";
import { InvalidCallData } from "../Errors/GenericErrors.sol";

/// @title GasZipPeriphery
/// @author LI.FI (https://li.fi)
/// @notice Provides functionality to swap ERC20 tokens to use the gas.zip protocol as a pre-bridge step (https://www.gas.zip/)
/// @custom:version 1.0.0
contract GasZipPeriphery is
ILiFi,
ReentrancyGuard,
SwapperV2,
Validatable,
WithdrawablePeriphery
{
contract GasZipPeriphery is ILiFi, WithdrawablePeriphery {
using SafeTransferLib for address;

/// State ///
IGasZip public immutable gasZipRouter;
address public immutable liFiDEXAggregator;
uint256 internal constant MAX_CHAINID_LENGTH_ALLOWED = 32;

/// Errors ///
error TooManyChainIds();
Expand Down Expand Up @@ -110,7 +102,7 @@ contract GasZipPeriphery is
) external pure returns (uint256 destinationChains) {
uint256 length = _chainIds.length;

if (length > 32) revert TooManyChainIds();
if (length > MAX_CHAINID_LENGTH_ALLOWED) revert TooManyChainIds();

for (uint256 i; i < length; ++i) {
// Shift destinationChains left by 8 bits and add the next chainID
Expand Down
6 changes: 4 additions & 2 deletions src/Periphery/Permit2Proxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ contract Permit2Proxy is WithdrawablePeriphery {
_assetId,
_amount
);
bytes32 permit = _getTokenPermissionsHash(tokenPermissions);
bytes32 tokenPermissionsHash = _getTokenPermissionsHash(
tokenPermissions
);

// Witness
Permit2Proxy.LiFiCall memory lifiCall = LiFiCall(
Expand All @@ -213,7 +215,7 @@ contract Permit2Proxy is WithdrawablePeriphery {
// PermitTransferWithWitness
msgHash = _getPermitWitnessTransferFromHash(
PERMIT2.DOMAIN_SEPARATOR(),
permit,
tokenPermissionsHash,
address(this),
_nonce,
_deadline,
Expand Down
3 changes: 1 addition & 2 deletions src/Periphery/ReceiverAcrossV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ contract ReceiverAcrossV3 is ILiFi, TransferrableOwnership {
address payable receiver,
uint256 amount
) private {
assetId.safeApprove(address(executor), 0);
assetId.safeApprove(address(executor), amount);
assetId.safeApproveWithRetry(address(executor), amount);
try
executor.swapAndCompleteBridgeTokens(
_transactionId,
Expand Down
Loading