jf_commitment/lib.rs
1// Copyright (c) 2022 Espresso Systems (espressosys.com)
2// This file is part of the Jellyfish library.
3
4// You should have received a copy of the MIT License
5// along with the Jellyfish library. If not, see <https://mit-license.org/>.
6//! Trait definition for cryptographic commitment scheme
7#![no_std]
8
9use ark_std::{borrow::Borrow, fmt::Debug, hash::Hash, UniformRand};
10
11/// A glorified [`bool`] that leverages compile lints to encourage the caller to
12/// use the result.
13///
14/// Intended as the return type for verification of proofs, signatures, etc.
15/// Recommended for use in the nested [`Result`] pattern: see <https://sled.rs/errors>.
16type VerificationResult = Result<(), ()>;
17
18pub trait CommitmentScheme {
19 /// Input to the commitment
20 type Input;
21 /// The type of output commitment value
22 type Output: Clone + Debug + PartialEq + Eq + Hash;
23 /// The type of the hiding/blinding factor
24 type Randomness: Clone + Debug + PartialEq + Eq + UniformRand;
25 /// Error type
26 type Error: ark_std::error::Error;
27
28 /// Commit algorithm that takes `input` and blinding randomness `r`
29 /// (optional for hiding commitment schemes), outputs a commitment.
30 fn commit<T: Borrow<Self::Input>>(
31 input: T,
32 r: Option<&Self::Randomness>,
33 ) -> Result<Self::Output, Self::Error>;
34
35 /// Verify algorithm that output `Ok` if accepted, or `Err` if rejected.
36 fn verify<T: Borrow<Self::Input>>(
37 input: T,
38 r: Option<&Self::Randomness>,
39 comm: &Self::Output,
40 ) -> Result<VerificationResult, Self::Error>;
41}