Anyone can sandwich a partial repayment of the borrower to steal the surplus fee #114
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
duplicate-994
edited-by-warden
satisfactory
satisfies C4 submission criteria; eligible for awards
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2023-12-ethereumcreditguild/blob/2376d9af792584e3d15ec9c32578daa33bb56b43/src/governance/ProfitManager.sol#L292
Vulnerability details
Explanation
When the borrower calls the
partialRepay
function, it triggers a call to theProfitManager
contract, specifically to thenotifyPnL
function. This function manages the profits from the repayment, and part of the profits are added to the surplus.As there is no restrictions to staking and unstaking, a bad actor can mint a lot of credit tokens and stake them into the surplus contract right before the
partialRepay
is called by the borrower, and unstake and burn the tokens right after, which makes it possible to extract value without really investing on the protocol, stealing from the lenders.This also makes it possible for the borrower to end up paying a little less in fees, as he can do the same with a flash loan, minting credit tokens, staking them, calling the
partialRepay
function, unstaking and then burning the tokens, and repaying the flash loan if it seems profitable.Impact
As there is a potential for a sandwich attack that can drain the fees from the surplus, it can lead to no one being incentivized to provide liquidity for the surplus.
Proof of Concept
Borrower tries to repay a part of the loan
Bad actor snipes it, sets the sandwich attack
Bad actor makes a second transaction go right after the borrower repayment
This is due to the
partialRepay
function calling thenotifyPnL
function from the ProfitManager contract, which handles the profit made in the same txTools Used
VSCode
Recommended Mitigation Steps
The rewards could be queued to be distributed and need to be executed on a future block to prevent this kind of attack.
Assessed type
Context
The text was updated successfully, but these errors were encountered: