Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement no_std support #280

Merged
merged 40 commits into from
Sep 28, 2019
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
c4499ab
turn off default features in Cargo.toml, and define and select as app…
xoloki Mar 27, 2019
91d36eb
use dependency injection to pass RNGs around rather than creating the…
xoloki Mar 27, 2019
5984ec0
include std/alloc explicitly for curve25519-dalek since we aren't get…
xoloki Apr 1, 2019
bb86ad1
use merlin from fork for nostd fixes
xoloki Apr 1, 2019
dd4ee75
turn off fancy serde error code to try to fix nostd errors
xoloki Apr 1, 2019
be9c393
use upstream dalek curve release, without using serde; remove all nai…
xoloki May 8, 2019
84e6924
add byte buffer data structures to enable naive serialization without…
xoloki May 13, 2019
93842a7
add no_std cfg_attr in base lib.rs; remove unused serialization code …
xoloki May 13, 2019
5f6d068
only reference core directly if we're in std mode; if we're in alloc …
xoloki May 13, 2019
23813f1
try putting cfg_if in generators to pickup alloc Vec
xoloki May 13, 2019
06f5e81
use cfg_if to pickup Vec in alloc mode
xoloki May 13, 2019
f0d37d0
use cfg_if to pickup Vec in alloc mode
xoloki May 13, 2019
9c2bc09
use cfg_if to pickup iter and Borrow in alloc mode
xoloki May 13, 2019
60eb7e8
use core::iter; replace vec! usage
xoloki May 13, 2019
d01f0c6
remove println
xoloki May 13, 2019
baa759f
re-enable range proof serialzation
xoloki May 15, 2019
de18a44
use naive curve point serialization in internal data structures
xoloki May 17, 2019
196f072
make API backward compatible in std mode, renaming templated function…
xoloki May 30, 2019
332458f
remove unnecessary import and use of ThreadRng; make standardized ref…
xoloki May 30, 2019
f929674
use version only major version for curve25519 dependency
xoloki Jun 5, 2019
602d600
force usage of curve25519 1.2.x
xoloki Jun 26, 2019
dac9547
use updated merlin without alloc target
xoloki Jul 3, 2019
b921580
fix existing test and build errors; pass rng where necessary to helpe…
xoloki Jul 3, 2019
4c8179b
fix bad rebase
xoloki Jul 19, 2019
093315f
test is failing upstream so leave it
xoloki Jul 19, 2019
7facdf8
use rand 0.6 to avoid std errors during no_std build
xoloki Jul 24, 2019
4aa64c9
fmt fixes
xoloki Jul 24, 2019
f248649
fix bad rebase
xoloki Aug 2, 2019
c664af1
remove new use of vec! from develop branch
xoloki Aug 2, 2019
931288d
fix yoloproofs, only include them in std mode
xoloki Aug 2, 2019
b935b5b
remove cfg_if and just repeat cfg directives as necessary; use alloc:…
xoloki Aug 5, 2019
c70332d
make rand dependency optional, and select it always when std feature …
xoloki Aug 6, 2019
dc1238b
remove alloc feature and just use alloc everywhere, now building with…
xoloki Aug 12, 2019
ee0678e
pull in review changes
xoloki Aug 12, 2019
c1890b1
Merge branch 'develop' into nostd
xoloki Aug 12, 2019
415e355
fmt fixes
xoloki Aug 12, 2019
b451bcc
keep public API backwards compatible when in std mode
xoloki Aug 14, 2019
04533f5
Fix bad copypasta, remove template parameters
xoloki Aug 14, 2019
4a523df
revert test change to disable test that was failing locally
xoloki Aug 14, 2019
76c0e75
restore original test code
hdevalence Aug 14, 2019
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
25 changes: 14 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ keywords = ["cryptography", "crypto", "ristretto", "zero-knowledge", "bulletproo
description = "A pure-Rust implementation of Bulletproofs using Ristretto"

[dependencies]
curve25519-dalek = { version = "^1.2.3", features = ["serde"] }
subtle = "2"
sha3 = "0.8"
digest = "0.8"
rand = "0.6"
byteorder = "1"
serde = "1"
serde_derive = "1"
failure = "0.1"
merlin = "1.1"
clear_on_drop = "0.2"
curve25519-dalek = { version = "^1.2.3", default-features = false, features = ["u64_backend", "nightly", "serde", "alloc"] }
subtle = { version = "2", default-features = false }
sha3 = { version = "0.8", default-features = false }
digest = { version = "0.8", default-features = false }
rand_core = { version = "0.4", default-features = false, features = ["alloc"] }
rand = { version = "0.6", default-features = false, optional = true }
byteorder = { version = "1", default-features = false }
serde = { version = "1", default-features = false, features = ["alloc"] }
serde_derive = { version = "1", default-features = false }
failure = { version = "0.1", default-features = false, features = ["derive"] }
merlin = { version = "1.2", default-features = false }
clear_on_drop = { version = "0.2", default-features = false, features = ["nightly"] }

[dev-dependencies]
hex = "0.3"
Expand All @@ -31,8 +32,10 @@ bincode = "1"
rand_chacha = "0.1"

[features]
default = ["std", "avx2_backend"]
avx2_backend = ["curve25519-dalek/avx2_backend"]
yoloproofs = []
std = ["rand", "rand/std"]

[[test]]
name = "range_proof"
Expand Down
3 changes: 3 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! Errors related to proving and verifying proofs.

extern crate alloc;
use alloc::vec::Vec;

/// Represents an error in proof creation, verification, or parsing.
#[derive(Fail, Clone, Debug, Eq, PartialEq)]
pub enum ProofError {
Expand Down
4 changes: 3 additions & 1 deletion src/generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
#![allow(non_snake_case)]
#![deny(missing_docs)]

extern crate alloc;

use alloc::vec::Vec;
use curve25519_dalek::constants::RISTRETTO_BASEPOINT_COMPRESSED;
use curve25519_dalek::constants::RISTRETTO_BASEPOINT_POINT;
use curve25519_dalek::ristretto::RistrettoPoint;
use curve25519_dalek::scalar::Scalar;
use curve25519_dalek::traits::MultiscalarMul;

use digest::{ExtendableOutput, Input, XofReader};
use sha3::{Sha3XofReader, Sha3_512, Shake256};

Expand Down
7 changes: 5 additions & 2 deletions src/inner_product_proof.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#![allow(non_snake_case)]
#![doc(include = "../docs/inner-product-protocol.md")]

use std::borrow::Borrow;
use std::iter;
extern crate alloc;

use alloc::borrow::Borrow;
use alloc::vec::Vec;

use core::iter;
use curve25519_dalek::ristretto::{CompressedRistretto, RistrettoPoint};
use curve25519_dalek::scalar::Scalar;
use curve25519_dalek::traits::VartimeMultiscalarMul;
Expand Down
12 changes: 11 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![feature(nll)]
#![feature(external_doc)]
#![feature(try_trait)]
Expand All @@ -6,9 +7,17 @@
#![doc(html_logo_url = "https://doc.dalek.rs/assets/dalek-logo-clear.png")]

extern crate byteorder;

extern crate alloc;

#[cfg(feature = "std")]
extern crate core;
extern crate digest;

#[cfg(feature = "std")]
extern crate rand;

extern crate digest;
extern crate rand_core;
extern crate sha3;

extern crate clear_on_drop;
Expand Down Expand Up @@ -56,4 +65,5 @@ pub mod range_proof_mpc {
}

#[cfg(feature = "yoloproofs")]
#[cfg(feature = "std")]
pub mod r1cs;
15 changes: 13 additions & 2 deletions src/range_proof/dealer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
//! [the API for the aggregated multiparty computation protocol](../aggregation/index.html#api-for-the-aggregated-multiparty-computation-protocol).

use core::iter;

extern crate alloc;

use alloc::vec::Vec;

use curve25519_dalek::ristretto::RistrettoPoint;
use curve25519_dalek::scalar::Scalar;
use merlin::Transcript;
Expand All @@ -15,6 +20,8 @@ use inner_product_proof;
use range_proof::RangeProof;
use transcript::TranscriptProtocol;

use rand_core::{CryptoRng, RngCore};

use util;

use super::messages::*;
Expand Down Expand Up @@ -295,15 +302,19 @@ impl<'a, 'b> DealerAwaitingProofShares<'a, 'b> {
/// performing local aggregation,
/// [`receive_trusted_shares`](DealerAwaitingProofShares::receive_trusted_shares)
/// saves time by skipping verification of the aggregated proof.
pub fn receive_shares(mut self, proof_shares: &[ProofShare]) -> Result<RangeProof, MPCError> {
pub fn receive_shares<T: RngCore + CryptoRng>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this needs to be a new receive_shares_with_rng function, because receive_shares is part of the public API and can't change without a major version bump.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll rework these so the API doesn't change in std mode.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Sorry again for missing this on the first pass of review 😞

mut self,
proof_shares: &[ProofShare],
rng: &mut T,
) -> Result<RangeProof, MPCError> {
let proof = self.assemble_shares(proof_shares)?;

let Vs: Vec<_> = self.bit_commitments.iter().map(|vc| vc.V_j).collect();

// See comment in `Dealer::new` for why we use `initial_transcript`
let transcript = &mut self.initial_transcript;
if proof
.verify_multiple(self.bp_gens, self.pc_gens, transcript, &Vs, self.n)
.verify_multiple_with_rng(self.bp_gens, self.pc_gens, transcript, &Vs, self.n, rng)
.is_ok()
{
Ok(proof)
Expand Down
7 changes: 4 additions & 3 deletions src/range_proof/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
//! For more explanation of how the `dealer`, `party`, and `messages` modules orchestrate the protocol execution, see
//! [the API for the aggregated multiparty computation protocol](../aggregation/index.html#api-for-the-aggregated-multiparty-computation-protocol).

extern crate alloc;

use alloc::vec::Vec;
use core::iter;
use curve25519_dalek::ristretto::{CompressedRistretto, RistrettoPoint};
use curve25519_dalek::scalar::Scalar;

use generators::{BulletproofGens, PedersenGens};

/// A commitment to the bits of a party's value.
Expand Down Expand Up @@ -87,8 +90,6 @@ impl ProofShare {
poly_commitment: &PolyCommitment,
poly_challenge: &PolyChallenge,
) -> Result<(), ()> {
use std::iter;

use curve25519_dalek::traits::{IsIdentity, VartimeMultiscalarMul};

use inner_product_proof::inner_product;
Expand Down
Loading