mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-06 01:32:18 +00:00
23072983ff
* Verify signatures of attestations * Implement BLS Signing for attestations * Remove custody bit 0 from the attestation for now * Fixes tests for attestations * Fix tests to ensure they use proper attester indice * Run gazelle * Goimports * Test attestation sigs in block operations * Change formatting and make sure signatures are actually verified * Fix duplicate import * Fix duplicate import from merge * Organize attestation sig to be conssitent with codebase * Update to comments * Change signatures to use aggregation * Run gazelle * Change function to return err instead of bool Also gofmt * Fix for comments * Move createAggregationSignature to a function in attestations.go
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package bls_test
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/rand"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/bls"
|
|
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
|
)
|
|
|
|
func TestMarshalUnmarshal(t *testing.T) {
|
|
b := []byte("hi")
|
|
b32 := bytesutil.ToBytes32(b)
|
|
pk, err := bls.SecretKeyFromBytes(b32[:])
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
pk2, err := bls.SecretKeyFromBytes(b32[:])
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !bytes.Equal(pk.Marshal(), pk2.Marshal()) {
|
|
t.Errorf("Keys not equal, received %#x == %#x", pk.Marshal(), pk2.Marshal())
|
|
}
|
|
}
|
|
|
|
func TestSignVerify(t *testing.T) {
|
|
priv, _ := bls.RandKey(rand.Reader)
|
|
pub := priv.PublicKey()
|
|
msg := []byte("hello")
|
|
sig := priv.Sign(msg, 0)
|
|
if !sig.Verify(pub, msg, 0) {
|
|
t.Error("Signature did not verify")
|
|
}
|
|
}
|
|
|
|
func TestVerifyAggregate(t *testing.T) {
|
|
pubkeys := make([]*bls.PublicKey, 0, 100)
|
|
sigs := make([]*bls.Signature, 0, 100)
|
|
msg := []byte("hello")
|
|
for i := 0; i < 100; i++ {
|
|
priv, _ := bls.RandKey(rand.Reader)
|
|
pub := priv.PublicKey()
|
|
sig := priv.Sign(msg, 0)
|
|
pubkeys = append(pubkeys, pub)
|
|
sigs = append(sigs, sig)
|
|
}
|
|
aggSig := bls.AggregateSignatures(sigs)
|
|
if !aggSig.VerifyAggregate(pubkeys, msg, 0) {
|
|
t.Error("Signature did not verify")
|
|
}
|
|
}
|