add square root example

This commit is contained in:
collin 2020-06-22 21:39:24 -07:00
parent 2f3a51860b
commit ea81f9bc98
6 changed files with 23 additions and 2 deletions

View File

@ -115,13 +115,14 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
impl<F: Field + PrimeField, G: GroupType<F>> ConstraintSynthesizer<F> for Compiler<F, G> { impl<F: Field + PrimeField, G: GroupType<F>> ConstraintSynthesizer<F> for Compiler<F, G> {
fn generate_constraints<CS: ConstraintSystem<F>>(self, cs: &mut CS) -> Result<(), SynthesisError> { fn generate_constraints<CS: ConstraintSystem<F>>(self, cs: &mut CS) -> Result<(), SynthesisError> {
let _result = let result =
generate_constraints::<_, G, _>(cs, self.program, self.program_inputs.get_inputs()).map_err(|e| { generate_constraints::<_, G, _>(cs, self.program, self.program_inputs.get_inputs()).map_err(|e| {
log::error!("{}", e); log::error!("{}", e);
SynthesisError::Unsatisfiable SynthesisError::Unsatisfiable
})?; })?;
// Write results to file or something // Write results to file or something
log::info!("{}", result);
Ok(()) Ok(())
} }

View File

@ -193,7 +193,14 @@ impl<F: Field + PrimeField, G: GroupType<F>> fmt::Display for ConstrainedValue<F
ConstrainedValue::Integer(ref value) => write!(f, "{}", value), ConstrainedValue::Integer(ref value) => write!(f, "{}", value),
ConstrainedValue::Field(ref value) => write!(f, "{:?}", value), ConstrainedValue::Field(ref value) => write!(f, "{:?}", value),
ConstrainedValue::Group(ref value) => write!(f, "{:?}", value), ConstrainedValue::Group(ref value) => write!(f, "{:?}", value),
ConstrainedValue::Boolean(ref value) => write!(f, "{}", value.get_value().unwrap()), ConstrainedValue::Boolean(ref value) => write!(
f,
"{}",
value
.get_value()
.map(|v| v.to_string())
.unwrap_or(format!("[allocated]"))
),
ConstrainedValue::Array(ref array) => { ConstrainedValue::Array(ref array) => {
write!(f, "[")?; write!(f, "[")?;
for (i, e) in array.iter().enumerate() { for (i, e) in array.iter().enumerate() {

1
examples/square_root/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
outputs/

View File

@ -0,0 +1,3 @@
[package]
name = "square_root"
version = "0.1.0"

View File

@ -0,0 +1,4 @@
// The program inputs for square_root/src/main.leo
[main]
a: field = 337;
b: field = 113569;

View File

@ -0,0 +1,5 @@
// The 'square_root' main function.
// prove knowledge of the square root `a` of a number `b`:
function main(a: field, b: field) -> bool {
return a * a == b
}