This example implements a counter that increments based on off-chain RISC Zero Steel proofs submitted to the Counter contract. The contract interacts with ERC-20 tokens, using Steel proofs to verify that an account holds at least 1 token before incrementing the counter.
The Counter contract is designed to interact with the Ethereum blockchain, leveraging the power of RISC Zero Steel proofs to perform a specific operation: incrementing a counter based on the token holdings of an account.
The core functionality of the Counter contract is to increment an internal counter whenever a valid proof was submitted. This proof must demonstrate that a specified account holds at least one unit of a particular ERC-20 token. The contract ensures that the counter is only incremented when the proof is verified and the condition of holding at least one token is met.
Users or entities can submit proofs to the Counter contract. These proofs are generated off-chain using the RISC Zero zkVM. The proof encapsulates the verification of an account's token balance without exposing the account's details or requiring direct on-chain queries.
Upon receiving a Steel proof, the Counter contract decodes the proof and validates it against the contract's state at a certain block height. This ensures that the account in question actually holds at least one token at the time the proof was generated.
The contract maintains an internal counter, which is publicly viewable. This counter represents the number of successful verifications that have occurred. The contract includes functionality to query the current value of the counter at any time.
First, install Rust and Foundry, and then restart your terminal.
# Install Rust
curl https://sh.rustup.rs -sSf | sh
# Install Foundry
curl -L https://foundry.paradigm.xyz | bash
Next, you will need to install the cargo risczero
tool.
We'll use cargo binstall
to get cargo-risczero
installed, and then install the risc0
toolchain.
See RISC Zero installation for more details.
cargo install cargo-binstall
cargo binstall cargo-risczero
cargo risczero install
Now you have all the tools you need to develop and deploy an application with RISC Zero.
Note: To request an API key complete the form here.
With the Bonsai proving service, you can produce a Groth16 SNARK proof that is verifiable on-chain. You can get started by setting the following environment variables with your API key and associated URL.
export BONSAI_API_KEY="YOUR_API_KEY" # see form linked above
export BONSAI_API_URL="BONSAI_URL" # provided with your api key
When you're ready, follow the deployment guide to get your application running on Sepolia or a local network.