herumi / mcl-wasm

59 stars 18 forks source link

Intermittent issue with GT.setStr() #8

Closed mhewett-ks closed 5 years ago

mhewett-ks commented 5 years ago

I am using another library to generate a vector in Fp12 using pairing using the BLS12-381 curve. I have verified that the prime number used in MCL and the other library is the same: "1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab"

Sometimes I can import the generated vector into MCL but sometimes I can't.

let T_mcl = new mcl.GT();
T_mcl.setStr("aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll", 16);

When it generates an error, I get the following error:

Error: err _wrapInput 024aafb1494c5705191048d6a5a5dbd15c53cefc309b116c18f5249d3d6e7a5adf63f5e4671b9ece8de85fa3e52772fe 08bec5faf7102c80d41a2ecbaed227c66cdc71a280923d10e54e1655861dfacf82195ac85f0b14991f539b7af42ed1fd 1126a2a76e9d0640d1ec7435403f1852ba9ba586c0fbc077ad933f83366a37e0ded6de746476c472037159a05ede4194 0f03d764b62f9fbe5b615ec06c14f85b9cf3757e854ad6bca0d05b2b71aa5568a3f19067a7213665e02c6eaadca65187 13e78998946a4ace985a4af55ad5da899fa6b68d193b05651be4fac94faf9b9225f126bfcbf4d57321b108c5ce162f7c 0d129457d425ecc1974e52d88993f2cc4518e5872dfe450b4741f018e17393cbd84af8fac20aad3d67d35533df5d8f83 1473537ed46ab451960ef0e847c731cdca709ff07f618fe3f2cb34376aa041337648cf503b2e54c82f82e3827c0230a2 095d1ca249729d03f91efeef1d50f0c13bc741c757f1047b5b02518f9a9a39ee2ed070b09005e0fdb821983f90effcaa 1743618588e05954c5dedc20de67c0f0ecb5219b7c8dd5bdb9d0c56cc4d3aa6398ebd7de4b3bf3381c1b1be42d59543a 0bcc1edcfcf91cd4a2ee7b4c3c598c5eff370c403906e4c49fc955cf06a0e5c40f07533b8897c3996b421ed77a88f34b 0feeda626ac7d5d4053ffe3a234937d63e20f62565d5e841131138c8854af6e81ae6cbd4e1d5e7a33f401f32226d223a 09fdb778bbcec71c1d02102e4d9d580e488911a6f3bf7dd6da3b2e0ada58057a1d657052b9696ae18286c0c251f321b0
    at mycode.js:14416
    at e.value (mycode.js:14530)
    at e.value (mycode.js:14918)
    at mycode_wasm.js:formatted:14174
    at a (mycode_wasm.js:formatted:14185)
    at s (mycode_a.js:1)

Here are some examples that work and some that don't. I can't see any pattern. Can you tell me why MCL would accept some of them and not others?

MCL Fp12: (fail)
=================================
0b3e560ab08e86f5e26cc622be8835e0c06fc2d95f1f742727b4145520b396f6a751c8f01cbb4b521d60503f4e5e9aa0
041cbe5d421f1bfd0319be2f9f0e745a079f65ce49c8ce56b6e5842c836ae031a5ee08464aaf5780f6ff64728ee06530
18538ccbfddce4e45e7a841d6b841fbe019111ba2e8100650cb549aee96f35cc84c540e26da06cea3aa0e0469458b517
101d8c53358bdb2dfd3da885f3a20cd6cd8036ea824e1712c6430ee0cb6710e0f01cde640c7394a8732e0f2d428d6e8f
0a9f9c6cded8744161bd07a3070e0d0e2e694cb6656119ad19c7518838c44d7347f3bc31c237b5c42ffedd06f0f9ac85
1394de16798a46954b4aadc6f051dff0c0dfc1cb8fd1155a8964e6c8ed51eeb405d4a9368a64c7291034e6ec77f1292a
0a8dfd2de1208e4543fc7b8be02d7eda56c8c312303083f3bb03a335b36ace6c01be3abfde03ab0fb7dba0318c47a479
15bd6165f36c4273ec342d30abfb3ab52955b20d9db2711dc861638ee2198a04165ac2e0e99d005c35da2f241f64ec34
08457fe07a2101ee07ae99ac731ddaa46c2b6a08fc1760b8d712933670fb290ba05947150da1ab1e5c94c60c29a88d98
173cc1819bb8658b8bf17d13fc0bb466c10234ded92420745316ca8fd77d64bd7b8b20a0a6e6c59bd695a4aef87e8ca0
18ae0ed714ed1e0d45d2116267563017f0a16d0ec1af1296d28720a6d7d1ca8cecc3148a39885517c4a292806fb2c9c0
0910a189e176eaa80b42fde37afaf99f199e4dd6bfa0235b6d138cbe8acd265de05ca5094a60c6a00a7479f443cdf6f0

