QA Report #173
Labels
bug
Something isn't working
QA (Quality Assurance)
Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
safeApprove, safeIncreaseAllowance and safeDecreaseAllowance will be failed if allowance is not zero
Lines of code
https://github.com/code-423n4/2022-06-connext/blob/4dd6149748b635f95460d4c3924c7e3fb6716967/contracts/contracts/core/connext/helpers/Executor.sol#L143
https://github.com/code-423n4/2022-06-connext/blob/4dd6149748b635f95460d4c3924c7e3fb6716967/contracts/contracts/core/connext/facets/PortalFacet.sol#L185
https://github.com/code-423n4/2022-06-connext/blob/4dd6149748b635f95460d4c3924c7e3fb6716967/contracts/contracts/core/connext/libraries/AssetLogic.sol#L288
https://github.com/code-423n4/2022-06-connext/blob/4dd6149748b635f95460d4c3924c7e3fb6716967/contracts/contracts/core/connext/facets/BridgeFacet.sol#L1029
https://github.com/code-423n4/2022-06-connext/blob/4dd6149748b635f95460d4c3924c7e3fb6716967/contracts/contracts/core/connext/helpers/Executor.sol#L205
https://github.com/code-423n4/2022-06-connext/blob/4dd6149748b635f95460d4c3924c7e3fb6716967/contracts/contracts/core/connext/facets/BridgeFacet.sol#L1043
https://github.com/code-423n4/2022-06-connext/blob/4dd6149748b635f95460d4c3924c7e3fb6716967/contracts/contracts/core/connext/libraries/AssetLogic.sol#L347
Vulnerability details
Impact
safeApprove, safeIncreaseAllowance and safeDecreaseAllowance will be failed if allowance is not zero.
This lead to broken logic in swapping (and other actions) these special tokens such as USDT.
Proof of Concept
According to SafeERC20 implementation https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/utils/SafeERC20.sol
You will see that both safeIncreaseAllowance and safeDecreaseAllowance still use token.approve.selector as same as safeApprove. Except that safeApprove require approval to be zero.
But sadly, USDT also require approval to be zero in all case when calling
token.approve.selector
as safeIncreaseAllowance and safeDecreaseAllowance are also callingtoken.approve.selector
. They are required to have zero allowance before call.From your note
This mean after backUnbacked call there may be dust token (non-zero allowance). If this case happened, subsequence swap will be failed as safeIncreaseAllowance is always revert due to non-zero allowance.
Tools Used
Manual
Recommended Mitigation Steps
You should call approve(0) and approve(totalRepayAmount) instead? or with a try catch to not affect gas on all cases
You can safely use this function in your contract to approve token seamlessly without extra gas cost.
The text was updated successfully, but these errors were encountered: