multiparty / jiff

JavaScript library for building web-based applications that employ secure multi-party computation (MPC).
https://multiparty.org/jiff/
MIT License
260 stars 53 forks source link

RangeError: Maximum call stack size exceeded when using BigNumber #218

Closed themighty1 closed 3 years ago

themighty1 commented 3 years ago

Hi, thank you for developing JIFF. In my circuit I need to xor bits and later to convert bits to BigNumbers and perform multiplication. However, as soon as I add jiff_instance.apply_extension(jiff_bignumber, options); I get an error on the console when running my setup:


(node:207634) UnhandledPromiseRejectionWarning: RangeError: Maximum call stack size exceeded
    at RegExp.test (<anonymous>)
    at new BigNumber (/home/default2/Desktop/jiff/jiff/node_modules/bignumber.js/bignumber.js:194:37)
    at BigNumber.P.modulo.P.mod (/home/default2/Desktop/jiff/jiff/node_modules/bignumber.js/bignumber.js:1743:24)
    at Object.mod (/home/default2/Desktop/jiff/jiff/lib/ext/jiff-server-bignumber.js:25:12)
    at Object.jiffClient.helpers.extended_gcd (/home/default2/Desktop/jiff/jiff/lib/client/util/helpers.js:122:70)
    at Object.jiffClient.helpers.extended_gcd (/home/default2/Desktop/jiff/jiff/lib/client/util/helpers.js:122:35)
    at Object.jiffClient.helpers.extended_gcd (/home/default2/Desktop/jiff/jiff/lib/client/util/helpers.js:122:35)
    at Object.jiffClient.helpers.extended_gcd (/home/default2/Desktop/jiff/jiff/lib/client/util/helpers.js:122:35)
    at Object.jiffClient.helpers.extended_gcd (/home/default2/Desktop/jiff/jiff/lib/client/util/helpers.js:122:35)
    at Object.jiffClient.helpers.extended_gcd (/home/default2/Desktop/jiff/jiff/lib/client/util/helpers.js:122:35)

The code for my server and clients below:

// ----------------------------------SERVER-----------------------------------//

var express = require('express');
var app = express();
var server = require('http').Server(app);

server.listen(9111, function() {
  console.log('listening on 9111');
});

var JIFFServer = require('./lib/jiff-server.js');
var jiff_bignumber = require('./lib/ext/jiff-server-bignumber.js');
var jiff_instance = new JIFFServer(server, { logs:true });
jiff_instance.apply_extension(jiff_bignumber);
console.log('Server is running on port 9111');

// -----------------------------------CLIENT 1 -----------------------------------//

var JIFFClient = require('./lib/jiff-client');
var jiff_bignumber = require('./lib/ext/jiff-server-bignumber.js');

function onConnect() {
    console.log('connected to server!');
    var shares = jiff_instance.protocols.bits.share(1)
    var result = shares[1][0].sxor_bit(shares[2][0])

    jiff_instance.protocols.bits.open([result]).then(function(res){
        console.log('the result is', res)
    })
}

var options = { party_count: 2, party_id: 1, crypto_provider: true, onConnect: onConnect};
var jiff_instance = new JIFFClient('http://localhost:9111', 'our-setup-application', options);
jiff_instance.apply_extension(jiff_bignumber, options);
jiff_instance.connect();

//---------------------------------CLIENT 2 ----------------------------------------//

var JIFFClient = require('./lib/jiff-client');
var jiff_bignumber = require('./lib/ext/jiff-server-bignumber.js');

function onConnect() {
    console.log('connected to server!');
    var shares = jiff_instance.protocols.bits.share(1)
    var result = shares[1][0].sxor_bit(shares[2][0])

    jiff_instance.protocols.bits.open([result]).then(function(res){
      console.log('the result is', res)
    })
}

var options = { party_count: 2, party_id: 2, crypto_provider: true, onConnect: onConnect };
var jiff_instance = new JIFFClient('http://localhost:9111', 'our-setup-application', options);
jiff_instance.apply_extension(jiff_bignumber, options);
jiff_instance.connect();

If I remove jiff_instance.apply_extension(jiff_bignumber); the my code runs fine. I would appreciate any ideas in solving this.

themighty1 commented 3 years ago

nvm, I was using jiff-server-bignumber.js in the client.