A malicious actor could steal some part of the interest with a sandwich attack #1024
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
high quality report
This report is of especially high quality
satisfactory
satisfies C4 submission criteria; eligible for awards
Lines of code
https://github.com/code-423n4/2023-12-ethereumcreditguild/blob/2376d9af792584e3d15ec9c32578daa33bb56b43/src/loan/SurplusGuildMinter.sol#L142
https://github.com/code-423n4/2023-12-ethereumcreditguild/blob/2376d9af792584e3d15ec9c32578daa33bb56b43/src/governance/ProfitManager.sol#L396-L400
https://github.com/code-423n4/2023-12-ethereumcreditguild/blob/2376d9af792584e3d15ec9c32578daa33bb56b43/src/loan/SurplusGuildMinter.sol#L247-L269
Vulnerability details
Impact
A malicious actor could steal some part of the interest with a
sandwich
attack when a borrowerrepays
a loan. The attacker carries no risk of slashing but enjoys free rewards. Using aflashbots
service to carry out the sandwich bundles he can guarantee profit with0 risk
. The more funds the attacker possesses the more the rewards can be stolen.Proof of Concept
There is no limitation for a user to not stake and unstake in the same block. Because it is possible to stake and unstake in the same block the malicious actor could
sandwich
therepay
call from anyone as follows.stake => repay => unstake
When a user stakes the
getRewards
for that user is called and theProfitManager(profitManager).claimRewards(address(this))
is invoked for theSGM
.This will update the
userStake.profitIndex
to the latestprofitIndex
notifyPnL(gauge, amount)
with interest that is repaid as the amount variable. This updates thegaugeProfitIndex
to a greaterprofitIndex
.profitIndexes
. Since the global index was increased after the user staked it is now greater than theuserProfitIndex
which results in thedeltaIndex > 0
. User get rewards minted having only staked before the repayment.Coded POC
Add this test to
SurplusGuildMinter.t.sol
file and add importimport "@forge-std/console.sol";
Run with
forge test --match-path ./test/unit/loan/SurplusGuildMinter.t.sol -vvv
Tools Used
Manual review
Recommended Mitigation Steps
Prevent users staking and unstaking in the same block to receive rewards even if there is profit from the repayment, as normal users wouldn't do that. Or add a minimum stake time.
Assessed type
Timing
The text was updated successfully, but these errors were encountered: