Shroud SDK Documentation

Complete reference for integrating Zero-Knowledge proofs with Halo2, Risc0 zkVM, Nova folding, and Fflonk into your Solana applications.

TypeScriptNode.jsSolana Devnet
Installation
Get started with the Shroud SDK in your project

Install via npm:

npm install @shroud/sdk

Or with yarn:

yarn add @shroud/sdk
Quick Start
Generate and verify your first ZK proof in minutes
import { Shroud } from "@shroud/sdk";

// Initialize the client
const shroud = new Shroud({ 
  network: "devnet",
  rpcUrl: "https://api.devnet.solana.com"
});

// Generate a proof using Halo2
const proof = await shroud.prover.generate({
  backend: "halo2",
  inputs: {
    secret: 12345,
    public: { 
      amount: 100,
      recipient: "0x..." 
    }
  }
});

// Verify proof on Solana
const result = await shroud.solana.verifyProof(proof);
console.log("Verification:", result.success);
Core Architecture
Understanding the Shroud SDK structure

Project Structure

/shroud-sdk
  /src
    /core
      ShroudClient.ts      # Main SDK client
      ProofEngine.ts       # Proof generation engine
      BackendManager.ts    # Backend abstraction layer
      types.ts             # TypeScript definitions
    /backends
      /halo2
        halo2.prover.ts
        halo2.verifier.ts
      /risc0
        risc0.prover.ts
        risc0.verifier.ts
      /nova
        nova.prover.ts
        nova.verifier.ts
      /fflonk
        fflonk.prover.ts
        fflonk.verifier.ts
    /solana
      SolanaClient.ts      # Solana integration
      SolanaVerifier.ts    # On-chain verifier
    index.ts

Main Components

ShroudClient

Main entry point for the SDK. Manages configuration and provides access to the ProofEngine and SolanaClient.

ProofEngine

Handles proof generation and verification. Supports dynamic backend selection (Halo2, Risc0, Nova, Fflonk).

BackendManager

Abstracts different ZK proving systems. Dynamically loads the appropriate prover/verifier.

SolanaClient

Manages Solana blockchain interactions. Submits proofs to on-chain verifier programs.

Supported ZK Backends
Choose the right proving system for your use case

Halo2Plonkish

Flexible Plonkish system with custom gates. Best for complex circuits requiring custom constraints.

const proof = await shroud.prover.generate({
  backend: "halo2",
  inputs: {
    secret: privateData,
    public: publicData
  }
});

Risc0 zkVMzkVM

General-purpose zkVM. Write proofs in Rust. Ideal for complex business logic.

const proof = await shroud.prover.generate({
  backend: "risc0",
  inputs: {
    program: "guest_program",
    data: computationData
  }
});

Nova FoldingIVC

Incremental verifiable computation. Perfect for recursive proofs and rollups.

const proof = await shroud.prover.generate({
  backend: "nova",
  inputs: {
    steps: recursiveSteps,
    initialState: state0
  }
});

FflonkFast SNARK

Ultra-fast proving with polynomial commitments. Optimized for high throughput.

const proof = await shroud.prover.generate({
  backend: "fflonk",
  inputs: {
    circuit: circuitData,
    witness: witnessData
  }
});

Choosing a Backend

  • Halo2: Custom circuits, flexible constraints, privacy protocols
  • Risc0: Complex computations, business logic, existing Rust code
  • Nova: Recursive proofs, rollups, incremental verification
  • Fflonk: High-speed proving, production scale, minimal latency
Solana Integration
Submit and verify proofs on Solana blockchain

Configuration

import { Shroud } from "@shroud/sdk";
import { Keypair } from "@solana/web3.js";

const shroud = new Shroud({
  network: "devnet", // or "mainnet-beta"
  rpcUrl: "https://api.devnet.solana.com",
  programId: "xxxxxxxxxxxxxxxxxxxxxxxx", // Shroud verifier program
  signer: Keypair.fromSecretKey(secretKey) // Your wallet
});

Submit Proof On-Chain

// Generate proof
const proof = await shroud.prover.generate({
  backend: "halo2",
  inputs: {
    secret: secretValue,
    public: { amount: 1000 }
  }
});

// Submit to Solana
const txSignature = await shroud.solana.verifyProof(proof, {
  computeUnits: 400_000, // Optional: adjust compute budget
  priorityFee: 1000       // Optional: priority fee in micro-lamports
});

console.log("Transaction:", txSignature);

Query Verification Status

// Check if proof was verified
const status = await shroud.solana.getProofStatus(txSignature);

if (status.verified) {
  console.log("Proof verified successfully!");
  console.log("Public outputs:", status.publicOutputs);
} else {
  console.log("Verification failed:", status.error);
}

Advanced: Direct Program Call

import { PublicKey, Transaction } from "@solana/web3.js";

// Build custom transaction
const ix = await shroud.solana.createVerifyInstruction({
  proof: serializedProof,
  publicInputs: publicData,
  backend: "risc0"
});

const tx = new Transaction().add(ix);
const signature = await shroud.solana.sendTransaction(tx);
API Reference
Complete type definitions and method signatures

ShroudConfig

interface ShroudConfig {
  network: "devnet" | "mainnet-beta";
  rpcUrl?: string;
  programId?: string;
  signer?: Keypair | Wallet;
  logLevel?: "debug" | "info" | "warn" | "error";
}

