Introduce inputize abstractions to simplify circuit code.

This commit is contained in:
Sean Bowe
2018-03-04 23:33:05 -07:00
parent 51c35a9bcf
commit e52befb58e
3 changed files with 43 additions and 144 deletions
+23
View File
@@ -60,6 +60,29 @@ impl<E: Engine> AllocatedNum<E> {
})
}
pub fn inputize<CS>(
&self,
mut cs: CS
) -> Result<(), SynthesisError>
where CS: ConstraintSystem<E>
{
let input = cs.alloc_input(
|| "input variable",
|| {
Ok(*self.value.get()?)
}
)?;
cs.enforce(
|| "enforce input is correct",
|lc| lc + input,
|lc| lc + CS::one(),
|lc| lc + self.variable
);
Ok(())
}
pub fn into_bits_strict<CS>(
&self,
mut cs: CS