Expand description
Kontor Proof-of-Retrievability (PoR) library
This library provides a unified Proof-of-Retrievability system using Nova recursive SNARKs. It supports both single-file and multi-file proofs through a consistent API.
§Main Components
api: High-level unified API for single and multi-file proofsmerkle: Merkle tree implementation with Poseidon hashingerasure: Reed-Solomon erasure coding for fault tolerancecircuit: Unified Nova circuit supporting dynamic numbers of filesledger: File ledger for multi-file aggregationconfig: Centralized configuration constants
§Error Handling
This library uses Result types for robust error handling. Core functions return
Result<T, KontorPoRError> to provide detailed error information:
prepare_file()returnsResult<(PreparedFile, FileMetadata), KontorPoRError>reconstruct_file()returnsResult<Vec<u8>, KontorPoRError>build_tree()returnsResult<(MerkleTree, F), KontorPoRError>get_padded_proof_for_leaf()returnsResult<CircuitMerkleProof, KontorPoRError>
§Quick Start
§Basic Usage
use kontor_crypto::{api::{self, PorSystem}, FileLedger, KontorPoRError};
// 1. Prepare file with Reed-Solomon erasure coding (fixed 31-byte symbols)
// Deterministic nonce ensures unique file_id (e.g., user_id + timestamp)
let data = b"Hello, world! This is test data for Nova PoR.";
let nonce = b"user_alice_1704067200";
let (prepared, metadata) = api::prepare_file(data, "test.dat", nonce)?;
// 2. Create ledger and add the file
let mut ledger = FileLedger::new();
ledger.add_file(&metadata)?;
// 3. Create PorSystem and generate proof
let system = PorSystem::new(&ledger);
let challenge = api::Challenge::new(metadata.clone(), 1000, 3, api::FieldElement::from(42u64), String::from("node_1"));
let proof = system.prove(vec![&prepared], &[challenge.clone()])?;
// 4. Verify the proof
let is_valid = system.verify(&proof, &[challenge])?;
assert!(is_valid);§Multi-File Proof
use kontor_crypto::{api::{self, PorSystem}, FileLedger, KontorPoRError};
// 1. Prepare multiple files (deterministic nonces ensure unique file_ids)
let (prepared1, metadata1) = api::prepare_file(b"File 1 content", "file1.dat", b"upload_001")?;
let (prepared2, metadata2) = api::prepare_file(b"File 2 content", "file2.dat", b"upload_002")?;
// 2. Build ledger
let mut ledger = FileLedger::new();
ledger.add_file(&metadata1)?;
ledger.add_file(&metadata2)?;
// 3. Create challenges and prove (different seeds supported for multi-batch aggregation)
let system = PorSystem::new(&ledger);
let challenges = vec![
api::Challenge::new(metadata1.clone(), 1000, 2, api::FieldElement::from(42u64), String::from("node_1")),
api::Challenge::new(metadata2.clone(), 1001, 2, api::FieldElement::from(43u64), String::from("node_1")),
];
let files = vec![&prepared1, &prepared2];
let proof = system.prove(files, &challenges)?;
let is_valid = system.verify(&proof, &challenges)?;
assert!(is_valid);Re-exports§
pub use api::prepare_file;pub use api::reconstruct_file;pub use api::tree_depth_from_metadata;pub use api::PorSystem;pub use api::Challenge;pub use api::FieldElement;pub use api::FileMetadata;pub use api::PorParams;pub use api::PreparedFile;pub use api::Proof;pub use circuit::CircuitWitness;pub use circuit::FileProofWitness;pub use circuit::PorCircuit;pub use error::KontorPoRError;pub use error::Result;pub use ledger::FileDescriptor;pub use ledger::FileLedger;pub use merkle::build_tree;pub use merkle::build_tree_from_leaves;pub use merkle::get_leaf_hash;pub use merkle::get_padded_proof_for_leaf;pub use merkle::hash_leaf_data;pub use merkle::hash_node;pub use merkle::verify_merkle_proof_in_place;pub use merkle::CircuitMerkleProof;pub use merkle::MerkleTree;pub use utils::derive_index_from_bits;pub use utils::field_from_uniform_bytes;pub use utils::leaf_to_bytes31;
Modules§
- api
- A high-level, unified API for the Nova-based Proof-of-Retrievability system.
- circuit
- Nova PoR circuit module structure.
- circuit_
safety - Compile-time and runtime safety checks for circuit uniformity.
- config
- Centralized configuration for the Kontor PoR system.
- erasure
- Reed-Solomon erasure coding module for the Kontor PoR system.
- error
- Error types for the Kontor PoR library
- ledger
- File ledger for aggregated Merkle tree management.
- merkle
- Merkle tree implementation for the Kontor PoR system.
- metrics
- Performance metrics and structured output for benchmarking and production monitoring.
- params
- Parameter caching and management for dynamic circuit shapes.
- poseidon
- Poseidon hash utilities for API and circuit.
- utils
- Stateless helper functions for the Kontor PoR library
Macros§
- non_
uniform_ ok - Macro to explicitly mark non-uniform code that’s acceptable.
- uniform_
constraints - Macro to mark circuit code that MUST maintain uniform constraint count.