The EtherPot contract
To demonstrate reentrancy attacks, we need a smart contract that accepts, stores, and transfers assets (Ethers in this case). We'll name this smart contract EtherPot
. The code for EtherPot
is shown next. Please note that this is not a secure contract and has security bugs.
The contract comprises three functions apart from the constructor
function. It has a single-balance state variable of the mapping
type. The mapping maps addresses to their Ether (stored as wei) balances stored within the contract. The constructor is payable in case the owner wants to deploy the contract with the initial Ether balance (although it is not compulsory).
The AddEther
function is tagged as payable because any address wanting to deposit Ethers with EtherPot
has to call this function. Within this function, the mapping is updated with the address and the Ether amount is sent in wei. Each contract has an inbuilt Ether balance maintained and can be accessed using the following...