prysm-pulse/shared/bls/spectest/fast_aggregate_verify_test.go
Preston Van Loon 14dbc2b74d
Add blst for BLS (#6539)
* 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>
2020-09-16 21:28:28 +08:00

70 lines
2.1 KiB
Go

package spectest
import (
"encoding/hex"
"path"
"testing"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/ghodss/yaml"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/bls/iface"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
)
func TestFastAggregateVerifyYaml(t *testing.T) {
flags := &featureconfig.Flags{}
reset := featureconfig.InitWithReset(flags)
t.Run("herumi", testFastAggregateVerifyYaml)
reset()
flags.EnableBlst = true
reset = featureconfig.InitWithReset(flags)
t.Run("blst", testFastAggregateVerifyYaml)
reset()
}
func testFastAggregateVerifyYaml(t *testing.T) {
testFolders, testFolderPath := testutil.TestFolders(t, "general", "bls/fast_aggregate_verify/small")
for i, folder := range testFolders {
t.Run(folder.Name(), func(t *testing.T) {
file, err := testutil.BazelFileBytes(path.Join(testFolderPath, folder.Name(), "data.yaml"))
require.NoError(t, err)
test := &FastAggregateVerifyTest{}
require.NoError(t, yaml.Unmarshal(file, test))
pubkeys := make([]iface.PublicKey, len(test.Input.Pubkeys))
for j, raw := range test.Input.Pubkeys {
pkBytes, err := hex.DecodeString(raw[2:])
require.NoError(t, err)
pk, err := bls.PublicKeyFromBytes(pkBytes)
require.NoError(t, err)
pubkeys[j] = pk
}
msgBytes, err := hex.DecodeString(test.Input.Message[2:])
require.NoError(t, err)
sigBytes, err := hex.DecodeString(test.Input.Signature[2:])
require.NoError(t, err)
sig, err := bls.SignatureFromBytes(sigBytes)
if err != nil {
if test.Output == false {
return
}
t.Fatalf("Cannot unmarshal input to signature: %v", err)
}
verified := sig.FastAggregateVerify(pubkeys, bytesutil.ToBytes32(msgBytes))
if verified != test.Output {
t.Fatalf("Signature does not match the expected verification output. "+
"Expected %#v but received %#v for test case %d", test.Output, verified, i)
}
t.Log("Success")
})
}
}