-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement experimental aggregate signatures
- Loading branch information
1 parent
ebf0851
commit c74827e
Showing
5 changed files
with
131 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,50 @@ | ||
package validatorregistry | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ethereum/go-ethereum/crypto" | ||
blst "github.com/supranational/blst/bindings/go" | ||
) | ||
|
||
var dst = []byte("BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_") | ||
|
||
func VerifySignature(sig *blst.P2Affine, pubkey *blst.P1Affine, msg *RegistrationMessage) bool { | ||
func VerifyAggregateSignature(sig *blst.P2Affine, pks []*blst.P1Affine, msg *AggregateRegistrationMessage) bool { | ||
if msg.Version < 1 { | ||
return false | ||
} | ||
if len(pks) != int(msg.Count) { | ||
fmt.Println(len(pks), int(msg.Count)) | ||
return false | ||
} | ||
msgHash := crypto.Keccak256(msg.Marshal()) | ||
msgs := make([][]byte, len(pks)) | ||
for i := range pks { | ||
msgs[i] = msgHash | ||
} | ||
return sig.AggregateVerify(true, pks, true, msgs, dst) | ||
} | ||
|
||
func VerifySignature(sig *blst.P2Affine, pubkey *blst.P1Affine, msg *LegacyRegistrationMessage) bool { | ||
msgHash := crypto.Keccak256(msg.Marshal()) | ||
return sig.Verify(true, pubkey, true, msgHash, dst) | ||
} | ||
|
||
func CreateSignature(sk *blst.SecretKey, msg *RegistrationMessage) *blst.P2Affine { | ||
func CreateAggregateSignature(sks []*blst.SecretKey, msg *AggregateRegistrationMessage) *blst.P2Affine { | ||
msgHash := crypto.Keccak256(msg.Marshal()) | ||
aggregate := new(blst.P2Aggregate) | ||
for _, sk := range sks { | ||
aff := new(blst.P2Affine) | ||
sig := aff.Sign(sk, msgHash, dst) | ||
ok := aggregate.Add(sig, true) | ||
if !ok { | ||
panic("failure") | ||
} | ||
} | ||
return aggregate.ToAffine() | ||
} | ||
|
||
func CreateSignature(sk *blst.SecretKey, msg *LegacyRegistrationMessage) *blst.P2Affine { | ||
msgHash := crypto.Keccak256(msg.Marshal()) | ||
return new(blst.P2Affine).Sign(sk, msgHash, dst) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters