Skip to content

Commit 61fe7c6

Browse files
authored
Merge pull request #201 from dalek-cryptography/note-edits-2
Some note touchups
2 parents 08ba98e + cc57967 commit 61fe7c6

File tree

3 files changed

+82
-23
lines changed

3 files changed

+82
-23
lines changed

README.md

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ relative speed compared to the fastest implementation.
6767
| libsecp-endo | secp256k1 | 16800 | **2.30x** | 2080 | **2.00x** |
6868
| Monero | ed25519 (unsafe) | 53300 | **7.30x** | 4810 | **4.63x** |
6969

70-
This crate also contains other benchmarks; see the *Benchmarks*
70+
This crate also contains other benchmarks; see the *Tests and Benchmarks*
7171
section below for details.
7272

7373
## WARNING
@@ -76,14 +76,64 @@ This code is still research-quality. It is not (yet) suitable for
7676
deployment. The development roadmap can be found in the
7777
[Milestones][gh_milestones] section of the [Github repo][gh_repo].
7878

79-
## Tests
80-
81-
Run tests with `cargo test`.
79+
## Example
80+
81+
```rust
82+
# extern crate rand;
83+
# use rand::thread_rng;
84+
#
85+
# extern crate curve25519_dalek;
86+
# use curve25519_dalek::scalar::Scalar;
87+
#
88+
# extern crate merlin;
89+
# use merlin::Transcript;
90+
#
91+
# extern crate bulletproofs;
92+
# use bulletproofs::{BulletproofGens, PedersenGens, RangeProof};
93+
#
94+
# fn main() {
95+
// Generators for Pedersen commitments. These can be selected
96+
// independently of the Bulletproofs generators.
97+
let pc_gens = PedersenGens::default();
98+
99+
// Generators for Bulletproofs, valid for proofs up to bitsize 64
100+
// and aggregation size up to 1.
101+
let bp_gens = BulletproofGens::new(64, 1);
102+
103+
// A secret value we want to prove lies in the range [0, 2^32)
104+
let secret_value = 1037578891u64;
105+
106+
// The API takes a blinding factor for the commitment.
107+
let blinding = Scalar::random(&mut thread_rng());
108+
109+
// The proof can be chained to an existing transcript.
110+
// Here we create a transcript with a doctest domain separator.
111+
let mut prover_transcript = Transcript::new(b"doctest example");
112+
113+
// Create a 32-bit rangeproof.
114+
let (proof, committed_value) = RangeProof::prove_single(
115+
&bp_gens,
116+
&pc_gens,
117+
&mut prover_transcript,
118+
secret_value,
119+
&blinding,
120+
32,
121+
).expect("A real program could handle errors");
122+
123+
// Verification requires a transcript with identical initial state:
124+
let mut verifier_transcript = Transcript::new(b"doctest example");
125+
assert!(
126+
proof
127+
.verify_single(&bp_gens, &pc_gens, &mut verifier_transcript, &committed_value, 32)
128+
.is_ok()
129+
);
130+
# }
131+
```
82132

83-
## Benchmarks
133+
## Tests and Benchmarks
84134

85-
This crate uses [criterion.rs][criterion] for benchmarks. Run
86-
benchmarks with `cargo bench`.
135+
Run tests with `cargo test`.
136+
Run benchmarks with `cargo bench`. This crate uses [criterion.rs][criterion] for benchmarks.
87137

88138
## Features
89139

docs/notes.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,30 +270,36 @@ we finally obtain
270270
\\]
271271
This is equivalent to the original inner-product equation, but has a single
272272
inner product with \\({\mathbf{a}}\_{L}\\) on the left, \\({\mathbf{a}}\_{R}\\) on
273-
the right, and non-secret terms factored out.
273+
the right, and non-secret terms factored out. Let's call the left-hand side of the single inner product equation "unblinded" \\({\mathbf{l}(x)}\\) and the right-hand side "unblinded" \\({\mathbf{r}(x)}\\), such that
274+
\\[
275+
\begin{aligned}
276+
\text{unblinded } \mathbf{l}(x) &= {\mathbf{a}}\_{L} - z {\mathbf{1}} \\\\
277+
\text{unblinded } \mathbf{r}(x) &= {\mathbf{y}}^{n} \circ ({\mathbf{a}}\_{R} + z {\mathbf{1}}) + z^{2} {\mathbf{2}}^{n} \\\\
278+
z^{2}v + \delta(y,z) &= {\langle \text{unblinded } \mathbf{l}(x), \text{unblinded } \mathbf{r}(x) \rangle}
279+
\end{aligned}
280+
\\]
274281

