partialRepay and repay can be sandwiched #147
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
downgraded by judge
Judge downgraded the risk level of this issue
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/main/src/loan/LendingTerm.sol#L562
Vulnerability details
Impact
Due to the gauge profit distribution mechanism, every borrower would be able to claim back a certain percentage of their repayment. Similarly, individuals with significant capital (whales) can exploit this situation to make substantial profits without assuming any risk.
Proof of Concept
When a borrower makes a payment through either partialRepay or repay, notifyPnL is called. This function sends the profit (interest + start fee) to the Profit Manager, which then distributes the profit to the buffer, credit token holders, gauge voters, and other special addresses. The issue arises from the instant distribution of profits to gauge voters.
This implies that anyone with capital can claim some of these profits by simply depositing capital before a borrower initiates payment. Afterwards, they can claim the rewards using getRewards and unstake to avoid the risk of slashing.
Example
This operation can be executed by one whale simultaneously in every market and every term, as the money is only needed to sandwich.
Note that the borrower can perform the same operation, and they even have the ability to flash-loan and stake a huge weight, and thus extract a big amount of their repayment back.
POC
Gist - https://gist.github.com/0x3b33/7ca9b8a4861c96e0b97ad35c4abf5ff9
Add in - security/2023-12-ethereumcreditguild/test/unit/loan/.sol
Run it with:
Tools Used
Manual review
Recommended Mitigation Steps
I suggest implementing a mechanism for gauges to drip in a manner similar to how credit does.
Assessed type
Error
The text was updated successfully, but these errors were encountered: