Routers Are Not Enforced To Repay AAVE Portal Loan #143
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
sponsor acknowledged
Technically the issue is correct, but we're not going to resolve it for XYZ reasons
Lines of code
https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/BridgeFacet.sol#L984
Vulnerability details
Background
AAVE Portal
AAVE portal provides a trusted credit line that allows bridges to take on an unbacked position, and Connext intents to use this credit line to provide fast-liquidity for its users in the event the routers do not have sufficient liquidity.
Connext will assign one (1) router to be responsible for taking on credit risk of borrowing an unbacked position from AAVE portal as per Source Code
Under normal circumstance, the
BridgeFacet._reconcile
function will automatically repay back the loan to AAVE portal when the nomad message arrives. However, if the repayment fails for certain reason, Connext expects that the router will use therepayAavePortal
function out-of-band to help Connext to repay the loan.Ultimately, it is Connext that take on the credit risk because AAVE portal only provides a trusted credit line to Connext, but not to the individual routers.
Nomad Message
When nomad message arrives, it will call
BridgeFacet.handle
function, which will in turn trigger the internal_reconcile
function. Note that thehandle
or_reconcile
function cannot be reverted under any circumstances because nomad message cannot be reprocessed on the nomad side.Proof-of-Concept
Alice transfers
1,000,000
DAI from Ethereum domain to Polygon domainNone of the existing routers have sufficient liquidity, thus the sequencer decided that AAVE Portal should be used
Bob's router has been selected to take on the credit risk for the unbacked position, and Connext proceeds to borrow
1,000,000
DAI from AAVE Portal and send the1,000,000
DAI to Alice's wallet on Polygon domainWhen slow nomad message arrives,
BridgeFacet._reconcile
function is triggered to attempt to repay back the loan to AAVE portal. This function will in turn trigger theBridgeFacet._reconcileProcessPortal
function where the portal repayment logic resides.Within the
BridgeFacet._reconcileProcessPortal
, notice that if theAssetLogic.swapFromLocalAssetIfNeededForExactOut
swap fails, it will return_amount
.Within the
BridgeFacet._reconcileProcessPortal
, notice that if the ``AavaPool.backUnbackedexternal repayment call fails, it will set
amountIn = 0` , and then return `return (_amount - amountIn)` , which is basically the same as `_amount`.When the
_reconcileProcessPortal
function call returned at Line 603, it will set thetoDistribute
to theamount
.amount
in this example is1,000,000
DAI.Next, at Line 611, the contract will increase Bob's router balance by
1,000,000
DAIBob notices that his router balance has increased by
1,000,000
DAI, and he could not resist the tempation of1,000,000
DAI. Therefore, instead of helping Connext to repay the loan viarepayAavePortal
function out-of-band, he decided to quickly withdraws all his liquidty from his router.Bob gained
1,000,000
DAI, while Connext still owns AAVE portal1,000,000
DAIImpact
If routers decided not to repay the loan, Connext will incur large amount of debt from AAVE portal.
Recommended Mitigation Steps
Understood that there is a whitelist for routers that can use portals to ensure that only trusted routers could use this feature. In this case, the trust entirely depends on the integrity of the router owner and the assumption that the owner will not act against Connext and its community. However, as seen in many of the past security incidents, trusted actor or even own protocol team member might turn rogue when dealing with significant gain. In the above example,
1,000,000
DAI. It is common to see even larger amount of funds transferring across the bridge.Therefore, to overcome the above-mentioned risk, some protocol would implement
m-of-n
multisig or validation, which help to mitigate the risk of a single trusted actor from turning rogue and perform malicious action.Therefore, it is recommended to reconsider such design and explore other alternatives. One such alternative would be as follows:
The text was updated successfully, but these errors were encountered: