Solutions to the reentrancy problem
We can adopt quite a few security best practices to resolve the reentrancy problem. In fact, following some of these security best practices not only solves the reentrancy issue but also many other issues that cannot be envisaged while writing contracts. As part of the solution, we need a target
contract and a Hacker
contract. The Hacker
contract will remain the same from the previous code listing; however, the EtherPot
contract will undergo changes because it now implements secure coding principles.
Some of the solutions for a reentrancy attack are mentioned next. These solutions can be implemented together to develop more secure contracts:
- Check for contract accounts: This is an optional solution that you can implement to solve reentrancy attacks. In this case, the contract will not allow other contracts to interact with it. If the requirement is that the other contracts should not interact with the current control, the contract accounts...