add error handling to several pending methods (#30)

This commit is contained in:
2023-10-04 15:43:24 +02:00
committed by GitHub
parent 8256c27609
commit 13e471aeaf
12 changed files with 203 additions and 120 deletions

View File

@@ -51,14 +51,14 @@ impl<C: CurveGroup> CCS<C> {
// complete the hadamard chain
let mut hadamard_result = vec![C::ScalarField::one(); self.m];
for M_j in vec_M_j.into_iter() {
hadamard_result = hadamard(&hadamard_result, &mat_vec_mul_sparse(M_j, z));
hadamard_result = hadamard(&hadamard_result, &mat_vec_mul_sparse(M_j, z))?;
}
// multiply by the coefficient of this step
let c_M_j_z = vec_scalar_mul(&hadamard_result, &self.c[i]);
// add it to the final vector
result = vec_add(&result, &c_M_j_z);
result = vec_add(&result, &c_M_j_z)?;
}
// make sure the final vector is all zeroes

View File

@@ -22,8 +22,10 @@ impl<F: PrimeField> R1CS<F> {
let Az = mat_vec_mul_sparse(&self.A, z);
let Bz = mat_vec_mul_sparse(&self.B, z);
let Cz = mat_vec_mul_sparse(&self.C, z);
let AzBz = hadamard(&Az, &Bz);
assert_eq!(AzBz, Cz);
let AzBz = hadamard(&Az, &Bz)?;
if AzBz != Cz {
return Err(Error::NotSatisfied);
}
Ok(())
}
@@ -60,7 +62,9 @@ impl<F: PrimeField> RelaxedR1CS<F> {
let uCz = vec_scalar_mul(&Cz, &self.u);
let uCzE = vec_add(&uCz, &self.E);
let AzBz = hadamard(&Az, &Bz);
assert_eq!(AzBz, uCzE);
if AzBz != uCzE {
return Err(Error::NotSatisfied);
}
Ok(())
}