Skip to content

Commit

Permalink
fix: re-add array_is_constant
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Aug 2, 2023
1 parent 23f05fe commit 218448e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions crates/noirc_evaluator/src/ssa_refactor/ir/instruction/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn simplify_bb_func(
BlackBoxFunc::Blake2s => simplify_hash(dfg, arguments, acvm::blackbox_solver::blake2s),
BlackBoxFunc::Keccak256 => {
match (dfg.get_array_constant(arguments[0]), dfg.get_numeric_constant(arguments[1])) {
(Some((input, _)), Some(num_bytes)) => {
(Some((input, _)), Some(num_bytes)) if array_is_constant(dfg, &input) => {
let input_bytes: Vec<u8> = to_u8_vec(dfg, input);

let num_bytes = num_bytes.to_u128() as usize;
Expand All @@ -185,7 +185,7 @@ fn simplify_bb_func(
}
}
BlackBoxFunc::HashToField128Security => match dfg.get_array_constant(arguments[0]) {
Some((input, _)) => {
Some((input, _)) if array_is_constant(dfg, &input) => {
let input_bytes: Vec<u8> = to_u8_vec(dfg, input);

let field = acvm::blackbox_solver::hash_to_field_128_security(&input_bytes)
Expand Down Expand Up @@ -266,13 +266,17 @@ fn to_u8_vec(dfg: &DataFlowGraph, values: im::Vector<Id<Value>>) -> Vec<u8> {
.collect()
}

fn array_is_constant(dfg: &DataFlowGraph, values: &im::Vector<Id<Value>>) -> bool {
values.iter().all(|value| dfg.get_numeric_constant(*value).is_some())
}

fn simplify_hash(
dfg: &mut DataFlowGraph,
arguments: &[ValueId],
hash_function: fn(&[u8]) -> Result<[u8; 32], BlackBoxResolutionError>,
) -> SimplifyResult {
match dfg.get_array_constant(arguments[0]) {
Some((input, _)) => {
Some((input, _)) if array_is_constant(dfg, &input) => {
let input_bytes: Vec<u8> = to_u8_vec(dfg, input);

let hash = hash_function(&input_bytes)
Expand Down Expand Up @@ -309,7 +313,11 @@ fn simplify_signature(
Some((public_key_y, _)),
Some((signature, _)),
Some((hashed_message, _)),
) => {
) if array_is_constant(dfg, &public_key_x)
&& array_is_constant(dfg, &public_key_y)
&& array_is_constant(dfg, &signature)
&& array_is_constant(dfg, &hashed_message) =>
{
let public_key_x: [u8; 32] = to_u8_vec(dfg, public_key_x)
.try_into()
.expect("ECDSA public key fields are 32 bytes");
Expand Down

0 comments on commit 218448e

Please sign in to comment.