Demo project for EsyaSoft to batch electricity bills, generate Merkle proofs, and verify them using Merkle trees. This project leverages the Lambdaworks library for Merkle tree functionality and Ethereum smart contracts for on-chain Merkle root storage.
This project requires Foundry and Cargo to be installed. Follow these steps to get the project up and running.
-
Rust and Cargo: Install from rust-lang.org.
-
Foundry: Install Foundry by running:
curl -L https://foundry.paradigm.xyz | bash foundryup
The following diagram illustrates the overall architecture of the project:
Start by setting up the project directory and building the necessary components. Run the following command:
make init
This command performs the following:
- Creates an
output
directory for generated proofs. - Initializes and updates Git submodules.
- Builds the batcher Rust application.
- Builds the contracts using Foundry.
- Starts a local Ethereum node using Anvil.
-
Deploy Contracts: Deploys the
MerkleRootStorage
smart contract to the local Anvil network.make deploy_contracts
This command deploys the contract by running a
forge script
command, which executes theMerkleRootStorageScript
script located in thecontracts
folder. -
Generate Proofs: Generates Merkle proofs for each bill in the specified
bills_path
.make generate_proofs
This command uses the
generate-proof
subcommand, reading the list of bills from../data/electricity_bills.json
and generating proofs for each. Thecertificate_key
is required to associate the Merkle root with a unique identifier in the contract. -
Verify a Bill: Verifies a specific bill’s proof against the on-chain Merkle root.
make verify_bill
This command verifies a specific bill's proof stored in
../output/merkle_proof_2.json
. It compares the Merkle root on-chain with the locally computed root for the bill specified byindex
. -
Verify a Corrupted Bill: Verifies a corrupted bill's proof, demonstrating how an invalid bill fails verification.
make verify_bill_corrupted
This command runs the verify-proof subcommand using a corrupted bill file, located at ../data/electricity_bill_2_corrupted.json, with proof data stored in ../output/merkle_proof_2.json. This example showcases failure handling by verifying a proof with mismatched data.
This project demonstrates how to batch and verify data using Merkle trees in Rust and Ethereum smart contracts, making it easy to verify large datasets efficiently on-chain. This setup can be easily adapted to other data batching and proof generation use cases.