Submitted by SBSecurity, also found by JCN, grearlake, EV_om, Arz, Soul22, carrotsmuggler, Infect3d, Mike_Bello90, evmboi32, smiling_heretic, SECURITISE, zhaojie, rbserver, almurhasan, EllipticPoint (1, 2), 0xanmol, 0xbepresent, kaden, c47ch3m4ll, whitehat-boys, 0x_6a70, 0xfave, Byteblockers (1, 2), CaeraDenoir, critical-or-high, ether_sky, and cccz
https://github.com/code-423n4/2023-12-ethereumcreditguild/blob/2376d9af792584e3d15ec9c32578daa33bb56b43/src/loan/SurplusGuildMinter.sol#L114-L155
https://github.com/code-423n4/2023-12-ethereumcreditguild/blob/2376d9af792584e3d15ec9c32578daa33bb56b43/src/loan/SurplusGuildMinter.sol#L158-L212
https://github.com/code-423n4/2023-12-ethereumcreditguild/blob/2376d9af792584e3d15ec9c32578daa33bb56b43/src/loan/SurplusGuildMinter.sol#L216-L290
A malicious borrower can reduce all Guild holders rewards with a big flashloan, upon full repayment.
A borrower opens a loan with the minimum borrowable amount in term with no mandatory partial repayment. Waits for the loan to accumulate interest, then transfers the funds to an alternative account - EXPLOITER. EXPLOITER takes a flash loan, stakes the amount through SurplusGuildMinter, repays the original loan, lowering the rewards for all other GUILD holders by increasing the _gaugeWeight with his staked tokens. Afterward, the EXPLOITER unstakes and returns the flashloan.
The attacker ends up with his collateral, his loan repaid, credit reward and a big percentage of the reward intended for GUILD holders since he is the largest staker for this term at the time of the attack. He receives significant credit and guild rewards as a staker, which is incorrect because he was a staker only for that specific transaction.
He only pays the unavoidable interest payment, typically around $4-5, along with gas costs in the scenario described below.
Note: The attack can be simplified further by having a substantial amount of tokens and bypassing the flashloan step. By frontrunning the notifyPnL() function with a stake(), followed by a backrun with an unstake(), this way the attacker can instantly accumulate rewards without being a long-term staker like others in the system.
The exploiter has two accounts:
Prerequisites: The exploiter requires approximately $10 balance before the attack to cover the loan interest.
Here are the detailed steps to execute the described attack:
Create new file in test/unit/loan called DeflateGuildHoldersRewards.t.sol:
There are tests for both cases  one without the attack and another with the attack scenario.
Run them with:
Providing recommendations is challenging due to the large codebase, and code changes might affect other parts of the system.
The things we came up with to protect against this are to not allow staking and unstaking in the same block, implementing staking/unstaking fee, or implement a warm-up period during which stakers are unable to accumulate interest.
We are open to collaborate with the development team to find a proper mitigation for the problem.
Context
eswak (Ethereum Credit Guild) acknowledged, but disagreed with severity and commented:
TrungOre (judge) decreased severity to Medium
btk (warden) commented:
Slavcheww (warden) commented:
btk (warden) commented:
Slavcheww (warden) commented:
