From 4870030c5afd7be28ec396c23ff993e9482aa64a Mon Sep 17 00:00:00 2001 From: Pratyush Mishra Date: Sun, 21 Mar 2021 17:00:25 +0300 Subject: [PATCH] Move `bench-utils` into `std`, and simplify workspace (#29) --- .github/workflows/ci.yml | 9 ---- Cargo.toml | 33 ++++++++++-- README.md | 11 +--- bench-utils/Cargo.toml | 23 -------- bench-utils/LICENSE-APACHE | 1 - bench-utils/LICENSE-MIT | 1 - {std/src => src}/error.rs | 0 {std/src => src}/io/error.rs | 0 {std/src => src}/io/mod.rs | 0 {std/src => src}/lib.rs | 2 + bench-utils/src/lib.rs => src/perf_trace.rs | 60 +++++++++++++++------ {std/src => src}/rand_helper.rs | 0 std/Cargo.toml | 25 --------- 13 files changed, 76 insertions(+), 89 deletions(-) delete mode 100644 bench-utils/Cargo.toml delete mode 120000 bench-utils/LICENSE-APACHE delete mode 120000 bench-utils/LICENSE-MIT rename {std/src => src}/error.rs (100%) rename {std/src => src}/io/error.rs (100%) rename {std/src => src}/io/mod.rs (100%) rename {std/src => src}/lib.rs (99%) rename bench-utils/src/lib.rs => src/perf_trace.rs (75%) rename {std/src => src}/rand_helper.rs (100%) delete mode 100644 std/Cargo.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 35cc8f6..81d3385 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -116,14 +116,5 @@ jobs: - name: ark-std run: | - cd std cargo build -p ark-std --no-default-features --target thumbv6m-none-eabi cargo check --examples -p ark-std --no-default-features --target thumbv6m-none-eabi - cd .. - - - name: bench-utils - run: | - cd bench-utils - cargo build -p bench-utils --no-default-features --target thumbv6m-none-eabi - cargo check --examples -p bench-utils --no-default-features --target thumbv6m-none-eabi - cd .. diff --git a/Cargo.toml b/Cargo.toml index 9686af2..51c78dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,32 @@ -[workspace] +[package] +name = "ark-std" +version = "0.1.0" +authors = [ "arkworks contributors" ] +description = "A library for no_std compatibility" +homepage = "https://arkworks.rs" +repository = "https://github.com/arkworks-rs/utils" +documentation = "https://docs.rs/ark-std/" +keywords = [ "no_std" ] +categories = ["cryptography"] +include = ["Cargo.toml", "src", "README.md", "LICENSE-APACHE", "LICENSE-MIT"] +license = "MIT/Apache-2.0" +edition = "2018" -members = [ - "bench-utils", - "std", -] +[dependencies] +rand = { version = "0.7", default-features = false } +# rand = { version = "0.8", default-features = false, features = ["std_rng"] } +rand_xorshift = "0.2" +# rand_xorshift = "0.3" +rayon = { version = "1", optional = true } + +colored = { version = "2", optional = true } + + +[features] +default = [ "std" ] +std = [] +parallel = [ "rayon", "std" ] +print-trace = [ "std", "colored" ] [profile.release] opt-level = 3 diff --git a/README.md b/README.md index 693bc76..4a38fb7 100644 --- a/README.md +++ b/README.md @@ -7,19 +7,12 @@

-The arkworks ecosystem consist of Rust libraries for designing and working with __zero knowledge succinct non-interactive arguments (zkSNARKs)__. This repository contains efficient implementations some of the key algebraic components underlying zkSNARKs: finite fields, elliptic curves, and polynomials. +The arkworks ecosystem consists of Rust libraries for designing and working with __zero knowledge succinct non-interactive arguments (zkSNARKs)__. This repository contains `ark-std`, a library that serves as a compatibility layer for `no_std` use cases, and also contains useful methods and types used by the rest of the arkworks ecosystem. This library is released under the MIT License and the Apache v2 License (see [License](#license)). **WARNING:** This is an academic proof-of-concept prototype, and in particular has not received careful code review. This implementation is NOT ready for production use. -## Directory structure - -This repository contains several Rust crates: - -* [`ark-std`](std): Provides implementations for `no_std` compatibility -* [`bench-utils`](bench-utils): Provides helper functions for profiling performance in arkworks - ## Build guide The library compiles on the `stable` toolchain of the Rust compiler. To install the latest version of Rust, first install `rustup` by following the instructions [here](https://rustup.rs/), or via your platform's package manager. Once `rustup` is installed, install the Rust toolchain by invoking: @@ -49,7 +42,7 @@ cargo +nightly bench ## License -The crates in this repo are licensed under either of the following licenses, at your discretion. +The crates in this repository are licensed under either of the following licenses, at your discretion. * Apache License Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) diff --git a/bench-utils/Cargo.toml b/bench-utils/Cargo.toml deleted file mode 100644 index bd03445..0000000 --- a/bench-utils/Cargo.toml +++ /dev/null @@ -1,23 +0,0 @@ -[package] -name = "bench-utils" -version = "0.1.0" -authors = [ "arkworks contributors" ] -description = "A helper library for profiling performance in arkworks" -homepage = "https://arkworks.rs" -repository = "https://github.com/arkworks-rs/utils" -documentation = "https://docs.rs/bench-utils/" -keywords = ["profiling"] -categories = ["development-tools::profiling"] -include = ["Cargo.toml", "src", "README.md", "LICENSE-APACHE", "LICENSE-MIT"] -license = "MIT/Apache-2.0" -edition = "2018" - -################################# Dependencies ################################ - -[dependencies] -colored = { version = "2", optional = true } - -[features] -default = [] -std = [] # Not needed except for print-trace -print-trace = [ "std", "colored" ] diff --git a/bench-utils/LICENSE-APACHE b/bench-utils/LICENSE-APACHE deleted file mode 120000 index 965b606..0000000 --- a/bench-utils/LICENSE-APACHE +++ /dev/null @@ -1 +0,0 @@ -../LICENSE-APACHE \ No newline at end of file diff --git a/bench-utils/LICENSE-MIT b/bench-utils/LICENSE-MIT deleted file mode 120000 index 76219eb..0000000 --- a/bench-utils/LICENSE-MIT +++ /dev/null @@ -1 +0,0 @@ -../LICENSE-MIT \ No newline at end of file diff --git a/std/src/error.rs b/src/error.rs similarity index 100% rename from std/src/error.rs rename to src/error.rs diff --git a/std/src/io/error.rs b/src/io/error.rs similarity index 100% rename from std/src/io/error.rs rename to src/io/error.rs diff --git a/std/src/io/mod.rs b/src/io/mod.rs similarity index 100% rename from std/src/io/mod.rs rename to src/io/mod.rs diff --git a/std/src/lib.rs b/src/lib.rs similarity index 99% rename from std/src/lib.rs rename to src/lib.rs index 4a5ee65..dd98ef2 100644 --- a/std/src/lib.rs +++ b/src/lib.rs @@ -47,6 +47,8 @@ pub use std::*; mod rand_helper; pub use rand_helper::*; +pub mod perf_trace; + /// Returns the ceiling of the base-2 logarithm of `x`. /// /// ``` diff --git a/bench-utils/src/lib.rs b/src/perf_trace.rs similarity index 75% rename from bench-utils/src/lib.rs rename to src/perf_trace.rs index 2448786..23d9d24 100644 --- a/bench-utils/src/lib.rs +++ b/src/perf_trace.rs @@ -1,12 +1,40 @@ -#![no_std] #![allow(unused_imports)] - +//! This module contains macros for logging to stdout a trace of wall-clock time required +//! to execute annotated code. One can use this code as follows: +//! ``` +//! use ark_std::{start_timer, end_timer}; +//! let start = start_timer!(|| "Addition of two integers"); +//! let c = 5 + 7; +//! end_timer!(start); +//! ``` +//! The foregoing code should log the following to stdout. +//! ```text +//! Start: Addition of two integers +//! End: Addition of two integers... 1ns +//! ``` +//! +//! These macros can be arbitrarily nested, and the nested nature is made apparent +//! in the output. For example, the following snippet: +//! ``` +//! use ark_std::{start_timer, end_timer}; +//! let start = start_timer!(|| "Addition of two integers"); +//! let start2 = start_timer!(|| "Inner"); +//! let c = 5 + 7; +//! end_timer!(start2); +//! end_timer!(start); +//! ``` +//! should print out the following: +//! ```text +//! Start: Addition of two integers +//! Start: Inner +//! End: Inner ... 1ns +//! End: Addition of two integers... 1ns +//! ``` +//! +//! Additionally, one can use the `add_to_trace` macro to log additional context +//! in the output. pub use self::inner::*; -// This isn't needed except for use in the print-trace code below -#[cfg(feature = "std")] -extern crate std; - #[macro_use] #[cfg(feature = "print-trace")] pub mod inner { @@ -31,7 +59,7 @@ pub mod inner { #[macro_export] macro_rules! start_timer { ($msg:expr) => {{ - use $crate::inner::{ + use $crate::perf_trace::inner::{ compute_indent, AtomicUsize, Colorize, Instant, Ordering, ToString, NUM_INDENT, PAD_CHAR, }; @@ -41,9 +69,9 @@ pub mod inner { let indent_amount = 2 * NUM_INDENT.fetch_add(0, Ordering::Relaxed); let indent = compute_indent(indent_amount); - $crate::println!("{}{:8} {}", indent, start_info, msg); + $crate::perf_trace::println!("{}{:8} {}", indent, start_info, msg); NUM_INDENT.fetch_add(1, Ordering::Relaxed); - $crate::TimerInfo { + $crate::perf_trace::TimerInfo { msg: msg.to_string(), time: Instant::now(), } @@ -56,7 +84,7 @@ pub mod inner { end_timer!($time, || ""); }}; ($time:expr, $msg:expr) => {{ - use $crate::inner::{ + use $crate::perf_trace::inner::{ compute_indent, format, AtomicUsize, Colorize, Instant, Ordering, ToString, NUM_INDENT, PAD_CHAR, }; @@ -88,7 +116,7 @@ pub mod inner { // Todo: Recursively ensure that *entire* string is of appropriate // width (not just message). - $crate::println!( + $crate::perf_trace::println!( "{}{:8} {:. {{ - use $crate::{ + use $crate::perf_trace::{ compute_indent, compute_indent_whitespace, format, AtomicUsize, Colorize, Instant, Ordering, ToString, NUM_INDENT, PAD_CHAR, }; @@ -125,9 +153,9 @@ pub mod inner { // Todo: Recursively ensure that *entire* string is of appropriate // width (not just message). - $crate::println!("{}{}", start_indent, start_msg); - $crate::println!("{}{}", msg_indent, final_message,); - $crate::println!("{}{}", start_indent, end_msg); + $crate::perf_trace::println!("{}{}", start_indent, start_msg); + $crate::perf_trace::println!("{}{}", msg_indent, final_message,); + $crate::perf_trace::println!("{}{}", start_indent, end_msg); }}; } @@ -156,7 +184,7 @@ mod inner { #[macro_export] macro_rules! start_timer { ($msg:expr) => { - $crate::TimerInfo + $crate::perf_trace::TimerInfo }; } #[macro_export] diff --git a/std/src/rand_helper.rs b/src/rand_helper.rs similarity index 100% rename from std/src/rand_helper.rs rename to src/rand_helper.rs diff --git a/std/Cargo.toml b/std/Cargo.toml deleted file mode 100644 index 3f0cef9..0000000 --- a/std/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -name = "ark-std" -version = "0.1.0" -authors = [ "arkworks contributors" ] -description = "A library for no_std compatibility" -homepage = "https://arkworks.rs" -repository = "https://github.com/arkworks-rs/utils" -documentation = "https://docs.rs/ark-std/" -keywords = [ "no_std" ] -categories = ["cryptography"] -include = ["Cargo.toml", "src", "README.md", "LICENSE-APACHE", "LICENSE-MIT"] -license = "MIT/Apache-2.0" -edition = "2018" - -[dependencies] -rand = { version = "0.7", default-features = false } -# rand = { version = "0.8", default-features = false, features = ["std_rng"] } -rand_xorshift = "0.2" -# rand_xorshift = "0.3" -rayon = { version = "1", optional = true } - -[features] -default = [ "std" ] -std = [] -parallel = [ "rayon", "std" ]