@@ -363,7 +363,8 @@ impl DependencyContext {
363
363
}
364
364
365
365
// Start tracking calls when their argument value ids first appear,
366
- // or when their instruction id comes up
366
+ // or when their instruction id comes up (in case there were
367
+ // no non-constant arguments)
367
368
for argument in & arguments {
368
369
if let Some ( calls) = self . call_arguments . get ( argument) {
369
370
for call in calls {
@@ -530,34 +531,41 @@ impl DependencyContext {
530
531
531
532
/// Update sets of value ids that can be traced back to the Brillig calls being tracked
532
533
fn update_children ( & mut self , parents : & [ ValueId ] , children : & [ ValueId ] ) {
533
- let mut parents: HashSet < _ > = HashSet :: from_iter ( parents. iter ( ) . copied ( ) ) ;
534
+ // Don't update sets for the calls not yet being tracked
535
+ let mut tracked =
536
+ self . tainted . iter_mut ( ) . filter ( |( _, tainted_ids) | tainted_ids. tracking ) . peekable ( ) ;
537
+ if tracked. peek ( ) . is_some ( ) {
538
+ let mut parents: HashSet < _ > = HashSet :: from_iter ( parents. iter ( ) . copied ( ) ) ;
534
539
535
- // Also include the current EnableSideEffectsIf condition in parents
536
- // (as it would affect every following statement)
537
- self . side_effects_condition . map ( |v| parents. insert ( v) ) ;
540
+ // Also include the current EnableSideEffectsIf condition in parents
541
+ // (as it would affect every following statement)
542
+ self . side_effects_condition . map ( |v| parents. insert ( v) ) ;
538
543
539
- for ( _, tainted_ids) in self . tainted . iter_mut ( ) {
540
- // Don't update sets for the calls not yet being tracked
541
- if tainted_ids. tracking {
544
+ tracked. for_each ( |( _, tainted_ids) | {
542
545
tainted_ids. update_children ( & parents, children) ;
543
- }
546
+ } ) ;
544
547
}
545
548
}
546
549
547
550
/// Check if any of the recorded Brillig calls have been properly constrained
548
551
/// by given values after recording partial constraints, if so stop tracking them
549
552
fn clear_constrained ( & mut self , constrained_values : & [ ValueId ] , function : & Function ) {
550
- // Remove numeric constants
551
- let constrained_values: HashSet < _ > = constrained_values
552
- . iter ( )
553
- . filter ( |v| function. dfg . get_numeric_constant ( * * v) . is_none ( ) )
554
- . copied ( )
555
- . collect ( ) ;
556
-
557
- self . tainted . iter_mut ( ) . for_each ( |( _, tainted_ids) | {
558
- tainted_ids. store_partial_constraints ( & constrained_values) ;
559
- } ) ;
560
- self . tainted . retain ( |_, tainted_ids| !tainted_ids. check_constrained ( ) ) ;
553
+ // Skip untracked calls
554
+ let mut tracked =
555
+ self . tainted . iter_mut ( ) . filter ( |( _, tainted_ids) | tainted_ids. tracking ) . peekable ( ) ;
556
+ if tracked. peek ( ) . is_some ( ) {
557
+ // Remove numeric constants
558
+ let constrained_values: HashSet < _ > = constrained_values
559
+ . iter ( )
560
+ . filter ( |v| function. dfg . get_numeric_constant ( * * v) . is_none ( ) )
561
+ . copied ( )
562
+ . collect ( ) ;
563
+
564
+ tracked. for_each ( |( _, tainted_ids) | {
565
+ tainted_ids. store_partial_constraints ( & constrained_values) ;
566
+ } ) ;
567
+ self . tainted . retain ( |_, tainted_ids| !tainted_ids. check_constrained ( ) ) ;
568
+ }
561
569
}
562
570
563
571
/// Process ArrayGet instruction for tracked Brillig calls
@@ -570,12 +578,17 @@ impl DependencyContext {
570
578
) {
571
579
use acvm:: acir:: AcirField ;
572
580
573
- // Only allow numeric constant indices
574
- if let Some ( value) = function. dfg . get_numeric_constant ( index) {
575
- if let Some ( index) = value. try_to_u32 ( ) {
576
- self . tainted . iter_mut ( ) . for_each ( |( _, tainted_ids) | {
577
- tainted_ids. process_array_get ( array, index as usize , element_results) ;
578
- } ) ;
581
+ // Skip untracked calls
582
+ let mut tracked =
583
+ self . tainted . iter_mut ( ) . filter ( |( _, tainted_ids) | tainted_ids. tracking ) . peekable ( ) ;
584
+ if tracked. peek ( ) . is_some ( ) {
585
+ // Only allow numeric constant indices
586
+ if let Some ( value) = function. dfg . get_numeric_constant ( index) {
587
+ if let Some ( index) = value. try_to_u32 ( ) {
588
+ tracked. for_each ( |( _, tainted_ids) | {
589
+ tainted_ids. process_array_get ( array, index as usize , element_results) ;
590
+ } ) ;
591
+ }
579
592
}
580
593
}
581
594
}
0 commit comments