Skip to content

techninja8/pipf-primitive

Repository files navigation

Pedersen Vector Commitments with Inner Product Proofs

License: MIT

A Rust implementation of Pedersen Vector Commitments with logarithmic-sized Inner Product Arguments (IPA). This library provides efficient zero-knowledge proofs for inner product relations between committed vectors.

Overview

This library implements Pedersen Vector Commitments with Inner Product Proofs, a cryptographic primitive that allows:

  1. Creating compact commitments to vectors of arbitrary length
  2. Proving knowledge of vectors satisfying specific inner product relations
  3. Generating logarithmic-sized proofs (O(log n) complexity instead of O(n))

The implementation is based on the Bulletproofs inner product argument and uses the Ristretto255 prime-order group via the curve25519-dalek library.

Features

  • Pedersen Vector Commitments: Efficiently commit to multiple vectors with a single group element
  • Logarithmic-sized Proofs: Proofs are O(log n) size regardless of vector length
  • Zero-Knowledge: Prove inner product relations without revealing the vectors
  • Built on curve25519-dalek: Leverages high-quality cryptographic primitives
  • Fiat-Shamir Transformation: Non-interactive proofs using the Merlin transcript protocol

Installation

Add this to your Cargo.toml:

[dependencies]
pipf = "0.1.0"
curve25519-dalek = "4.0"
merlin = "3.0"
rand = "0.8"

Usage

Creating Generators

use pipf::{create_generators, Generators};

// Create generators for vectors of size 8 (must be power of 2)
let n = 8;
let gens = create_generators(n);

Creating a Commitment

use curve25519_dalek::scalar::Scalar;
use rand::rngs::OsRng;
use pipf::{pedersen_vector_commitment};

// Create random vectors a and b
let a: Vec<Scalar> = (0..n).map(|_| Scalar::random(&mut OsRng)).collect();
let b: Vec<Scalar> = (0..n).map(|_| Scalar::random(&mut OsRng)).collect();
let r = Scalar::random(&mut OsRng);

// Create commitment P = sum(a_i * G_i + b_i * H_i) + r * G
let P = pedersen_vector_commitment(&a, &b, r, &gens);

Computing Inner Product

use pipf::inner_product;

// Calculate inner product c = <a,b>
let c = inner_product(&a, &b);

Generating a Proof

use merlin::Transcript;
use pipf::generate_inner_product_proof;

// Create a transcript for the Fiat-Shamir transformation
let mut prover_transcript = Transcript::new(b"example-inner-product");

// Generate a proof that vectors a and b satisfy <a,b> = c
let proof = generate_inner_product_proof(a, b, r, &gens, &mut prover_transcript);

Verifying a Proof

use pipf::verify_inner_product_proof;

// Create a fresh transcript for verification
let mut verifier_transcript = Transcript::new(b"example-inner-product");

// Verify the proof
let valid = verify_inner_product_proof(P, c, &proof, &gens, &mut verifier_transcript);
assert!(valid, "Proof verification failed!");

Testing

Run the test suite:

cargo test

To run the example:

cargo run --features="example"

Benchmarking

The implementation provides the following performance characteristics (on a typical modern machine):

Vector Size Proof Generation Verification Proof Size
8 ~0.5 ms ~0.5 ms ~192 bytes
16 ~1.0 ms ~1.0 ms ~224 bytes
32 ~2.0 ms ~2.0 ms ~256 bytes
64 ~4.0 ms ~4.0 ms ~288 bytes
128 ~8.0 ms ~8.0 ms ~320 bytes

Applications

This library is useful for:

  • Zero-knowledge range proofs
  • Private smart contracts
  • Anonymous credentials
  • Confidential transaction systems
  • Privacy-preserving protocols

How It Works

The library implements the inner product argument from Bulletproofs, which allows proving that:

  1. The prover knows vectors a, b such that <a,b> = c
  2. The vectors are correctly committed in a Pedersen commitment

The proof system recursively reduces the problem size by half in each round, resulting in logarithmic-sized proofs.

Security

This implementation provides:

  • Soundness: A valid proof convinces the verifier with overwhelming probability if the statement is true
  • Zero-Knowledge: The proof reveals nothing about the committed vectors beyond the claimed inner product
  • Binding: The prover cannot change the committed vectors after creating the commitment

License

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

References

  • Bulletproofs: Short Proofs for Confidential Transactions and More (IEEE S&P 2018)
  • Efficient Zero-Knowledge Arguments for Arithmetic Circuits in the Discrete Log Setting (EUROCRYPT 2016)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages