Skip to content

Commit 457780e

Browse files
committed
doc: fix readme example
1 parent 3469edf commit 457780e

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

README.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,28 @@ This library provides a flexible framework for creating zero-knowledge proofs fo
99
## Quick Example
1010

1111
```rust
12-
use sigma_rs::{LinearRelation, Protocol, ProtocolWitness, Nizk};
13-
use sigma_rs::codec::Shake128DuplexSponge;
14-
use curve25519_dalek::RistrettoPoint as G;
12+
use curve25519_dalek::ristretto::RistrettoPoint;
13+
use curve25519_dalek::scalar::Scalar;
14+
use group::Group;
15+
let mut instance = sigma_rs::LinearRelation::new();
16+
let mut rng = rand::thread_rng();
1517

18+
// Define the statement:
1619
// Prove knowledge of (x, r) such that C = x·G + r·H (Pedersen commitment)
17-
let mut relation = LinearRelation::<G>::new();
18-
19-
// Allocate variables
20-
let x = relation.allocate_scalar();
21-
let r = relation.allocate_scalar();
22-
let [G_var, H_var] = relation.allocate_elements();
23-
24-
// Define constraint: C = x·G + r·H
25-
let C = relation.allocate_eq(x * G_var + r * H_var);
26-
27-
// Set public values and compute the commitment
28-
relation.set_elements([(G_var, G::generator()), (H_var, H)]);
29-
relation.compute_image(&[x_val, r_val]).unwrap();
30-
31-
// Create non-interactive proof
32-
let nizk = relation.into_nizk(b"pedersen-proof");
33-
let proof = nizk.prove_batchable(&witness, &mut rng)?;
20+
let [var_x, var_r] = instance.allocate_scalars();
21+
let [var_G, var_H] = instance.allocate_elements();
22+
instance.allocate_eq(var_G * var_x + var_H * var_r);
23+
instance.set_elements([(var_G, RistrettoPoint::generator()), (var_H, RistrettoPoint::random(&mut rng))]);
24+
25+
// Assign the image of the linear map.
26+
let witness = vec![Scalar::random(&mut rng), Scalar::random(&mut rng)];
27+
instance.compute_image(&witness);
28+
29+
// Create a non-interactive argument for the instance.
30+
let nizk = instance.into_nizk(b"your session identifier").unwrap();
31+
let narg_string: Vec<u8> = nizk.prove_batchable(&witness, &mut rng).unwrap();
32+
// Print the narg string.
33+
println!("{}", hex::encode(narg_string));
3434
```
3535

3636
## Composition Example

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
//! let mut instance = sigma_rs::LinearRelation::new();
2323
//! let mut rng = rand::thread_rng();
2424
//!
25-
//! // Define the proof statement.
25+
//! // Define the statement:
26+
//! // Prove knowledge of (x, r) such that C = x·G + r·H (Pedersen commitment)
2627
//! let [var_x, var_r] = instance.allocate_scalars();
2728
//! let [var_G, var_H] = instance.allocate_elements();
2829
//! instance.allocate_eq(var_G * var_x + var_H * var_r);

0 commit comments

Comments
 (0)