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

Move circuit-dependent test utils behind the circuit feature. #453

Merged
merged 5 commits into from
Jan 29, 2025
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
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
- uses: actions/checkout@v4
- name: Run tests
Expand All @@ -28,6 +27,8 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
id: toolchain
- run: rustup override set ${{steps.toolchain.outputs.name}}
- if: matrix.os == 'ubuntu-latest'
run: sudo apt-get -y install libfontconfig1-dev
- name: Remove lockfile to build with latest dependencies
run: rm Cargo.lock
- name: Build crate
Expand Down Expand Up @@ -101,7 +102,6 @@ jobs:
container:
image: xd009642/tarpaulin:develop-nightly
options: --security-opt seccomp=unconfined

steps:
- uses: actions/checkout@v4
- name: Generate coverage report
Expand All @@ -116,6 +116,7 @@ jobs:
- uses: actions/checkout@v4
- run: cargo fetch
# Requires #![deny(rustdoc::broken_intra_doc_links)] in crates.
- run: sudo apt-get -y install libfontconfig1-dev
- name: Check intra-doc links
run: cargo doc --all-features --document-private-items

Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ and this project adheres to Rust's notion of
- `orchard::pczt::Zip32Derivation::extract_account_index`

### Changed
- MSRV is now 1.66
- MSRV is now 1.70
- Migrated to `nonempty 0.11`.

