maidsafe / bls_dkg

Implementation of a BLS DKG mechanism, requires signing key, encryption key and SocketAddr of participants
BSD 3-Clause "New" or "Revised" License
22 stars 17 forks source link

Convert Signature and Public key into G1 and G2 format. #119

Open wdcs-amitkumar opened 2 years ago

wdcs-amitkumar commented 2 years ago

Hi Team !! Thanks you bls-dkg to provide such a complex implemetation in rust.

I would like to request if it is possible to convert public key and signature into G1 and G2 format. So that I can verify dkg-bls signature in the ethereum smart contract.

Currently I tried to input those PK and SIG in python ECC library Line 40 , 51

but it produces G1 and G2 of length 115 but this smart contract Line 38 verifyBLSTest()

accepts G1 G2 value of length 77.

In short do any way to get G1 G2 values in for required length ??

wdcs-amitkumar commented 2 years ago

Meanwhile I tried to convert public key and signature into G1 and G2 and found that They are producing output of different length.

Screenshot from 2022-01-10 02-27-34

image

wdcs-amitkumar commented 2 years ago

BLS_VERIFY_ETH.pdf

Just for reference of Signature I generated from BLS DKG rust and Python

maqi commented 2 years ago

Hi, @amitcz,

Thank you for the comment.

First, regarding the table of PK/Sig length you attached above, I think for bls_dkg, it shall be 192 for the PK and 384 for the Sig ?

Second, the format of PK/Sig that bls_dkg using is from threshold_crypto . In that crate, you can define the length of PK/Sig by changing the value of PK_SIZE and SIG_SIZE. That crate has test using mock PK/Sig type by change the PK_SIZE and SIG_SIZE to 4. I am not sure whether the bls_dkg can support a changed PK_SZIE/SIG_SIZE directly, worth to have a try.

Hope this helps. Cheers,

davidrusu commented 2 years ago

Just to add some notes here,

@amitcz there are a few different representations of G1/G2 points and there's a distinction between PublicKeySets and PublicKeys that you may missing.

G1/G1 can be in compressed or affine forms (or projective, but this is rarely serialized), these sizes are in the table below

             | G1 |  G2 |
-------------------------
| compressed | 48 |  96 |
| affine     | 96 | 192 |

Make sure you are converting your G1/G2 points into the representation your function expects.

Second, you may be confusing the PublicKeySet for the PublicKey. make sure to call public_key()

BLS-DKG exposes the compressed G1/G2 points, by calling to_bytes() on the PublicKey / PublicKeyShare / Signature / SignatureShare

This compressed representation should be parse-able by other BLS libraries and from that you can convert to Affine if necessary.

wdcs-amitkumar commented 2 years ago

Hi, @amitcz,

Thank you for the comment.

First, regarding the table of PK/Sig length you attached above, I think for bls_dkg, it shall be 192 for the PK and 384 for the Sig ?

Second, the format of PK/Sig that bls_dkg using is from threshold_crypto . In that crate, you can define the length of PK/Sig by changing the value of PK_SIZE and SIG_SIZE. That crate has test using mock PK/Sig type by change the PK_SIZE and SIG_SIZE to 4. I am not sure whether the bls_dkg can support a changed PK_SZIE/SIG_SIZE directly, worth to have a try.

Hope this helps. Cheers,

https://github.com/maidsafe/bls_dkg/blob/58e26b0d33b501912effc4e571f93a80d56624a5/src/key_gen/tests.rs#L273 This line prints public key : 384 characters and Signature : 192 characters What encoding has been used ??

wdcs-amitkumar commented 2 years ago

Hi Team Maidsafe!!

Thank you for your efforts, I am able to get Affine values for my public key and signature. Here is the code with changes :

Screenshot from 2022-01-11 02-15-08

One last help I need How can i convert those hex affine values into big int that following contract can take as input

Line 42 : bls-verifier-contract

Again very much thankful for all your support. Waiting for response :)

davidrusu commented 2 years ago

I don't think we can help you much with your contract, but those numbers are hex encoded, if you want the decimal representation, you can simply re-encode as decimal

wdcs-amitkumar commented 2 years ago

Hi @davidrusu

I tried to convert public key points , it is giving 115 character numbers, But smart contract (since it supports max uin256 size) only takes 77 character number as input.

Still hopeful

It it possible to get 77 character long public key from your repo.

Appreciated if provided with code snippet. Thanks :)

davidrusu commented 2 years ago

PublicKeys are always 48 bytes when compressed and 96 bytes in Affine.

it is giving 115 character numbers,

I'm not sure what a "character" is, but you should be counting in bytes, not characters.

maqi commented 2 years ago

It it possible to get 77 character long public key from your repo.

You may try with the threshold_crypto repo to refactor the PK_SIZE and SIG_SIZE to what you want. However, this may comes with cost of reduced security.