mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-24 02:31:44 +03:00
add square root example
This commit is contained in:
parent
2f3a51860b
commit
ea81f9bc98
@ -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(())
|
||||||
}
|
}
|
||||||
|
@ -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
1
examples/square_root/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
outputs/
|
3
examples/square_root/Leo.toml
Normal file
3
examples/square_root/Leo.toml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[package]
|
||||||
|
name = "square_root"
|
||||||
|
version = "0.1.0"
|
4
examples/square_root/inputs/square_root.in
Normal file
4
examples/square_root/inputs/square_root.in
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
// The program inputs for square_root/src/main.leo
|
||||||
|
[main]
|
||||||
|
a: field = 337;
|
||||||
|
b: field = 113569;
|
5
examples/square_root/src/main.leo
Normal file
5
examples/square_root/src/main.leo
Normal 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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user