275282
Blinding the inner product
276283
--------------------------
277284

278285
The prover cannot send the left and right vectors in
279-
the single inner-product equation to the verifier without revealing information
286+
the single inner-product equation (unblinded \\({\mathbf{l}(x)}\\) and \\({\mathbf{r}(x)}\\)) to the verifier without revealing information
280287
about the value \\(v\\), and since the inner-product argument is not
281288
zero-knowledge, they cannot be used there either.
282289

283290
Instead, the prover chooses vectors of blinding factors
284291
\\[
285292
{\mathbf{s}}\_{L}, {\mathbf{s}}\_{R} \\;{\xleftarrow{\\$}}\\; {\mathbb Z\_p}^{n},
286293
\\]
287-
and uses them to construct vector polynomials
294+
and uses them to construct blinded vector polynomials from the unblinded vector polynomials \\({\mathbf{l}(x)}\\) and \\({\mathbf{r}(x)}\\):
288295
\\[
289296
\begin{aligned}
290297
{\mathbf{l}}(x) &= {\mathbf{l}}\_{0} + {\mathbf{l}}\_{1} x = ({\mathbf{a}}\_{L} + {\mathbf{s}}\_{L} x) - z {\mathbf{1}} & \in {\mathbb Z\_p}\[x\]^{n} \\\\
291298
{\mathbf{r}}(x) &= {\mathbf{r}}\_{0} + {\mathbf{r}}\_{1} x = {\mathbf{y}}^{n} \circ \left( ({\mathbf{a}}\_{R} + {\mathbf{s}}\_{R} x\right) + z {\mathbf{1}}) + z^{2} {\mathbf{2}}^{n} &\in {\mathbb Z\_p}\[x\]^{n}
292299
\end{aligned}
293300
\\]
294-
These are the left and right sides of the combined inner product with \\({\mathbf{a}}\_{L}\\), \\({\mathbf{a}}\_{R}\\)
295-
replaced by blinded terms \\({\mathbf{a}}\_{L} + {\mathbf{s}}\_{L} x\\),
296-
\\({\mathbf{a}}\_{R} + {\mathbf{s}}\_{R} x\\). Notice that since only the
301+
The "blinded" \\({\mathbf{l}}(x)\\) and \\({\mathbf{r}}(x)\\) have \\({\mathbf{a}}\_{L}\\), \\({\mathbf{a}}\_{R}\\) replaced by blinded terms \\({\mathbf{a}}\_{L} + {\mathbf{s}}\_{L} x\\),
302+
\\({\mathbf{a}}\_{R} + {\mathbf{s}}\_{R} x\\). The \\({\mathbf{l}}\_{0}\\) and \\({\mathbf{r}}\_{0}\\) terms represent the degree-zero terms of the polynomial with respect to \\(x\\), and the \\({\mathbf{l}}\_{1}\\) and \\({\mathbf{r}}\_{1}\\) terms represent the degree-one terms. Notice that since only the
297303
blinding factors \\({\mathbf{s}}\_{L}\\), \\({\mathbf{s}}\_{R}\\) are multiplied
298304
by \\(x\\), the vectors \\({\mathbf{l}}\_{0}\\) and \\({\mathbf{r}}\_{0}\\) are
299305
exactly the left and right sides of the unblinded single inner-product:
@@ -519,7 +525,7 @@ check the final equality directly.
519525