1829f462f86f3449f2aca26d0b3ff41f1b4704dc236043a6fbf60b6be9438366eb6432ac794611eb011e2bae2aca4833
125995a77f1516ddf578e8e5d15a72039e3031b6c2a04d53a988294164a3e5d1142041941a896faf2e5c5f899f4d4925
10680fe131756d99a27912c8bf94147883fe54f822166d0c1d10b92ef457343c5815475001f58067368983e243c8f773
14792dc0b71218ce19d4b30ef53c8f5201f71f584bad46032e94baa33a329059ad7264a0a45273f70b3868da6f135c5d
042a0b4f59ec290fe622ffbfd9ac3ba57841c92666a8ffd2761b36dfe212d7c1a4e3bcdfe666211708ac7e9b32f4ab36
0b5edf17a6caafb41503e91563dcddb8dcd0dfeacd50eccf73be40679d7f18b7de73da018d61f6ea07aafb0e464c726a
149d3325e1cc8c5ed4feee01be4fac905f3f30560a5124d591ab86e446cbc849cff8435b8e4078ef7ace0fb439a29aa0
06f4ad36efab491bb49f884535de905a3a0273bda9973f1d1bf43bbaaa55495e0add61325bb0cff3f12be626b4b2a688
0421aa872e2c5ba4794423b0f3b7f29a963690cd901f62e8389634351f92fd8b6ea500b899d2fa354bc10fe8c462343a
18c40e7eba316281bc0acd73b94abf7c4d3f905196777a25d7493f2327fcad8e2eb2a17831f0301fb4df008b98983e10
0204187311bdeb973fcb2d22e27bf034c13438e2c5c0956ecf9334f242a24a6ff819b97966fca0f6b2a2f45e99e84ca6
08ff8bf29900b954cec1ca136fc927d4737d85da9064de5fea7cc4388ec251b22fc4ba0b5b70ffa47ef6e806bb4b2825

024aafb1494c5705191048d6a5a5dbd15c53cefc309b116c18f5249d3d6e7a5adf63f5e4671b9ece8de85fa3e52772fe
08bec5faf7102c80d41a2ecbaed227c66cdc71a280923d10e54e1655861dfacf82195ac85f0b14991f539b7af42ed1fd
1126a2a76e9d0640d1ec7435403f1852ba9ba586c0fbc077ad933f83366a37e0ded6de746476c472037159a05ede4194
0f03d764b62f9fbe5b615ec06c14f85b9cf3757e854ad6bca0d05b2b71aa5568a3f19067a7213665e02c6eaadca65187
13e78998946a4ace985a4af55ad5da899fa6b68d193b05651be4fac94faf9b9225f126bfcbf4d57321b108c5ce162f7c
0d129457d425ecc1974e52d88993f2cc4518e5872dfe450b4741f018e17393cbd84af8fac20aad3d67d35533df5d8f83
1473537ed46ab451960ef0e847c731cdca709ff07f618fe3f2cb34376aa041337648cf503b2e54c82f82e3827c0230a2
095d1ca249729d03f91efeef1d50f0c13bc741c757f1047b5b02518f9a9a39ee2ed070b09005e0fdb821983f90effcaa
1743618588e05954c5dedc20de67c0f0ecb5219b7c8dd5bdb9d0c56cc4d3aa6398ebd7de4b3bf3381c1b1be42d59543a
0bcc1edcfcf91cd4a2ee7b4c3c598c5eff370c403906e4c49fc955cf06a0e5c40f07533b8897c3996b421ed77a88f34b
0feeda626ac7d5d4053ffe3a234937d63e20f62565d5e841131138c8854af6e81ae6cbd4e1d5e7a33f401f32226d223a
09fdb778bbcec71c1d02102e4d9d580e488911a6f3bf7dd6da3b2e0ada58057a1d657052b9696ae18286c0c251f321b0

