Skip to content

Commit ec19cb3

Browse files
committed
Make closure of challenge phase FnOnce.
It allows for the challenge phase to accept closures that take some more context, e.g. moving non-Clone values in the challenge closure. This works in stable since Rust 1.35; cfr. rust-lang/rust#28796. This closes issue dalek-cryptography#244.
1 parent d287c7a commit ec19cb3

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/r1cs/constraint_system.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub trait RandomizableConstraintSystem: ConstraintSystem {
106106
/// ```
107107
fn specify_randomized_constraints<F>(&mut self, callback: F) -> Result<(), R1CSError>
108108
where
109-
F: 'static + Fn(&mut Self::RandomizedCS) -> Result<(), R1CSError>;
109+
F: 'static + FnOnce(&mut Self::RandomizedCS) -> Result<(), R1CSError>;
110110
}
111111

112112
/// Represents a constraint system in the second phase:

src/r1cs/prover.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ pub struct Prover<'g, T: BorrowMut<Transcript>> {
3737

3838
/// This list holds closures that will be called in the second phase of the protocol,
3939
/// when non-randomized variables are committed.
40-
deferred_constraints: Vec<Box<dyn Fn(&mut RandomizingProver<'g, T>) -> Result<(), R1CSError>>>,
40+
deferred_constraints:
41+
Vec<Box<dyn FnOnce(&mut RandomizingProver<'g, T>) -> Result<(), R1CSError>>>,
4142

4243
/// Index of a pending multiplier that's not fully assigned yet.
4344
pending_multiplier: Option<usize>,
@@ -182,7 +183,7 @@ impl<'g, T: BorrowMut<Transcript>> RandomizableConstraintSystem for Prover<'g, T
182183

183184
fn specify_randomized_constraints<F>(&mut self, callback: F) -> Result<(), R1CSError>
184185
where
185-
F: 'static + Fn(&mut Self::RandomizedCS) -> Result<(), R1CSError>,
186+
F: 'static + FnOnce(&mut Self::RandomizedCS) -> Result<(), R1CSError>,
186187
{
187188
self.deferred_constraints.push(Box::new(callback));
188189
Ok(())

src/r1cs/verifier.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ pub struct Verifier<T: BorrowMut<Transcript>> {
4343
/// when non-randomized variables are committed.
4444
/// After that, the option will flip to None and additional calls to `randomize_constraints`
4545
/// will invoke closures immediately.
46-
deferred_constraints: Vec<Box<dyn Fn(&mut RandomizingVerifier<T>) -> Result<(), R1CSError>>>,
46+
deferred_constraints:
47+
Vec<Box<dyn FnOnce(&mut RandomizingVerifier<T>) -> Result<(), R1CSError>>>,
4748

4849
/// Index of a pending multiplier that's not fully assigned yet.
4950
pending_multiplier: Option<usize>,
@@ -134,7 +135,7 @@ impl<T: BorrowMut<Transcript>> RandomizableConstraintSystem for Verifier<T> {
134135

135136
fn specify_randomized_constraints<F>(&mut self, callback: F) -> Result<(), R1CSError>
136137
where
137-
F: 'static + Fn(&mut Self::RandomizedCS) -> Result<(), R1CSError>,
138+
F: 'static + FnOnce(&mut Self::RandomizedCS) -> Result<(), R1CSError>,
138139
{
139140
self.deferred_constraints.push(Box::new(callback));
140141
Ok(())

0 commit comments

Comments
 (0)