Переглянути джерело

Don't separately account for halftriples that are created as a byproduct of RDPF creation

Ian Goldberg 1 рік тому
батько
коміт
3565cedf03
5 змінених файлів з 29 додано та 15 видалено
  1. 7 2
      mpcio.cpp
  2. 1 1
      mpcio.hpp
  3. 12 7
      mpcops.cpp
  4. 8 4
      mpcops.hpp
  5. 1 1
      rdpf.cpp

+ 7 - 2
mpcio.cpp

@@ -604,7 +604,10 @@ MultTriple MPCTIO::triple(yield_t &yield)
     return val;
 }
 
-HalfTriple MPCTIO::halftriple(yield_t &yield)
+// When halftriple() is used internally to another preprocessing
+// operation, don't tally it, so that it doesn't appear sepearately in
+// the stats from the preprocessing operation that invoked it
+HalfTriple MPCTIO::halftriple(yield_t &yield, bool tally)
 {
     HalfTriple val;
     if (mpcio.player < 2) {
@@ -612,7 +615,9 @@ HalfTriple MPCTIO::halftriple(yield_t &yield)
         if (mpcpio.mode != MODE_ONLINE) {
             yield();
             recv_server(&val, sizeof(val));
-            mpcpio.halftriples[thread_num].inc();
+            if (tally) {
+                mpcpio.halftriples[thread_num].inc();
+            }
         } else {
             mpcpio.halftriples[thread_num].get(val);
         }

+ 1 - 1
mpcio.hpp

@@ -362,7 +362,7 @@ public:
     // preprocessing phase, read them from the server.
 
     MultTriple triple(yield_t &yield);
-    HalfTriple halftriple(yield_t &yield);
+    HalfTriple halftriple(yield_t &yield, bool tally=true);
     SelectTriple selecttriple(yield_t &yield);
 
     // These ones only work during the online phase

+ 12 - 7
mpcops.cpp

@@ -54,18 +54,20 @@ void mpc_cross(MPCTIO &tio, yield_t &yield,
 // P0 holds the (complete) value x, P1 holds the (complete) value y;
 // compute additive shares of z = x*y.  x, y, and z are each at most
 // nbits bits long.  The parameter is called x, but P1 will pass y
-// there.
+// there.  When called by another task during preprocessing, set tally
+// to false so that the required halftriples aren't accounted for
+// separately from the main preprocessing task.
 //
 // Cost:
 // 1 word sent in 1 message
 // consumes 1 HalfTriple
 void mpc_valuemul(MPCTIO &tio, yield_t &yield,
     RegAS &z, value_t x,
-    nbits_t nbits)
+    nbits_t nbits, bool tally)
 {
     const value_t mask = MASKBITS(nbits);
     size_t nbytes = BITBYTES(nbits);
-    auto [X, Z] = tio.halftriple(yield);
+    auto [X, Z] = tio.halftriple(yield, tally);
 
     // Send x+X
     value_t blind_x = (x + X) & mask;
@@ -157,14 +159,16 @@ void mpc_oswap(MPCTIO &tio, yield_t &yield,
 }
 
 // P0 and P1 hold XOR shares of x. Compute additive shares of the same
-// x. x is at most nbits bits long.
+// x. x is at most nbits bits long.  When called by another task during
+// preprocessing, set tally to false so that the required halftriples
+// aren't accounted for separately from the main preprocessing task.
 //
 // Cost:
 // nbits-1 words sent in 1 message
 // consumes nbits-1 HalfTriples
 void mpc_xs_to_as(MPCTIO &tio, yield_t &yield,
     RegAS &as_x, RegXS xs_x,
-    nbits_t nbits)
+    nbits_t nbits, bool tally)
 {
     const value_t mask = MASKBITS(nbits);
 
@@ -190,8 +194,9 @@ void mpc_xs_to_as(MPCTIO &tio, yield_t &yield,
     std::vector<coro_t> coroutines;
     for (nbits_t i=0; i<nbits-1; ++i) {
         coroutines.emplace_back(
-            [&tio, &as_bitand, &xs_x, i, nbits](yield_t &yield) {
-                mpc_valuemul(tio, yield, as_bitand[i], (xs_x.xshare>>i)&1, nbits);
+            [&tio, &as_bitand, &xs_x, i, nbits, tally](yield_t &yield) {
+                mpc_valuemul(tio, yield, as_bitand[i],
+                    (xs_x.xshare>>i)&1, nbits, tally);
             });
     }
     run_coroutines(yield, coroutines);

+ 8 - 4
mpcops.hpp

@@ -30,14 +30,16 @@ void mpc_cross(MPCTIO &tio, yield_t &yield,
 // P0 holds the (complete) value x, P1 holds the (complete) value y;
 // compute additive shares of z = x*y.  x, y, and z are each at most
 // nbits bits long.  The parameter is called x, but P1 will pass y
-// there.
+// there.  When called by another task during preprocessing, set tally
+// to false so that the required halftriples aren't accounted for
+// separately from the main preprocessing task.
 //
 // Cost:
 // 1 word sent in 1 message
 // consumes 1 HalfTriple
 void mpc_valuemul(MPCTIO &tio, yield_t &yield,
     RegAS &z, value_t x,
-    nbits_t nbits = VALUE_BITS);
+    nbits_t nbits = VALUE_BITS, bool tally = true);
 
 // P0 and P1 hold bit shares f0 and f1 of the single bit f, and additive
 // shares y0 and y1 of the value y; compute additive shares of
@@ -77,14 +79,16 @@ void mpc_oswap(MPCTIO &tio, yield_t &yield,
     nbits_t nbits = VALUE_BITS);
 
 // P0 and P1 hold XOR shares of x. Compute additive shares of the same
-// x. x is at most nbits bits long.
+// x. x is at most nbits bits long.  When called by another task during
+// preprocessing, set tally to false so that the required halftriples
+// aren't accounted for separately from the main preprocessing task.
 //
 // Cost:
 // nbits-1 words sent in 1 message
 // consumes nbits-1 HalfTriples
 void mpc_xs_to_as(MPCTIO &tio, yield_t &yield,
     RegAS &as_x, RegXS xs_x,
-    nbits_t nbits = VALUE_BITS);
+    nbits_t nbits = VALUE_BITS, bool tally = true);
 
 // P0 and P1 hold bit shares of f, and DPFnode XOR shares x0,y0 and
 // x1,y1 of x and y.  Set z to x=x0^x1 if f=0 and to y=y0^y1 if f=1.

+ 1 - 1
rdpf.cpp

@@ -582,7 +582,7 @@ RDPFTriple::RDPFTriple(MPCTIO &tio, yield_t &yield,
     }
     coroutines.emplace_back(
         [this, &tio, depth](yield_t &yield) {
-            mpc_xs_to_as(tio, yield, as_target, xs_target, depth);
+            mpc_xs_to_as(tio, yield, as_target, xs_target, depth, false);
         });
     run_coroutines(yield, coroutines);
 }