pub trait Sigma: Writable {
type Witness: Debug;
type Statement: Debug;
type AnnounceSecret: Debug;
type Announcement: Eq + Debug;
type Response: Debug;
type ChallengeLength: ArrayLength<u8>;
// Required methods
fn announce(
&self,
statement: &Self::Statement,
announce_secret: &Self::AnnounceSecret
) -> Self::Announcement;
fn gen_announce_secret<Rng: CryptoRng + RngCore>(
&self,
witness: &Self::Witness,
rng: &mut Rng
) -> Self::AnnounceSecret;
fn sample_response<Rng: CryptoRng + RngCore>(
&self,
rng: &mut Rng
) -> Self::Response;
fn respond(
&self,
witness: &Self::Witness,
statement: &Self::Statement,
announce_secret: Self::AnnounceSecret,
announce: &Self::Announcement,
challenge: &GenericArray<u8, Self::ChallengeLength>
) -> Self::Response;
fn implied_announcement(
&self,
statement: &Self::Statement,
challenge: &GenericArray<u8, Self::ChallengeLength>,
response: &Self::Response
) -> Option<Self::Announcement>;
fn hash_statement<H: Update>(
&self,
hash: &mut H,
statement: &Self::Statement
);
fn hash_announcement<H: Update>(
&self,
hash: &mut H,
announcement: &Self::Announcement
);
fn hash_witness<H: Update>(&self, hash: &mut H, witness: &Self::Witness);
}
Expand description
The Sigma
trait is used to define a Sigma protocol.
You will need to implement this yourself if you are unable to build your sigma protocol by composing it from existing sigma protocols.
The role of the main functions of the trait are depicted below:
Prover(witness, statement, rng) Verifier(statement)
======
announce_secret = gen_announce_secret(rng)
announcement = announce(statement, announce_secret)
announcement
+------------------->
challenge *uniformly sample ChallengeLength bytes*
<-------------------+
response = respond(witness, statement,
announce_secret, announcement,
challenge)
response
+------------------->
check
implied_announcement(statement, challenge, response)
==
announcement
The values taken and returned by the functions are all defined as associated types. In addition
there is ChallengeLength
associated type which defines the length of the challenge. Usually
the trait is implemented for a sigma protocol for all lengths less than some maximum like so:
use sigma_fun::generic_array::{
typenum::{self, type_operators::IsLessOrEqual, U32},
ArrayLength, GenericArray,
};
use sigma_fun::Sigma;
struct MySigma<L> {
// store the typenum in our type
challenge_len: core::marker::PhantomData<L>,
}
// implement Sigma for any length less than or eqaul to 32-bytes.
impl<L: ArrayLength<u8>> Sigma for MySigma<L>
where
L: IsLessOrEqual<U32>,
<L as IsLessOrEqual<U32>>::Output: typenum::marker_traits::NonZero
{
// ...
}
Required Associated Types§
sourcetype AnnounceSecret: Debug
type AnnounceSecret: Debug
The type for the secret the prover creates when generating the proof.
sourcetype Announcement: Eq + Debug
type Announcement: Eq + Debug
The type for the public announcement the prover sends in the first round of the protocol.
sourcetype Response: Debug
type Response: Debug
The type for the response the prover sends in the last round of the protocol.
sourcetype ChallengeLength: ArrayLength<u8>
type ChallengeLength: ArrayLength<u8>
The length as a typenum
Required Methods§
sourcefn announce(
&self,
statement: &Self::Statement,
announce_secret: &Self::AnnounceSecret
) -> Self::Announcement
fn announce( &self, statement: &Self::Statement, announce_secret: &Self::AnnounceSecret ) -> Self::Announcement
Generates the prover’s announcement message.
sourcefn gen_announce_secret<Rng: CryptoRng + RngCore>(
&self,
witness: &Self::Witness,
rng: &mut Rng
) -> Self::AnnounceSecret
fn gen_announce_secret<Rng: CryptoRng + RngCore>( &self, witness: &Self::Witness, rng: &mut Rng ) -> Self::AnnounceSecret
Generates the secret data to create the announcement
sourcefn sample_response<Rng: CryptoRng + RngCore>(
&self,
rng: &mut Rng
) -> Self::Response
fn sample_response<Rng: CryptoRng + RngCore>( &self, rng: &mut Rng ) -> Self::Response
Uniformly samples a response from the response space of the Sigma protocol.
sourcefn respond(
&self,
witness: &Self::Witness,
statement: &Self::Statement,
announce_secret: Self::AnnounceSecret,
announce: &Self::Announcement,
challenge: &GenericArray<u8, Self::ChallengeLength>
) -> Self::Response
fn respond( &self, witness: &Self::Witness, statement: &Self::Statement, announce_secret: Self::AnnounceSecret, announce: &Self::Announcement, challenge: &GenericArray<u8, Self::ChallengeLength> ) -> Self::Response
Generates the prover’s response for the verifier’s challenge.
sourcefn implied_announcement(
&self,
statement: &Self::Statement,
challenge: &GenericArray<u8, Self::ChallengeLength>,
response: &Self::Response
) -> Option<Self::Announcement>
fn implied_announcement( &self, statement: &Self::Statement, challenge: &GenericArray<u8, Self::ChallengeLength>, response: &Self::Response ) -> Option<Self::Announcement>
Computes what the announcement must be for the response
to be valid.
sourcefn hash_statement<H: Update>(&self, hash: &mut H, statement: &Self::Statement)
fn hash_statement<H: Update>(&self, hash: &mut H, statement: &Self::Statement)
Hashes the statement.
sourcefn hash_announcement<H: Update>(
&self,
hash: &mut H,
announcement: &Self::Announcement
)
fn hash_announcement<H: Update>( &self, hash: &mut H, announcement: &Self::Announcement )
Hashes the announcement.
sourcefn hash_witness<H: Update>(&self, hash: &mut H, witness: &Self::Witness)
fn hash_witness<H: Update>(&self, hash: &mut H, witness: &Self::Witness)
Hashes the witness.
Object Safety§
Implementors§
source§impl<A, B> Sigma for And<A, B>
impl<A, B> Sigma for And<A, B>
type Witness = (<A as Sigma>::Witness, <B as Sigma>::Witness)
type Statement = (<A as Sigma>::Statement, <B as Sigma>::Statement)
type Announcement = (<A as Sigma>::Announcement, <B as Sigma>::Announcement)
type AnnounceSecret = (<A as Sigma>::AnnounceSecret, <B as Sigma>::AnnounceSecret)
type Response = (<A as Sigma>::Response, <B as Sigma>::Response)
type ChallengeLength = <A as Sigma>::ChallengeLength
source§impl<A, B> Sigma for Eq<A, B>where
A: Sigma,
B: Sigma<ChallengeLength = A::ChallengeLength, Witness = A::Witness, Response = A::Response, AnnounceSecret = A::AnnounceSecret>,
impl<A, B> Sigma for Eq<A, B>where
A: Sigma,
B: Sigma<ChallengeLength = A::ChallengeLength, Witness = A::Witness, Response = A::Response, AnnounceSecret = A::AnnounceSecret>,
type Witness = <A as Sigma>::Witness
type Statement = (<A as Sigma>::Statement, <B as Sigma>::Statement)
type AnnounceSecret = <A as Sigma>::AnnounceSecret
type Announcement = (<A as Sigma>::Announcement, <B as Sigma>::Announcement)
type Response = <A as Sigma>::Response
type ChallengeLength = <A as Sigma>::ChallengeLength
source§impl<A: Sigma, B: Sigma<ChallengeLength = A::ChallengeLength>> Sigma for Or<A, B>
impl<A: Sigma, B: Sigma<ChallengeLength = A::ChallengeLength>> Sigma for Or<A, B>
type Witness = Either<<A as Sigma>::Witness, <B as Sigma>::Witness>
type Statement = (<A as Sigma>::Statement, <B as Sigma>::Statement)
type Announcement = (<A as Sigma>::Announcement, <B as Sigma>::Announcement)
type AnnounceSecret = (Either<(<A as Sigma>::AnnounceSecret, <B as Sigma>::Response), (<A as Sigma>::Response, <B as Sigma>::AnnounceSecret)>, GenericArray<u8, <Or<A, B> as Sigma>::ChallengeLength>)
type ChallengeLength = <A as Sigma>::ChallengeLength
type Response = ((<A as Sigma>::Response, GenericArray<u8, <Or<A, B> as Sigma>::ChallengeLength>), <B as Sigma>::Response)
source§impl<L> Sigma for sigma_fun::ed25519::DL<L>
Available on crate feature ed25519
only.
impl<L> Sigma for sigma_fun::ed25519::DL<L>
ed25519
only.type Witness = Scalar
type Statement = (EdwardsPoint, EdwardsPoint)
type AnnounceSecret = Scalar
type Announcement = EdwardsPoint
type Response = Scalar
type ChallengeLength = L
source§impl<L> Sigma for sigma_fun::ed25519::DLG<L>
Available on crate feature ed25519
only.
impl<L> Sigma for sigma_fun::ed25519::DLG<L>
ed25519
only.