Skip to content

Commit

Permalink
feat: add support for reading boolean arrays from toml (#900)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored Feb 23, 2023
1 parent f729a00 commit 93d83bf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/nargo/tests/test_data/main_bool_arg/Prover.toml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
x = true
y = [true, false]
4 changes: 3 additions & 1 deletion crates/nargo/tests/test_data/main_bool_arg/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
fn main(x : bool) {
fn main(x : bool, y: [bool;2]) {
if x {
constrain 1 != 2;
}

constrain x;
constrain y[0] != y[1];
}
14 changes: 14 additions & 0 deletions crates/noirc_abi/src/input_parser/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ enum TomlTypes {
ArrayNum(Vec<u64>),
// Array of hexadecimal integers
ArrayString(Vec<String>),
// Array of booleans
ArrayBool(Vec<bool>),
// Struct of TomlTypes
Table(BTreeMap<String, TomlTypes>),
}
Expand Down Expand Up @@ -122,6 +124,18 @@ impl InputValue {

InputValue::Vec(array_elements)
}
TomlTypes::ArrayBool(arr_bool) => {
let array_elements = vecmap(arr_bool, |elem_bool| {
if elem_bool {
FieldElement::one()
} else {
FieldElement::zero()
}
});

InputValue::Vec(array_elements)
}

TomlTypes::Table(table) => {
let fields = match param_type {
AbiType::Struct { fields } => fields,
Expand Down

0 comments on commit 93d83bf

Please sign in to comment.