From 3a10dc2126c15cc3ae18fad1a8e71f987f93fe0b Mon Sep 17 00:00:00 2001 From: Pablo Deymonnaz Date: Fri, 6 Dec 2024 17:17:59 -0300 Subject: [PATCH 1/3] Compliance test for BLS signature --- chainio/clients/avsregistry/writer_test.go | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/chainio/clients/avsregistry/writer_test.go b/chainio/clients/avsregistry/writer_test.go index 11537dc5..714b9e7d 100644 --- a/chainio/clients/avsregistry/writer_test.go +++ b/chainio/clients/avsregistry/writer_test.go @@ -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" ) @@ -72,3 +74,32 @@ func TestWriterMethods(t *testing.T) { require.NotNil(t, receipt) }) } + +func TestAvsRegistryWriterTest_ComplianceBLSSignature(t *testing.T) { + // read input from JSON if available, otherwise use default values + var defaultInput = struct { + messageBytes []byte `json:"message_bytes"` + bls_priv_key string `json:"bls_priv_key"` + }{ + messageBytes: []byte("Hello, world!Hello, world!123456"), + bls_priv_key: "12248929636257230549931416853095037629726205319386239410403476017439825112537", + } + + testData := testutils.NewTestData(defaultInput) + + // The message to sign + var messageArray [32]byte + copy(messageArray[:], testData.Input.messageBytes[:32]) + + // The private key as a string + privKey, _ := bls.NewPrivateKey(testData.Input.bls_priv_key) + keyPair := bls.NewKeyPair(privKey) + + sig := keyPair.SignMessage(messageArray) + + x := sig.G1Affine.X.String() + y := sig.G1Affine.Y.String() + + assert.Equal(t, x, "15790168376429033610067099039091292283117017641532256477437243974517959682102") + assert.Equal(t, y, "4960450323239587206117776989095741074887370703941588742100855592356200866613") +} From c02699ac7d14436aa1d230a9d718c7b8be5824a0 Mon Sep 17 00:00:00 2001 From: Pablo Deymonnaz Date: Mon, 9 Dec 2024 16:55:56 -0300 Subject: [PATCH 2/3] TestBlsSignature name change for compliance repo --- chainio/clients/avsregistry/writer_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chainio/clients/avsregistry/writer_test.go b/chainio/clients/avsregistry/writer_test.go index 714b9e7d..c418ef5b 100644 --- a/chainio/clients/avsregistry/writer_test.go +++ b/chainio/clients/avsregistry/writer_test.go @@ -75,7 +75,7 @@ func TestWriterMethods(t *testing.T) { }) } -func TestAvsRegistryWriterTest_ComplianceBLSSignature(t *testing.T) { +func TestBlsSignature(t *testing.T) { // read input from JSON if available, otherwise use default values var defaultInput = struct { messageBytes []byte `json:"message_bytes"` From 4328000ebddead80075136130e8e3d3722119b66 Mon Sep 17 00:00:00 2001 From: Pablo Deymonnaz Date: Mon, 9 Dec 2024 17:50:14 -0300 Subject: [PATCH 3/3] fixing TestBlsSignature (problem with case in field) --- chainio/clients/avsregistry/writer_test.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/chainio/clients/avsregistry/writer_test.go b/chainio/clients/avsregistry/writer_test.go index c418ef5b..79326d6b 100644 --- a/chainio/clients/avsregistry/writer_test.go +++ b/chainio/clients/avsregistry/writer_test.go @@ -78,24 +78,25 @@ func TestWriterMethods(t *testing.T) { func TestBlsSignature(t *testing.T) { // read input from JSON if available, otherwise use default values var defaultInput = struct { - messageBytes []byte `json:"message_bytes"` - bls_priv_key string `json:"bls_priv_key"` + Message string `json:"message"` + BlsPrivKey string `json:"bls_priv_key"` }{ - messageBytes: []byte("Hello, world!Hello, world!123456"), - bls_priv_key: "12248929636257230549931416853095037629726205319386239410403476017439825112537", + Message: "Hello, world!Hello, world!123456", + BlsPrivKey: "12248929636257230549931416853095037629726205319386239410403476017439825112537", } testData := testutils.NewTestData(defaultInput) - // The message to sign - var messageArray [32]byte - copy(messageArray[:], testData.Input.messageBytes[:32]) + messageArray := []byte(testData.Input.Message) + + var messageArray32 [32]byte + copy(messageArray32[:], messageArray) // The private key as a string - privKey, _ := bls.NewPrivateKey(testData.Input.bls_priv_key) + privKey, _ := bls.NewPrivateKey(testData.Input.BlsPrivKey) keyPair := bls.NewKeyPair(privKey) - sig := keyPair.SignMessage(messageArray) + sig := keyPair.SignMessage(messageArray32) x := sig.G1Affine.X.String() y := sig.G1Affine.Y.String()