Ether can be locked in the PoolFactory contract without a way to retrieve it
The PoolFactory contract's createPool function allows a borrower to send Ether while specifying a non-zero ERC20 collateral token address, causing the Ether to be locked in the contract with no way to retrieve it. An attacker could not directly steal funds, but a user error could permanently lock Ether.
Originally disclosed on Code4rena
Submitted by broccolirob
If a borrower calls the createPool function with a non-zero value, but also includes an ERC20 token address for _collateralToken, then the Ether value sent will be locked in the PoolFactory contract forever.
In the _createPool function, a _collateralToken address other than the zero address will set the amount variable to zero. That amount variable will be passed to create2 which will send 0 wei to the newly created Pool contract.
uint256 amount = _collateralToken == address(0) ? _collateralAmount : 0;
Impact
A borrower can accidentally lock Ether in the PoolFactory without the ability to retrieve it.
Proof of Concept
A borrower reuses a script they made to create a pool and deposit collateral. They intend to deposit Ether as collateral so they send value with the transaction, but forget to change the _collateralToken address to address(0). The Pool contract will be deployed using the _collateralToken, and will lock the Ether sent in the PoolFactory
Tools Used
Manual analysis and Hardhat.
Recommended Mitigation Steps
If msg.value is greater than 0, make sure the _collateralToken address is set to address(0).
ritik99 (Sublime) disputed and disagreed with severity:
We will add this check but the scenario laid out is more about sanity checks on the side of the end-user. Assets are not stolen or compromised directly but because of user error. Such cases are better handled via UI/UX. We would suggest a (1) Low rating given the likelihood
Marking down to medium risk based on the c4 documentation and some external requirements on how this would have to occur.
2 — Med: Assets not at direct risk, but the function of the protocol or its availability could be impacted, or leak value with a hypothetical attack path with stated assumptions, but external requirements.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The createPool function does not validate that when Ether is sent, the collateral token address is the zero address, so the Ether is not forwarded to the new pool and remains stuck in the factory.
Impact
Ether sent by a borrower can be permanently locked in the PoolFactory contract, but this requires user error and does not directly risk other assets.
What the attacker needed
Borrower sends Ether with createPool; borrower specifies non-zero collateral token
The fix
The contract should be fixed by adding a check that if msg.value is greater than 0, the _collateralToken address must be the zero address.
How it was found
- Call createPool with a non-zero Ether value and a non-zero _collateralToken address.
- The _createPool function sets amount to zero because _collateralToken is not the zero address.
- The new Pool contract is deployed with zero Ether, and the sent Ether remains in the PoolFactory contract.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you create a pool, you can send Ether (the cryptocurrency) along with the request. But if you also specify a token address for the collateral, the code ignores the Ether you sent and it gets stuck in the factory contract forever. This is like accidentally leaving money in a vending machine that has no refund button.
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.