20,000 USDC
View results
Submission Details
Severity: high
Valid

`borrow` function can be frontrun by lender to put `auctionLength` to `1`

Summary

THe borrow function can be frontrun by a malicious lender to put the auctionLength of the lending pool to 1 which will allow the lender to immediately liquidate the new borrower.

Vulnerability Details

When someone wants to take a loan they have the call the borrow function with the poolId they want to borrow from. The lender of this pool could be watching the mempool and decide to call the setPool function to update their pool with the minimum amount of auctionLength which is 1 (i.e. 1 second). With higher gas fees this transaction will be executed before the borrower's.

File: Lender.sol
L130: function setPool(Pool calldata p) public returns (bytes32 poolId) {
// validate the pool
if (
p.lender != msg.sender ||
p.minLoanSize == 0 ||
p.maxLoanRatio == 0 ||
p.auctionLength == 0 ||
p.auctionLength > MAX_AUCTION_LENGTH ||
p.interestRate > MAX_INTEREST_RATE
) revert PoolConfig();

https://github.com/Cyfrin/2023-07-beedle/blob/658e046bda8b010a5b82d2d85e824f3823602d27/src/Lender.sol#L130

File: Lender.sol
L232: function borrow(Borrow[] calldata borrows) public { // @audit - Can be frontrun by lender to put `auctionLength` to 1
for (uint256 i = 0; i < borrows.length; i++) {
bytes32 poolId = borrows[i].poolId;

https://github.com/Cyfrin/2023-07-beedle/blob/658e046bda8b010a5b82d2d85e824f3823602d27/src/Lender.sol#L232

The malicious lender can then put the loan up for auction by calling startAuction. The auction will end at the next mined block which doesn't let any one the time to buy it. The lender can then call seizeLoan to liquidate the newly created loan and receive the collateral.

Impact

Lenders can immeditely liquidate new loans to steal borrower's collateral.

Tools Used

Manual review + Foundry

Recommendations

Have a minimal auctionLength amount, for example 1 day. In addition, a delay can be added when updating existing pools.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.