Skip to content

Commit

Permalink
Move bench-utils into std, and simplify workspace (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pratyush authored Mar 21, 2021
1 parent eea15d1 commit 4870030
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 89 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..
33 changes: 28 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,12 @@
<a href="https://deps.rs/repo/github/arkworks-rs/utils"><img src="https://deps.rs/repo/github/arkworks-rs/utils/status.svg"></a>
</p>

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:
Expand Down Expand Up @@ -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)
Expand Down
23 changes: 0 additions & 23 deletions bench-utils/Cargo.toml

This file was deleted.

1 change: 0 additions & 1 deletion bench-utils/LICENSE-APACHE

This file was deleted.

1 change: 0 additions & 1 deletion bench-utils/LICENSE-MIT

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions std/src/lib.rs → src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
///
/// ```
Expand Down
60 changes: 44 additions & 16 deletions bench-utils/src/lib.rs → src/perf_trace.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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,
};
Expand All @@ -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(),
}
Expand All @@ -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,
};
Expand Down Expand Up @@ -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} {:.<pad$}{}",
indent,
end_info,
Expand All @@ -102,7 +130,7 @@ pub mod inner {
#[macro_export]
macro_rules! add_to_trace {
($title:expr, $msg:expr) => {{
use $crate::{
use $crate::perf_trace::{
compute_indent, compute_indent_whitespace, format, AtomicUsize, Colorize, Instant,
Ordering, ToString, NUM_INDENT, PAD_CHAR,
};
Expand All @@ -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);
}};
}

Expand Down Expand Up @@ -156,7 +184,7 @@ mod inner {
#[macro_export]
macro_rules! start_timer {
($msg:expr) => {
$crate::TimerInfo
$crate::perf_trace::TimerInfo
};
}
#[macro_export]
Expand Down
File renamed without changes.
25 changes: 0 additions & 25 deletions std/Cargo.toml

This file was deleted.

0 comments on commit 4870030

Please sign in to comment.