added missing dependency, implemented r1cs import from json file
This commit is contained in:
parent
30e62b13ec
commit
8e84f13eba
3 changed files with 90 additions and 32 deletions
63
Cargo.lock
generated
63
Cargo.lock
generated
|
@ -1,19 +1,3 @@
|
|||
[root]
|
||||
name = "zokrates"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bincode 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"clap 2.26.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gcc 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.6.3"
|
||||
|
@ -73,6 +57,11 @@ dependencies = [
|
|||
"vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dtoa"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "gcc"
|
||||
version = "0.3.42"
|
||||
|
@ -83,6 +72,11 @@ name = "glob"
|
|||
version = "0.2.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "kernel32-sys"
|
||||
version = "0.2.2"
|
||||
|
@ -181,6 +175,11 @@ name = "num-traits"
|
|||
version = "0.1.36"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "0.3.15"
|
||||
|
@ -253,6 +252,17 @@ dependencies = [
|
|||
"synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.6.0"
|
||||
|
@ -357,6 +367,23 @@ name = "winapi-build"
|
|||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "zokrates"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bincode 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"clap 2.26.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gcc 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[metadata]
|
||||
"checksum aho-corasick 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "500909c4f87a9e52355b26626d890833e9e1d53ac566db76c36faa984b889699"
|
||||
"checksum ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6"
|
||||
|
@ -365,8 +392,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
|
||||
"checksum byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff81738b726f5d099632ceaffe7fb65b90212e8dce59d518729e7e8634032d3d"
|
||||
"checksum clap 2.26.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3451e409013178663435d6f15fdb212f14ee4424a3d74f979d081d0a66b6f1f2"
|
||||
"checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab"
|
||||
"checksum gcc 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)" = "291055c78f59ca3d84c99026c9501c469413d386bb46be1e1cf1d285cd1db3b0"
|
||||
"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
|
||||
"checksum itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8324a32baf01e2ae060e9de58ed0bc2320c9a2833491ee36cd3b4c414de4db8c"
|
||||
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
|
||||
"checksum lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "cf186d1a8aa5f5bee5fd662bc9c1b949e0259e1bcc379d1f006847b0080c7417"
|
||||
"checksum lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c9e5e58fa1a4c3b915a561a78a22ee0cac6ab97dca2504428bc1cb074375f8d5"
|
||||
|
@ -379,6 +408,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "287a1c9969a847055e1122ec0ea7a5c5d6f72aad97934e131c83d5c08ab4e45c"
|
||||
"checksum num-rational 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "54ff603b8334a72fbb27fe66948aac0abaaa40231b3cecd189e76162f6f38aaf"
|
||||
"checksum num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "a16a42856a256b39c6d3484f097f6713e14feacd9bfb02290917904fae46c81c"
|
||||
"checksum num-traits 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3c2bd9b9d21e48e956b763c9f37134dc62d9e95da6edb3f672cacb6caf3cd3"
|
||||
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
|
||||
"checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d"
|
||||
"checksum redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "8dde11f18c108289bef24469638a04dce49da56084f2d50618b226e47eb04509"
|
||||
|
@ -389,6 +419,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum serde 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "6a7046c9d4c6c522d10b2d098f9bebe2bef227e0e74044d8c1bfcf6b476af799"
|
||||
"checksum serde_derive 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "1afcaae083fd1c46952a315062326bc9957f182358eb7da03b57ef1c688f7aa9"
|
||||
"checksum serde_derive_internals 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bd381f6d01a6616cdba8530492d453b7761b456ba974e98768a18cad2cd76f58"
|
||||
"checksum serde_json 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)" = "57781ed845b8e742fc2bf306aba8e3b408fe8c366b900e3769fbc39f49eb8b39"
|
||||
"checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694"
|
||||
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
|
||||
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
|
||||
|
|
|
@ -18,6 +18,7 @@ clap = "2.26.2"
|
|||
# serialization and deserialization
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
serde_json = "1.0"
|
||||
bincode = "0.8.0"
|
||||
regex = "0.2"
|
||||
|
||||
|
|
58
src/r1cs.rs
58
src/r1cs.rs
|
@ -9,7 +9,7 @@ use std::collections::HashMap;
|
|||
use std::collections::BTreeMap;
|
||||
use absy::*;
|
||||
use absy::Expression::*;
|
||||
use field::Field;
|
||||
use field::{Field, FieldPrime};
|
||||
|
||||
// for r1cs import, can be moved.
|
||||
// r1cs data strucutre reflecting JSON standard format:
|
||||
|
@ -364,27 +364,53 @@ pub fn flattened_program<T: Field>(
|
|||
|
||||
for cons in r1cs.constraints {
|
||||
assert!(cons.len() == 3); // entries for a,b,c
|
||||
let mut lhs_a: Expression<T> = Number(T::from(0));
|
||||
let mut lhs_b: Expression<T> = Number(T::from(0));
|
||||
let mut rhs: Expression<T> = Number(T::from(0));
|
||||
|
||||
// right hand side of definition
|
||||
let mut rhs: Expression<T>;
|
||||
let mut first = true;
|
||||
|
||||
for (var_offset, val) in &cons[0] {
|
||||
let var = r1cs.variables[var_offset.parse::<usize>().unwrap()].clone(); // get variable name
|
||||
let term = Expression::Mult(box Number(T::from(*val as i32)), box Identifier(var));
|
||||
if first {
|
||||
lhs_a = term;
|
||||
first = !first;
|
||||
} else {
|
||||
lhs_a = Expression::Add(box lhs_a, box term);
|
||||
}
|
||||
}
|
||||
println!("lhs a: {:?}", lhs_a);
|
||||
|
||||
first = true;
|
||||
|
||||
for (var_offset, val) in &cons[1] {
|
||||
let var = r1cs.variables[var_offset.parse::<usize>().unwrap()].clone(); // get variable name
|
||||
let term = Expression::Mult(box Number(T::from(*val as i32)), box Identifier(var));
|
||||
if first {
|
||||
lhs_b = term;
|
||||
first = !first;
|
||||
} else {
|
||||
lhs_b = Expression::Add(box lhs_b, box term);
|
||||
}
|
||||
}
|
||||
println!("lhs b: {:?}", lhs_b);
|
||||
|
||||
first = true;
|
||||
|
||||
// Expression: c0+c1+c2...
|
||||
for (c_var_offset, c_val) in cons[2] {
|
||||
let counter = 0;
|
||||
let var = r1cs.variables[c_var_offset.parse::<usize>().unwrap()]; // get variable name
|
||||
if counter ==0{
|
||||
rhs = Expression::Identifier(var);
|
||||
for (var_offset, val) in &cons[2] {
|
||||
let var = r1cs.variables[var_offset.parse::<usize>().unwrap()].clone(); // get variable name
|
||||
let term = Expression::Mult(box Number(T::from(*val as i32)), box Identifier(var));
|
||||
if first {
|
||||
rhs = term;
|
||||
first = !first;
|
||||
} else {
|
||||
rhs = Expression::Add(box rhs, box Expression::Identifier(var));
|
||||
rhs = Expression::Add(box rhs, box term);
|
||||
}
|
||||
println!("rhs: {:?}", rhs);
|
||||
}
|
||||
|
||||
|
||||
let a_entries = cons[0].clone();
|
||||
let b_entries = cons[1].clone();
|
||||
let c_entries = cons[2].clone();
|
||||
println!("a entries: {:?}", a_entries);
|
||||
println!("rhs: {:?}", rhs);
|
||||
statements.push(Statement::Condition(Expression::Mult(box lhs_a, box lhs_b), rhs));
|
||||
}
|
||||
|
||||
let mut functs = Vec::new();
|
||||
|
|
Loading…
Reference in a new issue