From 7e1e32bfbec7882c201f5346ae87702a41e46dcc Mon Sep 17 00:00:00 2001 From: skaunov Date: Sun, 21 Jan 2024 10:16:11 +0300 Subject: [PATCH 1/2] Example for draft PR Error handling is mocked just for example; return type for the modified method have been left incompatible as it shows the idea to the point. --- src/lib.rs | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a2bdc104..d93c94c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ +#![feature(iterator_try_reduce)] #![cfg_attr(not(feature = "std"), no_std)] //! This crate implements common "gadgets" that make //! programming rank-1 constraint systems easier. @@ -131,12 +132,31 @@ pub trait R1CSVar { impl> R1CSVar for [T] { type Value = Vec; - fn cs(&self) -> ark_relations::r1cs::ConstraintSystemRef { - let mut result = ark_relations::r1cs::ConstraintSystemRef::None; - for var in self { - result = var.cs().or(result); + fn cs(&self) -> Result, &str> { + if let Some(Ok(result)) = self.iter().map(|x| Ok(x.cs())).reduce( + |x: Result, _>, y| { + if let Ok(x) = x { + let y = y?; + if x != y { + if x.is_none() { + return Ok(y); + } + if y.is_none() { + return Ok(x); + } + Err("todo!(CSs are not reducible to one)") + } else { + return Ok(x); + } + } else { + x + } + }, + ) { + Ok(result.to_owned()) + } else { + Err("empty input") } - result } fn value(&self) -> Result { From ed11638adb4b057edc2b63b42dca1950f5d88100 Mon Sep 17 00:00:00 2001 From: skaunov Date: Sun, 21 Jan 2024 10:40:32 +0300 Subject: [PATCH 2/2] Tiny cleaning of changes --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index d93c94c9..c6072b0e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,3 @@ -#![feature(iterator_try_reduce)] #![cfg_attr(not(feature = "std"), no_std)] //! This crate implements common "gadgets" that make //! programming rank-1 constraint systems easier.