Skip to content

privacy-ethereum/zkpdf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Proving PDFs in ZKP

This repository contains tools for verifying PDF documents within zero-knowledge proof systems. Learn more in this blog post: https://pse.dev/blog/zkpdf-unlocking-verifiable-data

Why?

Sometimes you need to prove that:

  • A PDF is signed by a trusted authority
  • A specific text appears on a given page without revealing the entire document.

This repo enables such proving capability using SP1-based circuits.

Structure

  • pdf-utils/ – Rust crates for:
    • Validating PKCS#7 signatures (RSA-SHA256)
    • Extracting Unicode text from PDF streams
    • WebAssembly bindings for browser integration
  • circuits/ – SP1-compatible zero-knowledge circuits for signature and text proofs
  • app/ – Minimal React frontend to demo proof generation and verification

Documentation

Installation

Add the PDF verification library to your Rust project:

[dependencies]
zkpdf-lib = { git = "https://github.com/privacy-ethereum/zkpdf", branch = "main", subdir = "circuits/lib" }

Quick Start

use zkpdf_lib::{verify_pdf_claim, PDFCircuitInput};

// Create input for PDF verification
let input = PDFCircuitInput {
    pdf_bytes: pdf_data,
    page_number: 0,
    offset: 100,
    substring: "Important Document".to_string(),
};

// Verify PDF
let result = verify_pdf_claim(input)?;

How it Works

  1. Parse the PDF using pure Rust (no OpenSSL or C deps)
  2. Generate a zk proof using SP1 circuits
  3. Verify the proof on-chain or off-chain

Setup

Follow these steps to run the prover API and the demo frontend.

Requirements

1. Clone the Repository

git clone git@github.com:privacy-scaling-explorations/zkpdf
cd zkpdf

2. Run the Prover API

Start the prover service from the circuits/script directory. If you have access to the Succinct Prover Network, export your API key and run:

cd circuits/script
SP1_PROVER=network \
NETWORK_PRIVATE_KEY=<PROVER_NETWORK_KEY> \
RUST_LOG=info \
cargo run --release --bin prover

This will start the prover API on port 3001.

Note: If you don’t have access to the Succinct Prover Network, you can omit the environment variables to run the prover locally. (This will take longer.)

For local proof generation, refer to scripts/evm.rs or run:

RUST_LOG=info cargo run --release --bin evm -- --system groth16

3. Run the Frontend

In a separate terminal, build the WASM module and start the Next.js app:

# Build WASM module (requires Rust + wasm-pack)
cd pdf-utils/wasm && ./generate_wasm.sh && cd ../../app

# Start the frontend
yarn install
yarn dev

Visit http://localhost:3000 to view the interface.

zkpdf-video.mp4

Use Cases

  • Prove that a document is signed without showing its contents
  • Selectively reveal fields from government-issued certificates
  • Use verified document facts in smart contracts

License

This project is licensed under the MIT License - see the LICENSE file for details.