Skip to content

Commit

Permalink
fix: audit issues 03, 09 & 12
Browse files Browse the repository at this point in the history
  • Loading branch information
Al3xGROS committed Dec 13, 2024
1 parent cab9a83 commit f434388
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/contracts/Teleporter/AvalancheICTTRouterFixedFees.sol
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ contract AvalancheICTTRouterFixedFees is

uint256 primaryFeeAmount = (adjustedAmount * primaryRelayerFeeBips) / BASIS_POINTS_DIVIDER;
uint256 secondaryFeeAmount = destinationBridge.isMultihop
? (amount * secondaryRelayerFeeBips) / BASIS_POINTS_DIVIDER
? (adjustedAmount * secondaryRelayerFeeBips) / BASIS_POINTS_DIVIDER
: 0;

if (
Expand Down Expand Up @@ -191,7 +191,7 @@ contract AvalancheICTTRouterFixedFees is

uint256 primaryFeeAmount = (adjustedAmount * primaryRelayerFeeBips) / BASIS_POINTS_DIVIDER;
uint256 secondaryFeeAmount = destinationBridge.isMultihop
? (amount * secondaryRelayerFeeBips) / BASIS_POINTS_DIVIDER
? (adjustedAmount * secondaryRelayerFeeBips) / BASIS_POINTS_DIVIDER
: 0;

if (
Expand Down Expand Up @@ -264,8 +264,14 @@ contract AvalancheICTTRouterFixedFees is
);
}

SafeERC20.safeIncreaseAllowance(IERC20(feeToken), bridgeSource, primaryFeeAmount);
WrappedNativeToken(payable(feeToken)).deposit{value: primaryFeeAmount}();
WrappedNativeToken wrappedFeeToken = WrappedNativeToken(payable(feeToken));
uint256 wrappedNativeBalance = wrappedFeeToken.balanceOf(address(this));
wrappedFeeToken.deposit{value: primaryFeeAmount}();
wrappedNativeBalance = wrappedFeeToken.balanceOf(address(this)) - wrappedNativeBalance;

if (wrappedNativeBalance > 0) {
SafeERC20.safeIncreaseAllowance(IERC20(feeToken), bridgeSource, wrappedNativeBalance);
}

uint256 bridgeAmount = msg.value - primaryFeeAmount;

Expand Down Expand Up @@ -319,8 +325,14 @@ contract AvalancheICTTRouterFixedFees is
);
}

SafeERC20.safeIncreaseAllowance(IERC20(feeToken), bridgeSource, primaryFeeAmount);
WrappedNativeToken(payable(feeToken)).deposit{value: primaryFeeAmount}();
WrappedNativeToken wrappedFeeToken = WrappedNativeToken(payable(feeToken));
uint256 wrappedNativeBalance = wrappedFeeToken.balanceOf(address(this));
wrappedFeeToken.deposit{value: primaryFeeAmount}();
wrappedNativeBalance = wrappedFeeToken.balanceOf(address(this)) - wrappedNativeBalance;

if (wrappedNativeBalance > 0) {
SafeERC20.safeIncreaseAllowance(IERC20(feeToken), bridgeSource, wrappedNativeBalance);
}

uint256 bridgeAmount = msg.value - primaryFeeAmount;

Expand Down Expand Up @@ -349,6 +361,14 @@ contract AvalancheICTTRouterFixedFees is
return (primaryRelayerFeeBips, secondaryRelayerFeeBips);
}

/// @inheritdoc IAvalancheICTTRouterFixedFees
function getMinBridgeFeesForTokenOnDestinationChain(
bytes32 chainID,
address token
) external view returns (MinBridgeFees memory) {
return destinationChainTokenToMinBridgeFees[chainID][token];
}

/// @notice Always revert as you need to input minimal bridge fees for a token on a destination chain
function registerDestinationTokenBridge(
address, /* tokenAddress */
Expand Down
11 changes: 11 additions & 0 deletions src/interfaces/Teleporter/IAvalancheICTTRouterFixedFees.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ interface IAvalancheICTTRouterFixedFees is IAvalancheICTTRouter {
*/
function getRelayerFeesBips() external view returns (uint256, uint256);

/**
* @notice Get the minimum required fees to bridge a specific token to a given destination chain
* @param chainID The ID of the destination chain
* @param token The address of the token to be bridged
* @return A struct containing the minimum primary and secondary relayer fees for the token on the destination chain
*/
function getMinBridgeFeesForTokenOnDestinationChain(
bytes32 chainID,
address token
) external view returns (MinBridgeFees memory);

/**
* @notice Bridge ERC20 token to a destination chain. The relayer fees are set by the contract.
* @param tokenAddress Address of the ERC20 token contract
Expand Down

0 comments on commit f434388

Please sign in to comment.