Skip to content

Commit

Permalink
bugfix: type error in obliv (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-ozdemir authored Jul 1, 2024
1 parent 3479265 commit 1224730
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
2 changes: 1 addition & 1 deletion driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def doc(features):
set of features required
"""

cmd = ["cargo", "doc", "--document-private-items"]
cmd = ["cargo", "doc", "--document-private-items", "--no-deps"]
if features:
cmd = cmd + ["--features"] + [",".join(features)]
log_run_check(cmd)
Expand Down
19 changes: 19 additions & 0 deletions examples/ZoKrates/pf/2024_07_01_chad_bug_wit.zok
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// TEST_FILE
// FEATURES: r1cs poly
// CMD: $circ $file r1cs --proof-impl mirage --action count
def unsafe_baz<M>(field input) -> field[M]:
return [input; M]

def foo<M>(field input) -> field[M]:
unsafe witness field[M] inputs = unsafe_baz::<M>(input)
assert(inputs[0] == input)
return inputs

def bar<N,M>(field[N][M] input) -> field[M]:
return foo::<M>(input[0][0])

def main(field[8] a) -> bool:
field[8] x = bar::<2,8>([a, a])
field[8] y = bar::<2,8>([x, a])
//field[8] y = foo::<8>(x[0])
return true
34 changes: 22 additions & 12 deletions src/ir/opt/mem/obliv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,14 @@ impl OblivRewriter {
(
if let Some(aa) = self.tups.get(a) {
if suitable_const(i) {
trace!("simplify store at {}", i);
Some(term![Op::Update(get_const(i)); aa.clone(), self.get_t(v).clone()])
if matches!(check(aa), Sort::Tuple(..)) {
trace!("simplify store at {}", i);
Some(
term![Op::Update(get_const(i)); aa.clone(), self.get_t(v).clone()],
)
} else {
None
}
} else {
None
}
Expand All @@ -99,16 +105,20 @@ impl OblivRewriter {
let i = &t.cs()[1];
if let Some(aa) = self.tups.get(a) {
if suitable_const(i) {
trace!("simplify select at {}", i);
let tt = term![Op::Field(get_const(i)); aa.clone()];
(
Some(tt.clone()),
if check(&tt).is_scalar() {
Some(tt)
} else {
None
},
)
if matches!(check(aa), Sort::Tuple(..)) {
trace!("simplify select at {}", i);
let tt = term![Op::Field(get_const(i)); aa.clone()];
(
Some(tt.clone()),
if check(&tt).is_scalar() {
Some(tt)
} else {
None
},
)
} else {
(None, None)
}
} else {
(None, None)
}
Expand Down

0 comments on commit 1224730

Please sign in to comment.