An efficient zero-knowledge proof system for RigoBlock vault unitary value calculation with constant gas cost verification.
This project uses SP1 and sp1-contract-call to prove RigoBlock vault unitary value offchain for later onchain verification across multiple blockchain networks.
Traditional onchain calculation of vault unitary value has gas costs that scale linearly with the number of tokens and positions held by the vault. This ZK proof system provides:
- Constant Gas Cost: Proof verification costs the same regardless of vault complexity
- Offchain Computation: Heavy calculations happen offchain in the zkVM
- Cryptographic Guarantee: Zero-knowledge proofs ensure computation correctness
- Scalability: Works efficiently for vaults with any number of tokens/positions
- Multi-Chain Support: Works on Ethereum, Optimism, Base, Arbitrum, BNB Chain, and Unichain
- Ethereum Mainnet (Chain ID: 1)
- Optimism (Chain ID: 10)
- BNB Chain (Chain ID: 56)
- Base (Chain ID: 8453)
- Arbitrum One (Chain ID: 42161)
- Unichain (Chain ID: 130)
See MULTI_CHAIN_GUIDE.md for detailed multi-chain usage instructions.
The program simulates the following contract calls offchain:
updateUnitaryValue()- Updates the vault's unitary value based on current holdingsgetPoolTokens()- Retrieves the updated unitary value and total supply
These calls are executed in SP1's zero-knowledge virtual machine, generating a succinct proof that can be verified onchain at constant cost.
- Rust (The project will automatically use the correct nightly version via rust-toolchain file)
- SP1 - Install the SP1 toolchain with:
This installs the
curl -L https://sp1.succinct.xyz | bash sp1upsuccinctRust toolchain required to build the zkVM client program.
- Clone the repository:
git clone https://github.com/RigoBlock/unitary-value-zk.git
cd unitary-value-zk- Install SP1 toolchain (if not already installed):
curl -L https://sp1.succinct.xyz | bash
sp1up- Copy the example environment file and configure it:
cp .env.example .envEdit .env and set RPC URLs for the chains you want to use:
# Choose the chains you need
ETHEREUM_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR-API-KEY
OPTIMISM_RPC_URL=https://opt-mainnet.g.alchemy.com/v2/YOUR-API-KEY
BASE_RPC_URL=https://base-mainnet.g.alchemy.com/v2/YOUR-API-KEY
ARBITRUM_RPC_URL=https://arb-mainnet.g.alchemy.com/v2/YOUR-API-KEY
BNB_RPC_URL=https://bsc-dataseed.binance.org/
UNICHAIN_RPC_URL=https://unichain-rpc.example.com/
# Vault address
VAULT_ADDRESS=0x1234567890123456789012345678901234567890Run the proof generator on your chosen chain:
# On Ethereum
cargo run --bin rigoblock-basic --release -- --chain ethereum
# On Optimism
cargo run --bin rigoblock-basic --release -- --chain optimism
# On Base
cargo run --bin rigoblock-basic --release -- --chain baseFor detailed multi-chain usage, see MULTI_CHAIN_GUIDE.md.
First, build the project (this will compile both the host and client programs):
cargo build --releaseNote: The first build may take a while as it downloads and compiles dependencies, including SP1 circuits.
This runs the program in the zkVM but doesn't generate a proof. Specify the chain:
cargo run --bin rigoblock-basic --release -- --chain optimism --vault-address $VAULT_ADDRESSThis generates a zero-knowledge proof of the computation:
cargo run --bin rigoblock-basic --release -- --chain base --vault-address $VAULT_ADDRESS --proveThe proof will be saved to host/fixtures/plonk-fixture.json.
If you've set up the .env file with your chain RPC URLs, you can run:
# Execute without proving
cargo run --bin rigoblock-basic --release -- --chain optimism
# With proof generation
cargo run --bin rigoblock-basic --release -- --chain optimism --proveIf you get an error about the succinct toolchain not being installed, make sure you've run:
curl -L https://sp1.succinct.xyz | bash
sp1upThen restart your terminal or run source ~/.bashrc (or ~/.zshrc for zsh).
If you encounter network issues downloading SP1 verification keys during build, you can:
- Ensure you have a stable internet connection
- Try building again - the downloader will retry failed downloads
- Check the SP1 documentation for alternative installation methods
client/: The zkVM program that runs inside the SP1 zkVMhost/: The host program that orchestrates the proof generationsrc/basic.rs: Main program for proof generationsrc/onchain_verify.rs: Program for testing onchain proof verification
host/fixtures/: Generated proofs are saved herecontracts/: Solidity contracts for onchain verificationsrc/RigoBlockVaultVerifier.sol: Main verifier contract for vault proofs
The project consists of two main components:
-
Client Program (
client/src/main.rs):- Runs inside the SP1 zkVM (zero-knowledge virtual machine)
- Receives an EVM state sketch from the host
- Validates the EVM state against the provided state root
- Simulates the following contract calls:
updateUnitaryValue()- Updates the vault's unitary value calculationgetPoolTokens()- Retrieves the updated unitary value and total supply
- Commits the output for verification
-
Host Program (
host/src/basic.rs):- Connects to an Ethereum RPC endpoint
- Prepares an EVM state sketch at a specific block
- Simulates the same contract calls offchain to verify correctness
- Feeds the state sketch into the zkVM client
- Generates a zero-knowledge proof of the computation
- Verifies the proof and extracts public values
┌─────────────────┐
│ Ethereum RPC │
└────────┬────────┘
│
│ Fetch state at block
▼
┌─────────────────┐
│ Host Executor │ 1. Call updateUnitaryValue()
│ │ 2. Call getPoolTokens()
│ │ 3. Build EVM state sketch
└────────┬────────┘
│
│ State sketch
▼
┌─────────────────┐
│ SP1 zkVM │ 1. Validate state root
│ (Client Code) │ 2. Execute calls in zkVM
│ │ 3. Commit outputs
└────────┬────────┘
│
│ Public values
▼
┌─────────────────┐
│ Proof Generator│ Generate ZK proof
└────────┬────────┘
│
▼
plonk-fixture.json
Traditional onchain calculation of vault unitary value has gas costs that scale with the number of tokens and positions. By using ZK proofs:
- Gas cost is constant regardless of vault complexity
- Computation happens offchain
- Onchain verification is minimal and efficient
- The proof cryptographically guarantees the computation was done correctly
The project includes Solidity contracts for verifying proofs onchain. The RigoBlockVaultVerifier contract can be used via delegatecall from a vault to verify proofs in the vault's own context.
- Vault-Specific Verification: Ensures proofs are generated for the specific vault
- Chain ID Validation: Verifies proofs are for the correct blockchain
- Block Recency Checks: Validates that proofs are recent enough to be trusted (within 256 blocks by default)
- Delegatecall Support: Can be called from the vault itself
See the contracts README for detailed deployment instructions.
cargo run --bin rigoblock-onchain-verify --release -- \
--chain-id 11155111 \
--vault-address 0x... \
--block-number 12345678 \
--verifier-contract 0x... \
--active-fork-name cancunApache-2.0