Skip to content

Commit

Permalink
Merge pull request #669 from Zokrates/rc/0.6.1
Browse files Browse the repository at this point in the history
Release 0.6.1
  • Loading branch information
Schaeff committed Aug 14, 2020
2 parents 549375f + 07051a8 commit b0a0dd2
Show file tree
Hide file tree
Showing 29 changed files with 196 additions and 188 deletions.
2 changes: 1 addition & 1 deletion scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ echo "Published zokrates/zokrates:$TAG"
# Release on Github
git tag -f latest
git tag $TAG
git push origin --delete latest
git push origin -f latest
git push origin $TAG

# Build zokrates js
Expand Down
3 changes: 0 additions & 3 deletions zokrates_book/src/toolbox/zokrates_js.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ const options = {
source: "def main() -> (): return",
location: importLocation
};
},
config: {
is_release: true
}
};
const artifacts = zokratesProvider.compile(source, options);
Expand Down
2 changes: 1 addition & 1 deletion zokrates_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zokrates_cli"
version = "0.6.0"
version = "0.6.1"
authors = ["Jacob Eberhardt <jacob.eberhardt@tu-berlin.de>", "Dennis Kuhnert <mail@kyroy.com>", "Thibaut Schaeffer <thibaut@schaeff.fr>"]
repository = "https://github.com/JacobEberhardt/ZoKrates.git"
edition = "2018"
Expand Down
18 changes: 5 additions & 13 deletions zokrates_cli/src/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::io::{stdin, BufReader, BufWriter, Read, Write};
use std::path::{Path, PathBuf};
use std::string::String;
use zokrates_abi::Encode;
use zokrates_core::compile::{check, compile, CompilationArtifacts, CompileConfig, CompileError};
use zokrates_core::compile::{check, compile, CompilationArtifacts, CompileError};
use zokrates_core::ir::{self, ProgEnum};
use zokrates_core::proof_system::bellman::groth16::G16;
#[cfg(feature = "libsnark")]
Expand Down Expand Up @@ -274,8 +274,6 @@ fn cli_compile<T: Field>(sub_matches: &ArgMatches) -> Result<(), String> {

let hr_output_path = bin_output_path.to_path_buf().with_extension("ztf");

let is_release = sub_matches.occurrences_of("release") > 0;

let file = File::open(path.clone())
.map_err(|why| format!("Couldn't open input file {}: {}", path.display(), why))?;

Expand All @@ -294,11 +292,9 @@ fn cli_compile<T: Field>(sub_matches: &ArgMatches) -> Result<(), String> {
)
};

let compilation_config = CompileConfig::default().with_is_release(is_release);

