From 9ec3dd64608f56f562d03159b37ce9e40abb75fb Mon Sep 17 00:00:00 2001 From: Ruben De Smet Date: Tue, 28 May 2019 14:56:34 +0200 Subject: [PATCH] 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. https://github.com/rust-lang/rust/issues/28796. This closes issue #244. --- src/r1cs/constraint_system.rs | 2 +- src/r1cs/prover.rs | 4 ++-- src/r1cs/verifier.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/r1cs/constraint_system.rs b/src/r1cs/constraint_system.rs index 276bdbdf..49259f57 100644 --- a/src/r1cs/constraint_system.rs +++ b/src/r1cs/constraint_system.rs @@ -103,7 +103,7 @@ pub trait RandomizableConstraintSystem: ConstraintSystem { /// ``` fn specify_randomized_constraints(&mut self, callback: F) -> Result<(), R1CSError> where - F: 'static + Fn(&mut Self::RandomizedCS) -> Result<(), R1CSError>; + F: 'static + FnOnce(&mut Self::RandomizedCS) -> Result<(), R1CSError>; } /// Represents a constraint system in the second phase: diff --git a/src/r1cs/prover.rs b/src/r1cs/prover.rs index 0d7538d2..bb4a69e0 100644 --- a/src/r1cs/prover.rs +++ b/src/r1cs/prover.rs @@ -44,7 +44,7 @@ pub struct Prover<'t, 'g> { /// This list holds closures that will be called in the second phase of the protocol, /// when non-randomized variables are committed. - deferred_constraints: Vec) -> Result<(), R1CSError>>>, + deferred_constraints: Vec) -> Result<(), R1CSError>>>, /// Index of a pending multiplier that's not fully assigned yet. pending_multiplier: Option, @@ -170,7 +170,7 @@ impl<'t, 'g> RandomizableConstraintSystem for Prover<'t, 'g> { fn specify_randomized_constraints(&mut self, callback: F) -> Result<(), R1CSError> where - F: 'static + Fn(&mut Self::RandomizedCS) -> Result<(), R1CSError>, + F: 'static + FnOnce(&mut Self::RandomizedCS) -> Result<(), R1CSError>, { self.deferred_constraints.push(Box::new(callback)); Ok(()) diff --git a/src/r1cs/verifier.rs b/src/r1cs/verifier.rs index 0a4a61f6..fb1d7a5f 100644 --- a/src/r1cs/verifier.rs +++ b/src/r1cs/verifier.rs @@ -42,7 +42,7 @@ pub struct Verifier<'t> { /// when non-randomized variables are committed. /// After that, the option will flip to None and additional calls to `randomize_constraints` /// will invoke closures immediately. - deferred_constraints: Vec) -> Result<(), R1CSError>>>, + deferred_constraints: Vec) -> Result<(), R1CSError>>>, /// Index of a pending multiplier that's not fully assigned yet. pending_multiplier: Option, @@ -129,7 +129,7 @@ impl<'t> RandomizableConstraintSystem for Verifier<'t> { fn specify_randomized_constraints(&mut self, callback: F) -> Result<(), R1CSError> where - F: 'static + Fn(&mut Self::RandomizedCS) -> Result<(), R1CSError>, + F: 'static + FnOnce(&mut Self::RandomizedCS) -> Result<(), R1CSError>, { self.deferred_constraints.push(Box::new(callback)); Ok(())