Hi! The library returns a seemingly wrong value for the multiplication in bn128 Fr.
Here's an example: (I assumed that it's using little endian)
It gives 21005330981446606953608831075862683397340720297895507971069995954406343750754 while I'm expecting 19138581828712882593908706925461583697567205063300498062599267069621213248340.
Both the online calculator and the circom's * operation give the expected result.
constffjavascript=require("ffjavascript");asyncfunctioncheckBn128(){consta=5299619240641551281634865583518297030282874472190772894086521144482721001553n;constb=16950150798460657717958625567821834550301663161624707787222815936182638968203n;constbn128=awaitffjavascript.getCurveFromName("bn128",true);constcBuf=bn128.Fr.mul(newBufferFromBigUInt256LE(a),newBufferFromBigUInt256LE(b));constc=readBigUInt256LE(cBuf);// WRONG RESULT FOR c// Expecting 19138581828712882593908706925461583697567205063300498062599267069621213248340// reference: https://planetcalc.com/8326/// circomlib BabyAdd also gives the same result.console.log("c:");console.log(c);}checkBn128();/* util functions */functionreadBigUInt256LE(buffer){varvalue=0n;for(vari=0;i<32;i++){value+=BigInt(buffer[i])<<BigInt(i*8);}returnvalue;};functionnewBufferFromBigUInt256LE(value){varbuffer=Buffer.alloc(32);for(vari=0;i<32;i++){buffer[i]=Number(value&0xffn);value=value>>8n;}returnbuffer;};/* util function tests */functiontestNewBufferFromBigUInt256LE(){consta=5299619240641551281634865583518297030282874472190772894086521144482721001553n;constaBuf=newBufferFromBigUInt256LE(a);console.log('a buffer');console.log(aBuf);// expecting 51, 70, 95, BB, F6, F3, 93, 28, B6, E0, 34, 05, 01, D8, B8, 2A, C1, 77, 62, 9D, E0, B2, AC, 4E, 9B, 73, 3E, D6, 6A, 7A, B7, 0B// reference: https://www.rapidtables.com/convert/number/decimal-to-hex.htmlreturnaBuf;}functiontestReadBigUInt256LE(){constaPrime=readBigUInt256LE(testNewBufferFromBigUInt256LE());console.log("aPrime:");console.log(aPrime);}// testNewBufferFromBigUInt256LE();// testReadBigUInt256LE();
Hi! The library returns a seemingly wrong value for the multiplication in bn128
Fr.Here's an example: (I assumed that it's using little endian)
It gives
21005330981446606953608831075862683397340720297895507971069995954406343750754while I'm expecting19138581828712882593908706925461583697567205063300498062599267069621213248340.Both the online calculator and the circom's
*operation give the expected result.