The Ghost Protocol backend system provides zero-knowledge proof generation and verification for token ranges on the Internet Computer. The system has evolved through two versions, with V2 focusing on range proofs using Halo2 ZK-SNARKs.
- Status: Legacy/Deprecated
- Canister ID:
hi7bu-myaaa-aaaad-aaloa-cai - Network: IC Mainnet
- Interface: Candid UI
- Features:
- Basic token ownership proof generation
- Simple proof verification
- Cross-chain verification support
- Memory-efficient proof storage
- Status: Active Development
- Canister ID:
bkyz2-fmaaa-aaaaa-qaaaq-cai - Network: Local Development
- Interface: Local Candid UI
- Features:
- Enhanced proof generation using Halo2
- Specialized in range proofs
- Improved verification process
- Better memory management
- Advanced error handling
type TokenRangeInput = record {
balance: nat64;
min_range: nat64;
max_range: nat64;
};
type Result = variant {
Ok: nat64;
Err: text;
};
type Result_1 = variant {
Ok: bool;
Err: text;
};
service : {
generate_proof: (TokenRangeInput) -> (Result);
verify_proof_by_id: (text) -> (Result_1) query;
get_canister_metrics: () -> (CanisterMetrics) query;
health_check: () -> (Result_1) query;
};
pub struct TokenRangeCircuit {
value: Fr,
min_value: Fr,
max_value: Fr,
}
impl Circuit<Fr> for TokenRangeCircuit {
type Config = TokenRangeConfig;
type FloorPlanner = SimpleFloorPlanner;
fn synthesize(
&self,
config: Self::Config,
layouter: impl Layouter<Fr>,
) -> Result<(), Error> {
// Circuit implementation for range proofs
}
}- Convert input values to field elements
- Create circuit instance
- Generate proof using Halo2
- Store proof with unique ID
- Return proof ID to caller
- Retrieve proof by ID
- Load public inputs
- Verify proof using Halo2
- Return verification result
@startuml
package "Ghost Protocol V2" {
[Frontend Application] as Frontend
[ZK Canister V2] as Canister
database "Proof Storage" as Storage
package "Circuit Components" {
[TokenRangeCircuit] as Circuit
[ProofGenerator] as Generator
[ProofVerifier] as Verifier
}
Frontend --> Canister: API Calls
Canister --> Circuit: Create Circuit
Circuit --> Generator: Generate Proof
Generator --> Storage: Store Proof
Canister --> Verifier: Verify Proof
Verifier --> Storage: Retrieve Proof
}
note right of Circuit
Implements range check constraints
using Halo2 ZK-SNARKs
end note
note right of Storage
Stores proofs with unique IDs
and handles cleanup
end note
@endumldfx canister call zk_canister_v2 generate_proof '(
record {
balance = 1000 : nat64;
min_range = 0 : nat64;
max_range = 5000 : nat64
}
)'
# Expected Response:
# (variant { Ok = 1746117903585087000 : nat64 })dfx canister call zk_canister_v2 verify_proof_by_id '("1746117903585087000")'
# Expected Response:
# (variant { Ok = true })- Proof Generation Time: ~1-2 seconds
- Verification Time: ~0.5 seconds
- Memory Usage per Proof: ~1KB
- Success Rate: >99.9%
- CPU: Moderate during proof generation
- Memory: Efficient with automatic cleanup
- Storage: Optimized with proof expiration
- Properly implemented range constraints
- Secure witness assignments
- Protected private inputs
- Unique proof IDs
- Automatic proof expiration
- Memory cleanup routines
- Comprehensive input validation
- Clear error messages
- Graceful failure handling
-
Start local replica:
dfx start --background
-
Build and deploy:
dfx build dfx deploy
-
Run tests:
cargo test dfx canister call zk_canister_v2 test
backend/zk_canister_v2/
├── src/
│ ├── circuits.rs # ZK circuit implementation
│ ├── lib.rs # Main canister logic
│ ├── proof.rs # Proof generation/verification
│ └── storage.rs # Proof storage management
├── Cargo.toml
└── zk_canister_v2.did
-
Performance Optimizations
- Batch proof processing
- Parallel verification
- Memory usage optimization
-
Feature Enhancements
- Multiple range checks in one proof
- Custom constraint types
- Advanced proof composition
-
Integration Support
- SDK development
- Additional language bindings
- Documentation improvements