Skip to content

Commit 9798df7

Browse files
committed
sign/bls: rejects aggregated signatures built with duplicated messages.
1 parent 757dde4 commit 9798df7

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

sign/bls/bls.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,18 @@ func VerifyAggregate[K KeyGroup](pubs []*PublicKey[K], msgs [][]byte, aggSig Sig
365365
return false
366366
}
367367

368+
// 1. If any two input messages are equal, return INVALID.
369+
set := make(map[string]struct{}, len(msgs))
370+
for _, m := range msgs {
371+
k := string(m)
372+
if _, found := set[k]; found {
373+
return false
374+
}
375+
set[k] = struct{}{}
376+
}
377+
378+
// 2. CoreAggregateVerify algorithm checks an aggregated signature over
379+
// several (PK, message) pairs.
368380
for _, p := range pubs {
369381
if !p.Validate() {
370382
return false

sign/bls/bls_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ func TestBls(t *testing.T) {
2121
t.Run("G2/Errors", testErrors[bls.G2])
2222
t.Run("G1/Aggregation", testAggregation[bls.G1])
2323
t.Run("G2/Aggregation", testAggregation[bls.G2])
24+
t.Run("G1/DuplicatedMsg", testDuplicatedMsgs[bls.G1])
25+
t.Run("G2/DuplicatedMsg", testDuplicatedMsgs[bls.G2])
2426
}
2527

2628
func testBls[K bls.KeyGroup](t *testing.T) {
@@ -152,6 +154,34 @@ func testAggregation[K bls.KeyGroup](t *testing.T) {
152154
test.CheckOk(ok, "failed to verify aggregated signature", t)
153155
}
154156

157+
func testDuplicatedMsgs[K bls.KeyGroup](t *testing.T) {
158+
const N = 3
159+
160+
ikm := [32]byte{}
161+
_, _ = rand.Reader.Read(ikm[:])
162+
163+
duplicated_msg := []byte("signing the same messsage")
164+
msgs := make([][]byte, N)
165+
sigs := make([]bls.Signature, N)
166+
pubKeys := make([]*bls.PublicKey[K], N)
167+
168+
for i := range sigs {
169+
priv, err := bls.KeyGen[K](ikm[:], nil, nil)
170+
test.CheckNoErr(t, err, "failed to keygen")
171+
pubKeys[i] = priv.PublicKey()
172+
173+
msgs[i] = duplicated_msg
174+
sigs[i] = bls.Sign(priv, msgs[i])
175+
}
176+
177+
aggSig, err := bls.Aggregate(*new(K), sigs)
178+
test.CheckNoErr(t, err, "failed to aggregate")
179+
180+
test.CheckOk(
181+
bls.VerifyAggregate(pubKeys, msgs, aggSig) == false,
182+
"failed to reject aggregated signature with duplicated messages", t)
183+
}
184+
155185
func BenchmarkBls(b *testing.B) {
156186
b.Run("G1", benchmarkBls[bls.G1])
157187
b.Run("G2", benchmarkBls[bls.G2])

0 commit comments

Comments
 (0)