herumi / mcl-wasm

59 stars 18 forks source link

Multiply point with scalar value #30

Closed pat721 closed 1 year ago

pat721 commented 1 year ago

I'm currently trying to multiply a G2() point with a scalar value but I'm not sure if i do this correct.

const g2 = new mcl.G2();
 g2.setStr( "1 0x1800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed 0x198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c2 0x12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa 0x090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b"
  );

let privkey = new mcl.Fr();

privkey.setStr(
    "27342515244433913831915841113162642860753661339514809894050960669014459950989",
    10
  );

let generateV = mcl.mul(g2, privkey);

I always receive the following error: grafik

What am I doing wrong here?

herumi commented 1 year ago

What parameters do you use mcl.init with? The value of Fr::setStr must be less than or equal to Fr(-1).

const max_r = new mcl.Fr();
max_r.setInt(-1);
console.log(max_r.getStr());
pat721 commented 1 year ago

The init function is applied as following:

export async function init() {
  await mcl.init(mcl.BN_SNARK1);
  mcl.setMapToMode(1);
}

Side questions at this point: is 1 the right choice for the try and increment mapping mode?

pat721 commented 1 year ago

Okay it seems like my generated number is bigger than Fr(-1), I have to double check then. Sorry for the inconvenience. Is there documentation on the different parameters for the curves?