routerBalances[msg.sender][_local]
can be inflated in repayAavePortal
due to underflow in unchecked math
#211
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
duplicate
This issue or pull request already exists
Lines of code
https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/PortalFacet.sol#L80-L113
Vulnerability details
https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/libraries/AssetLogic.sol#L226-L250
When the
_local
iscanonicalToAdopted
,AssetLogic.swapFromLocalAssetIfNeededForExactOut()
will return thetotalAmount
asamountIn
, andtotalAmount
is the total of two input values:_backingAmount + _feeAmount
.At L91, it checks for
routerBalance < _maxIn
, but there is no guarantee that_maxIn >= amountIn
.As a result, when
repayAavePortal()
is called with_backingAmount + _feeAmount > routerBalance
and_local
is an adopted asset, L108 will underflow, and therouterBalance
can be inflated to a very high number.https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/RoutersFacet.sol#L591-L593
The
routerBalance
is used for sanity check and once it's been inflated, the router can withdraw possibly all the funds in the contract.Recommendation
Generally, we suggest not to use
unchecked
in critical storage updatesThe text was updated successfully, but these errors were encountered: