put behind config flag
This commit is contained in:
parent
db4fcd04d8
commit
ad4717e67f
6 changed files with 68 additions and 24 deletions
|
@ -56,6 +56,10 @@ pub fn subcommand() -> App<'static, 'static> {
|
|||
.long("allow-unconstrained-variables")
|
||||
.help("Allow unconstrained variables by inserting dummy constraints")
|
||||
.required(false)
|
||||
).arg(Arg::with_name("isolate-branches")
|
||||
.long("isolate-branches")
|
||||
.help("Isolate the execution of branches: a panic in a branch only makes the program panic if this branch is being logically executed")
|
||||
.required(false)
|
||||
).arg(Arg::with_name("ztf")
|
||||
.long("ztf")
|
||||
.help("Write human readable output (ztf)")
|
||||
|
@ -124,6 +128,7 @@ fn cli_compile<T: Field>(sub_matches: &ArgMatches) -> Result<(), String> {
|
|||
|
||||
let config = CompileConfig {
|
||||
allow_unconstrained_variables: sub_matches.is_present("allow-unconstrained-variables"),
|
||||
isolate_branches: sub_matches.is_present("isolate-branches"),
|
||||
};
|
||||
|
||||
let resolver = FileSystemResolver::with_stdlib_root(stdlib_path);
|
||||
|
|
|
@ -156,9 +156,10 @@ impl fmt::Display for CompileErrorInner {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
|
||||
pub struct CompileConfig {
|
||||
pub allow_unconstrained_variables: bool,
|
||||
pub isolate_branches: bool,
|
||||
}
|
||||
|
||||
type FilePath = PathBuf;
|
||||
|
|
|
@ -2177,6 +2177,7 @@ impl<'ast, T: Field> Flattener<'ast, T> {
|
|||
ZirStatement::IfElse(condition, consequence, alternative) => {
|
||||
let condition = self.flatten_boolean_expression(statements_flattened, condition);
|
||||
|
||||
if self.config.isolate_branches {
|
||||
let mut consequence_statements = vec![];
|
||||
let mut alternative_statements = vec![];
|
||||
|
||||
|
@ -2196,6 +2197,14 @@ impl<'ast, T: Field> Flattener<'ast, T> {
|
|||
|
||||
statements_flattened.extend(consequence_statements);
|
||||
statements_flattened.extend(alternative_statements);
|
||||
} else {
|
||||
consequence
|
||||
.into_iter()
|
||||
.for_each(|s| self.flatten_statement(statements_flattened, s));
|
||||
alternative
|
||||
.into_iter()
|
||||
.for_each(|s| self.flatten_statement(statements_flattened, s));
|
||||
}
|
||||
}
|
||||
ZirStatement::Definition(assignee, expr) => {
|
||||
// define n variables with n the number of primitive types for v_type
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
{
|
||||
"entry_point": "./tests/tests/panics/panic_isolation.zok",
|
||||
"config": {
|
||||
"allow_unconstrained_variables": false,
|
||||
"isolate_branches": true
|
||||
},
|
||||
"curves": ["Bn128"],
|
||||
"tests": [
|
||||
{
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"entry_point": "./tests/tests/panics/panic_isolation.zok",
|
||||
"config": {
|
||||
"allow_unconstrained_variables": false,
|
||||
"isolate_branches": false
|
||||
},
|
||||
"curves": ["Bn128"],
|
||||
"tests": [
|
||||
{
|
||||
"input": {
|
||||
"values": [
|
||||
"1",
|
||||
"1",
|
||||
"1",
|
||||
"1"
|
||||
]
|
||||
},
|
||||
"output": {
|
||||
"Err": {
|
||||
"UnsatisfiedConstraint": {
|
||||
"left": "1",
|
||||
"right": "0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -23,6 +23,7 @@ struct Tests {
|
|||
pub entry_point: Option<PathBuf>,
|
||||
pub curves: Option<Vec<Curve>>,
|
||||
pub max_constraint_count: Option<usize>,
|
||||
pub config: Option<CompileConfig>,
|
||||
pub tests: Vec<Test>,
|
||||
}
|
||||
|
||||
|
@ -119,18 +120,14 @@ pub fn test_inner(test_path: &str) {
|
|||
fn compile_and_run<T: Field>(t: Tests) {
|
||||
let entry_point = t.entry_point.unwrap();
|
||||
|
||||
let config = t.config.unwrap_or_default();
|
||||
|
||||
let code = std::fs::read_to_string(&entry_point).unwrap();
|
||||
|
||||
let stdlib = std::fs::canonicalize("../zokrates_stdlib/stdlib").unwrap();
|
||||
let resolver = FileSystemResolver::with_stdlib_root(stdlib.to_str().unwrap());
|
||||
|
||||
let artifacts = compile::<T, _>(
|
||||
code,
|
||||
entry_point.clone(),
|
||||
Some(&resolver),
|
||||
&CompileConfig::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let artifacts = compile::<T, _>(code, entry_point.clone(), Some(&resolver), &config).unwrap();
|
||||
|
||||
let bin = artifacts.prog();
|
||||
|
||||
|
|
Loading…
Reference in a new issue