Skip to content

Commit 1a10ce1

Browse files
committed
Merge branch 'release/2.0.0' into main
2 parents 4b9d2c9 + 7ac88e1 commit 1a10ce1

23 files changed

+452
-190
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
Entries are listed in reverse chronological order.
44

5+
## 2.0.0
6+
7+
* Switch from `failure` to `std`-compatible errors via `thiserror`.
8+
* Update `rand`, `curve25519-dalek`, `merlin` versions.
9+
* Adds `no_std` support by @xoloki.
10+
511
## 1.0.4
612

713
* Change doc-include paths to allow compilation on the latest Rust nightly

Cargo.toml

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
[package]
22
name = "bulletproofs"
3-
version = "1.0.4"
3+
# Before doing a release:
4+
# - update version field
5+
# - update html_root_url
6+
# - ensure yoloproofs was disabled in an atomic (revertable) commit
7+
# - update CHANGELOG
8+
version = "2.0.0"
49
authors = ["Cathie Yun <[email protected]>",
510
"Henry de Valence <[email protected]>",
611
"Oleg Andreev <[email protected]>"]
@@ -10,33 +15,33 @@ repository = "https://github.com/dalek-cryptography/bulletproofs"
1015
categories = ["cryptography"]
1116
keywords = ["cryptography", "crypto", "ristretto", "zero-knowledge", "bulletproofs"]
1217
description = "A pure-Rust implementation of Bulletproofs using Ristretto"
18+
edition = "2018"
1319

1420
[dependencies]
15-
curve25519-dalek = { version = "1.0.3", features = ["serde"] }
16-
subtle = "2"
17-
sha3 = "0.8"
18-
digest = "0.8"
19-
rand = "0.6"
20-
byteorder = "1"
21-
serde = "1"
22-
serde_derive = "1"
23-
failure = "0.1"
24-
merlin = "1.1"
25-
clear_on_drop = "0.2"
21+
curve25519-dalek = { version = "2", default-features = false, features = ["u64_backend", "nightly", "serde", "alloc"] }
22+
subtle = { version = "2", default-features = false }
23+
sha3 = { version = "0.8", default-features = false }
24+
digest = { version = "0.8", default-features = false }
25+
rand_core = { version = "0.5", default-features = false, features = ["alloc"] }
26+
rand = { version = "0.7", default-features = false, optional = true }
27+
byteorder = { version = "1", default-features = false }
28+
serde = { version = "1", default-features = false, features = ["alloc"] }
29+
serde_derive = { version = "1", default-features = false }
30+
thiserror = { version = "1", optional = true }
31+
merlin = { version = "2", default-features = false }
32+
clear_on_drop = { version = "0.2", default-features = false, features = ["nightly"] }
2633

2734
[dev-dependencies]
2835
hex = "0.3"
29-
criterion = "0.2"
36+
criterion = "0.3"
3037
bincode = "1"
31-
rand_chacha = "0.1"
38+
rand_chacha = "0.2"
3239

3340
[features]
41+
default = ["std", "avx2_backend"]
3442
avx2_backend = ["curve25519-dalek/avx2_backend"]
35-
# Disable the yoloproofs feature in the released crate.
36-
# To test it, use a git dependency on the develop branch and enable the
37-
# yoloproofs feature. Note that this means it's impossible to publish a crate
38-
# depending on the unstable R1CS API.
39-
#yoloproofs = []
43+
# yoloproofs = []
44+
std = ["rand", "rand/std", "thiserror"]
4045

4146
[[test]]
4247
name = "range_proof"

benches/generators.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
extern crate bulletproofs;
21
use bulletproofs::{BulletproofGens, PedersenGens};
32

43
#[macro_use]

benches/r1cs.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ use bulletproofs::{BulletproofGens, PedersenGens};
2323
use curve25519_dalek::ristretto::CompressedRistretto;
2424
use curve25519_dalek::scalar::Scalar;
2525
use merlin::Transcript;
26-
use rand::{thread_rng, Rng};
26+
use rand::seq::SliceRandom;
27+
use rand::Rng;
2728

2829
// Shuffle gadget (documented in markdown file)
2930