ProofGenerationOptions

interface ProofGenerationOptions {
  backend: "halo2" | "risc0" | "nova" | "fflonk";
  inputs: {
    secret?: any;        // Private inputs
    public?: any;        // Public inputs
    witness?: any;       // Circuit witness
    program?: string;    // For Risc0: program name
    steps?: any[];       // For Nova: computation steps
    circuit?: any;       // For Fflonk: circuit definition
  };
  options?: {
    optimize?: boolean;  // Enable proof optimization
    compression?: boolean; // Enable proof compression
  };
}

ProofEngine Methods

class ProofEngine {
  // Generate a proof
  async generate(options: ProofGenerationOptions): Promise<Proof>
  
  // Verify a proof locally
  async verify(proof: Proof): Promise<boolean>
  
  // Get supported backends
  getSupportedBackends(): string[]
  
  // Switch backend
  setBackend(backend: BackendType): void
}

SolanaClient Methods

class SolanaClient {
  // Submit proof for on-chain verification
  async verifyProof(
    proof: Proof, 
    options?: TransactionOptions
  ): Promise<string>
  
  // Get proof verification status
  async getProofStatus(signature: string): Promise<ProofStatus>
  
  // Create verify instruction (advanced)
  async createVerifyInstruction(
    params: VerifyInstructionParams
  ): Promise<TransactionInstruction>
  
  // Send custom transaction
  async sendTransaction(tx: Transaction): Promise<string>
}
Error Handling
Handle errors gracefully in production
import { 
  ShroudError, 
  ProofGenerationError,
  VerificationError,
  SolanaError 
} from "@shroud/sdk";

try {
  const proof = await shroud.prover.generate({
    backend: "halo2",
    inputs: { secret: data }
  });
  
  await shroud.solana.verifyProof(proof);
  
} catch (error) {
  if (error instanceof ProofGenerationError) {
    console.error("Failed to generate proof:", error.message);
    console.error("Backend:", error.backend);
  } else if (error instanceof VerificationError) {
    console.error("Verification failed:", error.message);
  } else if (error instanceof SolanaError) {
    console.error("Solana transaction failed:", error.message);
    console.error("Transaction logs:", error.logs);
  }
}
Production Integration Patterns
Best practices for production deployments

Singleton Pattern

// lib/shroud.ts
import { Shroud } from "@shroud/sdk";

let shroudInstance: Shroud | null = null;

export function getShroudClient(): Shroud {
  if (!shroudInstance) {
    shroudInstance = new Shroud({
      network: process.env.SOLANA_NETWORK as "devnet" | "mainnet-beta",
      rpcUrl: process.env.SOLANA_RPC_URL,
      programId: process.env.SHROUD_PROGRAM_ID,
      logLevel: process.env.NODE_ENV === "production" ? "warn" : "debug"
    });
  }
  return shroudInstance;
}

// Usage in API routes
import { getShroudClient } from "@/lib/shroud";

export async function POST(request: Request) {
  const shroud = getShroudClient();
  const proof = await shroud.prover.generate({ ... });
  return Response.json({ proof });
}

Async Queue for Proof Generation

// High-volume production workloads
import { Queue } from "bullmq";
import { getShroudClient } from "@/lib/shroud";

const proofQueue = new Queue("proofs", {
  connection: { host: "localhost", port: 6379 }
});

// Add proof generation job
async function requestProof(inputs: any) {
  const job = await proofQueue.add("generate", {
    backend: "halo2",
    inputs
  });
  return job.id;
}

// Worker process
proofQueue.process(async (job) => {
  const shroud = getShroudClient();
  const proof = await shroud.prover.generate(job.data);
  await shroud.solana.verifyProof(proof);
  return { proofId: proof.id };
});

Monitoring & Logging

import { getShroudClient } from "@/lib/shroud";
import { logger } from "@/lib/logger";

const shroud = getShroudClient();

// Listen to proof generation events
shroud.on("proof:generated", (proof) => {
  logger.info("Proof generated", {
    proofId: proof.id,
    backend: proof.backend,
    duration: proof.generationTime
  });
});

shroud.on("proof:verified", (result) => {
  logger.info("Proof verified on-chain", {
    signature: result.signature,
    slot: result.slot
  });
});

shroud.on("error", (error) => {
  logger.error("Shroud error", { error });
});
Extending with Custom Backends
Add support for new ZK proving systems
import { Backend, Proof } from "@shroud/sdk";

// Implement custom backend
class MyCustomBackend implements Backend {
  name = "my-backend";
  
  async generateProof(inputs: any): Promise<Proof> {
    // Your custom proving logic
    const proof = await myProvingSystem.prove(inputs);
    
    return {
      id: generateId(),
      backend: this.name,
      data: proof,
      publicInputs: inputs.public
    };
  }
  
  async verifyProof(proof: Proof): Promise<boolean> {
    return myProvingSystem.verify(proof.data);
  }
}

// Register custom backend
const shroud = new Shroud({ network: "devnet" });
shroud.registerBackend(new MyCustomBackend());

// Use custom backend
const proof = await shroud.prover.generate({
  backend: "my-backend",
  inputs: { ... }
});
Support & Resources
Get help and stay updated

GitHub Repository

Report issues, contribute code, and see example projects.

Discord Community

Join our community for support and discussions.

Example Projects

Browse working examples and templates.

API Reference

Detailed TypeScript API documentation.