Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
aaa7d98
Merge remote-tracking branch 'upstream/main'
Jun 16, 2025
c4b0a9f
test(robustness_tests): add new robustness tests for low-level bit ma…
Jun 18, 2025
3e03166
test(robustness): add simple case where wrong witness is used instead…
Jun 18, 2025
f305e0e
test(robustness): refactorize existing tests into loops that cover al…
Jun 20, 2025
bd33af9
test(robustness): minor renaming
Jun 20, 2025
42330f1
fix(sponge): update implementation to comply with new specification (…
nougzarm Jun 16, 2025
42c2fad
perf(sponge): optimize KeccakDuplexSponge absorb() method (#41)
nougzarm Jun 16, 2025
b0e3716
rm src/tests/composition_protocol.rs (#43)
Chausseaumoine Jun 16, 2025
f19a413
chore(keccak): slicker code and more stable dependencies (#45)
mmaker Jun 18, 2025
0cac53b
fix(keccak): follow duplex sponge implementation. (#46)
MariaGhandour Jun 23, 2025
cc54321
chore: more structured duplex sponge test vectors.
mmaker Jun 24, 2025
ec6627c
Update README.md (#47)
mmaker Jun 24, 2025
e20fe56
chore: refactor SchnorrProof implementation for improved code quality…
nougzarm Jun 28, 2025
856fa5f
Implement scalar multiplication, negation, and subtraction for variab…
nategraf Jun 30, 2025
cb53341
Add Neg and Sub imples for ScalarVar, GroupVar, and Term (#50)
nategraf Jun 30, 2025
a879515
chore(docs): update documentation for Linear Combinations section (#51)
nougzarm Jun 30, 2025
61dd1e3
refactor: simulator for sigma protocols.
mmaker Jun 30, 2025
0c373b1
refactor: Invalid instance/witness pair.
mmaker Jul 3, 2025
4b9a814
refactor: invalid instance/witness pair error
mmaker Jul 3, 2025
b53f7fd
Introduce ScalarTerm struct to support Add<Scalar> for ScalarVar and …
nategraf Jul 4, 2025
55c0b99
Code review and minor corrections (#52)
nougzarm Jul 4, 2025
49c872b
cargo fmt
mmaker Jul 4, 2025
eb2c983
chore: update test vectors from spec and RNG (#54)
vishady721 Jul 5, 2025
ff8f86c
test(robustness_tests): add new robustness tests for low-level bit ma…
Jun 18, 2025
d356496
fix(fiat_shamir): reject invalid witness in prover by returning an Er…
Jul 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ num-traits = "0.2.19"
rand = "0.8.5"
sha3 = "0.10.8"
thiserror = "1"
tiny-keccak = { version = "2.0.2", features = ["fips202"] }
keccak = "0.1.5"
zerocopy = "0.8"
zeroize = "1.8.1"

[dev-dependencies]
bls12_381 = "0.8.0"
curve25519-dalek = { version = "4", default-features = false, features = ["serde", "rand_core", "alloc", "digest", "precomputed-tables", "group"] }
hex = "0.4"
hex-literal = "0.4"
json = "0.12.4"
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"
sha2 = "0.10"
subtle = "2.6.1"

Expand Down
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ A Rust library for building and composing Σ-protocols (Sigma protocols) for zer

This library provides a flexible framework for creating zero-knowledge proofs for any statement expressible as a linear relation over group elements. Using the Fiat-Shamir transformation, these interactive protocols become non-interactive proofs suitable for real-world applications.

## Key Features

- **Universal**: Express any linear relation as a Sigma protocol
- **Composable**: Build complex proofs with AND/OR combinations
- **Generic**: Works with any prime-order group implementing the `group` trait
- **Secure**: Constant-time implementations prevent timing attacks
- **Flexible**: Both high-level macros and low-level constraint API

## Quick Example

```rust
Expand Down Expand Up @@ -86,4 +78,4 @@ This crate continues the work from the original `zkp` toolkit in [`dalek-cryptog
This project is funded through [NGI0 Entrust](https://nlnet.nl/entrust), a fund established by [NLnet](https://nlnet.nl) with financial support from the European Commission's [Next Generation Internet](https://ngi.eu) program. Learn more at the [NLnet project page](https://nlnet.nl/project/sigmaprotocols).

[<img src="https://nlnet.nl/logo/banner.png" alt="NLnet foundation logo" width="20%" />](https://nlnet.nl)
[<img src="https://nlnet.nl/image/logos/NGI0_tag.svg" alt="NGI Zero Logo" width="20%" />](https://nlnet.nl/entrust)
[<img src="https://nlnet.nl/image/logos/NGI0_tag.svg" alt="NGI Zero Logo" width="20%" />](https://nlnet.nl/entrust)
8 changes: 4 additions & 4 deletions examples/schnorr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ fn create_relation(P: RistrettoPoint) -> LinearRelation<RistrettoPoint> {
/// generate a proof that P = x * G
#[allow(non_snake_case)]
fn prove(x: Scalar, P: RistrettoPoint) -> ProofResult<Vec<u8>> {
let nizk = create_relation(P).into_nizk(b"schnorr-proof");
let nizk = create_relation(P).into_nizk(b"sigma-rs::examples");
nizk.prove_batchable(&vec![x], &mut OsRng)
}

/// Verify a proof of knowledge of discrete logarithm for the given public key P
#[allow(non_snake_case)]
fn verify(P: RistrettoPoint, proof: &[u8]) -> ProofResult<()> {
let nizk = create_relation(P).into_nizk(b"schnorr-proof");
let nizk = create_relation(P).into_nizk(b"sigma-rs::examples");
nizk.verify_batchable(proof)
}

Expand All @@ -61,9 +61,9 @@ fn main() {
// Verify the proof
match verify(P, &proof) {
Ok(()) => println!("✓ Proof verified successfully!"),
Err(e) => println!("✗ Proof verification failed: {:?}", e),
Err(e) => println!("✗ Proof verification failed: {e:?}"),
}
}
Err(e) => println!("✗ Failed to generate proof: {:?}", e),
Err(e) => println!("✗ Failed to generate proof: {e:?}"),
}
}
4 changes: 2 additions & 2 deletions examples/simple_composition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ fn main() {
// Verify the proof
match verify(P1, P2, Q, H, &proof) {
Ok(()) => println!("✓ Proof verified successfully!"),
Err(e) => println!("✗ Proof verification failed: {:?}", e),
Err(e) => println!("✗ Proof verification failed: {e:?}"),
}
}
Err(e) => println!("✗ Failed to generate proof: {:?}", e),
Err(e) => println!("✗ Failed to generate proof: {e:?}"),
}
}
26 changes: 21 additions & 5 deletions src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ pub trait Codec {
type Challenge;

/// Generates an empty codec that can be identified by a domain separator.
fn new(domain_sep: &[u8]) -> Self;
fn new(protocol_identifier: &[u8], session_identifier: &[u8], instance_label: &[u8]) -> Self;

/// Allows for precomputed initialization of the codec with a specific IV.
fn from_iv(iv: [u8; 32]) -> Self;

/// Absorbs data into the codec.
fn prover_message(&mut self, data: &[u8]);
Expand Down Expand Up @@ -57,11 +60,24 @@ where
{
type Challenge = <G as Group>::Scalar;

fn new(domain_sep: &[u8]) -> Self {
let hasher = H::new(domain_sep);
fn new(protocol_id: &[u8], session_id: &[u8], instance_label: &[u8]) -> Self {
let iv = {
let mut tmp = H::new([0u8; 32]);
tmp.absorb(protocol_id);
tmp.ratchet();
tmp.absorb(session_id);
tmp.ratchet();
tmp.absorb(instance_label);
tmp.squeeze(32).try_into().unwrap()
};

Self::from_iv(iv)
}

fn from_iv(iv: [u8; 32]) -> Self {
Self {
hasher,
_marker: Default::default(),
hasher: H::new(iv),
_marker: core::marker::PhantomData,
}
}

Expand Down
Loading