Comments (3)
Thanks for your reply the other day, @olehnikolaiev . It has been confirmed that the library does not update t
and n
fields properly.
According to the information above, I have tried the following code. This segment of code below conforms to the instructions in using-distributed-key-generation.md and using-threshold-signatures.md. Unfortunately, another problem was spotted.
#include "libBLS.h"
int main(int argc, char* argv[])
{
constexpr size_t num_signed = 3;
constexpr size_t num_all = 4;
std::vector<std::vector<libff::alt_bn128_Fr>> secret_shares_all; // matrix of all secret shares
std::vector<std::vector<libff::alt_bn128_G2>> public_shares_all; // matrix of all public shares
std::vector<DKGBLSWrapper> dkgs; // instances of DKGTEWrapper for each participant
std::shared_ptr<std::vector<std::shared_ptr<BLSPrivateKeyShare>>> skeys =
std::make_shared<std::vector<std::shared_ptr<BLSPrivateKeyShare>>>(); // private keys of participants
std::vector<BLSPublicKeyShare> pkeys; // public keys of participants
for (size_t i = 0; i < num_all; i++) {
DKGBLSWrapper dkg_wrap(num_signed, num_all);
dkgs.push_back(dkg_wrap);
std::shared_ptr<std::vector<libff::alt_bn128_Fr>> secret_shares_ptr =
dkg_wrap.createDKGSecretShares();
std::shared_ptr<std::vector<libff::alt_bn128_G2>> public_shares_ptr =
dkg_wrap.createDKGPublicShares();
secret_shares_all.push_back(*secret_shares_ptr);
public_shares_all.push_back(*public_shares_ptr);
}
// verify shares for each participant
for (size_t i = 0; i < num_all; i++) {
for (size_t j = 0; j < num_all; j++) {
assert(dkgs.at(i).VerifyDKGShare(
j,
secret_shares_all.at(i).at(j),
std::make_shared<std::vector<libff::alt_bn128_G2>>(public_shares_all.at(i))
)); // Assertions passed
}
}
std::vector<std::vector<libff::alt_bn128_Fr>> secret_key_shares;
for (size_t i = 0; i < num_all; i++) { // collect got secret shares in a vector
std::vector<libff::alt_bn128_Fr> secret_key_contribution;
for (size_t j = 0; j < num_all; j++) {
secret_key_contribution.push_back(secret_shares_all.at(j).at(i));
}
secret_key_shares.push_back(secret_key_contribution);
}
for (size_t i = 0; i < num_all; i++) {
BLSPrivateKeyShare pkey_share = dkgs.at(i).CreateBLSPrivateKeyShare(
std::make_shared<std::vector<libff::alt_bn128_Fr>>(
secret_key_shares.at(i)));
skeys->push_back(std::make_shared<BLSPrivateKeyShare>(pkey_share));
pkeys.push_back(BLSPublicKeyShare(
*pkey_share.getPrivateKey(),
num_signed,
num_all
));
}
// generate random message
std::default_random_engine rand_gen((unsigned int) time(0));
std::string message;
size_t msg_length = 32;
for (size_t length = 0; length < msg_length; ++length) {
message += char(rand_gen() % 128);
}
BLSSigShareSet sigSet(num_signed, num_all);
std::shared_ptr<std::array<uint8_t, 32>> byteArray = std::make_shared<std::array<uint8_t, 32>>();
std::copy(message.begin(), message.end(), byteArray->begin());
for (size_t i = 0; i < num_signed; ++i) {
std::shared_ptr<BLSPrivateKeyShare> skey = skeys->at(i + 1);
// sign with private key of each participant
std::shared_ptr<BLSSigShare> sigShare = skey->sign(
byteArray,
i + 1
);
sigSet.addSigShare(sigShare);
}
std::shared_ptr<BLSSignature> common_sig_ptr = sigSet.merge(); // create common signature
std::vector<size_t> participants(num_all);
for (size_t i = 0; i < num_signed; ++i) participants.at(i) = i + 1; // set participants indices 1,2,3
BLSPrivateKey common_skey(
skeys,
std::make_shared<std::vector<size_t>>(participants),
num_signed,
num_all
);
BLSPublicKey common_pkey(*(common_skey.getPrivateKey()));
assert(common_pkey.VerifySig(byteArray, common_sig_ptr)); // Assertion failed
return 0;
}
The assertion of merged signature failed at the end, whereas the assertions passed during verification of participant shares.
Is this also caused by the problem of updating t
and n
? If so, is there a workaround to use DKG and BLS-TSS at the same time? Thanks!
from libbls.
hello @gaoweihe ! thanks for reporting the issue. when creating BLSPublicKey
object from private or public key it doesn't fill the t
and n
fields. to use t
and n
fields you should use another constructor BLSPublicKey( std::shared_ptr< std::map< size_t, std::shared_ptr< BLSPublicKeyShare > > > map_pkeys_koefs, size_t _requiredSigners, size_t _totalSigners );
reagrding the second issue - std::shared_ptr<BLSPrivateKeyShare> skey = skeys->at(i + 1);
. here you should use skeys->at(i)
from libbls.
Thanks for your reply, @olehnikolaiev ! Your suggestions helped a lot.
I'm now closing this issue as the problem has been solved.
from libbls.
Related Issues (20)
- libBLS unit tests fail randonmly HOT 1
- make newest libBLS compatible with consensus HOT 4
- create threshold encryption sample app HOT 2
- add MAGIC_STRING to support threshold encryption HOT 1
- Linking error 'undefined reference to '__gmp_printf'' with the dependency 'libff.a' HOT 2
- Error serializing libff::alt_bn128_Fr during DKG HOT 4
- Function `DKGBLSWrapper::CreateTEPublicKey` declared but not defined HOT 1
- update threshold encryption implementation according to docs
- create npm package for threshold encryption client side
- "cmake --build build -- -j$(sysctl -n hw.ncpu) " Error HOT 5
- potential segmentation fault when serializing to string HOT 2
- init_alt_bn128_params() HOT 1
- serialing TEPrivatekeyShare and TEPublickeyShare HOT 2
- cross compile HOT 1
- add BLS aggregated signatures functionality HOT 1
- Enable linter
- Support of Ubuntu 20.04 HOT 2
- Investigate gnark
- Please add flags to cmake file of libbls to disable warnings
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libbls.