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

feat: support no_std #103

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ description = "A smaller faster implementation of Bulletproofs"
[dependencies]
blake2 = { version = "0.10", default-features = false }
byteorder = { version = "1", default-features = false }
curve25519-dalek = { package = "tari-curve25519-dalek", version = "4.0.3", features = ["serde", "rand_core"] }
curve25519-dalek = { package = "tari-curve25519-dalek", version = "4.0.3", default-features = false, features = ["alloc", "serde", "rand_core", "zeroize"] }
digest = { version = "0.10", default-features = false }
itertools = { version = "0.12", default-features = false, features = ["use_alloc"] }
merlin = { version = "3", default-features = false }
once_cell = { version = "1", default-features = false, features = ["critical-section"] }
rand = { version = "0.8", optional = true }
serde = { version = "1.0", default-features = false, features = ["alloc"] }
serde = { version = "1", default-features = false, features = ["alloc"] }
sha3 = { version = "0.10", default-features = false }
thiserror-no-std = { version = "2", default-features = false }
zeroize = { version = "1", default-features = false, features = ["alloc", "derive"] }
Expand Down
2 changes: 2 additions & 0 deletions src/commitment_opening.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

//! Bulletproofs+ commitment opening struct

use alloc::vec::Vec;

use curve25519_dalek::scalar::Scalar;
use zeroize::{Zeroize, ZeroizeOnDrop};

Expand Down
4 changes: 3 additions & 1 deletion src/extended_mask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

//! Bulletproofs+ embedded extended mask

use alloc::vec::Vec;

use curve25519_dalek::scalar::Scalar;
use zeroize::{Zeroize, ZeroizeOnDrop};

Expand Down Expand Up @@ -40,7 +42,7 @@ impl ExtendedMask {

#[cfg(test)]
mod test {
use std::convert::TryFrom;
use core::convert::TryFrom;

use super::*;

Expand Down
2 changes: 2 additions & 0 deletions src/generators/aggregated_gens_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// Copyright (c) 2018 Chain, Inc.
// SPDX-License-Identifier: MIT

use alloc::vec::Vec;

/// A convenience iterator struct for the generators
pub struct AggregatedGensIter<'a, P> {
pub(super) array: &'a Vec<Vec<P>>,
Expand Down
6 changes: 3 additions & 3 deletions src/generators/bulletproof_gens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
// Copyright (c) 2018 Chain, Inc.
// SPDX-License-Identifier: MIT

use std::{
use alloc::{sync::Arc, vec::Vec};
use core::{
convert::TryFrom,
fmt::{Debug, Formatter},
sync::Arc,
};

use byteorder::{ByteOrder, LittleEndian};
Expand Down Expand Up @@ -139,7 +139,7 @@ where
P: Compressable + Debug + Precomputable,
P::Compressed: Debug,
{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
f.debug_struct("RangeParameters")
.field("gens_capacity", &self.gens_capacity)
.field("party_capacity", &self.party_capacity)
Expand Down
2 changes: 1 addition & 1 deletion src/generators/generators_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Copyright (c) 2018 Chain, Inc.
// SPDX-License-Identifier: MIT

use std::marker::PhantomData;
use core::marker::PhantomData;

use digest::{core_api::XofReaderCoreWrapper, ExtendableOutput, Update, XofReader};
use sha3::{Shake256, Shake256ReaderCore};
Expand Down
5 changes: 3 additions & 2 deletions src/generators/pedersen_gens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
// Copyright (c) 2018 Chain, Inc.
// SPDX-License-Identifier: MIT

use std::{borrow::Borrow, convert::TryFrom, iter::once};
use alloc::vec::Vec;
use core::{borrow::Borrow, convert::TryFrom, iter::once};

use curve25519_dalek::{scalar::Scalar, traits::MultiscalarMul};
use zeroize::Zeroize;
Expand Down Expand Up @@ -124,7 +125,7 @@ where P: Compressable + MultiscalarMul<Point = P> + Clone

#[cfg(test)]
mod test {
use std::convert::TryFrom;
use core::convert::TryFrom;

use super::ExtensionDegree;

Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ pub use generators::bulletproof_gens::BulletproofGens;
pub use generators::pedersen_gens::PedersenGens;

pub mod ristretto;

#[macro_use]
extern crate alloc;
2 changes: 1 addition & 1 deletion src/protocols/curve_point_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

//! Bulletproofs+ `CurvePointProtocol` trait provides the required interface for curves using BP+.

use std::{
use core::{
borrow::Borrow,
ops::{Add, AddAssign},
};
Expand Down
8 changes: 3 additions & 5 deletions src/range_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@

//! Bulletproofs+ range parameters (generators and base points) needed for a batch of range proofs

use std::{
fmt::{Debug, Formatter},
sync::Arc,
};
use alloc::sync::Arc;
use core::fmt::{Debug, Formatter};

use crate::{
errors::ProofError,
Expand Down Expand Up @@ -116,7 +114,7 @@ where
P: Compressable + Debug + Precomputable,
P::Compressed: Debug,
{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
f.debug_struct("RangeParameters")
.field("pc_gens", &self.pc_gens)
.field("bp_gens", &self.bp_gens)
Expand Down
20 changes: 8 additions & 12 deletions src/range_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

#![allow(clippy::too_many_lines)]

use std::{
use alloc::vec::Vec;
use core::{
convert::{TryFrom, TryInto},
iter::once,
marker::PhantomData,
ops::{Add, Mul, Shr},
slice::ChunksExact,
Expand Down Expand Up @@ -440,24 +442,18 @@ where

// Compute L and R by multi-scalar multiplication
li.push(P::vartime_multiscalar_mul(
std::iter::once::<&Scalar>(&c_l)
once::<&Scalar>(&c_l)
.chain(d_l.iter())
.chain(a_lo_offset.iter())
.chain(b_hi.iter()),
std::iter::once(h_base)
.chain(g_base.iter())
.chain(gi_base_hi)
.chain(hi_base_lo),
once(h_base).chain(g_base.iter()).chain(gi_base_hi).chain(hi_base_lo),
));
ri.push(P::vartime_multiscalar_mul(
std::iter::once::<&Scalar>(&c_r)
once::<&Scalar>(&c_r)
.chain(d_r.iter())
.chain(a_hi_offset.iter())
.chain(b_lo.iter()),
std::iter::once(h_base)
.chain(g_base.iter())
.chain(gi_base_lo)
.chain(hi_base_hi),
once(h_base).chain(g_base.iter()).chain(gi_base_lo).chain(hi_base_hi),
));

// Get the round challenge and associated values
Expand Down Expand Up @@ -1242,7 +1238,7 @@ where

#[cfg(test)]
mod tests {
use std::convert::TryFrom;
use core::convert::TryFrom;

use curve25519_dalek::ristretto::{CompressedRistretto, RistrettoPoint};
use quickcheck::QuickCheck;
Expand Down
2 changes: 2 additions & 0 deletions src/range_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//! Bulletproofs+ generators, vector of commitments, vector of optional minimum promised
//! values and a vector of optional seed nonces for mask recovery

use alloc::vec::Vec;

use curve25519_dalek::scalar::Scalar;
use zeroize::Zeroize;

Expand Down
2 changes: 1 addition & 1 deletion src/range_witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

//! Bulletproofs+ commitment openings for the aggregated case

use std::convert::TryInto;
use core::convert::TryInto;

use zeroize::{Zeroize, ZeroizeOnDrop};

Expand Down
2 changes: 2 additions & 0 deletions src/ristretto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
//!
//! Implementation of BulletProofs for the Ristretto group for Curve25519.

use alloc::vec::Vec;

use curve25519_dalek::{
constants::{RISTRETTO_BASEPOINT_COMPRESSED, RISTRETTO_BASEPOINT_POINT},
ristretto::{CompressedRistretto, RistrettoPoint, VartimeRistrettoPrecomputation},
Expand Down
2 changes: 1 addition & 1 deletion src/utils/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
//! Bulletproofs+ utilities

use core::{
convert::TryFrom,
option::{Option, Option::Some},
result::{
Result,
Result::{Err, Ok},
},
};
use std::convert::TryFrom;

use blake2::Blake2bMac512;
use curve25519_dalek::scalar::Scalar;
Expand Down