Faster BLS publickey.Copy (#4770)

* Use balancesLength and randaoMixesLength to save copy on read
* use a cheaper copy for BLS publickey.Copy()
* Merge branch 'master' into bls-better-copy
* Merge refs/heads/master into bls-better-copy
* Merge refs/heads/master into bls-better-copy
* Merge refs/heads/master into bls-better-copy
* Merge refs/heads/master into bls-better-copy
* Merge branch 'master' of github.com:prysmaticlabs/prysm into bls-better-copy
* quick test
* Merge refs/heads/master into bls-better-copy
This commit is contained in:
Preston Van Loon 2020-02-06 09:35:38 -08:00 committed by GitHub
parent 3a9c8eb8b1
commit c7fb28d42e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View File

@ -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.

View File

@ -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")
}
}