Skip to content
Open
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
27 changes: 11 additions & 16 deletions packages/wbraid/Cargo.lock

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

29 changes: 29 additions & 0 deletions packages/wbraid/PROVENANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,32 @@ repository-root `REUSE.toml`.
- **Added AGPL-3.0-only headers to `crates/braid/fuzz/`** (`Cargo.toml` and
`.gitignore`), which carried no licence markers. The fuzz crate is its own
cargo workspace and keeps no lockfile, matching the source branch.

## Local modifications for building on stable Rust

The source branch assumes a nightly toolchain; the following changes make the
workspace build with stable Rust (1.96.0), with upstream behaviour restored on
nightly by enabling the named features:

- **Gated `crates/vsc`'s nightly feature gates** (`stmt_expr_attributes`,
`proc_macro_hygiene`) behind `cfg_attr(feature = "custom-warnings", ...)`,
and wrapped every `#[crate::warning(...)]` in statement, expression, or
file-module position the same way — those positions reject proc-macro
attributes on stable even though `custom_warning_macro` expands to a no-op
pass-through when its `on` feature is off. Item-position uses are unchanged.
- **Gated the libtest bench** `crates/vsc/benches/shuffle.rs`
(`#![feature(test)]`, a hard error on stable) behind a new empty
`nightly-benches` feature via `required-features`, so `--all-targets` builds
skip it on stable.
- **Pinned `primefield` to `0.14.0-rc.9` in `Cargo.lock`**: cargo's pre-release
semver rules resolve `p256 0.14.0-rc.9`'s `primefield 0.14.0-rc.9`
requirement to the API-incompatible `0.14.0` final release, which does not
compile against p256 rc.9.
- The `[[patch.unused]]` entry for `auto_generate_cdp` in `Cargo.lock` is
written by cargo because `packages/.cargo/config.toml` (an ancestor config)
declares that patch for the main workspace; it is inert here.

`cargo clippy --workspace` passes on stable. `cargo clippy --workspace
--all-targets` fails inside `crates/vsc`'s test modules and the
`shuffle_scaling` example (mostly `unwrap_used` and pedantic lints in test
code, identical on nightly); that upstream state is left untouched.
4 changes: 4 additions & 0 deletions packages/wbraid/crates/vsc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@ custom-warnings = ["custom_warning_macro/on"]
serde = ["dep:serde"]
long_running_tests = []
wasm = []
# The benches use the nightly-only libtest harness (#![feature(test)]); this
# feature keeps them out of stable builds of --all-targets.
nightly-benches = []

[[bench]]
name = "shuffle"
harness = true
required-features = ["nightly-benches"]

[dev-dependencies]
serde = { version = "1.0.219", features=["derive"] }
Expand Down
6 changes: 3 additions & 3 deletions packages/wbraid/crates/vsc/benches/shuffle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
//! This benchmark measures the performance of the Terelius-Wikstrom [`shuffler`][`cryptography::zkp::shuffle::Shuffler`]
//! for proof computation and proof verification. The benchmark will print timings for these functions.
//!
//! This benchmark can be run with
//! This benchmark requires a nightly toolchain and can be run with
//!
//! `cargo bench shuffle`
//! `cargo bench --features nightly-benches shuffle`
//!
//! You can include the P-256 benchmark with
//!
//! `cargo bench shuffle -- --include-ignored`
//! `cargo bench --features nightly-benches shuffle -- --include-ignored`

#![feature(test)]

Expand Down
5 changes: 4 additions & 1 deletion packages/wbraid/crates/vsc/src/dkgd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,8 @@ pub mod recipient;

