Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debt gets subtracted twice when refinancing a loan #2103

Open
codehawks-bot opened this issue Aug 8, 2023 · 0 comments
Open

Debt gets subtracted twice when refinancing a loan #2103

codehawks-bot opened this issue Aug 8, 2023 · 0 comments

Comments

@codehawks-bot
Copy link

Debt gets subtracted twice when refinancing a loan

Severity

High Risk

Relevant GitHub Links

https://github.com/Cyfrin/2023-07-beedle/blob/main/src/Lender.sol#L698

https://github.com/Cyfrin/2023-07-beedle/blob/main/src/Lender.sol#L636

https://github.com/Cyfrin/2023-07-beedle/blob/main/src/Lender.sol#L698

Summary

The debt of the loan at hand gets subtracted twice when refinancing it through refinance().

Vulnerability Details

Lender.sol's refinance() subtracts debt from the pool balance twice, which will lock another debt amount's worth of tokens in the new pool.

function refinance(Refinance[] calldata refinances) public {
        for (uint256 i = 0; i < refinances.length; i++) {
						...
           
			// update the old lenders pool
            _updatePoolBalance(
                oldPoolId,
                pools[oldPoolId].poolBalance + loan.debt + lenderInterest
            );

            pools[oldPoolId].outstandingLoans -= loan.debt;

            // @audit deducting from the balance #1
            _updatePoolBalance(poolId, pools[poolId].poolBalance - debt);
            pools[poolId].outstandingLoans += debt;
   
						...
			
            // @audit deducting from the balance #2
            pools[poolId].poolBalance -= debt;
	          
						...
        }
    }

Impact

It will lock debt * 2 worth of tokens in the new pool.

Tools Used

Manual Review

Recommendations

Consider removing the following line: https://github.com/Cyfrin/2023-07-beedle/blob/main/src/Lender.sol#L698

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment