Skip to content

Commit

Permalink
no_std for algebra and r1cs-core (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
debris authored Jan 31, 2020
1 parent e612178 commit 8a9343a
Show file tree
Hide file tree
Showing 97 changed files with 725 additions and 387 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ Cargo.lock
*.pyc
*.sage.py
params
*.swp
*.swo
41 changes: 33 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
language: rust
services: docker
sudo: required

before_install:
- set -e
- export SCCACHE_CACHE_SIZE=200M
- export SCCACHE_DIR="$TRAVIS_HOME/.cache/sccache"

install:
- (rustup component add rustfmt --toolchain nightly || true)
- (cargo install sccache || true)
- export PATH="$PATH:$TRAVIS_HOME/.cargo/bin"
- export RUSTC_WRAPPER="sccache"
Expand All @@ -21,15 +23,38 @@ before_cache:

after_script:
- sccache -s

rust:
- stable
- nightly
- set +e

matrix:
fast_finish: true
include:
- rust: stable
script:
- cargo test --all -- --skip dpc --skip integration_test
- cargo check --examples --all

- rust: nightly
install:
- rustup component add rustfmt
script:
- cargo fmt -- --check
- cargo test --all -- --skip dpc --skip integration_test
- cargo check --examples --all

- rust: stable
install:
- rustup target add thumbv6m-none-eabi
script:
# test algebra
- cd algebra
- cargo build -p algebra --no-default-features --target thumbv6m-none-eabi
- cargo check --examples -p algebra --no-default-features --target thumbv6m-none-eabi
- cd ..
# test r1cs-core
- cd r1cs-core
- cargo build -p r1cs-core --no-default-features --target thumbv6m-none-eabi
- cargo check --examples -p r1cs-core --no-default-features --target thumbv6m-none-eabi
- cd ..

script:
- if [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then cargo fmt -- --check; fi
- cargo test --all -- --skip "dpc" --skip "integration_test"
- cargo check --examples --all
- echo "script!"
13 changes: 12 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
[workspace]

members = [ "algebra", "ff-fft", "r1cs-core", "r1cs-std", "groth16", "gm17", "crypto-primitives", "dpc", "bench-utils" ]
members = [
"algebra",
"algebra-benches",
"bench-utils",
"crypto-primitives",
"dpc",
"ff-fft",
"gm17",
"groth16",
"r1cs-core",
"r1cs-std",
]

[profile.release]
opt-level = 3
Expand Down
30 changes: 30 additions & 0 deletions algebra-benches/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "algebra-benches"
version = "0.1.0"
authors = [
"Sean Bowe",
"Alessandro Chiesa",
"Matthew Green",
"Ian Miers",
"Pratyush Mishra",
"Howard Wu"
]
description = "A benchmark library for finite fields and elliptic curves"
homepage = "https://libzexe.org"
repository = "https://github.com/scipr/zexe"
documentation = "https://docs.rs/algebra/"
keywords = ["cryptography", "finite fields", "elliptic curves", "pairing"]
categories = ["cryptography"]
include = ["Cargo.toml", "src", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
license = "MIT/Apache-2.0"
edition = "2018"
publish = false

################################# Dependencies ################################

[dev-dependencies]
algebra = { path = "../algebra" }
blake2 = "0.8.1"
criterion = "0.3.1"
rand = "0.7"
rand_xorshift = { version = "0.2" }
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
mod g1 {
use algebra::UniformRand;
use rand::SeedableRng;
use rand_xorshift::XorShiftRng;
use std::ops::AddAssign;

use algebra::{
curves::bls12_377::{G1Affine, G1Projective as G1},
fields::bls12_377::Fr,
ProjectiveCurve,
ProjectiveCurve, UniformRand,
};
use core::ops::AddAssign;
use rand::SeedableRng;
use rand_xorshift::XorShiftRng;

#[bench]
fn bench_g1_rand(b: &mut ::test::Bencher) {
Expand Down Expand Up @@ -99,9 +97,9 @@ mod g2 {
fields::bls12_377::Fr,
ProjectiveCurve, UniformRand,
};
use core::ops::AddAssign;
use rand::SeedableRng;
use rand_xorshift::XorShiftRng;
use std::ops::AddAssign;

#[bench]
fn bench_g2_rand(b: &mut ::test::Bencher) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions algebra-benches/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

13 changes: 6 additions & 7 deletions algebra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@ edition = "2018"
################################# Dependencies ################################

[dependencies]
byteorder = { version = "1" }
rand = { version = "0.7" }
derivative = { version = "1" }
derivative = { version = "1", features = ["use_core"] }
num-traits = { version = "0.2", default-features = false }
rand = { version = "0.7", default-features = false }
rayon = { version = "1", optional = true }

[dev-dependencies]
blake2 = "0.8.1"
criterion = "0.3.1"
rand_xorshift = { version = "0.2" }
rand_xorshift = "0.2"

[features]
parallel = [ "rayon" ]
default = ["std"]
std = []
parallel = ["std", "rayon"]
16 changes: 8 additions & 8 deletions algebra/src/biginteger/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ macro_rules! bigint_impl {
while n >= 64 {
let mut t = 0;
for i in &mut self.0 {
::std::mem::swap(&mut t, i);
core::mem::swap(&mut t, i);
}
n -= 64;
}
Expand Down Expand Up @@ -90,7 +90,7 @@ macro_rules! bigint_impl {
while n >= 64 {
let mut t = 0;
for i in self.0.iter_mut().rev() {
::std::mem::swap(&mut t, i);
core::mem::swap(&mut t, i);
}
n -= 64;
}
Expand Down Expand Up @@ -213,7 +213,7 @@ macro_rules! bigint_impl {
}

impl Display for $name {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
for i in self.0.iter().rev() {
write!(f, "{:016X}", *i)?;
}
Expand All @@ -223,22 +223,22 @@ macro_rules! bigint_impl {

impl Ord for $name {
#[inline]
fn cmp(&self, other: &Self) -> ::std::cmp::Ordering {
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
for (a, b) in self.0.iter().rev().zip(other.0.iter().rev()) {
if a < b {
return ::std::cmp::Ordering::Less;
return ::core::cmp::Ordering::Less;
} else if a > b {
return ::std::cmp::Ordering::Greater;
return ::core::cmp::Ordering::Greater;
}
}

::std::cmp::Ordering::Equal
::core::cmp::Ordering::Equal
}
}

impl PartialOrd for $name {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<::std::cmp::Ordering> {
fn partial_cmp(&self, other: &Self) -> Option<::core::cmp::Ordering> {
Some(self.cmp(other))
}
}
Expand Down
8 changes: 3 additions & 5 deletions algebra/src/biginteger/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use crate::{
bytes::{FromBytes, ToBytes},
fields::BitIterator,
UniformRand,
io::{Read, Result as IoResult, Write},
UniformRand, Vec,
};
use core::fmt::{Debug, Display};
use rand::{
distributions::{Distribution, Standard},
Rng,
};
use std::{
fmt::{Debug, Display},
io::{Read, Result as IoResult, Write},
};

#[macro_use]
mod macros;
Expand Down
Loading

0 comments on commit 8a9343a

Please sign in to comment.