Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case for fallible cs() method #138

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,31 @@ pub trait R1CSVar<F: Field> {
impl<F: Field, T: R1CSVar<F>> R1CSVar<F> for [T] {
type Value = Vec<T::Value>;

fn cs(&self) -> ark_relations::r1cs::ConstraintSystemRef<F> {
let mut result = ark_relations::r1cs::ConstraintSystemRef::None;
for var in self {
result = var.cs().or(result);
fn cs(&self) -> Result<ark_relations::r1cs::ConstraintSystemRef<F>, &str> {
if let Some(Ok(result)) = self.iter().map(|x| Ok(x.cs())).reduce(
|x: Result<ark_relations::r1cs::ConstraintSystemRef<F>, _>, 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<Self::Value, ark_relations::r1cs::SynthesisError> {
Expand Down