This project is a lottery smart contract that uses zkSNARKs to verify the age of participants. The age check is done using ZoKrates, a toolbox for zkSNARKs on Ethereum.
The project is structured as follows:
contracts/
: Contains the Solidity smart contracts for the lottery.deploy/
: Contains the deployment scripts for the smart contracts.deployments/
: Contains the deployment outputs for the smart contracts.scripts/
: Contains scripts for deploying and interacting with the smart contracts.test/
: Contains the test scripts for the smart contracts.ZoKrates/
: Contains the ZoKrates code for the age check.
- Node.js and npm installed
- Hardhat installed globally (
npm install -g hardhat
)
-
Clone the repository and navigate into the project directory
-
Install the project dependencies with
npm install
Run npx hardhat compile
to compile the Solidity contracts.
Run npx hardhat test
to execute the test scripts.
-
Update the
hardhat.config.ts
file with your network details -
Run
npx hardhat run scripts/deploy.ts --network <network_name>
to deploy the contracts to the specified network.
-
Navigate into the ZoKrates directory with
cd ZoKrates
-
Build ZoKrates with the following commands
-
Build ZoKrates
cd ZoKrates
export ZOKRATES_STDLIB=$PWD/zokrates_stdlib/stdlib
cargo +nightly build --release
- Creates ageCheck.zok
cd target/release
mkdir code
cd code && touch ageCheck.zok
- Configure the ageCheck.zok
def main(private field birthYear, field comparisonYear, field minimumDifference) -> bool{
bool result = comparisonYear - birthYear >= minimumDifference;
return result;
}
- Execute all in
/zoKrates
zokrates compile -i code/ageCheck.zok
zokrates setup
zokrates compute-witness -a 1990 2020 18
zokrates generate-proof
zokrates export-verifier
- Deploy Lottery Smart Contract in localhost or live network
npx hardhat deploy --network <blockchain-network> --tags Lottery
- Paste Proof and Input Generated in enterLottery()
proof.txt