merge with develop
This commit is contained in:
commit
622b0c628e
58 changed files with 531 additions and 107 deletions
|
@ -33,10 +33,13 @@ jobs:
|
|||
- run:
|
||||
name: Generate code coverage report
|
||||
command: ./scripts/cov.sh
|
||||
- run:
|
||||
name: Publish book
|
||||
command: ./scripts/publish_book.sh
|
||||
- save_cache:
|
||||
paths:
|
||||
- /usr/local/cargo/registry
|
||||
- target/debug/.fingerprint
|
||||
- target/debug/build
|
||||
- target/debug/deps
|
||||
key: v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }}
|
||||
key: v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }}
|
||||
|
|
14
Cargo.lock
generated
14
Cargo.lock
generated
|
@ -632,6 +632,7 @@ dependencies = [
|
|||
"regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"zokrates_core 0.3.2",
|
||||
"zokrates_field 0.3.0",
|
||||
"zokrates_fs_resolver 0.3.2",
|
||||
]
|
||||
|
||||
|
@ -654,6 +655,19 @@ dependencies = [
|
|||
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"zokrates_field 0.3.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zokrates_field"
|
||||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"bincode 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-bigint 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
18
scripts/publish_book.sh
Executable file
18
scripts/publish_book.sh
Executable file
|
@ -0,0 +1,18 @@
|
|||
# Exit if any subcommand fails
|
||||
set -e
|
||||
|
||||
if [ "$CIRCLE_BRANCH" == "master" ]; then
|
||||
apt-get update
|
||||
apt-get -qq install git python-minimal
|
||||
python --version
|
||||
cargo install mdbook
|
||||
cd zokrates_book && mdbook build
|
||||
git config --global user.email "stefan.deml+zokratesbot@decentriq.ch"
|
||||
git clone https://github.com/Zokrates/zokrates.github.io.git
|
||||
git clone https://github.com/davisp/ghp-import.git
|
||||
cd zokrates.github.io
|
||||
TAG=$(cat ../zokrates_cli/Cargo.toml | grep '^version' | awk '{print $3}' | sed -e 's/"//g') && echo $TAG
|
||||
../ghp-import/ghp_import.py -n -p -f -m "Documentation upload. Version: $TAG" -b "master" -r https://zokratesbot:"$GH_TOKEN"@github.com/Zokrates/zokrates.github.io.git ../book
|
||||
echo "Published book"
|
||||
fi
|
||||
|
|
@ -13,6 +13,7 @@ libsnark = ["zokrates_core/libsnark"]
|
|||
clap = "2.26.2"
|
||||
bincode = "0.8.0"
|
||||
regex = "0.2"
|
||||
zokrates_field = { version = "0.3", path = "../zokrates_field" }
|
||||
zokrates_core = { version = "0.3", path = "../zokrates_core" }
|
||||
zokrates_fs_resolver = { version = "0.3", path = "../zokrates_fs_resolver"}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ extern crate bincode;
|
|||
extern crate clap;
|
||||
extern crate regex;
|
||||
extern crate zokrates_core;
|
||||
extern crate zokrates_field;
|
||||
extern crate zokrates_fs_resolver;
|
||||
|
||||
use bincode::{deserialize_from, serialize_into, Infinite};
|
||||
|
@ -20,12 +21,12 @@ use std::io::{stdin, BufRead, BufReader, BufWriter, Write};
|
|||
use std::path::{Path, PathBuf};
|
||||
use std::string::String;
|
||||
use zokrates_core::compile::compile;
|
||||
use zokrates_core::field::{Field, FieldPrime};
|
||||
use zokrates_core::ir;
|
||||
#[cfg(feature = "libsnark")]
|
||||
use zokrates_core::ir::r1cs_program;
|
||||
#[cfg(feature = "libsnark")]
|
||||
use zokrates_core::proof_system::{ProofSystem, GM17, PGHR13};
|
||||
use zokrates_field::field::{Field, FieldPrime};
|
||||
use zokrates_fs_resolver::resolve as fs_resolve;
|
||||
|
||||
#[cfg(feature = "libsnark")]
|
||||
|
@ -379,21 +380,11 @@ fn main() {
|
|||
})
|
||||
.collect();
|
||||
|
||||
let witness_map = program_ast
|
||||
.execute(arguments)
|
||||
let witness = program_ast
|
||||
.execute(&arguments)
|
||||
.unwrap_or_else(|e| panic!(format!("Execution failed: {}", e)));
|
||||
|
||||
println!(
|
||||
"\nWitness: \n\n{}",
|
||||
witness_map
|
||||
.iter()
|
||||
.filter_map(|(variable, value)| match variable {
|
||||
variable if variable.is_output() => Some(format!("{} {}", variable, value)),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<String>>()
|
||||
.join("\n")
|
||||
);
|
||||
println!("\nWitness: \n\n{}", witness.format_outputs());
|
||||
|
||||
// write witness to file
|
||||
let output_path = Path::new(sub_matches.value_of("output").unwrap());
|
||||
|
@ -402,10 +393,7 @@ fn main() {
|
|||
Err(why) => panic!("couldn't create {}: {}", output_path.display(), why),
|
||||
};
|
||||
let mut bw = BufWriter::new(output_file);
|
||||
for (var, val) in &witness_map {
|
||||
write!(&mut bw, "{} {}\n", var, val.to_dec_string())
|
||||
.expect("Unable to write data to file.");
|
||||
}
|
||||
write!(&mut bw, "{}", witness).expect("Unable to write data to file.");
|
||||
bw.flush().expect("Unable to flush buffer.");
|
||||
}
|
||||
#[cfg(feature = "libsnark")]
|
||||
|
@ -655,7 +643,7 @@ mod tests {
|
|||
|
||||
let (..) = r1cs_program(program_flattened.clone());
|
||||
let _ = program_flattened
|
||||
.execute(vec![FieldPrime::from(0)])
|
||||
.execute(&vec![FieldPrime::from(0)])
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
@ -689,7 +677,7 @@ mod tests {
|
|||
|
||||
let result = std::panic::catch_unwind(|| {
|
||||
let _ = program_flattened
|
||||
.execute(vec![FieldPrime::from(0)])
|
||||
.execute(&vec![FieldPrime::from(0)])
|
||||
.unwrap();
|
||||
});
|
||||
assert!(result.is_err());
|
||||
|
|
|
@ -23,6 +23,7 @@ serde_json = "1.0"
|
|||
bincode = "0.8.0"
|
||||
regex = "0.2"
|
||||
bimap = "0.1"
|
||||
zokrates_field = { version = "0.3.0", path = "../zokrates_field" }
|
||||
|
||||
[dev-dependencies]
|
||||
glob = "0.2.11"
|
||||
|
|
|
@ -12,10 +12,10 @@ pub use absy::parameter::Parameter;
|
|||
pub use absy::variable::Variable;
|
||||
use types::Signature;
|
||||
|
||||
use field::Field;
|
||||
use flat_absy::*;
|
||||
use imports::Import;
|
||||
use std::fmt;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct Prog<T: Field> {
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
//! @author Thibaut Schaeffer <thibaut@schaeff.fr>
|
||||
//! @date 2018
|
||||
use absy::Prog;
|
||||
use field::Field;
|
||||
use flat_absy::FlatProg;
|
||||
use flatten::Flattener;
|
||||
use imports::{self, Importer};
|
||||
|
@ -16,6 +15,7 @@ use static_analysis::Analyse;
|
|||
use std::fmt;
|
||||
use std::io;
|
||||
use std::io::BufRead;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum CompileError<T: Field> {
|
||||
|
@ -101,8 +101,8 @@ pub fn compile_aux<T: Field, R: BufRead, S: BufRead, E: Into<imports::Error>>(
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use field::FieldPrime;
|
||||
use std::io::{BufReader, Empty};
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
#[test]
|
||||
fn no_resolver_with_imports() {
|
||||
|
|
|
@ -11,13 +11,13 @@ pub mod flat_variable;
|
|||
pub use self::flat_parameter::FlatParameter;
|
||||
pub use self::flat_variable::FlatVariable;
|
||||
|
||||
use field::Field;
|
||||
use helpers::{DirectiveStatement, Executable};
|
||||
#[cfg(feature = "libsnark")]
|
||||
use standard;
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::fmt;
|
||||
use types::Signature;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct FlatProg<T: Field> {
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
use absy::parameter::Parameter;
|
||||
use absy::variable::Variable;
|
||||
use bimap::BiMap;
|
||||
use field::Field;
|
||||
use flat_absy::*;
|
||||
use helpers::{DirectiveStatement, Helper, RustHelper};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
@ -16,6 +15,7 @@ use typed_absy::*;
|
|||
use types::conversions::cast;
|
||||
use types::Signature;
|
||||
use types::Type;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
/// Flattener, computes flattened program.
|
||||
#[derive(Debug)]
|
||||
|
@ -1509,9 +1509,9 @@ impl Flattener {
|
|||
mod tests {
|
||||
use super::*;
|
||||
use absy::variable::Variable;
|
||||
use field::FieldPrime;
|
||||
use types::Signature;
|
||||
use types::Type;
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
#[test]
|
||||
fn multiple_definition() {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use field::Field;
|
||||
use helpers::{Executable, Signed};
|
||||
use libsnark::{get_sha256round_witness};
|
||||
use serde_json;
|
||||
use standard;
|
||||
use std::fmt;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
|
||||
pub enum LibsnarkGadgetHelper {
|
||||
|
|
|
@ -5,9 +5,9 @@ mod rust;
|
|||
#[cfg(feature = "libsnark")]
|
||||
pub use self::libsnark_gadget::LibsnarkGadgetHelper;
|
||||
pub use self::rust::RustHelper;
|
||||
use field::Field;
|
||||
use flat_absy::{FlatExpression, FlatVariable};
|
||||
use std::fmt;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
|
||||
pub struct DirectiveStatement<T: Field> {
|
||||
|
@ -115,7 +115,7 @@ impl Signed for Helper {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use field::FieldPrime;
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
#[cfg(feature = "libsnark")]
|
||||
mod sha256libsnark {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use field::Field;
|
||||
use helpers::{Executable, Signed};
|
||||
use std::fmt;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
|
||||
pub enum RustHelper {
|
||||
|
@ -63,7 +63,7 @@ impl<T: Field> Executable<T> for RustHelper {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use field::FieldPrime;
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
#[test]
|
||||
fn bits_of_one() {
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
use absy::*;
|
||||
use compile::compile_aux;
|
||||
use compile::CompileError;
|
||||
use field::Field;
|
||||
use flat_absy::*;
|
||||
use std::fmt;
|
||||
use std::io;
|
||||
use std::io::BufRead;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
pub struct CompiledImport<T: Field> {
|
||||
pub flat_func: FlatFunction<T>,
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use field::Field;
|
||||
use flat_absy::FlatVariable;
|
||||
use num::Zero;
|
||||
use std::collections::BTreeMap;
|
||||
use std::fmt;
|
||||
use std::ops::{Add, Sub};
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct QuadComb<T: Field> {
|
||||
|
@ -118,7 +118,7 @@ impl<T: Field> Zero for LinComb<T> {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use field::FieldPrime;
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
mod linear {
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use field::Field;
|
||||
use flat_absy::{FlatExpression, FlatFunction, FlatProg, FlatStatement, FlatVariable};
|
||||
use helpers;
|
||||
use ir::{DirectiveStatement, Function, LinComb, Prog, QuadComb, Statement};
|
||||
use num::Zero;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
impl<T: Field> From<FlatFunction<T>> for Function<T> {
|
||||
fn from(flat_function: FlatFunction<T>) -> Function<T> {
|
||||
|
@ -138,7 +138,7 @@ impl<T: Field> From<helpers::DirectiveStatement<T>> for DirectiveStatement<T> {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use field::FieldPrime;
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
#[test]
|
||||
fn zero() {
|
||||
|
|
|
@ -1,19 +1,59 @@
|
|||
use field::Field;
|
||||
use helpers::Executable;
|
||||
use ir::*;
|
||||
use std::collections::BTreeMap;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
pub type ExecutionResult<T> = Result<Witness<T>, Error>;
|
||||
|
||||
pub struct Witness<T: Field>(BTreeMap<FlatVariable, T>);
|
||||
|
||||
impl<T: Field> Witness<T> {
|
||||
pub fn return_values(&self) -> Vec<T> {
|
||||
self.0
|
||||
.clone()
|
||||
.into_iter()
|
||||
.filter(|(k, _)| k.is_output())
|
||||
.map(|(_, v)| v)
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn format_outputs(&self) -> String {
|
||||
self.0
|
||||
.iter()
|
||||
.filter_map(|(variable, value)| match variable {
|
||||
variable if variable.is_output() => Some(format!("{} {}", variable, value)),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<String>>()
|
||||
.join("\n")
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Field> fmt::Display for Witness<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
self.0
|
||||
.iter()
|
||||
.map(|(k, v)| format!("{} {}", k, v.to_dec_string()))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Field> Prog<T> {
|
||||
pub fn execute(self, inputs: Vec<T>) -> Result<BTreeMap<FlatVariable, T>, Error<T>> {
|
||||
let main = self.main;
|
||||
assert_eq!(main.arguments.len(), inputs.len());
|
||||
pub fn execute<U: Into<T> + Clone>(&self, inputs: &Vec<U>) -> ExecutionResult<T> {
|
||||
let main = &self.main;
|
||||
self.check_inputs(&inputs)?;
|
||||
let mut witness = BTreeMap::new();
|
||||
witness.insert(FlatVariable::one(), T::one());
|
||||
for (arg, value) in main.arguments.iter().zip(inputs.iter()) {
|
||||
witness.insert(arg.clone(), value.clone());
|
||||
witness.insert(arg.clone(), value.clone().into());
|
||||
}
|
||||
|
||||
for statement in main.statements {
|
||||
for statement in &main.statements {
|
||||
match statement {
|
||||
Statement::Constraint(quad, lin) => match lin.is_assignee(&witness) {
|
||||
true => {
|
||||
|
@ -24,7 +64,10 @@ impl<T: Field> Prog<T> {
|
|||
let lhs_value = quad.evaluate(&witness);
|
||||
let rhs_value = lin.evaluate(&witness);
|
||||
if lhs_value != rhs_value {
|
||||
return Err(Error::Constraint(quad, lin, lhs_value, rhs_value));
|
||||
return Err(Error::UnsatisfiedConstraint {
|
||||
left: lhs_value.to_dec_string(),
|
||||
right: rhs_value.to_dec_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -44,7 +87,18 @@ impl<T: Field> Prog<T> {
|
|||
}
|
||||
}
|
||||
|
||||
Ok(witness)
|
||||
Ok(Witness(witness))
|
||||
}
|
||||
|
||||
fn check_inputs<U>(&self, inputs: &Vec<U>) -> Result<(), Error> {
|
||||
if self.main.arguments.len() == inputs.len() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Error::WrongInputCount {
|
||||
expected: self.main.arguments.len(),
|
||||
received: inputs.len(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,21 +123,35 @@ impl<T: Field> QuadComb<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub enum Error<T: Field> {
|
||||
Constraint(QuadComb<T>, LinComb<T>, T, T),
|
||||
#[derive(PartialEq, Serialize, Deserialize)]
|
||||
pub enum Error {
|
||||
UnsatisfiedConstraint { left: String, right: String },
|
||||
Solver,
|
||||
WrongInputCount { expected: usize, received: usize },
|
||||
}
|
||||
|
||||
impl<T: Field> fmt::Display for Error<T> {
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
Error::Constraint(ref quad, ref lin, ref left_value, ref right_value) => write!(
|
||||
f,
|
||||
"Expected {} to equal {}, but {} != {}",
|
||||
quad, lin, left_value, right_value
|
||||
),
|
||||
Error::UnsatisfiedConstraint {
|
||||
ref left,
|
||||
ref right,
|
||||
} => write!(f, "Expected {} to equal {}", left, right),
|
||||
Error::Solver => write!(f, ""),
|
||||
Error::WrongInputCount { expected, received } => write!(
|
||||
f,
|
||||
"Program takes {} input{} but was passed {} value{}",
|
||||
expected,
|
||||
if expected == 1 { "" } else { "s" },
|
||||
received,
|
||||
if received == 1 { "" } else { "s" }
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use field::Field;
|
||||
use flat_absy::flat_parameter::FlatParameter;
|
||||
use flat_absy::FlatVariable;
|
||||
use helpers::Helper;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use std::mem;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
mod expression;
|
||||
mod from_flat;
|
||||
|
@ -13,6 +13,9 @@ mod interpreter;
|
|||
use self::expression::LinComb;
|
||||
use self::expression::QuadComb;
|
||||
|
||||
pub use self::interpreter::Error;
|
||||
pub use self::interpreter::ExecutionResult;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub enum Statement<T: Field> {
|
||||
Constraint(QuadComb<T>, LinComb<T>),
|
||||
|
@ -250,7 +253,7 @@ pub fn r1cs_program<T: Field>(
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use field::FieldPrime;
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
mod statement {
|
||||
use super::*;
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#![feature(box_patterns, box_syntax)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
extern crate num;
|
||||
extern crate num_bigint;
|
||||
extern crate reduce; // better reduce function than Iter.fold
|
||||
|
@ -12,6 +10,7 @@ extern crate serde_derive;
|
|||
extern crate bimap;
|
||||
extern crate bincode;
|
||||
extern crate regex;
|
||||
extern crate zokrates_field;
|
||||
|
||||
mod flatten;
|
||||
mod helpers;
|
||||
|
@ -27,7 +26,6 @@ mod types;
|
|||
|
||||
pub mod absy;
|
||||
pub mod compile;
|
||||
pub mod field;
|
||||
pub mod flat_absy;
|
||||
pub mod ir;
|
||||
#[cfg(feature = "libsnark")]
|
||||
|
|
|
@ -10,7 +10,7 @@ use self::libc::{c_char, c_int, uint8_t};
|
|||
use std::ffi::CString;
|
||||
use std::string::String;
|
||||
|
||||
use field::Field;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
extern "C" {
|
||||
fn _sha256RoundConstraints() -> *mut c_char;
|
||||
|
@ -50,12 +50,12 @@ fn vec_as_u8_32_array(vec: &Vec<u8>) -> [u8; 32] {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use field::FieldPrime;
|
||||
use flat_absy::*;
|
||||
use helpers;
|
||||
use num_bigint::BigUint;
|
||||
use serde_json;
|
||||
use standard;
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
#[cfg(test)]
|
||||
mod sha256_gadget {
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
//! @author Jacob Eberhardt <jacob.eberhardt@tu-berlin.de>
|
||||
//! @date 2017
|
||||
|
||||
use field::Field;
|
||||
use flat_absy::flat_variable::FlatVariable;
|
||||
use flat_absy::*;
|
||||
use std::collections::HashMap;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
pub struct Optimizer {
|
||||
/// Map of renamings for reassigned variables while processing the program.
|
||||
|
@ -126,9 +126,9 @@ impl Optimizer {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use field::FieldPrime;
|
||||
use flat_absy::flat_parameter::FlatParameter;
|
||||
use types::{Signature, Type};
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
#[test]
|
||||
fn remove_synonyms() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use field::Field;
|
||||
use parser::tokenize::Position;
|
||||
use parser::tokenize::Token;
|
||||
use std::fmt;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub struct Error<T: Field> {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use field::Field;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
use parser::tokenize::{next_token, Position, Token};
|
||||
use parser::Error;
|
||||
|
@ -506,7 +506,7 @@ pub fn parse_expr<T: Field>(
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use field::FieldPrime;
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
mod terms {
|
||||
use super::*;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use field::Field;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
use parser::tokenize::{next_token, Position, Token};
|
||||
use parser::Error;
|
||||
|
@ -39,7 +39,7 @@ fn parse_comma_separated_expression_list_rec<T: Field>(
|
|||
mod tests {
|
||||
use super::*;
|
||||
use absy::Expression;
|
||||
use field::FieldPrime;
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
fn parse_comma_separated_list<T: Field>(
|
||||
input: String,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use field::Field;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
use std::io::prelude::*;
|
||||
use std::io::Lines;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use field::Field;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
use parser::tokenize::{next_token, Position, Token};
|
||||
use parser::Error;
|
||||
|
@ -55,7 +55,7 @@ pub fn parse_import<T: Field>(
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use field::FieldPrime;
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
#[test]
|
||||
fn quoted_path() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use field::Field;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
use std::io::prelude::*;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use field::Field;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
use std::io::prelude::*;
|
||||
use std::io::Lines;
|
||||
|
@ -569,7 +569,7 @@ fn parse_comma_separated_identifier_list_rec<T: Field>(
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use field::FieldPrime;
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
mod parse_statement1 {
|
||||
use super::*;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use field::Field;
|
||||
use std::fmt;
|
||||
use types::Type;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub enum Token<T: Field> {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use super::position::Position;
|
||||
use super::token::Token;
|
||||
use field::Field;
|
||||
use types::Type;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
pub fn parse_num<T: Field>(input: &String, pos: &Position) -> (Token<T>, String, Position) {
|
||||
let mut end = 0;
|
||||
|
@ -406,7 +406,7 @@ pub fn next_token<T: Field>(input: &String, pos: &Position) -> (Token<T>, String
|
|||
mod tests {
|
||||
|
||||
use super::*;
|
||||
use field::FieldPrime;
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
#[test]
|
||||
fn inline_comment() {
|
||||
|
|
|
@ -10,7 +10,7 @@ use regex::Regex;
|
|||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader};
|
||||
|
||||
use field::FieldPrime;
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
pub struct GM17 {}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ use regex::Regex;
|
|||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader};
|
||||
|
||||
use field::FieldPrime;
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
pub struct PGHR13 {}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
mod bn128;
|
||||
mod utils;
|
||||
|
||||
use field::FieldPrime;
|
||||
use std::fs::File;
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
pub use self::bn128::GM17;
|
||||
pub use self::bn128::PGHR13;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use field::Field;
|
||||
use flat_absy::flat_variable::FlatVariable;
|
||||
use std::cmp::max;
|
||||
use std::ffi::CString;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
// utility function. Converts a Fields vector-based byte representation to fixed size array.
|
||||
fn vec_as_u8_32_array(vec: &Vec<u8>) -> [u8; 32] {
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
|
||||
use absy::variable::Variable;
|
||||
use absy::*;
|
||||
use field::Field;
|
||||
use std::collections::HashSet;
|
||||
use std::fmt;
|
||||
use typed_absy::*;
|
||||
use types::Signature;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
use types::Type;
|
||||
|
||||
|
@ -814,7 +814,7 @@ impl Checker {
|
|||
mod tests {
|
||||
use super::*;
|
||||
use absy::parameter::Parameter;
|
||||
use field::FieldPrime;
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
pub fn new_with_args(
|
||||
scope: HashSet<ScopedVariable>,
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use field::Field;
|
||||
use flat_absy::{FlatExpression, FlatExpressionList, FlatFunction, FlatStatement};
|
||||
use flat_absy::{FlatParameter, FlatVariable};
|
||||
use helpers::{DirectiveStatement, Helper, LibsnarkGadgetHelper};
|
||||
|
@ -6,7 +5,6 @@ use reduce::Reduce;
|
|||
use std::collections::{BTreeMap, HashSet};
|
||||
use types::{Signature, Type};
|
||||
use zokrates_field::field::Field;
|
||||
use std::iter::once;
|
||||
|
||||
// for r1cs import, can be moved.
|
||||
// r1cs data structure reflecting JSON standard format:
|
||||
|
@ -197,8 +195,8 @@ impl<T: Field> Into<FlatFunction<T>> for DirectiveR1CS {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use field::FieldPrime;
|
||||
use serde_json;
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
#[test]
|
||||
fn deserialize_constraint() {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use field::Field;
|
||||
use std::collections::HashSet;
|
||||
use typed_absy::folder::*;
|
||||
use typed_absy::Folder;
|
||||
use typed_absy::*;
|
||||
use types::{Signature, Type};
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
pub struct DeadCode {
|
||||
called: HashSet<String>,
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
//! @author Thibaut Schaeffer <thibaut@schaeff.fr>
|
||||
//! @date 2018
|
||||
|
||||
use field::Field;
|
||||
use flat_absy::*;
|
||||
use helpers::DirectiveStatement;
|
||||
use std::collections::HashMap;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
pub trait Propagate<T: Field> {
|
||||
fn propagate(self) -> Self;
|
||||
|
@ -117,7 +117,7 @@ impl<T: Field> FlatProg<T> {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use field::FieldPrime;
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
#[cfg(test)]
|
||||
mod expression {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use field::Field;
|
||||
use std::collections::HashMap;
|
||||
use typed_absy::folder::*;
|
||||
use typed_absy::Folder;
|
||||
use typed_absy::*;
|
||||
use types::{Signature, Type};
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
pub struct Inliner<T: Field> {
|
||||
functions: Vec<TypedFunction<T>>,
|
||||
|
@ -257,7 +257,7 @@ impl<T: Field> Folder<T> for Inliner<T> {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use field::FieldPrime;
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
#[cfg(test)]
|
||||
mod heuristics {
|
||||
|
|
|
@ -16,9 +16,9 @@ use self::inline::Inliner;
|
|||
use self::power_check::PowerChecker;
|
||||
use self::propagation::Propagator;
|
||||
use self::unroll::Unroller;
|
||||
use field::Field;
|
||||
use flat_absy::FlatProg;
|
||||
use typed_absy::TypedProg;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
pub trait Analyse {
|
||||
fn analyse(self) -> Self;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use field::Field;
|
||||
use typed_absy::folder::*;
|
||||
use typed_absy::Folder;
|
||||
use typed_absy::*;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
pub struct PowerChecker {}
|
||||
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
//! @date 2018
|
||||
|
||||
use absy::variable::Variable;
|
||||
use field::Field;
|
||||
use std::collections::HashMap;
|
||||
use typed_absy::folder::*;
|
||||
use typed_absy::*;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
pub struct Propagator<T: Field> {
|
||||
constants: HashMap<TypedAssignee<T>, TypedExpression<T>>,
|
||||
|
@ -338,7 +338,7 @@ impl<T: Field> Folder<T> for Propagator<T> {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use field::FieldPrime;
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
#[cfg(test)]
|
||||
mod expression {
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
//! @date 2018
|
||||
|
||||
use absy::variable::Variable;
|
||||
use field::Field;
|
||||
use std::collections::HashMap;
|
||||
use typed_absy::folder::*;
|
||||
use typed_absy::*;
|
||||
use types::Type;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
pub struct Unroller {
|
||||
substitution: HashMap<String, usize>,
|
||||
|
@ -174,7 +174,7 @@ impl<T: Field> Folder<T> for Unroller {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use field::FieldPrime;
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
#[cfg(test)]
|
||||
mod statement {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
// Generic walk through a typed AST. Not mutating in place
|
||||
|
||||
use absy::variable::Variable;
|
||||
use field::Field;
|
||||
use typed_absy::*;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
pub trait Folder<T: Field>: Sized {
|
||||
fn fold_program(&mut self, p: TypedProg<T>) -> TypedProg<T> {
|
||||
|
|
|
@ -11,11 +11,11 @@ use absy::parameter::Parameter;
|
|||
use absy::variable::Variable;
|
||||
use types::Signature;
|
||||
|
||||
use field::Field;
|
||||
use flat_absy::*;
|
||||
use imports::Import;
|
||||
use std::fmt;
|
||||
use types::Type;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
pub use self::folder::Folder;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use field::Field;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
#[derive(PartialEq, PartialOrd, Clone, Eq, Ord, Debug)]
|
||||
pub struct Constraints<T: Field> {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use bimap::BiMap;
|
||||
use field::Field;
|
||||
use flat_absy::flat_parameter::FlatParameter;
|
||||
use flat_absy::flat_variable::FlatVariable;
|
||||
use flat_absy::*;
|
||||
|
@ -8,6 +7,7 @@ use reduce::Reduce;
|
|||
use types::constraints::Constraint;
|
||||
use types::signature::Signature;
|
||||
use types::Type;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
fn use_variable(
|
||||
bijection: &mut BiMap<String, FlatVariable>,
|
||||
|
@ -294,7 +294,7 @@ pub fn cast<T: Field>(from: &Type, to: &Type) -> FlatFunction<T> {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use field::FieldPrime;
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
#[cfg(test)]
|
||||
mod cast {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use field::Field;
|
||||
use std::fmt;
|
||||
use types::constraints::Constraints;
|
||||
pub use types::signature::Signature;
|
||||
use zokrates_field::field::Field;
|
||||
|
||||
mod constraints;
|
||||
pub mod conversions;
|
||||
|
@ -64,7 +64,7 @@ impl Type {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use field::FieldPrime;
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
#[test]
|
||||
fn array() {
|
||||
|
|
2
zokrates_core/tests/bench/add.code
Normal file
2
zokrates_core/tests/bench/add.code
Normal file
|
@ -0,0 +1,2 @@
|
|||
def main(field a, field b) -> (field):
|
||||
return a + b
|
27
zokrates_core/tests/bench/add.json
Normal file
27
zokrates_core/tests/bench/add.json
Normal file
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"tests": [
|
||||
{
|
||||
"input": {
|
||||
"values": ["1", "2"]
|
||||
},
|
||||
"output": {
|
||||
"Ok": {
|
||||
"values": ["3"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"input": {
|
||||
"values": ["1", "2", "42"]
|
||||
},
|
||||
"output": {
|
||||
"Err": {
|
||||
"WrongInputCount": {
|
||||
"expected": 2,
|
||||
"received": 3
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
3
zokrates_core/tests/bench/assert_one.code
Normal file
3
zokrates_core/tests/bench/assert_one.code
Normal file
|
@ -0,0 +1,3 @@
|
|||
def main(field a) -> (field):
|
||||
a == 1
|
||||
return 1
|
17
zokrates_core/tests/bench/assert_one.json
Normal file
17
zokrates_core/tests/bench/assert_one.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"tests": [
|
||||
{
|
||||
"input": {
|
||||
"values": ["0"]
|
||||
},
|
||||
"output": {
|
||||
"Err": {
|
||||
"UnsatisfiedConstraint": {
|
||||
"left": "1",
|
||||
"right": "0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
12
zokrates_core/tests/integration.rs
Normal file
12
zokrates_core/tests/integration.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
extern crate serde_json;
|
||||
extern crate zokrates_core;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
#[macro_use]
|
||||
mod utils;
|
||||
|
||||
zokrates_test! {
|
||||
add,
|
||||
assert_one,
|
||||
}
|
120
zokrates_core/tests/utils/mod.rs
Normal file
120
zokrates_core/tests/utils/mod.rs
Normal file
|
@ -0,0 +1,120 @@
|
|||
extern crate serde_json;
|
||||
|
||||
use std::io;
|
||||
use zokrates_core::compile::{compile as generic_compile, CompileError};
|
||||
use zokrates_core::field::{Field, FieldPrime};
|
||||
use zokrates_core::ir;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Tests {
|
||||
pub tests: Vec<Test>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Input {
|
||||
pub values: Vec<Val>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Test {
|
||||
pub input: Input,
|
||||
pub output: TestResult,
|
||||
}
|
||||
|
||||
pub type TestResult = Result<Output, ir::Error>;
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub struct ComparableResult(Result<Vec<FieldPrime>, ir::Error>);
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Output {
|
||||
values: Vec<Val>,
|
||||
}
|
||||
|
||||
type Val = String;
|
||||
|
||||
impl From<ir::ExecutionResult<FieldPrime>> for ComparableResult {
|
||||
fn from(r: ir::ExecutionResult<FieldPrime>) -> ComparableResult {
|
||||
ComparableResult(r.map(|v| v.return_values()))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TestResult> for ComparableResult {
|
||||
fn from(r: TestResult) -> ComparableResult {
|
||||
ComparableResult(r.map(|v| {
|
||||
v.values
|
||||
.into_iter()
|
||||
.map(|v| FieldPrime::from_dec_string(v))
|
||||
.collect()
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn compare(
|
||||
result: ir::ExecutionResult<FieldPrime>,
|
||||
expected: TestResult,
|
||||
) -> Result<(), String> {
|
||||
// extract outputs from result
|
||||
let result = ComparableResult::from(result);
|
||||
// deserialize expected result
|
||||
let expected = ComparableResult::from(expected);
|
||||
|
||||
if result != expected {
|
||||
return Err(format!(
|
||||
"Expected {:?} but found {:?}",
|
||||
expected.0, result.0
|
||||
));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn read_file(path: &str) -> String {
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
let mut file = File::open(format!("./tests/bench/{}", path)).expect("Unable to open the file");
|
||||
let mut contents = String::new();
|
||||
file.read_to_string(&mut contents)
|
||||
.expect("Unable to read the file");
|
||||
|
||||
contents
|
||||
}
|
||||
|
||||
pub fn compile(code: &str) -> Result<ir::Prog<FieldPrime>, CompileError<FieldPrime>> {
|
||||
generic_compile::<FieldPrime, &[u8], &[u8], io::Error>(&mut code.as_bytes(), None, None)
|
||||
}
|
||||
|
||||
macro_rules! zokrates_test {
|
||||
($($name:ident,)*) => {
|
||||
$(
|
||||
#[test]
|
||||
fn $name() {
|
||||
|
||||
use zokrates_core::field::{FieldPrime, Field};
|
||||
|
||||
let code_string = $crate::utils::read_file(&format!("./{}.code", stringify!($name)));
|
||||
let test_string = $crate::utils::read_file(&format!("./{}.json", stringify!($name)));
|
||||
|
||||
let bin = $crate::utils::compile(&code_string).unwrap();
|
||||
|
||||
let t: $crate::utils::Tests = serde_json::from_str(&test_string).unwrap();
|
||||
|
||||
for test in t.tests.into_iter() {
|
||||
let input = &test.input.values;
|
||||
let output = bin.execute(&input.iter().map(|v| FieldPrime::from_dec_string(v.clone())).collect());
|
||||
|
||||
let context = format!("
|
||||
{}
|
||||
|
||||
Called with input ({})
|
||||
", code_string, input.iter().map(|i| format!("{}", i)).collect::<Vec<_>>().join(", "));
|
||||
|
||||
match $crate::utils::compare(output, test.output) {
|
||||
Err(e) => panic!("{}{}", context, e),
|
||||
Ok(..) => {}
|
||||
};
|
||||
}
|
||||
}
|
||||
)*
|
||||
};
|
||||
}
|
143
zokrates_field/Cargo.lock
generated
Normal file
143
zokrates_field/Cargo.lock
generated
Normal file
|
@ -0,0 +1,143 @@
|
|||
[[package]]
|
||||
name = "bincode"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "0.1.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "num"
|
||||
version = "0.1.42"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-bigint"
|
||||
version = "0.1.44"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.39"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-iter"
|
||||
version = "0.1.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.1.43"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "0.4.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "0.6.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.82"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.82"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "0.15.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "zokrates_field"
|
||||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"bincode 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-bigint 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[metadata]
|
||||
"checksum bincode 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e103c8b299b28a9c6990458b7013dc4a8356a9b854c51b9883241f5866fac36e"
|
||||
"checksum byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "94f88df23a25417badc922ab0f5716cc1330e87f71ddd9203b3a3ccd9cedf75d"
|
||||
"checksum lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "cf186d1a8aa5f5bee5fd662bc9c1b949e0259e1bcc379d1f006847b0080c7417"
|
||||
"checksum num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e"
|
||||
"checksum num-bigint 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)" = "e63899ad0da84ce718c14936262a41cee2c79c981fc0a0e7c7beb47d5a07e8c1"
|
||||
"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea"
|
||||
"checksum num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "af3fdbbc3291a5464dc57b03860ec37ca6bf915ed6ee385e7c6c052c422b2124"
|
||||
"checksum num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31"
|
||||
"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
|
||||
"checksum proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)" = "77619697826f31a02ae974457af0b29b723e5619e113e9397b8b82c6bd253f09"
|
||||
"checksum quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "53fa22a1994bd0f9372d7a816207d8a2677ad0325b073f5c5332760f0fb62b5c"
|
||||
"checksum serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)" = "6fa52f19aee12441d5ad11c9a00459122bd8f98707cadf9778c540674f1935b6"
|
||||
"checksum serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)" = "96a7f9496ac65a2db5929afa087b54f8fc5008dcfbe48a8874ed20049b0d6154"
|
||||
"checksum syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)" = "9545a6a093a3f0bd59adb472700acc08cad3776f860f16a897dfce8c88721cbc"
|
||||
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
|
|
@ -2,6 +2,7 @@
|
|||
name = "zokrates_field"
|
||||
version = "0.3.0"
|
||||
authors = ["Guillaume Ballet <gballet@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ lazy_static! {
|
|||
|
||||
pub trait Pow<RHS> {
|
||||
type Output;
|
||||
fn pow(self, RHS) -> Self::Output;
|
||||
fn pow(self, _: RHS) -> Self::Output;
|
||||
}
|
||||
|
||||
pub trait Field:
|
||||
|
@ -56,7 +56,7 @@ pub trait Field:
|
|||
/// Returns this `Field`'s contents as little-endian byte vector
|
||||
fn into_byte_vector(&self) -> Vec<u8>;
|
||||
/// Returns an element of this `Field` from a little-endian byte vector
|
||||
fn from_byte_vector(Vec<u8>) -> Self;
|
||||
fn from_byte_vector(_: Vec<u8>) -> Self;
|
||||
/// Returns this `Field`'s contents as decimal string
|
||||
fn to_dec_string(&self) -> String;
|
||||
/// Returns an element of this `Field` from a decimal string
|
||||
|
@ -123,6 +123,14 @@ impl Field for FieldPrime {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for FieldPrime {
|
||||
fn default() -> Self {
|
||||
FieldPrime {
|
||||
value: BigInt::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for FieldPrime {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.value.to_str_radix(10))
|
|
@ -3,6 +3,5 @@ extern crate lazy_static;
|
|||
extern crate num;
|
||||
extern crate num_bigint;
|
||||
extern crate serde;
|
||||
extern crate bincode;
|
||||
|
||||
pub mod field;
|
||||
|
|
Loading…
Reference in a new issue