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

Compliance test for BLS signature #402

Merged
merged 9 commits into from
Jan 17, 2025
36 changes: 36 additions & 0 deletions chainio/clients/avsregistry/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (

chainioutils "github.com/Layr-Labs/eigensdk-go/chainio/utils"
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
"github.com/Layr-Labs/eigensdk-go/testutils"
"github.com/Layr-Labs/eigensdk-go/testutils/testclients"
"github.com/Layr-Labs/eigensdk-go/types"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -72,3 +74,37 @@ func TestWriterMethods(t *testing.T) {
require.NotNil(t, receipt)
})
}

// Compliance test for BLS signature
func TestBlsSignature(t *testing.T) {
// read input from JSON if available, otherwise use default values
// Data taken from
// https://github.com/Layr-Labs/eigensdk-compliance/blob/429459572302d9fd42c1184b7257703460ba09ca/data_files/bls_signature.json
var defaultInput = struct {
Message string `json:"message"`
BlsPrivKey string `json:"bls_priv_key"`
}{
Message: "Hello, world!Hello, world!123456",
BlsPrivKey: "12248929636257230549931416853095037629726205319386239410403476017439825112537",
}

testData := testutils.NewTestData(defaultInput)
// The message to sign
messageArray := []byte(testData.Input.Message)

var messageArray32 [32]byte
copy(messageArray32[:], messageArray)

// The private key as a string
privKey, _ := bls.NewPrivateKey(testData.Input.BlsPrivKey)
keyPair := bls.NewKeyPair(privKey)

sig := keyPair.SignMessage(messageArray32)

x := sig.G1Affine.X.String()
y := sig.G1Affine.Y.String()

// Values taken from previous run of this test
assert.Equal(t, x, "15790168376429033610067099039091292283117017641532256477437243974517959682102")
Copy link
Contributor

@afkbyte afkbyte Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I would add a comment on where these values are from

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

assert.Equal(t, y, "4960450323239587206117776989095741074887370703941588742100855592356200866613")
}
Loading