Skip to content

Commit

Permalink
reentrancy fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sriyantra committed Apr 30, 2022
1 parent 7b04581 commit 78c15b2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 1 addition & 2 deletions contracts/CEther.sol
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ contract CEther is CToken, CEtherInterface {

function doTransferOut(address payable to, uint amount) internal {
// Send the Ether and revert on failure
(bool success, ) = to.call.value(amount)("");
require(success, "doTransferOut failed");
to.transfer(amount);
}

function requireNoError(uint errCode, string memory message) internal pure {
Expand Down
6 changes: 4 additions & 2 deletions contracts/CToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -709,12 +709,13 @@ contract CToken is CTokenInterface, Exponential, TokenErrorReporter {
* On success, the cToken has redeemAmount less of cash.
* doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred.
*/
doTransferOut(redeemer, vars.redeemAmount);

/* We write previously calculated values into storage */
totalSupply = vars.totalSupplyNew;
accountTokens[redeemer] = vars.accountTokensNew;

doTransferOut(redeemer, vars.redeemAmount);

/* We emit a Transfer event, and a Redeem event */
emit Transfer(redeemer, address(this), vars.redeemTokens);
emit Redeem(redeemer, vars.redeemAmount, vars.redeemTokens);
Expand Down Expand Up @@ -809,13 +810,14 @@ contract CToken is CTokenInterface, Exponential, TokenErrorReporter {
* On success, the cToken borrowAmount less of cash.
* doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred.
*/
doTransferOut(borrower, borrowAmount);

/* We write the previously calculated values into storage */
accountBorrows[borrower].principal = vars.accountBorrowsNew;
accountBorrows[borrower].interestIndex = borrowIndex;
totalBorrows = vars.totalBorrowsNew;

doTransferOut(borrower, borrowAmount);

/* We emit a Borrow event */
emit Borrow(borrower, borrowAmount, vars.accountBorrowsNew, vars.totalBorrowsNew);

Expand Down

0 comments on commit 78c15b2

Please sign in to comment.