_ handleExecuteTransaction may not working correctly on fee-on-transfer tokens. Moreover, if it is failed, fund may be locked forever.
The bridge's transaction handler does not correctly account for fee-on-transfer tokens, applying the fee twice and attempting to transfer the full amount when only a reduced amount is available. This causes the failure handler to revert, potentially locking funds permanently.
Submitted by Chom, also found by csanuragjain
BridgeFacet.sol#L856-L877 Executor.sol#L142-L144 Executor.sol#L160-L166 Executor.sol#L194-L213
_handleExecuteTransaction may not working correctly on fee-on-transfer tokens. As duplicated fee is applied to fee on transfer token when executing a arbitrary call message passing request. Moreover, the Executor contract increase allowance on that token for that target contract in full amount without any fee, this may open a vulnerability to steal dust fund in the contract
Moreover, failure is trying to send full amount without any fee which is not possible because fee is already applied one time for example 100 Safemoon -> 90 Safemoon but trying to transfer 100 safemoon to _recovery address. Obviously not possible since we only have 90 Safemoon. This will revert and always revert causing loss of fund in all case of fee-on-transfer tokens.
Proof of Concept
A message to transfer 100 Safemoon with some contract call payload has been submitted by a relayer to _handleExecuteTransaction function on BridgeFacet these lines hit.
// execute calldata w/funds
AssetLogic.transferAssetFromContract(_asset, address(s.executor), _amount);
(bool success, bytes memory returnData) = s.executor.execute(
IExecutor.ExecutorArgs(
_transferId,
_amount,
_args.params.to,
_args.params.recovery,
_asset,
_reconciled
? LibCrossDomainProperty.formatDomainAndSenderBytes(_args.params.originDomain, _args.originSender)
: LibCrossDomainProperty.EMPTY_BYTES,
_args.params.callData
)
);
Noticed that 100 Safemoon is transferred to executor before contract execution. Now executor has 90 Safemoon due to 10% fee on transfer.
if (!isNative) {
SafeERC20Upgradeable.safeIncreaseAllowance(IERC20Upgradeable(_args.assetId), _args.to, _args.amount);
}
Next, we increase allowance of target contract to transfer 100 more Safemoon.
// Try to execute the callData
// the low level call will return `false` if its execution reverts
(success, returnData) = ExcessivelySafeCall.excessivelySafeCall(
_args.to,
gas,
isNative ? _args.amount : 0,
MAX_COPY,
_args.callData
);
After that, it call target contract
// Try to execute the callData
// the low level call will return `false` if its execution reverts
(success, returnData) = ExcessivelySafeCall.excessivelySafeCall(
_args.to,
gas,
isNative ? _args.amount : 0,
MAX_COPY,
_args.callData
);
Target contract tried to pull 100 Safemoon from Executor but now Executor only has 90 Safemoon, so contract call failed. Moving on to the failure handle.
function _handleFailure(
bool isNative,
bool hasIncreased,
address _assetId,
address payable _to,
address payable _recovery,
uint256 _amount
) private {
if (!isNative) {
// Decrease allowance
if (hasIncreased) {
SafeERC20Upgradeable.safeDecreaseAllowance(IERC20Upgradeable(_assetId), _to, _amount);
}
// Transfer funds
SafeERC20Upgradeable.safeTransfer(IERC20Upgradeable(_assetId), _recovery, _amount);
} else {
// Transfer funds
AddressUpgradeable.sendValue(_recovery, _amount);
}
}
isNative = false because of Safemoon
Trying to transfer 100 Safemoon to _recovery while only having 90 Safemoon in the contract. Thus failure handle is reverted.
Recommended Mitigation Steps
You should approve one step only. Avoid an extra token transfer.
LayneHaber (Connext) confirmed and commented:
Not sure I agree with the mitigation (perhaps a better alternative would be to transfer the balance of the executor), but understand the problems!
LayneHaber (Connext) acknowledged and commented:
Upon further reflection, choosing to remove support for fee on transfer tokens. The problems are much deeper than just issues on
execute— the minted token will not have fees on transfers (uses vanilla ERC20 implementation), and i doubt theStableSwapimplementations are taking these into account as well. Changing label to “acknowledged”!
LayneHaber (Connext) resolved:
error on fee: connext/nxtp@14df4c6
0xleastwood (judge) decreased severity to Medium and commented:
The destination chain will indeed be unable to handle bridge transfers involving fee-on-transfer tokens. Although, its worth adding that this is only made possible because
handleIncomingAssetandswapToLocalAssetIfNeededinxcalldo not fail when the provided asset has some fee-on-transfer behaviour.Because
_args.amountis not overridden with the actualamounttransferred in fromhandleIncomingAsset, routers on the destination chain will attempt to provide liquidity for the amount transferred by the user + the fee. Furthermore, when the transfer has been fully bridged, routers who fronted the liquidity will receive less funds than expected. However, I don’t actually think this issue warrantshighseverity, mainly because the bridge transfer should actually execute successfully.The only issue is that if routers front liquidity, they are exposing themselves to receiving slightly less funds due to the fee upon reconciliation. Hence, only value is being leaked and I think
mediumseverity makes more sense.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the contract does not check the actual balance received after a fee-on-transfer token transfer, so it later attempts to move the original amount instead of the reduced amount.
Impact
The failure handler always reverts for fee-on-transfer tokens, so funds can be locked permanently; the bridge later removed support for such tokens.
What the attacker needed
Bridge supports fee-on-transfer tokens; relayer submits a message with such a token
The fix
The project resolved the issue by removing support for fee-on-transfer tokens.
How it was found
- A relayer submits a message to transfer 100 fee-on-transfer tokens with a contract call payload to the bridge handler.
- The bridge transfers the tokens to the executor contract, which receives only 90 due to the fee.
- The executor increases allowance for the target contract by the full 100 amount.
- The target contract tries to pull 100 tokens but the executor only has 90, so the call fails.
- The failure handler attempts to transfer 100 tokens to the recovery address, but only 90 are available, so it reverts.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Some tokens take a small fee when they are transferred, so the receiver gets less than the sender sent. This bridge assumed the full amount would always arrive, so when it tried to send the full amount back after a failure, it did not have enough and the transaction got stuck.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.