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

fix: compute witness when println evaluated before input #891

Merged
merged 3 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions crates/nargo/tests/test_data/strings/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ fn main(message : pub str<11>, y : Field, hex_as_string : str<4>, hex_as_field :

let hash = std::hash::pedersen([x]);
std::println(hash);

let mimc_hash = std::hash::mimc_bn254(array);
std::println(mimc_hash);

constrain hex_as_string == "0x41";
// constrain hex_as_string != 0x41; This will fail with a type mismatch between str[4] and Field
Expand Down
25 changes: 16 additions & 9 deletions crates/noirc_evaluator/src/ssa/acir_gen/operations/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,18 +289,25 @@ fn evaluate_println(
log_string = format_field_string(field);
}
None => {
let var = var_cache.get(&node_id).unwrap_or_else(|| {
panic!(
"invalid input for print statement: {:?}",
ctx.try_get_node(node_id).expect("node is missing from SSA")
)
});
let mut var = var_cache
.get(&node_id)
.unwrap_or_else(|| {
panic!(
"invalid input for print statement: {:?}",
ctx.try_get_node(node_id).expect("node is missing from SSA")
)
})
.clone();
if let Some(field) = var.to_const() {
log_string = format_field_string(field);
} else if let Some(w) = var.cached_witness() {
log_witnesses.push(*w);
} else if let Some(w) = var.get_or_compute_witness(evaluator, false) {
// We check whether there has already been a cached witness for this node. If not, we generate a new witness and include it in the logs
// TODO we need a witness because of the directive, but we should use an expression
log_witnesses.push(w);
} else {
unreachable!("array element to be logged is missing a witness");
unreachable!(
"a witness should have been computed for the non-constant expression"
);
}
}
},
Expand Down