Skip to content

Commit

Permalink
Add no-std support via a default-enabled std feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
str4d committed Dec 16, 2024
1 parent f99b656 commit 159966b
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 13 deletions.
5 changes: 2 additions & 3 deletions Cargo.lock

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

10 changes: 7 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pasta_curves = "0.5"
proptest = { version = "1.0.0", optional = true }
rand = { version = "0.8", default-features = false }
reddsa = { version = "0.5", default-features = false }
nonempty = "0.7"
nonempty = { version = "0.10", default-features = false }
poseidon = { package = "halo2_poseidon", version = "0.1" }
serde = { version = "1.0", default-features = false, features = ["derive"] }
sinsemilla = "0.1"
Expand Down Expand Up @@ -81,8 +81,9 @@ pprof = { version = "0.11", features = ["criterion", "flamegraph"] }
bench = false

[features]
default = ["circuit", "multicore"]
circuit = ["dep:halo2_gadgets", "dep:halo2_proofs", "core2/std", "group/wnaf-memuse", "reddsa/std"]
default = ["circuit", "multicore", "std"]
std = ["core2/std", "group/wnaf-memuse", "reddsa/std"]
circuit = ["dep:halo2_gadgets", "dep:halo2_proofs", "std"]
unstable-frost = []
multicore = ["halo2_proofs?/multicore"]
dev-graph = ["halo2_proofs?/dev-graph", "image", "plotters"]
Expand All @@ -105,3 +106,6 @@ debug = true

[profile.bench]
debug = true

[patch.crates-io]
nonempty = { git = "https://github.com/nuttycom/nonempty.git", rev = "38d37189faecb2a0e3d6adc05aa24e1b93c2483b" }
3 changes: 3 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ impl fmt::Display for BuildError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for BuildError {}

#[cfg(feature = "circuit")]
Expand Down Expand Up @@ -200,6 +201,7 @@ impl fmt::Display for SpendError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for SpendError {}

/// The only error that can occur here is if outputs are disabled for this builder.
Expand All @@ -212,6 +214,7 @@ impl fmt::Display for OutputError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for OutputError {}

/// Information about a specific note to be spent in an [`Action`].
Expand Down
5 changes: 4 additions & 1 deletion src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ pub use batch::BatchValidator;
use core::fmt;

use blake2b_simd::Hash as Blake2bHash;
use memuse::DynamicUsage;
use nonempty::NonEmpty;
use zcash_note_encryption::{try_note_decryption, try_output_recovery_with_ovk};

#[cfg(feature = "std")]
use memuse::DynamicUsage;

use crate::{
action::Action,
address::Address,
Expand Down Expand Up @@ -474,6 +476,7 @@ impl<V> Bundle<Authorized, V> {
}
}

#[cfg(feature = "std")]
impl<V: DynamicUsage> DynamicUsage for Bundle<Authorized, V> {
fn dynamic_usage(&self) -> usize {
self.actions.tail.dynamic_usage()
Expand Down
2 changes: 1 addition & 1 deletion src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ impl IncomingViewingKey {
#[derive(Clone, Debug)]
pub struct PreparedIncomingViewingKey(PreparedNonZeroScalar);

#[cfg(feature = "circuit")]
#[cfg(feature = "std")]
impl memuse::DynamicUsage for PreparedIncomingViewingKey {
fn dynamic_usage(&self) -> usize {
self.0.dynamic_usage()
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#[macro_use]
extern crate alloc;

Check warning on line 21 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

doc list item without indentation

warning: doc list item without indentation --> src/bundle/commitments.rs:21:5 | 21 | /// with ZCASH_ORCHARD_ACTIONS_MEMOS_HASH_PERSONALIZATION | ^^ | = help: if this is supposed to be its own paragraph, add a blank line = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation help: indent this line | 21 | /// with ZCASH_ORCHARD_ACTIONS_MEMOS_HASH_PERSONALIZATION | +

#[cfg(feature = "std")]

Check warning on line 23 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

doc list item without indentation

warning: doc list item without indentation --> src/bundle/commitments.rs:23:5 | 23 | /// with ZCASH_ORCHARD_ACTIONS_NONCOMPACT_HASH_PERSONALIZATION | ^^ | = help: if this is supposed to be its own paragraph, add a blank line = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation help: indent this line | 23 | /// with ZCASH_ORCHARD_ACTIONS_NONCOMPACT_HASH_PERSONALIZATION | +
extern crate std;

Check warning on line 24 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

doc list item without indentation

warning: doc list item without indentation --> src/bundle/commitments.rs:24:5 | 24 | /// as defined in [ZIP-244: Transaction Identifier Non-Malleability][zip244] | ^ | = help: if this is supposed to be its own paragraph, add a blank line = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation help: indent this line | 24 | /// as defined in [ZIP-244: Transaction Identifier Non-Malleability][zip244] | +++

use alloc::vec::Vec;
Expand Down
6 changes: 3 additions & 3 deletions src/primitives/redpallas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::cmp::{Ord, Ordering, PartialOrd};
use pasta_curves::pallas;
use rand::{CryptoRng, RngCore};

#[cfg(feature = "circuit")]
#[cfg(feature = "std")]
pub use reddsa::batch;

#[cfg(test)]
Expand Down Expand Up @@ -127,7 +127,7 @@ impl VerificationKey<SpendAuth> {
}

/// Creates a batch validation item from a `SpendAuth` signature.
#[cfg(feature = "circuit")]
#[cfg(feature = "std")]
pub fn create_batch_item<M: AsRef<[u8]>>(
&self,
sig: Signature<SpendAuth>,
Expand All @@ -137,7 +137,7 @@ impl VerificationKey<SpendAuth> {
}
}

#[cfg(feature = "circuit")]
#[cfg(feature = "std")]
impl VerificationKey<Binding> {
/// Creates a batch validation item from a `Binding` signature.
pub fn create_batch_item<M: AsRef<[u8]>>(
Expand Down
4 changes: 2 additions & 2 deletions src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ff::{Field, FromUniformBytes, PrimeField, PrimeFieldBits};
use group::{Curve, Group, GroupEncoding, WnafBase, WnafScalar};
#[cfg(feature = "circuit")]
use halo2_gadgets::{poseidon::primitives as poseidon, sinsemilla::primitives as sinsemilla};
#[cfg(feature = "circuit")]
#[cfg(feature = "std")]
use memuse::DynamicUsage;
use pasta_curves::{
arithmetic::{CurveAffine, CurveExt},
Expand Down Expand Up @@ -157,7 +157,7 @@ impl PreparedNonIdentityBase {
#[derive(Clone, Debug)]
pub(crate) struct PreparedNonZeroScalar(WnafScalar<pallas::Scalar, PREPARED_WINDOW_SIZE>);

#[cfg(feature = "circuit")]
#[cfg(feature = "std")]
impl DynamicUsage for PreparedNonZeroScalar {
fn dynamic_usage(&self) -> usize {
self.0.dynamic_usage()
Expand Down
1 change: 1 addition & 0 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ impl fmt::Display for OverflowError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for OverflowError {}

/// The non-negative value of an individual Orchard note.
Expand Down

0 comments on commit 159966b

Please sign in to comment.