@@ -177,7 +178,7 @@ fn bench_kshuffle_prove(c: &mut Criterion) {
177178
.map(|_| Scalar::from(rng.gen_range(min, max)))
178179
.collect();
179180
let mut output = input.clone();
180-
rand::thread_rng().shuffle(&mut output);
181+
output.shuffle(&mut rand::thread_rng());
181182

182183
// Make kshuffle proof
183184
b.iter(|| {
@@ -219,7 +220,7 @@ fn bench_kshuffle_verify(c: &mut Criterion) {
219220
.map(|_| Scalar::from(rng.gen_range(min, max)))
220221
.collect();
221222
let mut output = input.clone();
222-
rand::thread_rng().shuffle(&mut output);
223+
output.shuffle(&mut rand::thread_rng());
223224

224225
let mut prover_transcript = Transcript::new(b"ShuffleBenchmark");
225226

benches/range_proof.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33
extern crate criterion;
44
use criterion::Criterion;
55

6-
extern crate rand;
6+
use rand;
77
use rand::Rng;
88

9-
extern crate curve25519_dalek;
109
use curve25519_dalek::scalar::Scalar;
1110

12-
extern crate merlin;
1311
use merlin::Transcript;
1412

15-
extern crate bulletproofs;
1613
use bulletproofs::RangeProof;
1714
use bulletproofs::{BulletproofGens, PedersenGens};
1815

docs/notes-r1cs.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,7 @@ the proof would still work if \\({\mathbf{a}}\_{O}\\) was rearranged on the righ
254254
If we reorder terms, we get:
255255

256256
\\[
257-
w\_c + \langle \mathbf{w}\_V, \mathbf{v} \rangle
258-
=
257+
w\_c + \langle \mathbf{w}\_V, \mathbf{v} \rangle =
259258
\langle \mathbf{a}\_L \circ \mathbf{a}\_R, \mathbf{y}^n \rangle -
260259
\langle \mathbf{a}\_O, \mathbf{y}^n \rangle +
261260
\langle \mathbf{w}\_L, \mathbf{a}\_L \rangle +
@@ -266,8 +265,7 @@ w\_c + \langle \mathbf{w}\_V, \mathbf{v} \rangle
266265
Merge the statements containing \\(\mathbf{a}\_O \\):
267266

268267
\\[
269-
w\_c + \langle \mathbf{w}\_V, \mathbf{v} \rangle
270-
=
268+
w\_c + \langle \mathbf{w}\_V, \mathbf{v} \rangle =
271269
\langle \mathbf{a}\_L \circ \mathbf{a}\_R, \mathbf{y}^n \rangle +
272270
\langle \mathbf{a}\_L, \mathbf{w}\_L \rangle +
273271
\langle \mathbf{a}\_O, -\mathbf{y}^n + \mathbf{w}\_O \rangle +
@@ -278,8 +276,7 @@ Rearrange \\(\langle \mathbf{a}\_L \circ \mathbf{a}\_R, \mathbf{y}^n \rangle\\)
278276
\\(\langle \mathbf{a}\_L, \mathbf{y}^n \circ \mathbf{a}\_R \rangle\\):
279277

280278
\\[
281-
w\_c + \langle \mathbf{w}\_V, \mathbf{v} \rangle
282-
=
279+
w\_c + \langle \mathbf{w}\_V, \mathbf{v} \rangle =
283280
\langle \mathbf{a}\_L, \mathbf{y}^n \circ \mathbf{a}\_R \rangle +
284281
\langle \mathbf{a}\_L, \mathbf{w}\_L \rangle +
285282
\langle \mathbf{a}\_O, -\mathbf{y}^n + \mathbf{w}\_O \rangle +
@@ -290,8 +287,7 @@ Multiply the \\( \langle \mathbf{a}\_R,
290287
\mathbf{w}\_R \rangle \\) term by \\(\mathbf{y}^n\\) one one side of the inner product and by \\(\mathbf{y}^{-n}\\) on the other side:
291288

292289
\\[
293-
w\_c + \langle \mathbf{w}\_V, \mathbf{v} \rangle
294-
=
290+
w\_c + \langle \mathbf{w}\_V, \mathbf{v} \rangle =
295291
\langle \mathbf{a}\_L, \mathbf{y}^n \circ \mathbf{a}\_R \rangle +
296292
\langle \mathbf{a}\_L, \mathbf{w}\_L \rangle +
297293
\langle \mathbf{a}\_O, -\mathbf{y}^n + \mathbf{w}\_O \rangle +
@@ -301,8 +297,7 @@ w\_c + \langle \mathbf{w}\_V, \mathbf{v} \rangle
301297
Merge the statements containing \\(\mathbf{y}^n \circ \mathbf{a}\_R\\):
302298

303299
\\[
304-
w\_c + \langle \mathbf{w}\_V, \mathbf{v} \rangle
305-
=
300+
w\_c + \langle \mathbf{w}\_V, \mathbf{v} \rangle =
306301
\langle \mathbf{a}\_L + \mathbf{y}^{-n} \circ \mathbf{w}\_R, \mathbf{y}^n \circ \mathbf{a}\_R \rangle +
307302
\langle \mathbf{a}\_L, \mathbf{w}\_L \rangle +
308303
\langle \mathbf{a}\_O, -\mathbf{y}^n + \mathbf{w}\_O \rangle

src/errors.rs

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,49 @@
11
//! Errors related to proving and verifying proofs.
22
3+
extern crate alloc;
4+
use alloc::vec::Vec;
5+
6+
#[cfg(feature = "std")]
7+
use thiserror::Error;
8+
39
/// Represents an error in proof creation, verification, or parsing.
4-
#[derive(Fail, Clone, Debug, Eq, PartialEq)]
10+
#[derive(Clone, Debug, Eq, PartialEq)]
11+
#[cfg_attr(feature = "std", derive(Error))]
512
pub enum ProofError {
613
/// This error occurs when a proof failed to verify.
7-
#[fail(display = "Proof verification failed.")]
14+
#[cfg_attr(feature = "std", error("Proof verification failed."))]
815
VerificationError,
916
/// This error occurs when the proof encoding is malformed.
10-
#[fail(display = "Proof data could not be parsed.")]
17+
#[cfg_attr(feature = "std", error("Proof data could not be parsed."))]
1118
FormatError,
1219
/// This error occurs during proving if the number of blinding
1320
/// factors does not match the number of values.
14-
#[fail(display = "Wrong number of blinding factors supplied.")]
21+
#[cfg_attr(feature = "std", error("Wrong number of blinding factors supplied."))]
1522
WrongNumBlindingFactors,
1623
/// This error occurs when attempting to create a proof with
1724
/// bitsize other than \\(8\\), \\(16\\), \\(32\\), or \\(64\\).
18-
#[fail(display = "Invalid bitsize, must have n = 8,16,32,64.")]
25+
#[cfg_attr(feature = "std", error("Invalid bitsize, must have n = 8,16,32,64."))]
1926
InvalidBitsize,
2027
/// This error occurs when attempting to create an aggregated
2128
/// proof with non-power-of-two aggregation size.
22-
#[fail(display = "Invalid aggregation size, m must be a power of 2.")]
29+
#[cfg_attr(
30+
feature = "std",
31+
error("Invalid aggregation size, m must be a power of 2.")
32+
)]
2333
InvalidAggregation,
2434
/// This error occurs when there are insufficient generators for the proof.
25-
#[fail(display = "Invalid generators size, too few generators for proof")]
35+
#[cfg_attr(
36+
feature = "std",
37+
error("Invalid generators size, too few generators for proof")
38+
)]
2639
InvalidGeneratorsLength,
2740
/// This error results from an internal error during proving.
2841
///
2942
/// The single-party prover is implemented by performing
3043
/// multiparty computation with ourselves. However, because the
3144
/// MPC protocol is not exposed by the single-party API, we
3245
/// consider its errors to be internal errors.
33-
#[fail(display = "Internal error during proof creation: {}", _0)]
46+
#[cfg_attr(feature = "std", error("Internal error during proof creation: {0}"))]
3447
ProvingError(MPCError),
3548
}
3649

@@ -52,38 +65,48 @@ impl From<MPCError> for ProofError {
5265
/// API: although the MPC protocol is used internally for single-party
5366
/// proving, its API should not expose the complexity of the MPC
5467
/// protocol.
55-
#[derive(Fail, Clone, Debug, Eq, PartialEq)]
68+
#[derive(Clone, Debug, Eq, PartialEq)]
69+
#[cfg_attr(feature = "std", derive(Error))]
5670
pub enum MPCError {
5771
/// This error occurs when the dealer gives a zero challenge,
5872
/// which would annihilate the blinding factors.
59-
#[fail(display = "Dealer gave a malicious challenge value.")]
73+
#[cfg_attr(feature = "std", error("Dealer gave a malicious challenge value."))]
6074
MaliciousDealer,
6175
/// This error occurs when attempting to create a proof with
6276
/// bitsize other than \\(8\\), \\(16\\), \\(32\\), or \\(64\\).
63-
#[fail(display = "Invalid bitsize, must have n = 8,16,32,64")]
77+
#[cfg_attr(feature = "std", error("Invalid bitsize, must have n = 8,16,32,64"))]
6478
InvalidBitsize,
6579
/// This error occurs when attempting to create an aggregated
6680
/// proof with non-power-of-two aggregation size.
67-
#[fail(display = "Invalid aggregation size, m must be a power of 2")]
81+
#[cfg_attr(
82+
feature = "std",
83+
error("Invalid aggregation size, m must be a power of 2")
84+
)]
6885
InvalidAggregation,
6986
/// This error occurs when there are insufficient generators for the proof.
70-
#[fail(display = "Invalid generators size, too few generators for proof")]
87+
#[cfg_attr(
88+
feature = "std",
89+
error("Invalid generators size, too few generators for proof")
90+
)]
7191
InvalidGeneratorsLength,
7292
/// This error occurs when the dealer is given the wrong number of
7393
/// value commitments.
74-
#[fail(display = "Wrong number of value commitments")]
94+
#[cfg_attr(feature = "std", error("Wrong number of value commitments"))]
7595
WrongNumBitCommitments,
7696
/// This error occurs when the dealer is given the wrong number of
7797
/// polynomial commitments.
78-
#[fail(display = "Wrong number of value commitments")]
98+
#[cfg_attr(feature = "std", error("Wrong number of value commitments"))]
7999
WrongNumPolyCommitments,
80100
/// This error occurs when the dealer is given the wrong number of
81101
/// proof shares.
82-
#[fail(display = "Wrong number of proof shares")]
102+
#[cfg_attr(feature = "std", error("Wrong number of proof shares"))]
83103
WrongNumProofShares,
84104
/// This error occurs when one or more parties submit malformed
85105
/// proof shares.
86-
#[fail(display = "Malformed proof shares from parties {:?}", bad_shares)]
106+
#[cfg_attr(
107+
feature = "std",
108+
error("Malformed proof shares from parties {bad_shares:?}")
109+
)]
87110
MalformedProofShares {
88111
/// A vector with the indexes of the parties whose shares were malformed.
89112
bad_shares: Vec<usize>,
@@ -94,27 +117,31 @@ pub enum MPCError {
94117
///
95118
/// XXX: should this be separate from a `ProofError`?
96119
#[cfg(feature = "yoloproofs")]
97-
#[derive(Fail, Clone, Debug, Eq, PartialEq)]
120+
#[derive(Clone, Debug, Eq, PartialEq)]
121+
#[cfg_attr(feature = "std", derive(Error))]
98122
pub enum R1CSError {
99123
/// Occurs when there are insufficient generators for the proof.
100-
#[fail(display = "Invalid generators size, too few generators for proof")]
124+
#[cfg_attr(
125+
feature = "std",
126+
error("Invalid generators size, too few generators for proof")
127+
)]
101128
InvalidGeneratorsLength,
102129
/// This error occurs when the proof encoding is malformed.
103-
#[fail(display = "Proof data could not be parsed.")]
130+
#[cfg_attr(feature = "std", error("Proof data could not be parsed."))]
104131
FormatError,
105132
/// Occurs when verification of an
106133
/// [`R1CSProof`](::r1cs::R1CSProof) fails.
107-
#[fail(display = "R1CSProof did not verify correctly.")]
134+
#[cfg_attr(feature = "std", error("R1CSProof did not verify correctly."))]
108135
VerificationError,
109136

110137
/// Occurs when trying to use a missing variable assignment.
111138
/// Used by gadgets that build the constraint system to signal that
112139
/// a variable assignment is not provided when the prover needs it.
113-
#[fail(display = "Variable does not have a value assignment.")]
140+
#[cfg_attr(feature = "std", error("Variable does not have a value assignment."))]
114141
MissingAssignment,
115142

116143
/// Occurs when a gadget receives an inconsistent input.
117-
#[fail(display = "Gadget error: {:?}", description)]
144+
#[cfg_attr(feature = "std", error("Gadget error: {description:?}"))]
118145
GadgetError {
119146
/// The description of the reasons for the error.
120147
description: String,

src/generators.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
#![allow(non_snake_case)]
55
#![deny(missing_docs)]
66

7+
extern crate alloc;
8+
9+
use alloc::vec::Vec;
710
use curve25519_dalek::constants::RISTRETTO_BASEPOINT_COMPRESSED;
811
use curve25519_dalek::constants::RISTRETTO_BASEPOINT_POINT;
912
use curve25519_dalek::ristretto::RistrettoPoint;
1013
use curve25519_dalek::scalar::Scalar;
1114
use curve25519_dalek::traits::MultiscalarMul;
12-
1315
use digest::{ExtendableOutput, Input, XofReader};
1416
use sha3::{Sha3XofReader, Sha3_512, Shake256};
1517

@@ -165,7 +167,7 @@ impl BulletproofGens {
165167

166168
/// Returns j-th share of generators, with an appropriate
167169
/// slice of vectors G and H for the j-th range proof.
168-
pub fn share(&self, j: usize) -> BulletproofGensShare {
170+
pub fn share(&self, j: usize) -> BulletproofGensShare<'_> {
169171
BulletproofGensShare {
170172
gens: &self,
171173
share: j,
@@ -251,7 +253,7 @@ impl<'a> Iterator for AggregatedGensIter<'a> {
251253
}
252254

253255
fn size_hint(&self) -> (usize, Option<usize>) {
254-
let size = self.n * self.m;
256+
let size = self.n * (self.m - self.party_idx) - self.gen_idx;
255257
(size, Some(size))
256258
}
257259
}

0 commit comments

Comments
 (0)