diff --git a/src/lib.rs b/src/lib.rs index a2bdc104..c6072b0e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -131,12 +131,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 {