MCL Fp12: (success)
====================================
05cbe955394ac1efcace09c96d9ee1da2346388c44179e23790fb20651dd78303ccdfbd146f7ddc2726f929ef92c7afa
1036beb1b9dc41874746401d198bf391690b9a65aadc57a04629042a05c8dd4ec70effa92e21b0b6e222222dc7b305bc
0e1c5dcd29da32ef1fc2853f3cdfa44e1ef564cdfc8ffee34c4631157704fac9b05f767c531b531f9e422baa099a59f2
050e74d7612deacd6bfa42d4040c50c1ef87d3f3425abb9d9ffc516536e0f4ab984b509fd1e7c433b89a4e9fb6028f74
16a26dae392e7400e811ba4ee37eddd445c29abdc1a4c06d6c027a7b8eed0da30d5e960b1f0c685b78a6482f515244d0
02a6a4fb61f24dc9bc91959c4fe50b43184d587aca8afe41a39d336e416bc5c9af19ede7592915e4d22c19ebc2c2ba92
0388b7968e1917f584d84bb604e7b56e455e409ea8e3e8b6caffc5e8301b94182a119e668c26793a1f7b9015d22a75d4
0252fc5652583acc0605aa8a15eed730837c54d986aaf96675248ccc63276fad62fa2db3d015a65f52c52e6b74c4a9ab
11dd2df486eaf2d99acb6f69cbc3d2e2d4f27e95fb1377239332557e193462baccf90c1a2bb9d9e7dbb1493121b18c71
09bac901d7983cf671a0aec7a0ac67908b4acaa427374ea5fb27f8e7145fc5e5d240b1bbe4cfe89f48a0e5251078555f
09ef30b52b2acdbf9767772bfdc2fffad2c8fe4fa14e9450ffe0c47903a585cf448aeb43796bd4c49dd85e4386514fe4
0651882f8eb779eb18f19730e756ad9660bc33f0e5cb05439e8ef3f3f31f29f60b03bee1002227634de66a6adbd5ebb2

01a9632cfe0668d05e81c352ad7165ffe4123cef8065888684e53c8f111eb6c4d8352163bd7493d89cd79bb6af47c407
06e0b8e3bb55158b180e1f1dbdf520f3cc5f5085ecb9cad4282a0040263e535fe59ad46ad312022594dded7b3d74586a
0c6e67913548940c1b52fe75f86ac39872d64d44fc818900381a5d92ce64d12f9f777bc921b2ffee841f0401375bff94
061551345d26f37a0e8d85f8fd587549b85150f5eba36a56862cb2ee0b1fce272d9bc0d00851ae9248d606bd61c3e3eb
1607fc2eff15b9eb43a57c8de30a06071a15bec7f6e60edf36db4237949348308e638281212c0e27f59e2a5cf5c92e6e
03ac2522cf855bcfd9fc371d722022a0117ce58315b0805f27706e67969958dc1b1edbb8362d87b61a0395ea447c401e
03183612bc8453ebda86e11fc1efc79faa4b6da56edc9903d538cd0f58ff1c437dd0b3b9abf701dd7b2e39ad7b145910
07087560301e6d9679e044aacb198b696ce233c2e571694561b7d18b72e5d78b1bdc16ab93e2e91b980cad75de866fde
03e28c1e37d344596a3c606a5146938579ac065de341996a8a0c97345980d9447a525174d27e20629487a80dea909464
0213270bcf0de1370e20f22aad2576e77a6ca83750c2ecd76336a241b5a34b3048ab94b6bf1468e41fe8be4bdc559203
02cd31cb41518ead8ec8248284f31e0c6ab8742d7fe12dbe35b7c6f43b83c06350fddf25b1867423c0bd8ae75603e365
19a8ab9b0368fd844e925796563e6e796ca90d464b3fd3f6215b0e0dd0ff15815ee2d0b1b71daf037d66e691b1876f03
herumi commented 5 years ago

T_mcl.setStr("aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll", 16);

The string must be 12 hexadecimal numbers, so You can't use 'ggg hhh iii jjj kkk lll.' And moreover, the value must be a p-th root of 1 in Fp12.

mhewett-ks commented 5 years ago

aaa bbb ccc ... was not a real example. The actual values that fail are shown.

herumi commented 5 years ago

I see. Thank you for the important information. It was the wrong specification of getStr. The parse of Fp dealed with '0b...' string with base 16 as a binary representation and throws an exception. I fixed it now. Could you try the new version?