Skip to content

Instantly share code, notes, and snippets.

Created April 3, 2017 01:09
What would you like to do?
Short attempt at verifying an aggregate signature using BLS and a single pubkey
#include <iostream>
#include "bls.h"
int main() {
std::cout << "Signature aggregation toy attempt\n";
// create instance of Bls class
bls::Bls my_bls = bls::Bls();
// define message
const char *msg = "That's how the cookie crumbles";
// generate public key from seed
const char *seed = "19283492834298123123";
bls::PubKey pubkey = my_bls.genPubKey(seed);
// create signature
bls::Sig sig = my_bls.signMsg(msg, seed, pubkey);
// validate signature
bool verification_result = my_bls.verifySig(pubkey, msg, sig);
if (verification_result == true) {
std::cout << "Verification: success!";
} else {
std::cout << "Verification: failure";
std::cout << "\n\n\n----------------\n\n";
// Now on to aggregation.
// create instance of Bls class
bls::Bls my_bls2 = bls::Bls();
// generate two seeds (NOTE: seeds should actually be random)
const char *seed_1 = "11111111111";
const char *seed_2 = "22222222222";
// generate both pubkeys
bls::PubKey pubkey_1 = my_bls2.genPubKey(seed_1);
bls::PubKey pubkey_2 = my_bls2.genPubKey(seed_2);
std::vector<bls::PubKey> pubkeys;
std::vector<bls::PubKey> pubkeys2;
const char *msg_1 = "message 1";
const char *msg_2 = "message 2";
std::vector<const char *> msgs;
std::vector<const char *> msgs2;
// sign both messages
bls::Sig sig_1 = my_bls2.signMsg(msg_1, seed_1, pubkey_1);
bls::Sig sig_2 = my_bls2.signMsg(msg_2, seed_2, pubkey_2);
// add signatures to vector
std::vector<bls::Sig> sigs;
// generate the aggregate signature of all signatures in the vector
bls::Sig agg_sig = my_bls2.aggregateSigs(sigs);
// Check that the signature is valid
// NOTE: using my_bls (the first one) here...
// works: bool temp = my_bls.verifyAggSig(msgs, pubkeys, agg_sig);
// fails: bool temp = my_bls.verifyAggSig(msgs2, pubkeys2, agg_sig);
bool temp = my_bls.verifySig(pubkey_1, msg_1, agg_sig); // also fails
if (temp == true) {
std::cout << "Successfully verified an aggregate signature against a single pubkey.";
} else {
std::cout << "Verification failed for single pubkey and aggregate signature.";
std::cout << "\n\n\n";
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment