Zero-knowledge circuits for PDF text extraction and digital signature verification using SP1. Generates cryptographic proofs that specific text appears in signed PDF documents.
This project provides SP1 circuits that can:
- Extract text from PDF documents
- Verify digital signatures
- Prove that specific text appears at exact positions
- Generate cryptographic proofs for blockchain verification
Add to your Cargo.toml:
[dependencies]
zkpdf-lib = { git = "https://github.com/privacy-ethereum/zkpdf", branch = "main", subdir = "circuits/lib" }📚 For complete API documentation, see Circuit Library Documentation
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 and generate proof
let result = verify_pdf_claim(input)?;To run the PDF verification without generating a proof:
cd script
cargo run --release -- --executeTo generate a core proof for PDF verification:
cd script
cargo run --release -- --proveWarning
Requires at least 16GB RAM for Groth16/PLONK proofs.
# Groth16 proof
cd script
cargo run --release --bin evm -- --system groth16
# PLONK proof
cd script
cargo run --release --bin evm -- --system plonkRun the HTTP API server for remote PDF verification:
# Set environment variables
export SP1_PROVER=network
export NETWORK_PRIVATE_KEY=0x...
# Run the server
cd script
cargo run --release --bin proverAPI Endpoints:
POST /prove- Generate PDF verification proofPOST /verify- Verify an existing proof
Example Request:
{
"pdf_bytes": [
/* PDF file bytes */
],
"page_number": 0,
"sub_string": "Important Document",
"offset": 100
}cd script
cargo run --release --bin vkey# Run all tests
cargo test
# Run specific circuit tests
cargo test -p zkpdf-libThe generated proofs can be verified on-chain using the provided Solidity contracts:
contract PdfVerifier {
function verifyPdfProof(
bytes calldata proof,
bytes32 messageDigestHash,
bytes32 signerKeyHash,
bytes32 substringHash,
bytes32 nullifier
) external view returns (bool);
}sp1-sdk– SP1 zero-knowledge frameworkpdf-utils– PDF processing librariesalloy-primitives– Cryptographic primitivesserde– Serialization framework
This project is licensed under the same terms as the parent repository.