Skip to content

About

A gas-efficient token distribution system using Merkle tree-based claims with ECDSA signature support. Users can claim tokens by providing cryptographic proofs of eligibility, with optional meta-transaction support (allowing a gas-payer to submit claims on behalf of recipients). Built with Foundry and designed for deployment on Ethereum and zkSync

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Merkle Airdrop

A gas-efficient token distribution system using Merkle tree-based claims with ECDSA signature support. Users can claim tokens by providing cryptographic proofs of eligibility, with optional meta-transaction support (allowing a gas-payer to submit claims on behalf of recipients).

Built with Foundry and designed for deployment on Ethereum and zkSync.

Architecture

                   +------------------+
                   |   BagelToken     |
                   |  (ERC20 + Ownable)|
                   +--------+---------+
                            |
                            | IERC20
                            v
+------------------+   +------------------+
|  GenerateInput   |   |  MerkleAirdrop   |
|  (script)        +-->|  (EIP712 +       |
|                  |   |   MerkleProof +  |
|  MakeMerkle      |   |   ECDSA)         |
|  (script)        |   +--------+---------+
+------------------+            |
                                | claim()
                                v
                       +------------------+
                       |  DeployMerkle    |
                       |  Airdrop         |
                       |  (script)        |
                       +------------------+

Contracts

BagelToken.sol

A simple ERC20 token with minting restricted to the contract owner.

  • Symbol: BAGEL
  • Access: Ownable
  • Key Function: mint(address to, uint256 amount) — owner-only minting

MerkleAirdrop.sol

The core airdrop contract implementing Merkle tree-based claims with ECDSA signature verification.

  • Inherits: EIP712
  • Key Functions:
    • claim(address account, uint256 amount, bytes32[] calldata proof, uint8 v, bytes32 r, bytes32 s) — claim tokens with Merkle proof and signature
    • getMessageHash(address account, uint256 amount) — returns the EIP-712 digest
    • getMerkleRoot() — returns the current Merkle root
    • getAirdropToken() — returns the airdrop token address
  • Events: Claim(address indexed account, uint256 amount)
  • Custom Errors: MerkleAirdrop__InvalidProof, MerkleAirdrop__InvalidSignature, MerkleAirdrop__AlreadyClaimed

Prerequisites

Setup

# Clone the repository
git clone https://github.com/BuildsWithKing/merkle-airdrop.git
cd merkle-airdrop

# Install dependencies
forge install

# Copy and configure environment variables
cp .env.example .env
# Edit .env with your configuration

Environment Variables

Variable Description
SEPOLIA_RPC_URL RPC URL for Sepolia testnet
ETHERSCAN_API_KEY API key for Etherscan verification
ZKSYNC_SEPOLIA_RPC_URL RPC URL for zkSync Sepolia

Makefile Commands

Command Description
make build Compile contracts
make test Run tests
make deploy Deploy to local/Sepolia
make deploy-zk Deploy to zkSync local node
make merkle Generate Merkle tree and proofs
make sign Sign a claim message
make claim Execute an airdrop claim
make balance Check token balance
make anvil Start Anvil local node
make zktest Run tests with zkSync support
make format Format Solidity code
make clean Clean build artifacts

Usage

Generate Merkle Tree

Generate the Merkle root and proofs for whitelisted addresses:

make merkle

This runs GenerateInput.s.sol followed by MakeMerkle.s.sol, producing output in script/target/.

Deploy Contracts

# Local
make deploy

# zkSync local node (requires Docker)
make deploy-zk

Claim Tokens

# Sign the claim message
make sign

# Execute claim
make claim

Check Balance

make balance

Scripts

Script Purpose
DeployMerkleAirdrop.s.sol Deploys BagelToken and MerkleAirdrop, funds the airdrop
Interact.s.sol Claims tokens from the most recent deployment
GenerateInput.s.sol Generates Merkle tree input from whitelisted addresses
MakeMerkle.s.sol Computes Merkle root and proofs
SplitSignature.s.sol Utility to split ECDSA signatures into v/r/s components

Testing

# Standard tests
forge test

# Tests with zkSync support
make zktest

Dependencies

Library Purpose
OpenZeppelin Contracts ERC20, Ownable, MerkleProof, EIP712, ECDSA, SafeERC20
forge-std Foundry standard library for testing and scripting
murky Merkle tree generation and proof computation
foundry-devops Deployment utilities and zkSync chain detection

Solidity Version

^0.8.30

License

MIT

About

A gas-efficient token distribution system using Merkle tree-based claims with ECDSA signature support. Users can claim tokens by providing cryptographic proofs of eligibility, with optional meta-transaction support (allowing a gas-payer to submit claims on behalf of recipients). Built with Foundry and designed for deployment on Ethereum and zkSync

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages