Reentrancy in contracts/BorrowerOperations.sol
Several external functions in the BorrowerOperations contract lack a re-entrancy guard, potentially allowing an attacker to re-enter and manipulate debt, collateral, or trove ownership. The report does not demonstrate a concrete exploit but flags the missing protection.
Submitted by heiho1, also found by jayjonah8
Impact
There are several potential re-entrant functions in contracts/BorrowerOperations.sol:
=> Function addColl() on line 346 is potentially re-entrant as it is external but has no re-entrancy guard declared. This function invokes _adjustTrove() which potentially impacts user debt, collateral top-ups or withdrawals.
- Same applies to
-- withdrawColl() on line 373 -- withdrawYUSD() on line 389 -- repayYUSD() on line 406 -- adjustTrove() on line 420
=> Function openTrove() on line 207 is potentially re-entrant as it is external but has no re-entrancy guard declared. This function invokes _openTroveInternal() which potentially impacts trove creation, YUSD withdrawals and YUSD gas compensation.
=> Function closeTrove() on line 628 is potentially re-entrant as it is external but has no re-entrancy guard declared. This function invokes troveManagerCached.removeStake(msg.sender) and troveManagerCached.closeTrove(msg.sender) impacting outcomes like debt, rewards and trove ownership.
Proof of Concept
https://solidity-by-example.org/hacks/re-entrancy/
Tools Used
Slither
Recommended Mitigation Steps
Potential solution is a re-entrancy guard similar to https://docs.openzeppelin.com/contracts/4.x/api/security#ReentrancyGuard
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the external functions that adjust troves and balances lack a re-entrancy guard, and state updates may occur after external calls.
Impact
An attacker could potentially re-enter these functions to manipulate debt, collateral, rewards, or trove ownership, though the report does not confirm exploitability.
What the attacker needed
Ability to call the vulnerable functions; a malicious contract to re-enter
The fix
Add a re-entrancy guard such as OpenZeppelin's ReentrancyGuard to the affected functions.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Re-entrancy is when a contract calls another contract, and that other contract calls back into the first one before it has finished updating its records. This can let an attacker repeat actions or see outdated information. The report says some functions that change important balances don't have a guard against this, but it doesn't show a working attack.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.