## [0.10.1] - 2024-12-16
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ authors = [
"Kris Nuttycombe <[email protected]>",
]
edition = "2021"
rust-version = "1.66"
rust-version = "1.70"
description = "The Orchard shielded transaction protocol"
license = "MIT OR Apache-2.0"
repository = "https://github.com/zcash/orchard"
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.66.0"
channel = "1.70.0"
components = [ "clippy", "rustfmt" ]
10 changes: 4 additions & 6 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ impl Builder {
.iter()
.map(|output| NoteValue::zero() - output.value),
)
.fold(Some(ValueSum::zero()), |acc, note_value| acc? + note_value)
.try_fold(ValueSum::zero(), |acc, note_value| acc + note_value)
.ok_or(OverflowError)?;
i64::try_from(value_balance).and_then(|i| V::try_from(i).map_err(|_| value::OverflowError))
}
Expand Down Expand Up @@ -813,7 +813,7 @@ fn build_bundle<B, R: RngCore>(
let mut bundle_meta = BundleMetadata::new(num_requested_spends, num_requested_outputs);
let pre_actions = indexed_spends
.into_iter()
.zip(indexed_outputs.into_iter())
.zip(indexed_outputs)
.enumerate()
.map(|(action_idx, ((spend_idx, spend), (out_idx, output)))| {
// Record the post-randomization spend location
Expand All @@ -836,9 +836,7 @@ fn build_bundle<B, R: RngCore>(
// Determine the value balance for this bundle, ensuring it is valid.
let value_balance = pre_actions
.iter()
.fold(Some(ValueSum::zero()), |acc, action| {
acc? + action.value_sum()
})
.try_fold(ValueSum::zero(), |acc, action| acc + action.value_sum())
.ok_or(OverflowError)?;

finisher(pre_actions, flags, value_balance, bundle_meta, rng)
Expand Down Expand Up @@ -1137,7 +1135,7 @@ impl OutputView for OutputInfo {
}

/// Generators for property testing.
#[cfg(any(test, feature = "test-dependencies"))]
#[cfg(all(feature = "circuit", any(test, feature = "test-dependencies")))]
#[cfg_attr(docsrs, doc(cfg(feature = "test-dependencies")))]
pub mod testing {
use alloc::vec::Vec;
Expand Down
5 changes: 2 additions & 3 deletions src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl<T: Authorization, V: fmt::Debug> fmt::Debug for Bundle<T, V> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
/// Helper struct for debug-printing actions without exposing `NonEmpty`.
struct Actions<'a, T>(&'a NonEmpty<Action<T>>);
impl<'a, T: fmt::Debug> fmt::Debug for Actions<'a, T> {
impl<T: fmt::Debug> fmt::Debug for Actions<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_list().entries(self.0.iter()).finish()
}
Expand Down Expand Up @@ -536,10 +536,9 @@ pub mod testing {
use proptest::prelude::*;

use crate::{
circuit::Proof,
primitives::redpallas::{self, testing::arb_binding_signing_key},
value::{testing::arb_note_value_bounded, NoteValue, ValueSum, MAX_NOTE_VALUE},
Anchor,
Anchor, Proof,
};

use super::{Action, Authorized, Bundle, Flags};
Expand Down
4 changes: 2 additions & 2 deletions src/bundle/commitments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ fn hasher(personal: &[u8; 16]) -> State {
Params::new().hash_length(32).personal(personal).to_state()
}

/// Write disjoint parts of each Orchard shielded action as 3 separate hashes:
/// Write disjoint parts of each Orchard shielded action as 3 separate hashes
/// as defined in [ZIP-244: Transaction Identifier Non-Malleability][zip244]:
/// * \[(nullifier, cmx, ephemeral_key, enc_ciphertext\[..52\])*\] personalized
/// with ZCASH_ORCHARD_ACTIONS_COMPACT_HASH_PERSONALIZATION
/// * \[enc_ciphertext\[52..564\]*\] (memo ciphertexts) personalized
/// with ZCASH_ORCHARD_ACTIONS_MEMOS_HASH_PERSONALIZATION
/// * \[(cv, rk, enc_ciphertext\[564..\], out_ciphertext)*\] personalized
/// with ZCASH_ORCHARD_ACTIONS_NONCOMPACT_HASH_PERSONALIZATION
/// as defined in [ZIP-244: Transaction Identifier Non-Malleability][zip244]
///
/// Then, hash these together along with (flags, value_balance_orchard, anchor_orchard),
/// personalized with ZCASH_ORCHARD_ACTIONS_HASH_PERSONALIZATION
Expand Down
2 changes: 2 additions & 0 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ pub mod fixed_bases;
pub mod sinsemilla;
pub mod util;

#[cfg(feature = "circuit")]
pub use self::sinsemilla::{OrchardCommitDomains, OrchardHashDomains};
#[cfg(feature = "circuit")]
pub use fixed_bases::{NullifierK, OrchardFixedBases, OrchardFixedBasesFull, ValueCommitV};

/// $\mathsf{MerkleDepth^{Orchard}}$
Expand Down
2 changes: 1 addition & 1 deletion src/constants/fixed_bases/commit_ivk_r.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub const Z: [u64; super::NUM_WINDOWS] = [

/// Full-width u-values for GENERATOR.
/// These can be reproduced by [`halo2_gadgets::ecc::chip::constants::find_zs_and_us`].
pub const U: [[[u8; 32]; super::H]; super::NUM_WINDOWS] = [
pub static U: [[[u8; 32]; super::H]; super::NUM_WINDOWS] = [
[
[
38, 43, 235, 53, 200, 116, 153, 194, 47, 92, 18, 54, 194, 221, 170, 155, 205, 143, 92,
Expand Down
2 changes: 1 addition & 1 deletion src/constants/fixed_bases/note_commit_r.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub const Z: [u64; super::NUM_WINDOWS] = [

/// Full-width u-values for GENERATOR.
/// These can be reproduced by [`halo2_gadgets::ecc::chip::constants::find_zs_and_us`].
pub const U: [[[u8; 32]; super::H]; super::NUM_WINDOWS] = [
pub static U: [[[u8; 32]; super::H]; super::NUM_WINDOWS] = [
[
[
114, 245, 9, 0, 5, 43, 7, 118, 244, 43, 15, 200, 116, 210, 0, 24, 161, 28, 185, 152,
Expand Down
2 changes: 1 addition & 1 deletion src/constants/fixed_bases/nullifier_k.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub const Z: [u64; super::NUM_WINDOWS] = [

/// Full-width u-values for GENERATOR
/// These can be reproduced by [`halo2_gadgets::ecc::chip::constants::find_zs_and_us`].
pub const U: [[[u8; 32]; super::H]; super::NUM_WINDOWS] = [
pub static U: [[[u8; 32]; super::H]; super::NUM_WINDOWS] = [
[
[
8, 177, 117, 90, 104, 127, 169, 131, 254, 128, 23, 151, 181, 247, 22, 208, 55, 1, 147,
Expand Down
2 changes: 1 addition & 1 deletion src/constants/fixed_bases/spend_auth_g.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub const Z: [u64; super::NUM_WINDOWS] = [

/// Full-width u-values for GENERATOR.
/// These can be reproduced by [`halo2_gadgets::ecc::chip::constants::find_zs_and_us`].
pub const U: [[[u8; 32]; super::H]; super::NUM_WINDOWS] = [
pub static U: [[[u8; 32]; super::H]; super::NUM_WINDOWS] = [
[
[
134, 139, 159, 167, 179, 203, 183, 86, 54, 69, 108, 127, 183, 40, 226, 188, 34, 72,
Expand Down
2 changes: 1 addition & 1 deletion src/constants/fixed_bases/value_commit_r.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub const Z: [u64; super::NUM_WINDOWS] = [

/// Full-width u-values for GENERATOR.
/// These can be reproduced by [`halo2_gadgets::ecc::chip::constants::find_zs_and_us`].
pub const U: [[[u8; 32]; super::H]; super::NUM_WINDOWS] = [
pub static U: [[[u8; 32]; super::H]; super::NUM_WINDOWS] = [
[
[
139, 239, 3, 113, 200, 111, 72, 118, 105, 23, 186, 243, 234, 10, 173, 186, 53, 143,
Expand Down
2 changes: 1 addition & 1 deletion src/note_encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl BatchDomain for OrchardDomain {
let (shared_secrets, ephemeral_keys): (Vec<_>, Vec<_>) = items.unzip();

SharedSecret::batch_to_affine(shared_secrets)
.zip(ephemeral_keys.into_iter())
.zip(ephemeral_keys)
.map(|(secret, ephemeral_key)| {
secret.map(|dhsecret| SharedSecret::kdf_orchard_inner(dhsecret, ephemeral_key))
})
Expand Down
4 changes: 2 additions & 2 deletions src/pczt/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl Bundle {
#[derive(Debug)]
pub struct Updater<'a>(&'a mut Bundle);

impl<'a> Updater<'a> {
impl Updater<'_> {
/// Provides read access to the bundle being updated.
pub fn bundle(&self) -> &Bundle {
self.0
Expand All @@ -42,7 +42,7 @@ impl<'a> Updater<'a> {
#[derive(Debug)]
pub struct ActionUpdater<'a>(&'a mut Action);

impl<'a> ActionUpdater<'a> {
impl ActionUpdater<'_> {
/// Sets the ZIP 32 derivation path for the spent note's signing key.
pub fn set_spend_zip32_derivation(&mut self, derivation: Zip32Derivation) {
self.0.spend.zip32_derivation = Some(derivation);
Expand Down
2 changes: 1 addition & 1 deletion src/primitives/redpallas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl<T: SigType> Eq for VerificationKey<T> {}

impl<T: SigType> PartialOrd for VerificationKey<T> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
<[u8; 32]>::from(self).partial_cmp(&<[u8; 32]>::from(other))
Some(self.cmp(other))
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,16 @@ impl Add for ValueSum {
}

impl<'a> Sum<&'a ValueSum> for Result<ValueSum, OverflowError> {
fn sum<I: Iterator<Item = &'a ValueSum>>(iter: I) -> Self {
iter.fold(Ok(ValueSum(0)), |acc, v| (acc? + *v).ok_or(OverflowError))
fn sum<I: Iterator<Item = &'a ValueSum>>(mut iter: I) -> Self {
iter.try_fold(ValueSum(0), |acc, v| acc + *v)
.ok_or(OverflowError)
}
}

impl Sum<ValueSum> for Result<ValueSum, OverflowError> {
fn sum<I: Iterator<Item = ValueSum>>(iter: I) -> Self {
iter.fold(Ok(ValueSum(0)), |acc, v| (acc? + v).ok_or(OverflowError))
fn sum<I: Iterator<Item = ValueSum>>(mut iter: I) -> Self {
iter.try_fold(ValueSum(0), |acc, v| acc + v)
.ok_or(OverflowError)
}
}

Expand Down