From 1ac6900103157d5fcb10608ec84962e775f54c31 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 | 5 +++-- src/r1cs/verifier.rs | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/r1cs/constraint_system.rs b/src/r1cs/constraint_system.rs index cf327f26..05e31734 100644 --- a/src/r1cs/constraint_system.rs +++ b/src/r1cs/constraint_system.rs @@ -106,7 +106,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 75c62d1f..96d44398 100644 --- a/src/r1cs/prover.rs +++ b/src/r1cs/prover.rs @@ -37,7 +37,8 @@ pub struct Prover<'g, T: BorrowMut> { /// 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, @@ -182,7 +183,7 @@ impl<'g, T: BorrowMut> RandomizableConstraintSystem for Prover<'g, 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(()) diff --git a/src/r1cs/verifier.rs b/src/r1cs/verifier.rs index cddbd425..28318749 100644 --- a/src/r1cs/verifier.rs +++ b/src/r1cs/verifier.rs @@ -43,7 +43,8 @@ pub struct Verifier> { /// 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, @@ -134,7 +135,7 @@ impl> RandomizableConstraintSystem for Verifier { 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(())