Routers are not Enforced to Repay AAVE Portal Loan
Originally disclosed on Code4rena
Submitted by xiaoming90
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 the repayAavePortal 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 the handle 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,000DAI from Ethereum domain to Polygon domain - None 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,000DAI from AAVE Portal and send the1,000,000DAI to Alice’s wallet on Polygon domain - When slow nomad message arrives,
BridgeFacet._reconcilefunction is triggered to attempt to repay back the loan to AAVE portal. This function will in turn trigger theBridgeFacet._reconcileProcessPortalfunction where the portal repayment logic resides. - Within the
BridgeFacet._reconcileProcessPortal, notice that if theAssetLogic.swapFromLocalAssetIfNeededForExactOutswap fails, it will return_amount. - Within the
BridgeFacet._reconcileProcessPortal, notice that if the ``AavaPool.backUnbackedexternal repayment call fails, it will setamountIn = 0, and then return [return (_amount - amountIn)](https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/facets/BridgeFacet.sol#L1061) , which is basically the same as_amount`. - When the
_reconcileProcessPortalfunction call returned at Line 603, it will set thetoDistributeto theamount.amountin this example is1,000,000DAI. - Next, at Line 611, the contract will increase Bob’s router balance by
1,000,000DAI - Bob notices that his router balance has increased by
1,000,000DAI, and he could not resist the tempation of1,000,000DAI. Therefore, instead of helping Connext to repay the loan viarepayAavePortalfunction out-of-band, he decided to quickly withdraws all his liquidty from his router. - Bob gained
1,000,000DAI, while Connext still owns AAVE portal1,000,000DAI
Impact
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:
Assuming that the AAVE portal interest rate is fixed, therefore, the amount of repayment is deterministic, and Connext can compute the amount of repayment that needs to be repaid at any point of time.
When the
BridgeFacet._reconcileProcessPortalswap orAavaPool.backUnbackedfails, do not immediately credit the Bob’s router balance. Instead, escrow the amount (1,000,000DAI) received from nomad in anEscrowcontract. Implement a function calledsettleAAVEPortalLoanwithin theEscrowcontract, which contains the logic to perform the necessary actions to repay AAVE portal loan. In this case, Bob is responsible for triggering theEscrow.settleAAVEPortalLoanto kick start the out-of-band repayment process. If the repayment is sucessful, Bob’s router will be credited with the earning for taking on credit risk.One positive side effect of this approach is that Bob will be incentivize to make the repayment as fast as possible because the longer he delays, the higher the interest rate, and thus less earning for him.
This approach is quite similar to the withdrawal pattern.
LayneHaber (Connext) acknowledged and commented:
This is correct, and using an escrow contract would be helpful, but in general the router has no incentive ever to repay aave loans (even with this fix). This eliminates the possibility of a router profiting from the mishandling of
reconcile, but doesn’t address the root of the trustedness, which is embedded at the aave layer (by being able to take out unbacked loans).
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A high-severity business logic bug in Connext Amarok contest. Code4rena made it public on 17 October 2022. Found in the 2022-06-connext audit contest (finding H-05).
About Business logic
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
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.