Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is a barrier and how to use it #244

Open
gutjuri opened this issue Feb 23, 2023 · 0 comments
Open

What is a barrier and how to use it #244

gutjuri opened this issue Feb 23, 2023 · 0 comments

Comments

@gutjuri
Copy link

gutjuri commented Feb 23, 2023

Hello,
I'm struggeling to fully grasp the concept of barriers, since I could not find documentation on it.

Suppose I have a Jiff application and I want to measure the time taken for share distribution, computation and opening.
Would a programme structured like this be able to do this accurately?

// Setup of jiffClient omitted.
// suppose that compute_parties = [1,2,3], input_parties = [4,5,6,7,8] and all_parties = [1,2,3,4,5,6,7,8]
// This is the code ran by a compute party. The input parties perform no computation but only send input shares.

var mean = function (X) {
  // [conversion of X to array of shares omitted] 
  var sum = X[0];
  for (var i = 1; i < X.length; i++) {
    sum = sum.sadd(X[i]);
  }
  return sum.cdiv(X.length);
};

// the computation code
var compute = function () {
  log("starting computation");
  jiffClient.wait_for(all_parties, function () {
    jiffClient.start_barrier();
    var t_start_recv = process.hrtime.bigint();
    log("all input parties ready");
    var X = jiffClient.share(null, null, compute_parties, input_parties);

    jiffClient.end_barrier().then(() => {
      var t_end_recv = process.hrtime.bigint();

      log(
        `received all secret shares in ${
          Number(t_end_recv - t_start_recv) / 1000000
        } ms`
      );
    });


    jiffClient.start_barrier();
    var start_t = process.hrtime.bigint();
    var m1 = mean(X);

    jiffClient.end_barrier().then(() => {
      var end_t = process.hrtime.bigint();
      console.log(`Computed result in ${Number(end_t - start_t) / 1000000} ms`);

        var start_t_open = process.hrtime.bigint();
        jiffClient.open(m1, compute_parties).then((res) => {
          var end_t_open = process.hrtime.bigint();
          console.log("res: ", res.toString());
          console.log(
            `Opened result in ${Number(end_t_open - start_t_open) / 1000000} ms`
          );
          jiffClient.disconnect(true, true);
        });
    });
  });
};

// wait only for the compute parties to preprocess
jiffClient.wait_for(compute_parties, function () {
  log("all compute parties ready");
  // no preprocessing: use server as crypto provider
  log("skipping preprocessing, server is crypto provider");
  compute();
});

log("submitted wait_for callback...");

I'd like to be able to accurately measure the duration of secret sharing, computation and share opening, because I want to compare these numbers among different platforms. Are barriers the right tool for this?

@gregfrasco gregfrasco added this to Jiff Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant