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

Implement no_std support via a default-enabled std feature flag. #151

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 26 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,36 @@ jobs:
matrix:
target:
- wasm32-wasi
- thumbv7em-none-eabihf
steps:
- uses: actions/checkout@v4
with:
path: crate_root
# We use a synthetic crate to ensure no dev-dependencies are enabled, which can
# be incompatible with some of these targets.
- name: Create synthetic crate for testing
run: cargo init --lib ci-build
- name: Copy Rust version into synthetic crate
run: cp crate_root/rust-toolchain.toml ci-build/
- name: Copy patch directives into synthetic crate
run: |
echo "[patch.crates-io]" >> ./ci-build/Cargo.toml
cat ./crate_root/Cargo.toml | sed "0,/.\+\(patch.crates.\+\)/d" >> ./ci-build/Cargo.toml
- name: Add no_std pragma to lib.rs
run: |
echo "#![no_std]" > ./ci-build/src/lib.rs
- name: Add sapling-crypto as a dependency of the synthetic crate
working-directory: ./ci-build
run: cargo add --no-default-features --path ../crate_root
- name: Add lazy_static with the spin_no_std feature
working-directory: ./ci-build
run: cargo add lazy_static --features "spin_no_std"
- name: Add target
working-directory: ./ci-build
run: rustup target add ${{ matrix.target }}
- name: Build crate
run: cargo build --no-default-features --verbose --target ${{ matrix.target }}
- name: Build for target
working-directory: ./ci-build
run: cargo build --verbose --target ${{ matrix.target }}

bitrot:
name: Bitrot check
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ and this library adheres to Rust's notion of

### Added
- `sapling_crypto::pczt::Zip32Derivation::extract_account_index`
- `no_std` compatibility has been introduced by means of a default-enabled
`std` feature flag.
- A default-enabled `circuit` is now provided to enable downstream users to
avoid the need to depend upon the `bellman` crate.

### Changed
- MSRV is now 1.66

## [0.4.0] - 2024-12-16

Expand Down
38 changes: 15 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 45 additions & 23 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = [
"Kris Nuttycombe <[email protected]>",
]
edition = "2021"
rust-version = "1.65"
rust-version = "1.66"
description = "Cryptographic library for Zcash Sapling"
homepage = "https://github.com/zcash/sapling-crypto"
repository = "https://github.com/zcash/sapling-crypto"
Expand All @@ -18,48 +18,50 @@ features = ["test-dependencies"]
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
ff = "0.13"
group = { version = "0.13", features = ["wnaf-memuse"] }
ff = { version = "0.13", default-features = false }
group = "0.13"

bls12_381 = "0.8"
jubjub = "0.10"
redjubjub = "0.7"
bls12_381 = { version = "0.8", default-features = false, features = ["alloc"] }
jubjub = { version = "0.10", default-features = false, features = ["alloc"] }
redjubjub = { version = "0.7", default-features = false }
zcash_spec = "0.1"

# Boilerplate
getset = "0.1"

# No-std support
core2 = { version = "0.3", default-features = false, features = ["alloc"] }

# Circuits
bellman = { version = "0.14", default-features = false, features = ["groth16"] }
bellman = { version = "0.14", features = ["groth16"], optional = true }
nuttycom marked this conversation as resolved.
Show resolved Hide resolved

# CSPRNG
rand = "0.8"
rand_core = "0.6"
rand = { version = "0.8", default-features = false }
rand_core = { version = "0.6", default-features = false }

# Digests
blake2b_simd = "1"
blake2s_simd = "1"
blake2b_simd = { version = "1", default-features = false }
blake2s_simd = { version = "1", default-features = false }

# Documentation
document-features = "0.2"
document-features = { version = "0.2", optional = true }

# Encodings
byteorder = "1"
hex = "0.4"
hex = { version = "0.4", default-features = false, features = ["alloc"] }

# Logging and metrics
memuse = "0.2.1"
tracing = "0.1"
memuse = { version = "0.2.2", default-features = false }
tracing = { version = "0.1", default-features = false }

# Note Commitment Trees
bitvec = "1"
incrementalmerkletree = { version = "0.7", features = ["legacy-api"] }
bitvec = { version = "1", default-features = false }
incrementalmerkletree = { version = "0.7", default-features = false, features = ["legacy-api"] }

# Note encryption
zcash_note_encryption = { version = "0.4", features = ["pre-zip-212"] }

# Secret management
subtle = "2.2.3"
subtle = { version = "2.2.3", default-features = false }

# Static constants
lazy_static = "1"
Expand All @@ -69,8 +71,9 @@ proptest = { version = "1", optional = true }

# ZIP 32
aes = "0.8"
fpe = "0.6"
zip32 = "0.1"
fpe = { version = "0.6", default-features = false, features = ["alloc"] }
zip32 = { version = "0.1.1", default-features = false }


[dev-dependencies]
chacha20poly1305 = "0.10"
Expand All @@ -83,10 +86,26 @@ rand_xorshift = "0.3"
pprof = { version = "0.11", features = ["criterion", "flamegraph"] } # MSRV 1.56

[features]
default = ["multicore"]
default = ["multicore", "std"]
std = [
"core2/std",
"document-features",
nuttycom marked this conversation as resolved.
Show resolved Hide resolved
"group/wnaf-memuse",
"redjubjub/std",
"circuit",
nuttycom marked this conversation as resolved.
Show resolved Hide resolved
]

## Enables creation of Sapling proofs
circuit = [
"bellman",
nuttycom marked this conversation as resolved.
Show resolved Hide resolved
"bls12_381/bits",
"bls12_381/groups",
"bls12_381/pairings",
"jubjub/bits",
]

## Enables multithreading support for creating proofs.
multicore = ["bellman/multicore"]
multicore = ["circuit", "bellman/multicore"]
nuttycom marked this conversation as resolved.
Show resolved Hide resolved

### A temporary feature flag that exposes granular APIs needed by `zcashd`. These APIs
### should not be relied upon and will be removed in a future release.
Expand All @@ -105,3 +124,6 @@ harness = false
[[bench]]
name = "pedersen_hash"
harness = false

[patch.crates-io]
redjubjub = { git = "https://github.com/nuttycom/redjubjub", rev = "e413019904400f4caa3550df7c4040befadfbb14" }
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# sapling-crypto

This repository contains a (work-in-progress) implementation of Zcash's "Sapling" cryptography.
This repository contains an implementation of Zcash's "Sapling" cryptography.

## `no_std` compatibility

Downstream users of this crate must enable the `spin_no_std` feature of the
`lazy_static` crate in order to take advantage of `no_std` builds; this is due
to the fact that `--no-default-features` builds of `lazy_static` still rely on
`std`.

## License

Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.65.0"
channel = "1.66.0"
components = ["clippy", "rustfmt"]
Loading
Loading