Procházet zdrojové kódy

addressing Ian comments on the code review + a removing a memory bug in the sanity check

avadapal před 11 měsíci
rodič
revize
556dbe07d6
4 změnil soubory, kde provedl 68 přidání a 51 odebrání
  1. 1 1
      Makefile
  2. 13 12
      duoram.hpp
  3. 21 16
      heap.cpp
  4. 33 22
      repro/repro-heap-extract.sh

+ 1 - 1
Makefile

@@ -56,5 +56,5 @@ cell.o: types.hpp bitutils.hpp duoram.hpp mpcio.hpp corotypes.hpp mpcio.tcc
 cell.o: coroutine.hpp duoram.tcc mpcops.hpp mpcops.tcc cdpf.hpp dpf.hpp
 cell.o: prg.hpp aes.hpp cdpf.tcc rdpf.hpp rdpf.tcc cell.hpp options.hpp
 heap.o: heap.hpp types.hpp bitutils.hpp mpcio.hpp corotypes.hpp mpcio.tcc
-heap.o: coroutine.hpp   mpcops.hpp mpcops.tcc cdpf.hpp dpf.hpp
+heap.o: coroutine.hpp duoram.hpp mpcops.hpp mpcops.tcc cdpf.hpp dpf.hpp
 heap.o: prg.hpp aes.hpp cdpf.tcc rdpf.hpp rdpf.tcc

+ 13 - 12
duoram.hpp

@@ -542,21 +542,22 @@ public:
     }
 
 
-    auto unit_vector(MPCTIO &tio, yield_t &yield, size_t nitems, RegXS foundidx)
-    {
-//      std::cout << "unit_vector .... \n";
-      std::vector<RegBS> standard_basis(nitems+1); 
-      if(player < 2)  
+   // The function unit_vector takes in an XOR-share of an index foundindx
+   // The function outputs _boolean shares_ of a standard-basis vector (with the non-zero index at foundindx) 
+   auto unit_vector(MPCTIO &tio, yield_t &yield, size_t nitems, RegXS foundidx)
+   {
+      std::vector<RegBS> standard_basis(nitems); 
+      if(player < 2)
       {
         U indoffset;
         dt->get_target(indoffset);
         indoffset -= foundidx;
         U peerindoffset;
-        tio.queue_peer(&indoffset, 64);
+        tio.queue_peer(&indoffset, BITBYTES(curdepth));
         yield();
-        tio.recv_peer(&peerindoffset, 64);
+        tio.recv_peer(&peerindoffset, BITBYTES(curdepth));
  
-        auto indshift = combine(indoffset, peerindoffset, 64);
+        auto indshift = combine(indoffset, peerindoffset, curdepth);
  
         // std::cout << "nitems = " << nitems << std::endl;
         // std::cout << "indshift = " << indshift << std::endl;
@@ -564,8 +565,8 @@ public:
         for(size_t j = 0; j < nitems; ++j)
         {
           RDPF<1>::LeafNode  leaf = se.next();
-          RegBS leaf_bs_share = dt->dpf[1].unit_bs(leaf);
-          standard_basis[j] = leaf_bs_share;        
+          //RegBS leaf_bs_share = dt->dpf[1].unit_bs(leaf);
+          standard_basis[j] = dt->dpf[1].unit_bs(leaf); // leaf_bs_share
         } 
        }
        else
@@ -574,7 +575,7 @@ public:
        }
        
        return standard_basis;
-    } 
+    }
 
     // Incrementally append a (shared) bit to the oblivious index
     void incr(RegBS bit)
@@ -592,7 +593,7 @@ public:
     // Get a copy of the index
     U index() { return idx; }
 
-    nbits_t depth() {return maxdepth;}
+    nbits_t depth() {return curdepth;}
 
     // Get the next wide-RDPF index
     nbits_t windex() { assert(next_windex < WIDTH); return next_windex++; }

