code-423n4 / 2021-04-basedloans-findings

0 stars 1 forks source link

Potential reentrancy caused by the `doTransferIn` function of the `CErc20` contract. #42

Closed code423n4 closed 3 years ago

code423n4 commented 3 years ago

Handle

shw

Vulnerability details

Impact

The doTransferIn function in the CErc20 contract transfers the underlying token to the contract itself by calling transferFrom. However, if the underlying token supports the ERC777 standard, the sender may register a transfer hook at the token contract to get the execution flow when transferFrom is called. He could then re-enter some functions in the CToken contract, such as mintFresh and repayBorrowFresh, which are in an intermediate state, causing unexpected results.

Proof of Concept

Referenced code: CErc20.sol#L147 CToken.sol#L530 CToken.sol#L893 CToken.sol#L1262

Tools Used

None

Recommended Mitigation Steps

Add reentrancy guards to critical functions in both CErc20 and CToken.

ghoul-sol commented 3 years ago

doTransferIn is called in 3 functions:

I don't see a way to re-enter.

cemozerr commented 3 years ago

I'm closing this as not a bug due to @ghoul-sol the fact that all the functions affected are protected by a nonReentrant modifier.