#[cfg(test)]
#[cfg_attr(coverage_nightly, coverage(off))]
#[crate::warning("Need more threshold parameter combinations")]
#[cfg_attr(
feature = "custom-warnings",
crate::warning("Need more threshold parameter combinations")
)]
mod tests;
9 changes: 6 additions & 3 deletions packages/wbraid/crates/vsc/src/dkgd/recipient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ impl<const P: usize> ParticipantPosition<P> {
/// Panics if the position is not in the range [1, P].
#[must_use]
pub fn new(position: u32) -> Self {
#[crate::warning("Possibly avoidable panics")]
#[cfg_attr(feature = "custom-warnings", crate::warning("Possibly avoidable panics"))]
assert!(position > 0);
assert!(position as usize <= P);

Expand All @@ -704,7 +704,7 @@ impl<const P: usize> ParticipantPosition<P> {
/// Panics if the position is not in the range [1, P].
#[must_use]
pub fn from_usize(position: usize) -> Self {
#[crate::warning("Possibly avoidable panics")]
#[cfg_attr(feature = "custom-warnings", crate::warning("Possibly avoidable panics"))]
assert!(position > 0);
assert!(position <= P);

Expand Down Expand Up @@ -745,7 +745,10 @@ pub fn combine<C: Context, const T: usize, const P: usize, const W: usize>(
let bases: Vec<[C::Element; W]> = ciphertexts.iter().map(|c| c.u().clone()).collect();
let mut divisors_acc: Vec<[C::Element; W]> = vec![<[C::Element; W]>::one(); ciphertexts.len()];

#[crate::warning("Ensure that the contributions are from distinct participants.")]
#[cfg_attr(
feature = "custom-warnings",
crate::warning("Ensure that the contributions are from distinct participants.")
)]
for contribution in contributions {
let factors = &contribution.partial.factors;
if factors.len() != ciphertexts.len() {
Expand Down
5 changes: 4 additions & 1 deletion packages/wbraid/crates/vsc/src/groups/p256/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ impl CryptographicGroup for P256Group {
let ds_tags: &[&[u8]] = &[b"context", b"independent_generators_p256_counter"];
let mut ret = vec![];

#[crate::warning("The following code is not optimized. Parallelize with rayon")]
#[cfg_attr(
feature = "custom-warnings",
crate::warning("The following code is not optimized. Parallelize with rayon")
)]
for i in 0..count {
// Cannot use platform dependent type in random oracle
let i_u64 = i as u64;
Expand Down
5 changes: 4 additions & 1 deletion packages/wbraid/crates/vsc/src/groups/ristretto255/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ impl CryptographicGroup for Ristretto255Group {
hasher.update(label);
hasher.update(b"independent_generators_ristretto");

#[crate::warning("The following code is not optimized. Parallelize with rayon")]
#[cfg_attr(
feature = "custom-warnings",
crate::warning("The following code is not optimized. Parallelize with rayon")
)]
let ret: Vec<RistrettoElement> = (0..count)
.into_par_iter()
.map(|i| {
Expand Down
9 changes: 6 additions & 3 deletions packages/wbraid/crates/vsc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@

#![allow(dead_code)]
// Only necessary for custom_warning_macro
#![feature(stmt_expr_attributes)]
#![cfg_attr(feature = "custom-warnings", feature(stmt_expr_attributes))]
// Only necessary for custom_warning_macro
#![feature(proc_macro_hygiene)]
#![cfg_attr(feature = "custom-warnings", feature(proc_macro_hygiene))]
#![doc = include_str!("../README.md")]
#![cfg_attr(coverage_nightly, feature(coverage_attribute))]

/// Defines implementation choices for key cryptographic functionalities.
pub mod context;
pub mod cryptosystem;
#[crate::warning("This module is not optimized.")]
#[cfg_attr(
feature = "custom-warnings",
crate::warning("This module is not optimized.")
)]
pub mod dkgd;
pub mod groups;
/// Abstractions for curve arithmetic, groups, elements and scalars.
Expand Down
14 changes: 12 additions & 2 deletions packages/wbraid/crates/vsc/src/utils/symm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ impl EncryptionData {
///
/// Returns `Error::EncryptionError` if key generation fails
pub fn gen_key() -> Result<SymmetricKey, Error> {
#[crate::warning("We should pass in our single rng entry point, instead of delegating to Key internal generator")]
#[cfg_attr(
feature = "custom-warnings",
crate::warning(
"We should pass in our single rng entry point, instead of delegating to Key internal generator"
)
)]
Ok(Key::<ChaCha20Poly1305>::generate())
}

Expand All @@ -73,7 +78,12 @@ pub fn gen_key() -> Result<SymmetricKey, Error> {
pub fn encrypt(key: SymmetricKey, data: &[u8]) -> Result<EncryptionData, Error> {
// https://docs.rs/chacha20poly1305/latest/chacha20poly1305/trait.AeadCore.html#method.generate_nonce
// 4,294,967,296 messages with random nonces can be encrypted under a given key
#[crate::warning("We should pass in our single rng entry point, instead of delegating to Nonce internal generator")]
#[cfg_attr(
feature = "custom-warnings",
crate::warning(
"We should pass in our single rng entry point, instead of delegating to Nonce internal generator"
)
)]
let nonce = Nonce::generate();
let cipher = ChaCha20Poly1305::new(&key);
let encrypted = cipher
Expand Down
20 changes: 16 additions & 4 deletions packages/wbraid/crates/vsc/src/zkp/shuffle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,10 @@ impl<C: Context, const W: usize> Shuffler<C, W> {
///
/// Returns a tuple of form (commitment exponents, re-encryption exponents)
pub(crate) fn gen_private_exponents(size: usize) -> (Vec<C::Scalar>, Vec<[C::Scalar; W]>) {
#[crate::warning("The following code is not optimized. Parallelize with rayon")]
#[cfg_attr(
feature = "custom-warnings",
crate::warning("The following code is not optimized. Parallelize with rayon")
)]
(0..size)
.into_par_iter()
.map(|_| {
Expand Down Expand Up @@ -455,7 +458,10 @@ impl<C: Context, const W: usize> Shuffler<C, W> {
// This means we start the computation at i = 1 (which is i = 2 in EVS)
// and our vector d_n has d_n[0] = b_n[0] (d1 = b1 in EVS)
let mut d_n = vec![b_n[0].clone()];
#[crate::warning("Figure out how this skip(1) behaves")]
#[cfg_attr(
feature = "custom-warnings",
crate::warning("Figure out how this skip(1) behaves")
)]
for (i, b) in b_n.iter().enumerate().skip(1) {
// cannot underflow, skip(1) starts at 1
#[allow(clippy::arithmetic_side_effects)]
Expand Down Expand Up @@ -729,7 +735,10 @@ impl<C: Context, const W: usize> Shuffler<C, W> {
let s_permuted = permutation.apply_inverse(&s_n)?;

let r_h_permuted = r_permuted.into_par_iter().zip(h_permuted.into_par_iter());
#[crate::warning("The following code is not optimized. Parallelize with rayon")]
#[cfg_attr(
feature = "custom-warnings",
crate::warning("The following code is not optimized. Parallelize with rayon")
)]
let u_n: Vec<C::Element> = r_h_permuted
.into_par_iter()
.map(|(r, h)| {
Expand All @@ -741,7 +750,10 @@ impl<C: Context, const W: usize> Shuffler<C, W> {

let s_w_permuted = w_permuted.into_par_iter().zip(s_permuted.into_par_iter());

#[crate::warning("The following code is not optimized. Parallelize with rayon")]
#[cfg_attr(
feature = "custom-warnings",
crate::warning("The following code is not optimized. Parallelize with rayon")
)]
let w_prime_n: Vec<Ciphertext<C, W>> = s_w_permuted
.into_par_iter()
.map(|(c, s)| c.re_encrypt(s, &self.pk.y))
Expand Down
Loading