+ 21 - 16
heap.cpp

@@ -156,9 +156,12 @@ int MinHeap::verify_heap_property(MPCTIO tio, yield_t & yield) {
     #endif
     
     auto HeapArray = oram.flat(tio, yield);
-    uint64_t heapreconstruction[num_items];
-    for (size_t j = 0; j <= num_items; ++j) {
+    uint64_t * heapreconstruction = new uint64_t[num_items + 1];
+    for (size_t j = 0; j < num_items; ++j) {
         heapreconstruction[j] = mpc_reconstruct(tio, yield,  HeapArray[j]);
+        //#ifdef VERBOSE
+        if(tio.player() < 2) std::cout << j << " -----> heapreconstruction[" << j << "] = " << heapreconstruction[j] << std::endl;
+        //#endif
     }
     
     for (size_t j = 1; j < num_items / 2; ++j) {
@@ -179,6 +182,9 @@ int MinHeap::verify_heap_property(MPCTIO tio, yield_t & yield) {
         assert(heapreconstruction[j] <= heapreconstruction[2 * j]);
         assert(heapreconstruction[j] <= heapreconstruction[2 * j + 1]);
     }
+
+    delete [] heapreconstruction;
+
     return 1;
 }
 
@@ -584,15 +590,15 @@ void Heap(MPCIO & mpcio,
     
     const PRACOptions & opts, char ** args) {
     // nbits_t depth     = atoi(args[0]);
-    // nbits_t depth2    = atoi(args[1]);
+    // nbits_t heapdepth    = atoi(args[1]);
     // size_t n_inserts  = atoi(args[2]);
     // size_t n_extracts = atoi(args[3]);
     // int is_optimized  = atoi(args[4]);
     // int run_sanity    = atoi(args[5]);
     int argc = 12;
 
-    int depth = 0;
-    int depth2 = 0;
+    int maxdepth = 0;
+    int heapdepth = 0;
     size_t n_inserts = 0;
     size_t n_extracts = 0;
     int is_optimized = 0;
@@ -602,9 +608,9 @@ void Heap(MPCIO & mpcio,
     for (int i = 0; i < argc; i += 2) {
         std::string option = args[i];
         if (option == "-m" && i + 1 < argc) {
-            depth = std::atoi(args[i + 1]);
+            maxdepth = std::atoi(args[i + 1]);
         } else if (option == "-d" && i + 1 < argc) {
-            depth2 = std::atoi(args[i + 1]);
+            heapdepth = std::atoi(args[i + 1]);
         } else if (option == "-i" && i + 1 < argc) {
             n_inserts = std::atoi(args[i + 1]);
         } else if (option == "-e" && i + 1 < argc) {
@@ -617,8 +623,8 @@ void Heap(MPCIO & mpcio,
     }
 
     // Use the values
-    std::cout << "depth: " << depth << std::endl;
-    std::cout << "depth2: " << depth2 << std::endl;
+    std::cout << "maxdepth: " << maxdepth << std::endl;
+    std::cout << "heapdepth: " << heapdepth << std::endl;
     std::cout << "n_inserts: " << n_inserts << std::endl;
     std::cout << "n_extracts: " << n_extracts << std::endl;
     std::cout << "is_optimized: " << is_optimized << std::endl;
@@ -628,8 +634,7 @@ void Heap(MPCIO & mpcio,
     //     depth = atoi( * args);
     //     ++args;
     // }
-    
-     size_t items = (size_t(1) << depth) - 1;
+
     
     // if ( * args) {
     //     items = atoi( * args);
@@ -638,11 +643,11 @@ void Heap(MPCIO & mpcio,
     
     MPCTIO tio(mpcio, 0, opts.num_threads);
     
-    run_coroutines(tio, [ & tio, depth, depth2, items, n_inserts, n_extracts, is_optimized, run_sanity, &mpcio](yield_t & yield) {
-        size_t size = size_t(1) << depth;
+    run_coroutines(tio, [ & tio, maxdepth, heapdepth, n_inserts, n_extracts, is_optimized, run_sanity, &mpcio](yield_t & yield) {
+        size_t size = size_t(1) << maxdepth;
         MinHeap tree(tio.player(), size);
         tree.initialize(tio, yield);
-        tree.num_items = (size_t(1) << depth2) - 1;
+        tree.num_items = (size_t(1) << heapdepth) - 1;
         tree.initialize_heap(tio, yield);
         std::cout << "\n===== Init Stats =====\n";
         tio.sync_lamport();
@@ -668,7 +673,7 @@ void Heap(MPCIO & mpcio,
         tio.sync_lamport();
         mpcio.dump_stats(std::cout);
         
-        if(run_sanity == 1) tree.verify_heap_property(tio, yield);
+        if(run_sanity == 1 && n_inserts != 0) tree.verify_heap_property(tio, yield);
          
         mpcio.reset_stats();
         tio.reset_lamport();
@@ -706,7 +711,7 @@ void Heap(MPCIO & mpcio,
         tree.print_heap(tio, yield);
         #endif
 
-        if(run_sanity == 1) tree.verify_heap_property(tio, yield);
+        if(run_sanity == 1 && n_extracts != 0) tree.verify_heap_property(tio, yield);
     }
     );
 }

+ 33 - 22
repro/repro-heap-extract.sh

@@ -4,10 +4,7 @@
    ./run-experiment heap -m 16 -d 16 -i 0 -e 1 -opt 0 -s 0 > basic_heap_extract_online_16
    echo "preprocessing_heap_16 (basic online)"
  
-   ./run-experiment -p  m:63 a:16 s:15  i15.3:1 c:32 p:128 > opt_heap_extract_preproc_16
-   echo "preprocessing_heap_16 (opt preproc)"
-   
-   ./run-experiment heap -m 16 -d 16 -i 0 -e 1 -opt 1 -s 0 > opt_heap_extract_online_16
+
    echo "preprocessing_heap_16 (opt online)"
 
 
@@ -17,11 +14,7 @@
    ./run-experiment heap -m 18 -d 18 -i 0 -e 1 -opt 0 -s 0 > basic_heap_extract_online_18
    echo "preprocessing_heap_18 (basic online)"
 
-   ./run-experiment -p m:71 a:18 s:17 i17.3:1 c:36 p:128 > opt_heap_extract_preproc_18
-   echo "preprocessing_heap_18 (opt preproc)"
-   
-   ./run-experiment heap -m 18 -d 18 -i 0 -e 1 -opt 1 -s 0 > opt_heap_extract_online_18
-   echo "preprocessing_heap_18 (opt online)"
+
 
    ./run-experiment -p m:80 a:20 s:19 r20:114 c:40 p:128 > basic_heap_extract_preproc_20
    echo "preprocessing_heap_20 (basic preproc)"
@@ -29,10 +22,7 @@
    ./run-experiment -t 16 heap -m 20 -d 20 -i 0 -e 1 -opt 0 -s 0 > basic_heap_extract_online_20
    echo "preprocessing_heap_20 (basic online)"
 
-   ./run-experiment -p m:80 a:20 s:19 i19.3:1 c:40 p:128 > opt_heap_extract_preproc_20
-   echo "preprocessing_heap_20 (opt preproc)"
- 
-   ./run-experiment heap -m 20 -d 20 -i 0 -e 1 -opt 1 -s 0 > opt_heap_extract_online_20
+
    echo "preprocessing_heap_20 (opt online)"
 
    ./run-experiment -p m:87 a:22 s:21 r22:126 c:44 p:128 > basic_heap_extract_preproc_22
@@ -41,10 +31,7 @@
    ./run-experiment -t 16 heap -m 22 -d 22 -i 0 -e 1 -opt 0 -s 0> basic_heap_extract_online_22
    echo "preprocessing_heap_22 (basic online)"
  
-   ./run-experiment -p m:87 a:22 s:21 i21.3:1 c:44 p:128  > opt_heap_extract_preproc_22
-   echo "preprocessing_heap_22 (opt preproc)"
- 
-   ./run-experiment -t 16 heap -m 22 -d 22 -i 0 -e 1 -opt 1 -s 0 > opt_heap_extract_online_22
+
    echo "preprocessing_heap_22 (opt online)"
 
   ./run-experiment -p m:95 a:24 s:23 r24:138 c:48 p:128 > basic_heap_extract_preproc_24
@@ -53,10 +40,7 @@
   ./run-experiment -t 64 heap -m 24 -d 24 -i 0 -e 1 -opt 0 -s 0> basic_heap_extract_online_24
   echo "preprocessing_heap_24 (basic online)"
  
-  ./run-experiment -p m:95 a:24 s:23 i23.3:1 c:48 p:128 > opt_heap_extract_preproc_24
-  echo "preprocessing_heap_24 (opt preproc)"
- 
-  ./run-experiment -t 32 heap -m 24 -d 24 -i 0 -e 1 -opt 1 -s 0 > opt_heap_extract_online_24
+
   echo "preprocessing_heap_24 (opt online)"
 
   ./run-experiment -p m:103 a:26 s:25 r26:150 c:52 p:128 > basic_heap_extract_preproc_26
@@ -65,6 +49,33 @@
   echo "preprocessing_heap_26 (basic online)"
  
   ./run-experiment -p m:103 a:26 s:25 i25.3:1 c:52 p:128 > opt_heap_extract_preproc_26
+
+
+
+   ./run-experiment -p  m:63 a:16 s:15  i15.3:1 c:32 p:128 > opt_heap_extract_preproc_16
+   echo "preprocessing_heap_16 (opt preproc)"
+   
+   ./run-experiment heap -m 16 -d 16 -i 0 -e 1 -opt 1 -s 0 > opt_heap_extract_online_16
+
+
+      ./run-experiment -p m:71 a:18 s:17 i17.3:1 c:36 p:128 > opt_heap_extract_preproc_18
+   echo "preprocessing_heap_18 (opt preproc)"
+   
+   ./run-experiment heap -m 18 -d 18 -i 0 -e 1 -opt 1 -s 0 > opt_heap_extract_online_18
+   echo "preprocessing_heap_18 (opt online)"
+
+      ./run-experiment -p m:80 a:20 s:19 i19.3:1 c:40 p:128 > opt_heap_extract_preproc_20
+   echo "preprocessing_heap_20 (opt preproc)"
+ 
+   ./run-experiment heap -m 20 -d 20 -i 0 -e 1 -opt 1 -s 0 > opt_heap_extract_online_20
+   ./run-experiment -p m:87 a:22 s:21 i21.3:1 c:44 p:128  > opt_heap_extract_preproc_22
+   echo "preprocessing_heap_22 (opt preproc)"
+ 
+   ./run-experiment -t 16 heap -m 22 -d 22 -i 0 -e 1 -opt 1 -s 0 > opt_heap_extract_online_22
+  ./run-experiment -p m:95 a:24 s:23 i23.3:1 c:48 p:128 > opt_heap_extract_preproc_24
+  echo "preprocessing_heap_24 (opt preproc)"
+ 
+  ./run-experiment -t 32 heap -m 24 -d 24 -i 0 -e 1 -opt 1 -s 0 > opt_heap_extract_online_24
   echo "preprocessing_heap_26 (opt preproc)"
  ./run-experiment -t 64 heap -m 26 -d 26 -i 0 -e 1 -opt 1 -s 0 > opt_heap_extract_online_26
-  echo "preprocessing_heap_26 (opt online)"
+  echo "preprocessing_heap_26 (opt online)"