Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply witness visibility on a parameter level rather than witness level #712

Merged
merged 2 commits into from
Jan 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 19 additions & 23 deletions crates/noirc_evaluator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ impl Evaluator {
);
}
AbiType::Array { length, typ } => {
let witnesses = self.generate_array_witnesses(visibility, length, typ)?;
let witnesses = self.generate_array_witnesses(length, typ)?;
if *visibility == AbiVisibility::Public {
self.public_inputs.extend(witnesses.clone());
}
igen.abi_array(name, Some(def), typ.as_ref(), *length, witnesses);
}
AbiType::Integer { sign: _, width } => {
Expand All @@ -157,17 +160,26 @@ impl Evaluator {
igen.create_new_variable(name.to_owned(), Some(def), obj_type, Some(witness));
}
AbiType::Struct { fields } => {
let mut struct_witnesses: BTreeMap<String, Vec<Witness>> = BTreeMap::new();
let new_fields = btree_map(fields, |(inner_name, value)| {
let new_name = format!("{name}.{inner_name}");
(new_name, value.clone())
});
self.generate_struct_witnesses(&mut struct_witnesses, visibility, &new_fields)?;

let mut struct_witnesses: BTreeMap<String, Vec<Witness>> = BTreeMap::new();
self.generate_struct_witnesses(&mut struct_witnesses, &new_fields)?;
if *visibility == AbiVisibility::Public {
let witnesses: Vec<Witness> =
struct_witnesses.values().flatten().cloned().collect();
self.public_inputs.extend(witnesses);
}
igen.abi_struct(name, Some(def), fields, struct_witnesses);
}
AbiType::String { length } => {
let typ = AbiType::Integer { sign: noirc_abi::Sign::Unsigned, width: 8 };
let witnesses = self.generate_array_witnesses(visibility, length, &typ)?;
let witnesses = self.generate_array_witnesses(length, &typ)?;
if *visibility == AbiVisibility::Public {
self.public_inputs.extend(witnesses.clone());
}
igen.abi_array(name, Some(def), &typ, *length, witnesses);
}
}
Expand All @@ -177,7 +189,6 @@ impl Evaluator {
fn generate_struct_witnesses(
&mut self,
struct_witnesses: &mut BTreeMap<String, Vec<Witness>>,
visibility: &AbiVisibility,
fields: &BTreeMap<String, AbiType>,
) -> Result<(), RuntimeErrorKind> {
for (name, typ) in fields {
Expand All @@ -186,28 +197,18 @@ impl Evaluator {
let witness = self.add_witness_to_cs();
struct_witnesses.insert(name.clone(), vec![witness]);
ssa::acir_gen::range_constraint(witness, *width, self)?;
if *visibility == AbiVisibility::Public {
self.public_inputs.push(witness);
}
}
AbiType::Boolean => {
let witness = self.add_witness_to_cs();
struct_witnesses.insert(name.clone(), vec![witness]);
ssa::acir_gen::range_constraint(witness, 1, self)?;
if *visibility == AbiVisibility::Public {
self.public_inputs.push(witness);
}
}
AbiType::Field => {
let witness = self.add_witness_to_cs();
struct_witnesses.insert(name.clone(), vec![witness]);
if *visibility == AbiVisibility::Public {
self.public_inputs.push(witness);
}
}
AbiType::Array { length, typ } => {
let internal_arr_witnesses =
self.generate_array_witnesses(visibility, length, typ)?;
let internal_arr_witnesses = self.generate_array_witnesses(length, typ)?;
struct_witnesses.insert(name.clone(), internal_arr_witnesses);
}
AbiType::Struct { fields, .. } => {
Expand All @@ -216,12 +217,11 @@ impl Evaluator {
let new_name = format!("{name}.{inner_name}");
new_fields.insert(new_name, value.clone());
}
self.generate_struct_witnesses(struct_witnesses, visibility, &new_fields)?
self.generate_struct_witnesses(struct_witnesses, &new_fields)?
}
AbiType::String { length } => {
let typ = AbiType::Integer { sign: noirc_abi::Sign::Unsigned, width: 8 };
let internal_str_witnesses =
self.generate_array_witnesses(visibility, length, &typ)?;
let internal_str_witnesses = self.generate_array_witnesses(length, &typ)?;
struct_witnesses.insert(name.clone(), internal_str_witnesses);
}
}
Expand All @@ -231,7 +231,6 @@ impl Evaluator {

fn generate_array_witnesses(
&mut self,
visibility: &AbiVisibility,
length: &u64,
typ: &AbiType,
) -> Result<Vec<Witness>, RuntimeErrorKind> {
Expand All @@ -246,9 +245,6 @@ impl Evaluator {
if let Some(ww) = element_width {
ssa::acir_gen::range_constraint(witness, ww, self)?;
}
if *visibility == AbiVisibility::Public {
self.public_inputs.push(witness);
}
}
Ok(witnesses)
}
Expand Down