Comment on page
Solidity by Example: the Re-entrancy Attack
How to use Phalcon Fork to learn Solidity by Example
Solidity by Example is a fantastic resource for beginners who are looking to learn Solidity. The website offers numerous examples of source code that developers can utilize and test. The source code can be easily accessed and compiled using the online Remix tool.
In this tutorial, we will explore how to use Phalcon Fork to deploy the compiled contract, send transactions, and debug a transaction using Phalcon Explorer.
The contract we are using is the demo of the re-entrancy vulnerability and how to attack it. We won’t go through the details of this vulnerability, and there are many useful documents on the Internet.
We first open it on Remix and then compile the contract.
We will use the Injected Provider to use Fork RPC. Please refer to this document for the detailed steps to use Phalcon Fork in Remix. In this case, I have added MetaMask as the injected Provider and used the account
0xb469Efca360131361487F0d4e072EFF758Fcd700as a testing account.
We first deploy the
EtherStorecontract (the vulnerable one) and then deploy the
Deploy the EtherStore contracct
Sign the transaction to deploy the contract. Ensure that the RPC is the added Phalcon Fork RPC (the top right of the MetaMask Notification). Otherwise, it will deploy to a new network! Please double-check before clicking Confirming.
The transaction to deploy the contract can be seen in the transaction list of the Fork.
We can use a similar method to deploy the
Attackcontract. When deploying the attack contract, we must pass an argument (the deployed
0x43caeBEBCe80117B5cA00047a97eD48b928b2Be0in this case).
Before launching the attack, two users need to deposit the Ether into the vulnerable contract. We use two addresses for this purpose.