You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/codec/shake_codec.rs
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,14 @@
1
1
//! Implementation of a Fiat-Shamir codec using SHAKE128
2
2
//!
3
-
//! This module defines `ShakeCodec`, a concrete implementation of the `Codec`
3
+
//! This module defines [`ShakeCodec`], a concrete implementation of the [`Codec`]
4
4
//! trait. It uses the SHAKE128 extendable output function (XOF) from the Keccak family
5
5
//! to generate Fiat-Shamir challenges for Sigma protocols.
6
6
//!
7
7
//! It allows commitments (group elements) to be absorbed into a codec,
8
8
//! and produces scalar challenges by squeezing bytes from the hash state.
9
9
//!
10
10
//! # Usage
11
-
//! - The prover and verifier absorb the same messages into identical `ShakeCodec` instances.
11
+
//! - The prover and verifier absorb the same messages into identical [`ShakeCodec`] instances.
12
12
//! - The prover and the verifier then squeeze the hash to generate a challenge scalar for the protocol. The verifier can check that the prover used the challenge output by the codec because he owns an identical codec.
/// The output is deterministic for a given set of input. Thus, both Prover and Verifier can generate the codec on their sides and ensure the same inputs have been used in both side of the protocol.
/// Creates a new non-interactive Sigma protocol, identified by a domain separator (usually fixed per protocol instantiation), and an initialized Sigma protocol instance.
60
+
/// Constructs a new [`NISigmaProtocol`] instance.
61
+
///
62
+
/// # Parameters
63
+
/// - `iv`: Domain separation tag for the hash function (e.g., protocol name or context).
64
+
/// - `instance`: An instance of the interactive Sigma protocol.
65
+
///
66
+
/// # Returns
67
+
/// A new [`NISigmaProtocol`] that can generate and verify non-interactive proofs.
59
68
pubfnnew(iv:&[u8],instance:P) -> Self{
60
69
let hash_state = C::new(iv);
61
70
Self{
@@ -64,7 +73,23 @@ where
64
73
}
65
74
}
66
75
67
-
/// Produces a non-interactive proof for a witness.
76
+
/// Generates a non-interactive proof for a witness.
77
+
///
78
+
/// Executes the interactive protocol steps (commit, derive challenge via hash, respond),
79
+
/// and checks the result locally for consistency.
80
+
///
81
+
/// # Parameters
82
+
/// - `witness`: The secret witness for the Sigma protocol.
83
+
/// - `rng`: A cryptographically secure random number generator.
84
+
///
85
+
/// # Returns
86
+
/// A tuple of:
87
+
/// - `P::Commitment`: The prover's commitment(s).
88
+
/// - `P::Challenge`: The challenge derived via Fiat-Shamir.
89
+
/// - `P::Response`: The prover's response.
90
+
///
91
+
/// # Panics
92
+
/// Panics if local verification fails.
68
93
pubfnprove(
69
94
&mutself,
70
95
witness:&P::Witness,
@@ -93,7 +118,21 @@ where
93
118
Ok((commitment, challenge, response))
94
119
}
95
120
96
-
/// Verify a non-interactive proof and returns a Result: `Ok(())` if the proof verifies successfully, `Err(())` otherwise.
121
+
/// Verifies a non-interactive proof using the Fiat-Shamir transformation.
122
+
///
123
+
/// # Parameters
124
+
/// - `commitment`: The commitment(s) sent by the prover.
125
+
/// - `challenge`: The challenge allegedly derived via Fiat-Shamir.
126
+
/// - `response`: The prover's response to the challenge.
127
+
///
128
+
/// # Returns
129
+
/// - `Ok(())` if the proof is valid.
130
+
/// - `Err(ProofError::VerificationFailure)` if the challenge is invalid or the response fails to verify.
0 commit comments