let resolver = FileSystemResolver::new();
let artifacts: CompilationArtifacts<T> =
compile(source, path, Some(&resolver), &compilation_config).map_err(|e| {
compile(source, path, Some(&resolver)).map_err(|e| {
format!(
"Compilation failed:\n\n{}",
e.0.iter()
Expand Down Expand Up @@ -482,10 +478,6 @@ fn cli() -> Result<(), String> {
.long("light")
.help("Skip logs and human readable output")
.required(false)
).arg(Arg::with_name("release")
.long("release")
.help("Apply release optimisations to minimise constraint count. This increases compilation time.")
.required(false)
)
)
.subcommand(SubCommand::with_name("check")
Expand Down Expand Up @@ -1009,7 +1001,7 @@ mod tests {

let resolver = FileSystemResolver::new();
let _: CompilationArtifacts<Bn128Field> =
compile(source, path, Some(&resolver), &CompileConfig::default()).unwrap();
compile(source, path, Some(&resolver)).unwrap();
}
}

Expand All @@ -1031,7 +1023,7 @@ mod tests {

let resolver = FileSystemResolver::new();
let artifacts: CompilationArtifacts<Bn128Field> =
compile(source, path, Some(&resolver), &CompileConfig::default()).unwrap();
compile(source, path, Some(&resolver)).unwrap();

let interpreter = ir::Interpreter::default();

Expand Down Expand Up @@ -1060,7 +1052,7 @@ mod tests {

let resolver = FileSystemResolver::new();
let artifacts: CompilationArtifacts<Bn128Field> =
compile(source, path, Some(&resolver), &CompileConfig::default()).unwrap();
compile(source, path, Some(&resolver)).unwrap();

let interpreter = ir::Interpreter::default();

Expand Down
1 change: 1 addition & 0 deletions zokrates_cli/tests/code/no_public.arguments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Empty file.
2 changes: 2 additions & 0 deletions zokrates_cli/tests/code/no_public.zok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def main():
return
52 changes: 17 additions & 35 deletions zokrates_cli/tests/contract/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,50 +85,32 @@ let jsonInterface = JSON.parse(solc.compile(jsonContractSource));
}
}

if (abiVersion == "v1") {
if (format == "g16" || format == "gm17") {
return verifyTxG16_GM17_ABIV1(proof, account, correct).on('receipt', handleReceipt)
.catch(handleError);
} else if (format == "pghr13") {
return verifyTxPGHR13_ABIV1(proof, account, correct).on('receipt', handleReceipt)
.catch(handleError);
}
} else {
return verifyTxABIV2(proof, account, correct).on('receipt', handleReceipt)
.catch(handleError);
}
return abiVersion == "v1" ?
verifyTx_ABIV1(proof, account, correct).on('receipt', handleReceipt)
.catch(handleError)
:
verifyTx_ABIV2(proof, account, correct).on('receipt', handleReceipt)
.catch(handleError)
}

function verifyTxABIV2(proof, account, correct) {
contract.methods.verifyTx(proof[0], proof[1]).send({
from: account,
gas: 5000000
})
}
function verifyTx_ABIV2(proof, account, correct) {

function verifyTxG16_GM17_ABIV1(proof, account, correct) {
return contract.methods.verifyTx(
proof[0][0],
proof[0][1],
proof[0][2],
proof[1]
).send({
var arguments = proof[0]
arguments = proof[1].length > 0 ? [arguments[0], proof[1]] : arguments

contract.methods.verifyTx(...arguments).send({
from: account,
gas: 5000000
})
}

function verifyTxPGHR13_ABIV1(proof, account, correct) {
function verifyTx_ABIV1(proof, account, correct) {

var arguments = proof[0]
arguments = proof[1].length > 0 ? [...arguments, proof[1]] : arguments

return contract.methods.verifyTx(
proof[0][0],
proof[0][1],
proof[0][2],
proof[0][3],
proof[0][4],
proof[0][5],
proof[0][6],
proof[0][7],
proof[1]
...arguments
).send({
from: account,
gas: 5000000
Expand Down
9 changes: 6 additions & 3 deletions zokrates_cli/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,14 @@ mod integration {
flattened_path.to_str().unwrap(),
"-o",
inline_witness_path.to_str().unwrap(),
"-a",
];

for arg in &inputs_raw {
compute_inline.push(arg);
if inputs_raw.len() > 0 {
compute_inline.push("-a");

for arg in &inputs_raw {
compute_inline.push(arg);
}
}

assert_cli::Assert::command(&compute_inline)
Expand Down
2 changes: 1 addition & 1 deletion zokrates_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zokrates_core"
version = "0.5.0"
version = "0.5.1"
authors = ["Jacob Eberhardt <jacob.eberhardt@tu-berlin.de>", "Dennis Kuhnert <mail@kyroy.com>"]
repository = "https://github.com/JacobEberhardt/ZoKrates"
readme = "README.md"
Expand Down
22 changes: 1 addition & 21 deletions zokrates_core/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,29 +140,12 @@ impl fmt::Display for CompileErrorInner {
}
}

#[derive(Debug, Default, Serialize, Deserialize)]
pub struct CompileConfig {
is_release: bool,
}

impl CompileConfig {
pub fn with_is_release(mut self, is_release: bool) -> Self {
self.is_release = is_release;
self
}

pub fn is_release(&self) -> bool {
self.is_release
}
}

type FilePath = PathBuf;

pub fn compile<T: Field, E: Into<imports::Error>>(
source: String,
location: FilePath,
resolver: Option<&dyn Resolver<E>>,
config: &CompileConfig,
) -> Result<CompilationArtifacts<T>, CompileErrors> {
let arena = Arena::new();

Expand All @@ -178,7 +161,7 @@ pub fn compile<T: Field, E: Into<imports::Error>>(
let ir_prog = ir::Prog::from(program_flattened);

// optimize
let optimized_ir_prog = ir_prog.optimize(config);
let optimized_ir_prog = ir_prog.optimize();

// analyse (check for unused constraints)
let optimized_ir_prog = optimized_ir_prog.analyse();
Expand Down Expand Up @@ -280,7 +263,6 @@ mod test {
source,
"./path/to/file".into(),
None::<&dyn Resolver<io::Error>>,
&CompileConfig::default(),
);
assert!(res.unwrap_err().0[0]
.value()
Expand All @@ -299,7 +281,6 @@ mod test {
source,
"./path/to/file".into(),
None::<&dyn Resolver<io::Error>>,
&CompileConfig::default(),
);
assert!(res.is_ok());
}
Expand Down Expand Up @@ -380,7 +361,6 @@ struct Bar { field a }
main.to_string(),
"main".into(),
Some(&CustomResolver),
&CompileConfig::default(),
)
.unwrap();

Expand Down
64 changes: 37 additions & 27 deletions zokrates_core/src/ir/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub struct LinComb<T>(pub Vec<(FlatVariable, T)>);

impl<T: Field> PartialEq for LinComb<T> {
fn eq(&self, other: &Self) -> bool {
self.as_canonical() == other.as_canonical()
self.clone().into_canonical() == other.clone().into_canonical()
}
}

Expand Down Expand Up @@ -152,42 +152,51 @@ impl<T: Field> LinComb<T> {
}

impl<T: Field> LinComb<T> {
pub fn as_canonical(&self) -> CanonicalLinComb<T> {
CanonicalLinComb(self.0.clone().into_iter().fold(
BTreeMap::new(),
|mut acc, (val, coeff)| {
// if we're adding 0 times some variable, we can ignore this term
if coeff != T::zero() {
match acc.entry(val) {
Entry::Occupied(o) => {
// if the new value is non zero, update, else remove the term entirely
if o.get().clone() + coeff.clone() != T::zero() {
*o.into_mut() = o.get().clone() + coeff;
} else {
o.remove();
pub fn into_canonical(self) -> CanonicalLinComb<T> {
CanonicalLinComb(
self.0
.into_iter()
.fold(BTreeMap::new(), |mut acc, (val, coeff)| {
// if we're adding 0 times some variable, we can ignore this term
if coeff != T::zero() {
match acc.entry(val) {
Entry::Occupied(o) => {
// if the new value is non zero, update, else remove the term entirely
if o.get().clone() + coeff.clone() != T::zero() {
*o.into_mut() = o.get().clone() + coeff;
} else {
o.remove();
}
}
Entry::Vacant(v) => {
// We checked earlier but let's make sure we're not creating zero-coeff terms
assert!(coeff != T::zero());
v.insert(coeff);
}
}
Entry::Vacant(v) => {
// We checked earlier but let's make sure we're not creating zero-coeff terms
assert!(coeff != T::zero());
v.insert(coeff);
}
}
}

acc
},
))
acc
}),
)
}

pub fn reduce(self) -> Self {
self.into_canonical().into()
}
}

impl<T: Field> QuadComb<T> {
pub fn as_canonical(&self) -> CanonicalQuadComb<T> {
pub fn into_canonical(self) -> CanonicalQuadComb<T> {
CanonicalQuadComb {
left: self.left.as_canonical(),
right: self.right.as_canonical(),
left: self.left.into_canonical(),
right: self.right.into_canonical(),
}
}

pub fn reduce(self) -> Self {
self.into_canonical().into()
}
}

impl<T: Field> fmt::Display for LinComb<T> {
Expand All @@ -197,7 +206,8 @@ impl<T: Field> fmt::Display for LinComb<T> {
false => write!(
f,
"{}",
self.as_canonical()
self.clone()
.into_canonical()
.0
.iter()
.map(|(k, v)| format!("{} * {}", v.to_compact_dec_string(), k))
Expand Down
11 changes: 3 additions & 8 deletions zokrates_core/src/optimizer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,14 @@ use self::directive::DirectiveOptimizer;
use self::duplicate::DuplicateOptimizer;
use self::redefinition::RedefinitionOptimizer;
use self::tautology::TautologyOptimizer;
use compile::CompileConfig;

use crate::ir::Prog;
use zokrates_field::Field;

impl<T: Field> Prog<T> {
pub fn optimize(self, config: &CompileConfig) -> Self {
let r = if config.is_release() {
// remove redefinitions
RedefinitionOptimizer::optimize(self)
} else {
self
};
pub fn optimize(self) -> Self {
// remove redefinitions
let r = RedefinitionOptimizer::optimize(self);
// remove constraints that are always satisfied
let r = TautologyOptimizer::optimize(r);
// // deduplicate directives which take the same input
Expand Down
Loading

0 comments on commit b0a0dd2

Please sign in to comment.