In this section, we covered a comprehensive range of topics including airdrops, signatures, and scripting.
We began by exploring more efficient methods for data verification using Merkle Trees. These structures allow us to prove that specific data is part of a larger dataset without manually iterating over arrays.
Next, we delved into the use and mechanics of signatures, which are crucial for ensuring transaction authenticity and integrity. We learned how to generate signatures with vm.sign
and cast wallet sign
, and how to implement them within our smart contracts using OpenZeppelin's ECDSA
library.
Following this, we developed few scripts for deploying and interacting with our smart contracts on different platforms, including Anvil, ZKsync local node, and ZKsync Sepolia.
Lastly, we examined various transaction types and the principles of the elliptic curve digital signature algorithm (ECDSA).
You'll know you did it right if you can run git --version and you see a response like git version x.x.x
You'll know you did it right if you can run forge --version and you see a response like forge 0.2.0 (816e00b 2023-03-16T00:05:26.396218Z) To get started, we are assuming you're working with vanilla foundry and not foundry-zksync to start.
git clone https://github.com/KMean/foundry-mrkle-airdrop.git
cd merkle-airdrop
make # or forge install && forge build if you don't have make
We are going to generate merkle proofs for an array of addresses to airdrop funds to. If you'd like to work with the default addresses and proofs already created in this repo, skip to deploy
If you'd like to work with a different array of addresses (the whitelist list in GenerateInput.s.sol), you will need to follow the following:
First, the array of addresses to airdrop to needs to be updated in `GenerateInput.s.sol. To generate the input file and then the merkle root and proofs, run the following:
Using make:
make merkle
Or using the commands directly:
forge script script/GenerateInput.s.sol:GenerateInput && forge script script/MakeMerkle.s.sol:MakeMerkle
# Optional, ensure you're on vanilla foundry
foundryup
# Run a local anvil node
make anvil
# Then, in a second terminal
make deploy
make anvil
make deploy
Copy the Bagel Token and Aidrop contract addresses and paste them into the AIRDROP_ADDRESS and TOKEN_ADDRESS variables in the MakeFile
The following steps allow the second default anvil address (0x70997970C51812dc3A010C7d01b50e0d17dc79C8) to call claim and pay for the gas on behalf of the first default anvil address (0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266) which will recieve the airdrop.
make sign
Retrieve the signature bytes outputted to the terminal and add them to Interact.s.sol making sure to remove the 0x prefix.
Additionally, if you have modified the claiming addresses in the merkle tree, you will need to update the proofs in this file too (which you can get from output.json)
Then run the following command:
make claim
Then, check the claiming address balance has increased by running
make balance
NOTE: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 is the default anvil address which has recieved the airdropped tokens.
foundryup
forge test