diff --git a/crates/noirc_evaluator/src/ssa_refactor/ir/instruction/call.rs b/crates/noirc_evaluator/src/ssa_refactor/ir/instruction/call.rs index f12c16065a7..5892d7e272b 100644 --- a/crates/noirc_evaluator/src/ssa_refactor/ir/instruction/call.rs +++ b/crates/noirc_evaluator/src/ssa_refactor/ir/instruction/call.rs @@ -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 = to_u8_vec(dfg, input); let num_bytes = num_bytes.to_u128() as usize; @@ -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 = to_u8_vec(dfg, input); let field = acvm::blackbox_solver::hash_to_field_128_security(&input_bytes) @@ -266,13 +266,17 @@ fn to_u8_vec(dfg: &DataFlowGraph, values: im::Vector>) -> Vec { .collect() } +fn array_is_constant(dfg: &DataFlowGraph, values: &im::Vector>) -> 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 = to_u8_vec(dfg, input); let hash = hash_function(&input_bytes) @@ -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");