need to change how to input arrays

This commit is contained in:
Edward Chen
2021-11-04 00:49:39 -04:00
parent ec74621ccf
commit 8c0afa7ffc
10 changed files with 117 additions and 45 deletions

View File

@@ -468,6 +468,8 @@ impl<E: Embeddable> Circify<E> {
visibility: Option<PartyId>,
) -> Result<()> {
let ssa_name = self.declare_env_name(name.clone(), ty)?.clone();
println!("SSA_NAME: {}", ssa_name);
println!("NAME: {}", name);
let t = self.e.declare(
&mut self.cir_ctx,
ty,
@@ -475,6 +477,7 @@ impl<E: Embeddable> Circify<E> {
if input { Some(name) } else { None },
visibility,
);
println!("TERM: {:#?}", t);
assert!(self.vals.insert(ssa_name, Val::Term(t)).is_none());
Ok(())
}

View File

@@ -152,7 +152,7 @@ impl CGen {
udef: false,
})
}
(a, b) => Err(format!("Cannot index {} by {}", b, a))
(a, b) => Err(format!("[Array Select] cannot index {} by {}", b, a))
}
}
@@ -165,7 +165,7 @@ impl CGen {
mem.store(i, idx_term, new_val);
Ok(val.clone())
}
(a, b) => Err(format!("Cannot index {} by {}", b, a)),
(a, b) => Err(format!("[Array Store] cannot index {} by {}", b, a)),
}
}
@@ -588,10 +588,11 @@ impl CGen {
for arg in fn_info.args.iter() {
let p = &arg.specifiers[0];
let vis = self.interpret_visibility(&p.node);
let ty = d_type_(arg.specifiers[1..].to_vec());
let base_ty = d_type_(arg.specifiers[1..].to_vec());
let d = &arg.declarator.as_ref().unwrap().node;
let derived_ty = derived_type_(base_ty.unwrap(), d.derived.to_vec());
let name = name_from_decl(d);
let r = self.circ.declare(name.clone(), &ty.unwrap(), true, vis);
let r = self.circ.declare(name.clone(), &derived_ty, true, vis);
self.unwrap(r);
}
self.gen_stmt(fn_info.body.clone());

View File

@@ -388,7 +388,7 @@ pub struct Ct {
values: Option<HashMap<String, Integer>>,
}
fn _idx_name(struct_name: &str, idx: usize) -> String {
fn idx_name(struct_name: &str, idx: usize) -> String {
format!("{}.{}", struct_name, idx)
}
@@ -444,7 +444,33 @@ impl Embeddable for Ct {
),
udef: false,
},
_ => unimplemented!(),
Ty::Array(n, ty) => {
let v: Vec<Self::T> = (0..n.unwrap())
.map(|i| {
self.declare(
ctx,
&*ty,
idx_name(&raw_name, i),
user_name.as_ref().map(|u| idx_name(u, i)),
visibility.clone(),
)
})
.collect();
let mut mem = ctx.mem.borrow_mut();
let id = mem.zero_allocate(n.unwrap(), 32, num_bits(*ty.clone()));
let arr = Self::T {
term: CTermData::CArray(
*ty.clone(),
Some(id),
),
udef: false,
};
for (i, t) in v.iter().enumerate() {
let val = t.term.term(&mem);
mem.store(id, bv_lit(i, 32), val);
}
arr
},
}
}
fn ite(&self, _ctx: &mut CirCtx, cond: Term, t: Self::T, f: Self::T) -> Self::T {

View File

@@ -194,7 +194,6 @@ impl MemVisitor for Replacer {
.to_usize()
.expect("oversize index");
if k_const < a_seq.len() {
println!("return term: {:#?}", a_seq[k_const]);
Some(a_seq[k_const].clone())
} else {
panic!("Oversize index: {}", k_const)

View File

@@ -152,6 +152,7 @@ impl ToABY {
// Initialize Server inputs
self.aby.setup.push("if (role == SERVER) {".to_string());
// TODO: add in gates based on type / number of inputs
for t in server_inputs.iter() {
self.aby
.setup