@@ -431,6 +431,7 @@ var add32_json = {
431
431
* @returns {number[] } Computed bit vector output
432
432
*/
433
433
function protocolPureEndToEnd ( circuit , inputs , chan , a , gg ) {
434
+
434
435
// Split inputs into two halves (to be divided
435
436
// between garbler and evaluator agents).
436
437
var bs = [ ] ;
@@ -529,61 +530,83 @@ describe('end-to-end', function() {
529
530
'compare-eq-zero-64-bit' : function ( a ) { return a . orBits ( ) . not ( ) ; }
530
531
}
531
532
533
+ // Check for command-line arguments.
534
+ var trials = 1 ;
535
+ var filename_only = "*" ;
536
+ if ( process . argv . length === 5 || process . argv . length === 7 ) {
537
+ for ( var i = 3 ; i <= 5 ; i += 2 )
538
+ if ( process . argv [ i ] === '--trials' )
539
+ trials = parseInt ( process . argv [ i + 1 ] ) ;
540
+ for ( var i = 3 ; i <= 5 ; i += 2 )
541
+ if ( process . argv [ i ] === '--circuit' )
542
+ filename_only = process . argv [ i + 1 ] ;
543
+ console . log ( filename_only ) ;
544
+ }
545
+
532
546
// Test each circuit.
533
547
for ( let i = 0 ; i < filenames . length ; i ++ ) {
534
- it ( filenames [ i ] , async function ( ) {
535
- this . timeout ( 4 * 60 * 1000 ) ; // Necessary for larger circuits.
536
-
537
- // Create the simulated communications channel.
538
- var chan = new channel . ChannelSimulated ( ) ;
539
-
540
- // Load circuit file and perform end-to-end test.
541
- let raw = await fs . readFile ( './circuits/bristol/' + filenames [ i ] + '.txt' , 'utf8' ) ;
542
- let c = circuit . fromBristolFashion ( raw ) ;
543
-
544
- var inputs = [ ] ;
545
- for ( var j = 0 ; j < c . value_in_count ; j ++ ) {
546
- inputs . push ( bits . random ( c . value_in_length [ j ] , i + j + 1 ) ) ;
547
- }
548
- let outEval = c . evaluate ( inputs ) ;
549
-
550
- // Load precomputed data if it is available.
551
- let a = null , gg = null ;
552
- try {
553
- let aString = await fs . readFile ( './circuits/gg/' + filenames [ i ] + '.assignment.json' , 'utf8' ) ;
554
- let ggString = await fs . readFile ( './circuits/gg/' + filenames [ i ] + '.gg.json' , 'utf8' ) ;
555
- a = assignment . Assignment . prototype . fromJSONString ( aString ) ;
556
- gg = gate . GatesGarbled . prototype . fromJSONString ( ggString ) ;
557
- } catch ( err ) { }
558
-
559
- let outEtoE = protocolPureEndToEnd ( c , inputs , chan , a , gg ) ;
560
-
561
- // Confirm that the circuit is mathematically correct if a
562
- // reference function for the circuit is provided.
563
- if ( filenames [ i ] in functions ) {
564
- let outRef = functions [ filenames [ i ] ] ( ...inputs ) ;
565
- expect ( outEval . toString ( ) ) . to . eql ( outRef . toString ( ) ) ;
566
- }
567
-
568
- // Do the evaluation and end-to-end protocol output bit vectors match?
569
- expect ( outEval . toString ( ) ) . to . eql ( outEtoE . toString ( ) ) ;
570
548
571
- // Confirm that communicated messages conform to schemas.
572
- let gatesGarbledSchemaString = await fs . readFile ( './schemas/gates.garbled.schema.json' , 'utf8' ) ;
573
- let gatesGarbledSchema = JSON . parse ( gatesGarbledSchemaString ) ;
574
- expect ( JSON . parse ( chan . direct [ 'gatesGarbled' ] ) ) . to . be . jsonSchema ( gatesGarbledSchema ) ;
575
-
576
- let assignmentSchemaString = await fs . readFile ( './schemas/assignment.schema.json' , 'utf8' ) ;
577
- let assignmentSchema = JSON . parse ( assignmentSchemaString ) ;
578
- expect ( JSON . parse ( chan . direct [ 'outputWireToLabels' ] ) ) . to . be . jsonSchema ( assignmentSchema ) ;
579
-
580
- let labelSchemaString = await fs . readFile ( './schemas/label.schema.json' , 'utf8' ) ;
581
- let labelSchema = JSON . parse ( labelSchemaString ) ;
582
- for ( var key in chan . direct ) {
583
- if ( key . startsWith ( "wire[" ) ) {
584
- expect ( JSON . parse ( chan . direct [ key ] ) ) . to . be . jsonSchema ( labelSchema ) ;
585
- }
586
- }
587
- } ) ;
588
- }
549
+ // Only test the specified circuit if a user specified one.
550
+ console . log ( filenames [ i ] , filename_only === filenames [ i ] ) ;
551
+ if ( filename_only === "*" || filename_only === filenames [ i ] ) {
552
+
553
+ // Test the circuit on each input.
554
+ for ( let trial = 0 ; trial < trials ; trial ++ ) {
555
+ it ( filenames [ i ] , async function ( ) {
556
+ this . timeout ( 4 * 60 * 1000 ) ; // Necessary for larger circuits.
557
+
558
+ // Create the simulated communications channel.
559
+ var chan = new channel . ChannelSimulated ( ) ;
560
+
561
+ // Load circuit file and perform end-to-end test.
562
+ let raw = await fs . readFile ( './circuits/bristol/' + filenames [ i ] + '.txt' , 'utf8' ) ;
563
+ let c = circuit . fromBristolFashion ( raw ) ;
564
+
565
+ var inputs = [ ] ;
566
+ for ( var j = 0 ; j < c . value_in_count ; j ++ ) {
567
+ inputs . push ( bits . random ( c . value_in_length [ j ] , 1 + trial + j ) ) ;
568
+ }
569
+ let outEval = c . evaluate ( inputs ) ;
570
+
571
+ // Load precomputed data if it is available.
572
+ let a = null , gg = null ;
573
+ try {
574
+ let aString = await fs . readFile ( './circuits/gg/' + filenames [ i ] + '.assignment.json' , 'utf8' ) ;
575
+ let ggString = await fs . readFile ( './circuits/gg/' + filenames [ i ] + '.gg.json' , 'utf8' ) ;
576
+ a = assignment . Assignment . prototype . fromJSONString ( aString ) ;
577
+ gg = gate . GatesGarbled . prototype . fromJSONString ( ggString ) ;
578
+ } catch ( err ) { }
579
+
580
+ let outEtoE = protocolPureEndToEnd ( c , inputs , chan , a , gg ) ;
581
+
582
+ // Confirm that the circuit is mathematically correct if a
583
+ // reference function for the circuit is provided.
584
+ if ( filenames [ i ] in functions ) {
585
+ let outRef = functions [ filenames [ i ] ] ( ...inputs ) ;
586
+ expect ( outEval . toString ( ) ) . to . eql ( outRef . toString ( ) ) ;
587
+ }
588
+
589
+ // Do the evaluation and end-to-end protocol output bit vectors match?
590
+ expect ( outEval . toString ( ) ) . to . eql ( outEtoE . toString ( ) ) ;
591
+
592
+ // Confirm that communicated messages conform to schemas.
593
+ let gatesGarbledSchemaString = await fs . readFile ( './schemas/gates.garbled.schema.json' , 'utf8' ) ;
594
+ let gatesGarbledSchema = JSON . parse ( gatesGarbledSchemaString ) ;
595
+ expect ( JSON . parse ( chan . direct [ 'gatesGarbled' ] ) ) . to . be . jsonSchema ( gatesGarbledSchema ) ;
596
+
597
+ let assignmentSchemaString = await fs . readFile ( './schemas/assignment.schema.json' , 'utf8' ) ;
598
+ let assignmentSchema = JSON . parse ( assignmentSchemaString ) ;
599
+ expect ( JSON . parse ( chan . direct [ 'outputWireToLabels' ] ) ) . to . be . jsonSchema ( assignmentSchema ) ;
600
+
601
+ let labelSchemaString = await fs . readFile ( './schemas/label.schema.json' , 'utf8' ) ;
602
+ let labelSchema = JSON . parse ( labelSchemaString ) ;
603
+ for ( var key in chan . direct ) {
604
+ if ( key . startsWith ( "wire[" ) ) {
605
+ expect ( JSON . parse ( chan . direct [ key ] ) ) . to . be . jsonSchema ( labelSchema ) ;
606
+ }
607
+ }
608
+ } ) ; // it()
609
+ } // for each trial
610
+ } // if a specified circuit
611
+ } // for each circuit
589
612
} ) ;
0 commit comments