82
82
}
83
83
}
84
84
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.
87
88
pub struct Arthur < H = DefaultHash , U = u8 , R = DefaultRng >
88
89
where
89
90
U : Unit ,
@@ -104,6 +105,9 @@ where
104
105
H : DuplexHash < U > ,
105
106
R : RngCore + CryptoRng ,
106
107
{
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.
107
111
#[ inline( always) ]
108
112
pub fn add_units ( & mut self , input : & [ U ] ) -> Result < ( ) , IOPatternError > {
109
113
// let serialized = bincode::serialize(input).unwrap();
@@ -119,16 +123,23 @@ where
119
123
Ok ( ( ) )
120
124
}
121
125
126
+ /// Ratchet the verifier's state.
122
127
#[ inline( always) ]
123
128
pub fn ratchet ( & mut self ) -> Result < ( ) , IOPatternError > {
124
129
self . safe . ratchet ( )
125
130
}
126
131
132
+ /// Return a reference to the random number generator associated to the protocol transcript.
127
133
#[ inline( always) ]
128
134
pub fn rng ( & mut self ) -> & mut ( impl CryptoRng + RngCore ) {
129
135
& mut self . rng
130
136
}
131
137
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.
132
143
pub fn transcript ( & self ) -> & [ u8 ] {
133
144
self . transcript . as_slice ( )
134
145
}
@@ -140,13 +151,17 @@ where
140
151
H : DuplexHash < U > ,
141
152
R : RngCore + CryptoRng ,
142
153
{
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.
143
157
fn public_units ( & mut self , input : & [ U ] ) -> Result < ( ) , IOPatternError > {
144
158
let len = self . transcript . len ( ) ;
145
159
self . add_units ( input) ?;
146
160
self . transcript . truncate ( len) ;
147
161
Ok ( ( ) )
148
162
}
149
163
164
+ /// Fill a slice `[Arthur::U]` with challenges from the verifier.
150
165
fn fill_challenge_units ( & mut self , output : & mut [ U ] ) -> Result < ( ) , IOPatternError > {
151
166
self . safe . squeeze ( output)
152
167
}
0 commit comments