Skip to main content

commonware_cryptography/zk/
mod.rs

1#[cfg(feature = "std")]
2pub mod bulletproofs;
3#[cfg(feature = "std")]
4pub mod circuit;
5#[cfg(feature = "std")]
6pub mod pedersen_to_plain;
7
8#[cfg(all(feature = "std", feature = "fuzz"))]
9pub mod fuzz {
10    use arbitrary::{Arbitrary, Unstructured};
11
12    pub enum Plan {
13        Bulletproofs(crate::zk::bulletproofs::fuzz::Plan),
14        PedersenToPlain(crate::zk::pedersen_to_plain::fuzz::Plan),
15        Circuit(crate::zk::circuit::fuzz::Plan),
16    }
17
18    impl<'a> Arbitrary<'a> for Plan {
19        fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
20            match u.int_in_range(0..=2)? {
21                0 => Ok(Self::Bulletproofs(u.arbitrary()?)),
22                1 => Ok(Self::PedersenToPlain(u.arbitrary()?)),
23                2 => Ok(Self::Circuit(u.arbitrary()?)),
24                _ => unreachable!("plan variant out of range"),
25            }
26        }
27    }
28
29    impl Plan {
30        pub fn run(self, u: &mut Unstructured<'_>) -> arbitrary::Result<()> {
31            match self {
32                Self::Bulletproofs(plan) => plan.run(u),
33                Self::PedersenToPlain(plan) => plan.run(u),
34                Self::Circuit(plan) => plan.run(u),
35            }
36        }
37    }
38}