Submitted by Ruhum, also found by 0x1f8b and WatchPug
PortalFacet.sol#L80-L113
The caller of repayAavePortal() can trigger an underflow to arbitrarily increase the callers balance through an underflow.
First, call repayAavePortal() where _backingAmount + _feeAmount > s.routerBalances[msg.sender][_local] && _maxIn > s.routerBalances[msg.sender][_local]. That will trigger the call to the AssetLogic contract:
By setting _local to the same value as the adopted asset, you trigger the following edge case:
So the amountIn value returned by swapFromLocalAssetIfNeededForExactOut() is the totalAmount value that was passed to it. And totalAmount == _backingAmount + _feeAmount.
Meaning the amountIn value is user-specified for this edge case. Finally, we reach the following line:
amountIn (user-specified) is subtracted from the routerBalances in an unchecked block. Thus, the attacker is able to trigger an underflow and increase their balance arbitrarily high. The repayAavePortal() function only verifies that routerBalance < _maxIn.
Heres a test as PoC:
After the call to swapFromLocalAssetIfNeededForExactOut() you should add the following check:
LayneHaber (Connext) confirmed and resolved:
0xleastwood (judge) commented:
