Skip to content

Reentrancy vulnerability in borrowFresh function

Description

The borrowFresh function in Compound performs a state update after doTransferOut, which can lead to a reentrancy attack. This occurs when an attacker can manipulate the function to execute multiple times before the state is updated, potentially draining the contract's funds.

Examples

Insecure Code

solidity
function borrowFresh(...) {
  ... 
  doTransferOut(...);
}

Secure Code

solidity
function borrowFresh(...) {
  accountBorrows[borrower].interestIndex = borrowIndex;
  ... 
  doTransferOut(...);
}

Remediation

Update the borrowFresh function to perform the state update before calling doTransferOut.

Rule Details

FieldValue
IDCODE-0281
CategoryCrypto
SeverityHIGH
CWECWE-841
ConfidenceHIGH
ImpactHIGH
LikelihoodLOW
ExploitabilityCOMPLEX
Tagsreentrancy, smart contract
OWASPN/A

References