Skip to content

Use expect for lint exceptions #113

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

Merged
merged 1 commit into from
Jul 3, 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
14 changes: 3 additions & 11 deletions benches/parallel.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2024, The Tari Project
// SPDX-License-Identifier: BSD-3-Clause

#![allow(missing_docs)]
#![expect(missing_docs)]

#[macro_use]
extern crate criterion;
Expand All @@ -27,8 +27,8 @@ const M_VALUES: [u32; 4] = [2, 4, 8, 10];
const BATCH_SIZES: [usize; 1] = [2];

// Generate a batch of witnesses, statements, and transcripts
#[allow(non_snake_case)]
#[allow(clippy::arithmetic_side_effects)]
#[expect(non_snake_case)]
#[expect(clippy::arithmetic_side_effects)]
fn generate_data<R: CryptoRngCore>(
params: &TriptychParameters,
b: usize,
Expand Down Expand Up @@ -82,8 +82,6 @@ fn generate_data<R: CryptoRngCore>(
(witnesses, statements, transcripts)
}

#[allow(non_snake_case)]
#[allow(non_upper_case_globals)]
fn generate_proof(c: &mut Criterion) {
let mut group = c.benchmark_group("generate_proof");
let mut rng = ChaCha12Rng::seed_from_u64(8675309);
Expand Down Expand Up @@ -113,8 +111,6 @@ fn generate_proof(c: &mut Criterion) {
group.finish();
}

#[allow(non_snake_case)]
#[allow(non_upper_case_globals)]
fn generate_proof_vartime(c: &mut Criterion) {
let mut group = c.benchmark_group("generate_proof_vartime");
let mut rng = ChaCha12Rng::seed_from_u64(8675309);
Expand Down Expand Up @@ -149,8 +145,6 @@ fn generate_proof_vartime(c: &mut Criterion) {
group.finish();
}

#[allow(non_snake_case)]
#[allow(non_upper_case_globals)]
fn verify_proof(c: &mut Criterion) {
let mut group = c.benchmark_group("verify_proof");
let mut rng = ChaCha12Rng::seed_from_u64(8675309);
Expand Down Expand Up @@ -185,8 +179,6 @@ fn verify_proof(c: &mut Criterion) {
group.finish();
}

#[allow(non_snake_case)]
#[allow(non_upper_case_globals)]
fn verify_batch_proof(c: &mut Criterion) {
let mut group = c.benchmark_group("verify_batch_proof");
let mut rng = ChaCha12Rng::seed_from_u64(8675309);
Expand Down
14 changes: 3 additions & 11 deletions benches/triptych.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2024, The Tari Project
// SPDX-License-Identifier: BSD-3-Clause

#![allow(missing_docs)]
#![expect(missing_docs)]

#[macro_use]
extern crate criterion;
Expand All @@ -25,8 +25,8 @@ const M_VALUES: [u32; 4] = [2, 4, 8, 10];
const BATCH_SIZES: [usize; 1] = [2];

// Generate a batch of witnesses, statements, and transcripts
#[allow(non_snake_case)]
#[allow(clippy::arithmetic_side_effects)]
#[expect(non_snake_case)]
#[expect(clippy::arithmetic_side_effects)]
fn generate_data<R: CryptoRngCore>(
params: &TriptychParameters,
b: usize,
Expand Down Expand Up @@ -72,8 +72,6 @@ fn generate_data<R: CryptoRngCore>(
(witnesses, statements, transcripts)
}

#[allow(non_snake_case)]
#[allow(non_upper_case_globals)]
fn generate_proof(c: &mut Criterion) {
let mut group = c.benchmark_group("generate_proof");
let mut rng = ChaCha12Rng::seed_from_u64(8675309);
Expand Down Expand Up @@ -103,8 +101,6 @@ fn generate_proof(c: &mut Criterion) {
group.finish();
}

#[allow(non_snake_case)]
#[allow(non_upper_case_globals)]
fn generate_proof_vartime(c: &mut Criterion) {
let mut group = c.benchmark_group("generate_proof_vartime");
let mut rng = ChaCha12Rng::seed_from_u64(8675309);
Expand Down Expand Up @@ -139,8 +135,6 @@ fn generate_proof_vartime(c: &mut Criterion) {
group.finish();
}

#[allow(non_snake_case)]
#[allow(non_upper_case_globals)]
fn verify_proof(c: &mut Criterion) {
let mut group = c.benchmark_group("verify_proof");
let mut rng = ChaCha12Rng::seed_from_u64(8675309);
Expand Down Expand Up @@ -175,8 +169,6 @@ fn verify_proof(c: &mut Criterion) {
group.finish();
}

#[allow(non_snake_case)]
#[allow(non_upper_case_globals)]
fn verify_batch_proof(c: &mut Criterion) {
let mut group = c.benchmark_group("verify_batch_proof");
let mut rng = ChaCha12Rng::seed_from_u64(8675309);
Expand Down
2 changes: 1 addition & 1 deletion examples/ringct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod test {
use rand_core::OsRng;
use triptych::parallel::*;

#[allow(non_snake_case)]
#[expect(non_snake_case)]
#[test]
fn ringct() {
// It's important to use a cryptographically-secure random number generator!
Expand Down
6 changes: 4 additions & 2 deletions lints.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
deny = [
# Prevent spelling mistakes in lints
'unknown_lints',

# Ensure all expectations are met
'unfulfilled_lint_expectations',

# Use the default groups:
# correctness, suspicious, style, complexity, perf
Expand All @@ -24,7 +27,6 @@ deny = [
'clippy::else_if_without_else',
'clippy::enum_glob_use',
'clippy::inline_always',
'clippy::match_on_vec_items',
'clippy::match_wild_err_arm',

# Style preferences
Expand Down Expand Up @@ -52,4 +54,4 @@ deny = [
warn = [
'clippy::uninlined_format_args',
'clippy::too_many_arguments',
]
]
13 changes: 6 additions & 7 deletions src/gray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use core::num::NonZeroU32;
use crypto_bigint::{NonZero, U64};

/// An iterator for arbitrary-base Gray codes.
#[allow(non_snake_case)]
#[expect(non_snake_case)]
pub(crate) struct GrayIterator {
N: u32, // base
M: u32, // number of digits
Expand All @@ -24,7 +24,7 @@ impl GrayIterator {
///
/// Operations using this iterator run in variable time, so don't use this for secret data.
/// If you need to get the Gray code decomposition for a secret value, use `decompose` directly.
#[allow(non_snake_case)]
#[expect(non_snake_case)]
pub(crate) fn new(N: u32, M: u32) -> Option<Self> {
// Check inputs
if N <= 1 || M == 0 {
Expand All @@ -45,7 +45,7 @@ impl GrayIterator {
/// You must provide a valid value `v` based on the supplied parameters `N` and `M`.
/// If anything goes wrong, returns `None`.
/// Otherwise, returns the Gray code as a `u32` digit vector.
#[allow(non_snake_case)]
#[expect(non_snake_case)]
pub(crate) fn decompose_vartime(N: u32, M: u32, mut v: u32) -> Option<Vec<u32>> {
if N <= 1 || M == 0 {
return None;
Expand Down Expand Up @@ -76,7 +76,7 @@ impl GrayIterator {
/// You must provide a valid value `v` based on the supplied parameters `N` and `M`.
/// If anything goes wrong, returns `None`.
/// Otherwise, returns the Gray code as a `u32` digit vector.
#[allow(non_snake_case)]
#[expect(non_snake_case)]
pub(crate) fn decompose(N: u32, M: u32, v: u32) -> Option<Vec<u32>> {
if N <= 1 || M == 0 {
return None;
Expand Down Expand Up @@ -126,7 +126,6 @@ impl Iterator for GrayIterator {
///
/// Keep in mind that this does not return the actual Gray code!
/// You must keep track of that yourself.
#[allow(non_snake_case)]
fn next(&mut self) -> Option<Self::Item> {
if self.i == 0 {
self.i = 1;
Expand Down Expand Up @@ -163,7 +162,7 @@ mod test {
use super::*;

#[test]
#[allow(non_snake_case)]
#[expect(non_snake_case)]
fn test_gray_iterator() {
// Set up parameters
let N = 3u32;
Expand Down Expand Up @@ -195,7 +194,7 @@ mod test {
}

#[test]
#[allow(non_snake_case)]
#[expect(non_snake_case)]
fn test_gray_iterator_vartime() {
// Set up parameters
let N = 3u32;
Expand Down
18 changes: 9 additions & 9 deletions src/parallel/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{domains, util::OperationTiming, Transcript};
/// `G`, `G1`, and `U` required by the protocol. You can either use [`TriptychParameters::new`] to have these generators
/// defined securely for you, or use [`TriptychParameters::new_with_generators`] if your use case requires specific
/// values for these.
#[allow(non_snake_case)]
#[expect(non_snake_case)]
#[derive(Clone, Eq, PartialEq)]
pub struct TriptychParameters {
n: u32,
Expand Down Expand Up @@ -53,7 +53,7 @@ impl TriptychParameters {
///
/// This function produces group generators `G`, `G1` and `U` for you.
/// If your use case requires specific generators, use [`TriptychParameters::new_with_generators`] instead.
#[allow(non_snake_case)]
#[expect(non_snake_case)]
pub fn new(n: u32, m: u32) -> Result<Self, ParameterError> {
// Use the default base point for `G` (this is arbitrary)
let G = RISTRETTO_BASEPOINT_POINT;
Expand Down Expand Up @@ -89,7 +89,7 @@ impl TriptychParameters {
///
/// The security of these generators cannot be checked by this function.
/// If you'd rather have the generators securely defined for you, use [`TriptychParameters::new`] instead.
#[allow(non_snake_case)]
#[expect(non_snake_case)]
pub fn new_with_generators(
n: u32,
m: u32,
Expand Down Expand Up @@ -199,23 +199,23 @@ impl TriptychParameters {
/// Get the group generator `G` from these [`TriptychParameters`].
///
/// This is the generator used for defining verification keys.
#[allow(non_snake_case)]
#[expect(non_snake_case)]
pub fn get_G(&self) -> &RistrettoPoint {
&self.G
}

/// Get the group generator `G1` from these [`TriptychParameters`].
///
/// This is the generator used for defining auxiliary verification keys.
#[allow(non_snake_case)]
#[expect(non_snake_case)]
pub fn get_G1(&self) -> &RistrettoPoint {
&self.G1
}

/// Get the group generator `U` from these [`TriptychParameters`].
///
/// This is the generator used for defining linking tags.
#[allow(non_snake_case)]
#[expect(non_snake_case)]
pub fn get_U(&self) -> &RistrettoPoint {
&self.U
}
Expand All @@ -237,20 +237,20 @@ impl TriptychParameters {
/// Get the value `N == n**m` from these [`TriptychParameters`].
///
/// This is the verification key vector size.
#[allow(non_snake_case)]
#[expect(non_snake_case)]
pub fn get_N(&self) -> u32 {
// This is guaranteed not to overflow
self.n.pow(self.m)
}

/// Get the value `CommitmentG` from these [`TriptychParameters`].
#[allow(non_snake_case)]
#[expect(non_snake_case)]
pub(crate) fn get_CommitmentG(&self) -> &Vec<RistrettoPoint> {
&self.CommitmentG
}

/// Get the value `CommitmentH` from these [`TriptychParameters`].
#[allow(non_snake_case)]
#[expect(non_snake_case)]
pub(crate) fn get_CommitmentH(&self) -> &RistrettoPoint {
&self.CommitmentH
}
Expand Down
Loading