This repository contains a smart contract and sample client and server implementations of zkRegistry, an offchain sparse Merkle tree (SMT) kept in sync with an Ethereum smart contract via ZK proofs generated by Noir.
Noir circuits are provided under circuits
and given suitable data may be tested via the nargo prove
command, e.g.
cd circuits/single_smt_op && nargo prove
The zkRegistry smart contract keeps track of the SMT root and accepts SMT transactions in the form of ZK proofs. It depends on a verifier smart contract that must be regenerated every time the Noir source code is modified. To do this, run
./prep-contracts.sh
Assuming the environment variables PRIVATE_KEY
(base-16 string) and RPC_URL
are set, run
cd contracts && forge script script/OffchainRegistry.s.sol --rpc-url $RPC_URL --broadcast
The contract address will then be printed to stdout.
Assuming guile-smt is installed, the server may be started by loading main.scm
:
cd server && guile -l main.scm
The client may be compiled using Cargo:
cd client && cargo build --release
Assuming the environment variables RPC_URL
, PRIVATE_KEY
, ZKREGISTRY_CONTRACT
and ZKREGISTRY_URL
have been set, a key may be added/updated/deleted by calling the insert
, update
or delete
subcommand of the zkregistry_client
binary together with a value (base-16 string), e.g.
./target/release/zkregistry_client insert "ab"