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

Fuzzing test fix #302

Merged
merged 4 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
name: Lint (${{ matrix.os }} + ${{ matrix.channel }})
needs: [format, format-cargo-toml, docs]
strategy:
fail-fast: false
fail-fast: true
matrix:
os:
- ubuntu-latest
Expand All @@ -58,15 +58,16 @@ jobs:
- run: cargo hakari manage-deps --yes
- run: cargo hakari verify
- run: cargo install cargo-hack --locked
- run: cargo clippy --workspace --all-features -vv
- run: cargo hack clippy --workspace --feature-powerset --tests
- run: cargo hack clippy --workspace --feature-powerset
- run: cargo hack clippy --workspace --feature-powerset --bins
- run: cargo hack clippy --workspace --feature-powerset --examples
- run: cargo hack clippy --workspace --feature-powerset --tests
test:
name: Test (${{ matrix.os }} + ${{ matrix.channel }})
needs: [format, format-cargo-toml, docs]
strategy:
fail-fast: false
fail-fast: true
matrix:
os:
- macos-latest
Expand All @@ -85,7 +86,7 @@ jobs:
name: Compile Benchmarks (${{ matrix.os }} + ${{ matrix.channel }})
needs: [format, format-cargo-toml, docs]
strategy:
fail-fast: false
fail-fast: true
matrix:
os:
- macos-latest
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Removed

### Fixed
- [\#302](https://github.com/Manta-Network/manta-rs/pull/302) Fix fuzzing test bug
- [\#296](https://github.com/Manta-Network/manta-rs/pull/296) Fix AssetMetadata display for values less than 1
- [\#294](https://github.com/Manta-Network/manta-rs/pull/294) Distinguish between panic-errors and possible-fix-errors

Expand Down
18 changes: 18 additions & 0 deletions manta-crypto/src/arkworks/ff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//! Arkworks Finite Field Backend

use manta_util::{byte_count, into_array_unchecked};
use num_integer::Integer;

#[doc(inline)]
pub use ark_ff::*;
Expand Down Expand Up @@ -53,6 +54,23 @@ field_try_into! {
try_into_u128 => u128,
}

/// Divides the [`BigInteger`]s `n` by `m` and returns the quotient and the remainder.
#[inline]
pub fn div_rem<B>(n: B, m: B) -> (B, B)
where
B: BigInteger,
{
let (quotient, remainder) = n.into().div_rem(&m.into());
(
B::try_from(quotient)
.ok()
.expect("Unable to compute modular reduction."),
B::try_from(remainder)
.ok()
.expect("Unable to compute modular reduction."),
)
}

/// Testing Suite
#[cfg(test)]
mod test {
Expand Down
5 changes: 3 additions & 2 deletions manta-crypto/src/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ pub mod fuzz {
use super::*;

#[cfg(all(feature = "arkworks", feature = "rand"))]
use crate::arkworks::ff::{BigInteger, PrimeField};
use crate::arkworks::ff::{div_rem, BigInteger, FpParameters, PrimeField};

/// Fuzz Trait
pub trait Fuzz<M = ()> {
Expand Down Expand Up @@ -612,7 +612,8 @@ pub mod fuzz {
where
R: RngCore + ?Sized,
{
P::from_repr(self.into_repr().fuzz(rng))
let (_, fuzzed_element) = div_rem(self.into_repr().fuzz(rng), P::Params::MODULUS);
P::from_repr(fuzzed_element)
.expect("Computing the field element from a big integer is not supposed to fail.")
}
}
Expand Down