@@ -425,89 +425,15 @@ impl<'a> Context<'a> {
425425 Instruction :: Constrain ( lhs, rhs, assert_message) => {
426426 let lhs = self . convert_numeric_value ( * lhs, dfg) ?;
427427 let rhs = self . convert_numeric_value ( * rhs, dfg) ?;
428-
429- let assert_payload = if let Some ( error) = assert_message {
430- match error {
431- ConstrainError :: StaticString ( string) => Some (
432- self . acir_context . generate_assertion_message_payload ( string. clone ( ) ) ,
433- ) ,
434- ConstrainError :: Dynamic ( error_selector, is_string_type, values) => {
435- if let Some ( constant_string) = try_to_extract_string_from_error_payload (
436- * is_string_type,
437- values,
438- dfg,
439- ) {
440- Some (
441- self . acir_context
442- . generate_assertion_message_payload ( constant_string) ,
443- )
444- } else {
445- let acir_vars: Vec < _ > = values
446- . iter ( )
447- . map ( |value| self . convert_value ( * value, dfg) )
448- . collect ( ) ;
449-
450- let expressions_or_memory =
451- self . acir_context . vars_to_expressions_or_memory ( & acir_vars) ?;
452-
453- Some ( AssertionPayload {
454- error_selector : error_selector. as_u64 ( ) ,
455- payload : expressions_or_memory,
456- } )
457- }
458- }
459- }
460- } else {
461- None
462- } ;
463-
428+ let assert_payload = self . convert_constrain_error ( dfg, assert_message) ?;
464429 self . acir_context . assert_eq_var ( lhs, rhs, assert_payload) ?;
465430 }
466431 Instruction :: ConstrainNotEqual ( lhs, rhs, assert_message) => {
467432 let lhs = self . convert_numeric_value ( * lhs, dfg) ?;
468433 let rhs = self . convert_numeric_value ( * rhs, dfg) ?;
469-
470- let assert_payload = if let Some ( error) = assert_message {
471- match error {
472- ConstrainError :: StaticString ( string) => Some (
473- self . acir_context . generate_assertion_message_payload ( string. clone ( ) ) ,
474- ) ,
475- ConstrainError :: Dynamic ( error_selector, is_string_type, values) => {
476- if let Some ( constant_string) = try_to_extract_string_from_error_payload (
477- * is_string_type,
478- values,
479- dfg,
480- ) {
481- Some (
482- self . acir_context
483- . generate_assertion_message_payload ( constant_string) ,
484- )
485- } else {
486- let acir_vars: Vec < _ > = values
487- . iter ( )
488- . map ( |value| self . convert_value ( * value, dfg) )
489- . collect ( ) ;
490-
491- let expressions_or_memory =
492- self . acir_context . vars_to_expressions_or_memory ( & acir_vars) ?;
493-
494- Some ( AssertionPayload {
495- error_selector : error_selector. as_u64 ( ) ,
496- payload : expressions_or_memory,
497- } )
498- }
499- }
500- }
501- } else {
502- None
503- } ;
504-
505- self . acir_context . assert_neq_var (
506- lhs,
507- rhs,
508- self . current_side_effects_enabled_var ,
509- assert_payload,
510- ) ?;
434+ let assert_payload = self . convert_constrain_error ( dfg, assert_message) ?;
435+ let predicate = self . current_side_effects_enabled_var ;
436+ self . acir_context . assert_neq_var ( lhs, rhs, predicate, assert_payload) ?;
511437 }
512438 Instruction :: Cast ( value_id, _) => {
513439 let acir_var = self . convert_numeric_value ( * value_id, dfg) ?;
@@ -579,6 +505,39 @@ impl<'a> Context<'a> {
579505 Ok ( warnings)
580506 }
581507
508+ /// Converts an optional constrain error message into an ACIR assertion payload
509+ fn convert_constrain_error (
510+ & mut self ,
511+ dfg : & DataFlowGraph ,
512+ assert_message : & Option < ConstrainError > ,
513+ ) -> Result < Option < AssertionPayload < FieldElement > > , RuntimeError > {
514+ let Some ( error) = assert_message else {
515+ return Ok ( None ) ;
516+ } ;
517+
518+ let assert_payload = match error {
519+ ConstrainError :: StaticString ( string) => {
520+ self . acir_context . generate_assertion_message_payload ( string. clone ( ) )
521+ }
522+ ConstrainError :: Dynamic ( error_selector, is_string_type, values) => {
523+ if let Some ( constant_string) =
524+ try_to_extract_string_from_error_payload ( * is_string_type, values, dfg)
525+ {
526+ self . acir_context . generate_assertion_message_payload ( constant_string)
527+ } else {
528+ let acir_vars: Vec < _ > = vecmap ( values, |value| self . convert_value ( * value, dfg) ) ;
529+
530+ let expressions_or_memory =
531+ self . acir_context . vars_to_expressions_or_memory ( & acir_vars) ?;
532+
533+ let error_selector = error_selector. as_u64 ( ) ;
534+ AssertionPayload { error_selector, payload : expressions_or_memory }
535+ }
536+ }
537+ } ;
538+ Ok ( Some ( assert_payload) )
539+ }
540+
582541 /// Remember the result of an instruction returning a single value
583542 fn define_result (
584543 & mut self ,
0 commit comments