bugfix: type error in obliv (#203)

This commit is contained in:
Alex Ozdemir
2024-07-01 15:09:41 -07:00
committed by GitHub
parent 347926501f
commit 1224730215
3 changed files with 42 additions and 13 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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
}
@@ -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)
}