Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster BLS publickey.Copy #4770

Merged
merged 10 commits into from Feb 6, 2020
6 changes: 2 additions & 4 deletions shared/bls/bls.go
Expand Up @@ -153,10 +153,8 @@ func (p *PublicKey) Marshal() []byte {

// Copy the public key to a new pointer reference.
func (p *PublicKey) Copy() (*PublicKey, error) {
rawBytes := p.p.Serialize()
newKey := &bls12.PublicKey{}
err := newKey.Deserialize(rawBytes)
return &PublicKey{p: newKey}, err
np := *p.p
return &PublicKey{p: &np}, nil
}

// Aggregate two public keys.
Expand Down
12 changes: 12 additions & 0 deletions shared/bls/bls_test.go
Expand Up @@ -278,3 +278,15 @@ func TestSignatureFromBytes(t *testing.T) {
})
}
}

func TestPublicKey_Copy(t *testing.T) {
pubkeyA := bls.RandKey().PublicKey()
pubkeyBytes := pubkeyA.Marshal()

pubkeyB, _ := pubkeyA.Copy()
pubkeyB.Aggregate(bls.RandKey().PublicKey())

if !bytes.Equal(pubkeyA.Marshal(), pubkeyBytes) {
t.Fatal("Pubkey was mutated after copy")
}
}