Skip to content

Commit a6153ca

Browse files
committed
Documentation.
1 parent 5703bed commit a6153ca

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/arthur.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ where
8282
}
8383
}
8484

85-
/// The state of an interactive proof system.
86-
/// Holds the state of the verifier, and provides the random coins for the prover.
85+
/// [`Arthur`] is the prover state in an interactive proof system.
86+
/// It internally holds the secret coins of the prover for zero-knowledge, and
87+
/// has the hash function state for the verifier state.
8788
pub struct Arthur<H = DefaultHash, U = u8, R = DefaultRng>
8889
where
8990
U: Unit,
@@ -104,6 +105,9 @@ where
104105
H: DuplexHash<U>,
105106
R: RngCore + CryptoRng,
106107
{
108+
/// Add a slice `[Arthur::U]` to the protocol transcript.
109+
/// The messages are also internally encoded in the protocol transcript,
110+
/// and used to re-seed the prover's random number generator.
107111
#[inline(always)]
108112
pub fn add_units(&mut self, input: &[U]) -> Result<(), IOPatternError> {
109113
// let serialized = bincode::serialize(input).unwrap();
@@ -119,16 +123,23 @@ where
119123
Ok(())
120124
}
121125

126+
/// Ratchet the verifier's state.
122127
#[inline(always)]
123128
pub fn ratchet(&mut self) -> Result<(), IOPatternError> {
124129
self.safe.ratchet()
125130
}
126131

132+
/// Return a reference to the random number generator associated to the protocol transcript.
127133
#[inline(always)]
128134
pub fn rng(&mut self) -> &mut (impl CryptoRng + RngCore) {
129135
&mut self.rng
130136
}
131137

138+
/// Return the current protocol transcript.
139+
/// The protocol transcript does not hold eny information about the length or the type of the messages being read.
140+
/// This is because the information is considered pre-shared within the [`IOPattern`].
141+
/// Additionally, since the verifier challenges are deterministically generated from the prover's messages,
142+
/// the transcript does not hold any of the verifier's messages.
132143
pub fn transcript(&self) -> &[u8] {
133144
self.transcript.as_slice()
134145
}
@@ -140,13 +151,17 @@ where
140151
H: DuplexHash<U>,
141152
R: RngCore + CryptoRng,
142153
{
154+
/// Add public messages to the protocol transcript.
155+
/// Messages input to this function are not added to the protocol transcript.
156+
/// They are however absorbed into the verifier's sponge for Fiat-Shamir, and used to re-seed the prover state.
143157
fn public_units(&mut self, input: &[U]) -> Result<(), IOPatternError> {
144158
let len = self.transcript.len();
145159
self.add_units(input)?;
146160
self.transcript.truncate(len);
147161
Ok(())
148162
}
149163

164+
/// Fill a slice `[Arthur::U]` with challenges from the verifier.
150165
fn fill_challenge_units(&mut self, output: &mut [U]) -> Result<(), IOPatternError> {
151166
self.safe.squeeze(output)
152167
}

src/merlin.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ use crate::safe::Safe;
55
use crate::traits::{ByteReader, UnitTranscript};
66
use crate::DefaultHash;
77

8-
/// Merlin is wrapper around a sponge that provides a secure
9-
/// Fiat-Shamir implementation for public-coin protocols.
8+
/// [`Merlin`] contains the verifier state.
9+
/// Internally, it is a wrapper around a SAFE sponge.
10+
/// Given as input an [`IOPattern`] and a protocol transcript, it allows to
11+
/// de-serialize elements from the transcript and make them available to the zero-knowledge verifier.
1012
#[derive(Clone)]
1113
pub struct Merlin<'a, H = DefaultHash, U = u8>
1214
where
@@ -48,6 +50,7 @@ impl<'a, U: Unit, H: DuplexHash<U>> Merlin<'a, H, U> {
4850
}
4951

5052
impl<'a, H: DuplexHash<U>, U: Unit> UnitTranscript<U> for Merlin<'a, H, U> {
53+
/// Add native elements to the sponge without writing them to the protocol transcript.
5154
#[inline]
5255
fn public_units(&mut self, input: &[U]) -> Result<(), IOPatternError> {
5356
self.safe.absorb(input)
@@ -67,6 +70,7 @@ impl<'a, H: DuplexHash<U>, U: Unit> core::fmt::Debug for Merlin<'a, H, U> {
6770
}
6871

6972
impl<'a, H: DuplexHash<u8>> ByteReader for Merlin<'a, H, u8> {
73+
/// Read the next `input.len()` bytes from the transcript and return them.
7074
#[inline]
7175
fn fill_next_bytes(&mut self, input: &mut [u8]) -> Result<(), IOPatternError> {
7276
self.fill_next_units(input)

0 commit comments

Comments
 (0)