520526
If the prover can demonstrate that the above \\(P'\\) has such structure
521527
over generators \\({\mathbf{G}}\\), \\({\mathbf{H}}\\) and \\(Q\\) for all
522-
\\(w \in {\mathbb Z\_{p}^{*}}\\), then the original \\(P\\) and \\(c\\) must satisfy
528+
\\(w \in {\mathbb Z\_{p}^{\*}}\\), then the original \\(P\\) and \\(c\\) must satisfy
523529
the original relation
524530
\\((P = {\langle {\mathbf{a}}, {\mathbf{G}} \rangle} + {\langle {\mathbf{b}}, {\mathbf{H}} \rangle}
525531
\wedge c = {\langle {\mathbf{a}}, {\mathbf{b}} \rangle})\\).
@@ -606,7 +612,10 @@ additional and final step involves sending a pair of scalars
606612
Aggregated Range Proof
607613
======================
608614

609-
We want to take advantage of the logarithmic size of the inner-product protocol, by creating an aggregated range proof for \\(m\\) values that is smaller than \\(m\\) individual range proofs.
615+
The goal of an _aggregated range proof_ is to enable a group of parties to produce proofs of their individual statements
616+
(individual range proofs for the corresponding value commitments), that can be aggregated in a more compact proof.
617+
This is more efficient due to the logarithmic size of the inner-product protocol: an aggregated range proof for \\(m\\)
618+
values is smaller than \\(m\\) individual range proofs.
610619

611620
The aggregation protocol is a multi-party computation protocol, involving \\(m\\) parties (one party per value) and one dealer, where the parties don't reveal their secrets to each other. The parties share their commitments with the dealer, and the dealer generates and returns challenge variables. The parties then share their proof shares with the dealer, and the dealer combines their shares to create an aggregated proof.
612621

src/range_proof/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,23 @@ impl RangeProof {
104104
///
105105
/// // The proof can be chained to an existing transcript.
106106
/// // Here we create a transcript with a doctest domain separator.
107-
/// let mut transcript = Transcript::new(b"doctest example");
107+
/// let mut prover_transcript = Transcript::new(b"doctest example");
108108
///
109109
/// // Create a 32-bit rangeproof.
110110
/// let (proof, committed_value) = RangeProof::prove_single(
111111
/// &bp_gens,
112112
/// &pc_gens,
113-
/// &mut transcript,
113+
/// &mut prover_transcript,
114114
/// secret_value,
115115
/// &blinding,
116116
/// 32,
117117
/// ).expect("A real program could handle errors");
118118
///
119119
/// // Verification requires a transcript with identical initial state:
120-
/// let mut transcript = Transcript::new(b"doctest example");
120+
/// let mut verifier_transcript = Transcript::new(b"doctest example");
121121
/// assert!(
122122
/// proof
123-
/// .verify_single(&bp_gens, &pc_gens, &mut transcript, &committed_value, 32)
123+
/// .verify_single(&bp_gens, &pc_gens, &mut verifier_transcript, &committed_value, 32)
124124
/// .is_ok()
125125
/// );
126126
/// # }
@@ -171,23 +171,23 @@ impl RangeProof {
171171
///
172172
/// // The proof can be chained to an existing transcript.
173173
/// // Here we create a transcript with a doctest domain separator.
174-
/// let mut transcript = Transcript::new(b"doctest example");
174+
/// let mut prover_transcript = Transcript::new(b"doctest example");
175175
///
176176
/// // Create an aggregated 32-bit rangeproof and corresponding commitments.
177177
/// let (proof, commitments) = RangeProof::prove_multiple(
178178
/// &bp_gens,
179179
/// &pc_gens,
180-
/// &mut transcript,
180+
/// &mut prover_transcript,
181181
/// &secrets,
182182
/// &blindings,
183183
/// 32,
184184
/// ).expect("A real program could handle errors");
185185
///
186186
/// // Verification requires a transcript with identical initial state:
187-
/// let mut transcript = Transcript::new(b"doctest example");
187+
/// let mut verifier_transcript = Transcript::new(b"doctest example");
188188
/// assert!(
189189
/// proof
190-
/// .verify_multiple(&bp_gens, &pc_gens, &mut transcript, &commitments, 32)
190+
/// .verify_multiple(&bp_gens, &pc_gens, &mut verifier_transcript, &commitments, 32)
191191
/// .is_ok()
192192
/// );
193193
/// # }

0 commit comments

Comments
 (0)