Chia-Network / bls-signatures

BLS signatures in C++, using the blst library for BLS12-381
Apache License 2.0
298 stars 212 forks source link

js bindings - aggregated public keys not working with multiple messages #465

Closed rickyk586 closed 2 months ago

rickyk586 commented 2 months ago

is it possible to use aggregated public keys with aggregated signatures on multiple messages? This gives a false verification:

import loadBls from 'bls-signatures';

const BLS = await loadBls();

var seed = Uint8Array.from([
    0,  50, 6,  244, 24,  199, 1,  25,  52,  88,  192,
    19, 18, 12, 89,  6,   220, 18, 102, 58,  209, 82,
    12, 62, 89, 110, 182, 9,   44, 20,  254, 22
]);

// Generate some more private keys
seed[0] = 1;
var sk1 = BLS.AugSchemeMPL.key_gen(seed);
seed[0] = 2;
var sk2 = BLS.AugSchemeMPL.key_gen(seed);
seed[0] = 3;
var sk3 = BLS.AugSchemeMPL.key_gen(seed);
seed[0] = 4;
var sk4 = BLS.AugSchemeMPL.key_gen(seed);
var message = Uint8Array.from([1,2,3,4,5,6,7]);
var message2 = Uint8Array.from([1,2,3,4,5,6,8]);

// Generate first sig
var pk1 = sk1.get_g1();
var sig1 = BLS.AugSchemeMPL.sign(sk1, message);

// Generate second sig
var pk2 = sk2.get_g1();
var sig2 = BLS.AugSchemeMPL.sign(sk2, message);

// Generate third sig
var pk3 = sk3.get_g1();
var sig3 = BLS.AugSchemeMPL.sign(sk3, message2);

// Generate forth sig
var pk4 = sk4.get_g1();
var sig4 = BLS.AugSchemeMPL.sign(sk4, message2);

// Generate aggregated public keys
var aggPk1 = pk1.add(pk2);
var aggPk2 = pk3.add(pk4);

// Signatures can be non-interactively combined by anyone
var aggSig = BLS.AugSchemeMPL.aggregate([sig1, sig2, sig3, sig4]);

const ok = BLS.AugSchemeMPL.aggregate_verify([aggPk1, aggPk2], [message, message2], aggSig);
console.log(ok); // false

or is this the only way to do it:

const ok2 = BLS.AugSchemeMPL.aggregate_verify([pk1, pk2, pk3, pk4], [message, message, message2, message2], aggSig);
console.log(ok2); // true
rickyk586 commented 2 months ago

I believe this answers my question that it cannot be done with aggregate public keys when there are multiple messages:

In the context of BLS12-381 and the BLS signature scheme, verifying an aggregated signature over different messages requires access to all the original public keys and messages involved in the aggregation. Here's why:

BLS Signature Aggregation Basics:

  1. Same Message Aggregation:

    • When multiple signers sign the same message, their signatures can be aggregated by simply adding them together:
      [ s_{\text{agg}} = s_1 + s_2 + \dots + s_n ]
    • Their public keys can also be aggregated similarly:
      [ \text{pk}_{\text{agg}} = \text{pk}_1 + \text{pk}_2 + \dots + \text{pk}_n ]
    • Verification can then proceed using the aggregated signature and public key: [ e(s{\text{agg}}, G) = e(H(m), \text{pk}{\text{agg}}) ]
  2. Different Messages Aggregation:

    • When aggregating signatures over different messages, the process is more complex due to the potential for rogue-key attacks.
    • The aggregated signature is still the sum of individual signatures: [ s_{\text{agg}} = s_1 + s_2 + \dots + s_n ]
    • However, verification requires pairing each hashed message with its corresponding public key: [ e(s{\text{agg}}, G) = \prod{i=1}^{n} e(H(m_i), \text{pk}_i) ]
    • This equation necessitates knowledge of each individual public key and message.

Implications for Your Scenario:

Why Aggregated Public Keys Alone Are Insufficient:

Recommendation:

References:

Answer:

You need to use all the original public keys and messages to verify the aggregated signature—you cannot verify it using only their aggregated public keys.