mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-07 10:12:19 +00:00
14dbc2b74d
* Add blst third party dep * initial build * add init * blst passing tests * add feature flag * blst and herumi for spec tests * maybe this works for mac * Actually set feature flag * Add stub for VerifyMultipleSignatures for blst * verifyCompressed * use correct cores sizes * aggregate public keys * add multi-sig verification * encode not hash * revert back * go mod tidy * update blst to latest commit * add batch decompress * fix * add test * gofmt * update blst * go mod tidy * remove kubesec, fix * mod tidy * disable some remote cache * disable some remote cache * disable some remote cache * disable some remote cache * Switch to -D__ADX__ * update * tidy * fix build * Make blst for only linux,amd64 * gofmt * lint * lint * gazelle * fix build tag * more stub methods * shift adx instructions to x86 * fix arm64 * Revert "fix arm64" This reverts commit 4d34ac21b7509a1b385374e3039efecfcab614c1. * add one more in * Revert "Revert "fix arm64"" This reverts commit 1c8ae24ad16ff9811590f1058b9d98c90b63251a. * try darwin now * Revert "try darwin now" This reverts commit 6f884714b8e14a7a803b72157672b6e942047f37. * Add sha256 * remove TODO * checkpoint * finally builds * fix up * add tag * try again * explicit disabling * remove * select properly * fix * better * make CI happy too * Update .bazelrc * Update .bazelrc * fix tests * revert back * Update shared/bls/blst/public_key.go Co-authored-by: Victor Farazdagi <simple.square@gmail.com> * Update shared/bls/blst/public_key.go Co-authored-by: Victor Farazdagi <simple.square@gmail.com> * clean up tests * more clean up * clean up * add * Update shared/bls/blst/signature.go * Update shared/bls/blst/signature.go * Update .buildkite-bazelrc Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> * try again * remove go tag * revert change * gaz * gazelle ignore Co-authored-by: nisdas <nishdas93@gmail.com> Co-authored-by: Victor Farazdagi <simple.square@gmail.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
85 lines
2.1 KiB
Go
85 lines
2.1 KiB
Go
package herumi
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/dgraph-io/ristretto"
|
|
bls12 "github.com/herumi/bls-eth-go-binary/bls"
|
|
"github.com/pkg/errors"
|
|
"github.com/prysmaticlabs/prysm/shared/bls/iface"
|
|
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
)
|
|
|
|
var maxKeys = int64(100000)
|
|
var pubkeyCache, _ = ristretto.NewCache(&ristretto.Config{
|
|
NumCounters: maxKeys,
|
|
MaxCost: 1 << 22, // ~4mb is cache max size
|
|
BufferItems: 64,
|
|
})
|
|
|
|
// PublicKey used in the BLS signature scheme.
|
|
type PublicKey struct {
|
|
p *bls12.PublicKey
|
|
}
|
|
|
|
// PublicKeyFromBytes creates a BLS public key from a BigEndian byte slice.
|
|
func PublicKeyFromBytes(pubKey []byte) (iface.PublicKey, error) {
|
|
if featureconfig.Get().SkipBLSVerify {
|
|
return &PublicKey{}, nil
|
|
}
|
|
if len(pubKey) != params.BeaconConfig().BLSPubkeyLength {
|
|
return nil, fmt.Errorf("public key must be %d bytes", params.BeaconConfig().BLSPubkeyLength)
|
|
}
|
|
if cv, ok := pubkeyCache.Get(string(pubKey)); ok {
|
|
return cv.(*PublicKey).Copy(), nil
|
|
}
|
|
p := &bls12.PublicKey{}
|
|
err := p.Deserialize(pubKey)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "could not unmarshal bytes into public key")
|
|
}
|
|
pubKeyObj := &PublicKey{p: p}
|
|
pubkeyCache.Set(string(pubKey), pubKeyObj.Copy(), 48)
|
|
return pubKeyObj, nil
|
|
}
|
|
|
|
// AggregatePublicKeys aggregates the provided raw public keys into a single key.
|
|
func AggregatePublicKeys(pubs [][]byte) (iface.PublicKey, error) {
|
|
if len(pubs) == 0 {
|
|
return &PublicKey{}, nil
|
|
}
|
|
p, err := PublicKeyFromBytes(pubs[0])
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
for _, k := range pubs[1:] {
|
|
pubkey, err := PublicKeyFromBytes(k)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
p.Aggregate(pubkey)
|
|
}
|
|
return p, nil
|
|
}
|
|
|
|
// Marshal a public key into a LittleEndian byte slice.
|
|
func (p *PublicKey) Marshal() []byte {
|
|
return p.p.Serialize()
|
|
}
|
|
|
|
// Copy the public key to a new pointer reference.
|
|
func (p *PublicKey) Copy() iface.PublicKey {
|
|
np := *p.p
|
|
return &PublicKey{p: &np}
|
|
}
|
|
|
|
// Aggregate two public keys.
|
|
func (p *PublicKey) Aggregate(p2 iface.PublicKey) iface.PublicKey {
|
|
if featureconfig.Get().SkipBLSVerify {
|
|
return p
|
|
}
|
|
p.p.Add(p2.(*PublicKey).p)
|
|
return p
|
|
}
|