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

Add feature gating for no-std #21

Merged
merged 5 commits into from
Feb 1, 2024
Merged
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
81 changes: 51 additions & 30 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
on: [push, pull_request]
on: [pull_request]

name: Rust CI

Expand All @@ -7,37 +7,55 @@ jobs:
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: Swatinem/rust-cache@v1
- uses: actions-rs/cargo@v1
with:
command: check
- uses: actions/checkout@v4
- name: Install rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Load rust cache
uses: astriaorg/[email protected]
- name: Run cargo check, failing on warnings
run: cargo check --profile ci --all-targets
# It'd be nice to fail on warnings, but we're not ready for that.
# env:
# RUSTFLAGS: "-D warnings"

test:
name: Test Suite
runs-on: buildjet-16vcpu-ubuntu-2204
steps:
- uses: actions/checkout@v4
- name: Install rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install nextest
uses: taiki-e/install-action@nextest
- name: Load rust cache
uses: astriaorg/[email protected]
- name: Run tests with nextest
run: cargo nextest run --cargo-profile ci
env:
CARGO_TERM_COLOR: always

build_no_alloc:
name: build without alloc
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup target add thumbv7em-none-eabihf
- uses: Swatinem/rust-cache@v1
- uses: actions-rs/cargo@v1
with:
command: test
command: build
args: --target thumbv7em-none-eabihf --no-default-features

fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand All @@ -50,19 +68,22 @@ jobs:
command: fmt
args: --all -- --check

# clippy:
# name: Clippy
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - uses: actions-rs/toolchain@v1
# with:
# profile: minimal
# toolchain: stable
# override: true
# - uses: Swatinem/rust-cache@v1
# - run: rustup component add clippy
# - uses: actions-rs/cargo@v1
# with:
# command: clippy
# args: -- -D warnings
no-std:
name: no_std compatibility check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: Swatinem/rust-cache@v1
- uses: actions-rs/cargo@v1
with:
command: check
args: --no-default-features
- uses: actions-rs/cargo@v1
with:
command: build
args: --no-default-features
34 changes: 22 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@ description = "decaf377-rdsa is a randomizable signature scheme using the decaf3
repository = "https://github.com/penumbra-zone/decaf377-rdsa"

[dependencies]
blake2b_simd = "0.5"
byteorder = "1.3"
decaf377 = { version = "0.5", default-features = false }
digest = "0.9"
rand_core = "0.6"
# No Alloc, No Std
blake2b_simd = { version = "0.5", default-features = false }
cfg-if = "1.0"
decaf377 = { git = "https://github.com/penumbra-zone/decaf377", tag = "v0.8.0", default-features = false }
digest = { version = "0.9", default-features = false }
rand_core = { version = "0.6", default-features = false }
hex = { version = "0.4", default-features = false }
# Only to satisfy Cargo
zeroize = { version = "1.7", default-features = false }
# Alloc, No Std
ark-ff = { version = "0.4", optional = true, default-features = false }
ark-serialize = { version = "0.4", optional = true }
# Std
serde = { version = "1", optional = true, features = ["derive"] }
thiserror = "1.0"
ark-serialize = "0.4"
ark-ff = { version = "0.4", default-features = false }
hex = "0.4"
thiserror = { version = "1.0", optional = true }

# Frost deps
# TODO: make optional ? use published versions?
[dev-dependencies]
bincode = "1"
criterion = "0.3"
Expand All @@ -37,5 +40,12 @@ harness = false

[features]
default = ["serde", "std"]
std = ["ark-ff/std"]
alloc = ["ark-ff", "ark-serialize"]
std = ["alloc", "ark-ff/std", "blake2b_simd/std", "decaf377/arkworks", "digest/std", "hex/std", "rand_core/std", "thiserror"]
parallel = ["ark-ff/parallel", "decaf377/parallel"]

# Create profile for running checks in CI that are mostly "release" mode,
# but also checking the `debug_assert `lines.
[profile.ci]
inherits = "release"
debug-assertions = true
1 change: 0 additions & 1 deletion src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

use std::convert::TryFrom;

use ark_ff::Zero;
use decaf377::{Element, FieldExt, Fr};
use rand_core::{CryptoRng, RngCore};

Expand Down
35 changes: 21 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![doc = include_str!("../README.md")]
use cfg_if::cfg_if;

pub mod batch;
cfg_if! {
if #[cfg(feature = "std")] {
pub mod batch;

mod domain;
mod error;
mod hash;
mod signature;
mod signing_key;
mod verification_key;
mod domain;
mod error;
mod hash;
mod signature;
mod signing_key;
mod verification_key;

use hash::HStar;
use hash::HStar;

pub use domain::{Binding, Domain, SpendAuth};
pub use error::Error;
pub use signature::Signature;
pub use signing_key::SigningKey;
pub use verification_key::{VerificationKey, VerificationKeyBytes};
pub use domain::{Binding, Domain, SpendAuth};
pub use error::Error;
pub use signature::Signature;
pub use signing_key::SigningKey;
pub use verification_key::{VerificationKey, VerificationKeyBytes};

pub use decaf377::Fr;
pub use decaf377::Fr;
} else {
}
}
Loading