From 0ab756ce360b54205f55c16f16eac898092271ad Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Mon, 9 Dec 2024 18:18:40 -0500 Subject: [PATCH] chore: fix go mod --- p2p/go.mod | 1 + p2p/go.sum | 1 + p2p/pkg/rpc/provider/service_test.go | 65 ++++++++++++++++++---------- 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/p2p/go.mod b/p2p/go.mod index 4c0c9b35b..3dbc51efb 100644 --- a/p2p/go.mod +++ b/p2p/go.mod @@ -7,6 +7,7 @@ require ( github.com/Masterminds/semver/v3 v3.2.1 github.com/armon/go-radix v1.0.0 github.com/bufbuild/protovalidate-go v0.6.0 + github.com/cloudflare/circl v1.5.0 github.com/cockroachdb/pebble v1.1.2 github.com/ethereum/go-ethereum v1.14.11 github.com/go-logr/logr v1.4.2 diff --git a/p2p/go.sum b/p2p/go.sum index 75b523568..2ab7df191 100644 --- a/p2p/go.sum +++ b/p2p/go.sum @@ -52,6 +52,7 @@ github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UF github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cilium/ebpf v0.2.0/go.mod h1:To2CFviqOWL/M0gIMsvSMlqe7em/l1ALkX1PyjrX2Qs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cloudflare/circl v1.5.0 h1:hxIWksrX6XN5a1L2TI/h53AGPhNHoUBo+TD1ms9+pys= github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaYPt5hWxV3MUfO5dFPFiOXg9CyG5/kCfayTqsJ4= github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU= github.com/cockroachdb/errors v1.11.3 h1:5bA+k2Y6r+oz/6Z/RFlNeVCesGARKuC6YymtcDrbC/I= diff --git a/p2p/pkg/rpc/provider/service_test.go b/p2p/pkg/rpc/provider/service_test.go index 1e01fd161..7e947817b 100644 --- a/p2p/pkg/rpc/provider/service_test.go +++ b/p2p/pkg/rpc/provider/service_test.go @@ -23,6 +23,7 @@ import ( providerapiv1 "github.com/primev/mev-commit/p2p/gen/go/providerapi/v1" providerapi "github.com/primev/mev-commit/p2p/pkg/rpc/provider" "github.com/primev/mev-commit/x/util" + "github.com/stretchr/testify/assert" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/test/bufconn" @@ -486,30 +487,46 @@ func TestBidHandling(t *testing.T) { } } -// func TestBLSKeys(t *testing.T) { - -// iv := make([]byte, 32) -// _, err := rand.Read(iv) -// assert.NoError(t, err) -// blsPrivKey, err := bls.KeyGen[bls.G1](iv, []byte{}, []byte{}) -// assert.NoError(t, err) - -// pubKey := blsPrivKey.PublicKey() - -// // Keccak the value 0x53c61cfb8128ad59244e8c1d26109252ace23d14 -// value := common.Hex2Bytes("53c61cfb8128ad59244e8c1d26109252ace23d14") -// hash := crypto.Keccak256Hash(value) -// t.Logf("Keccak hash: %s", hash.Hex()) - -// signature := bls.Sign(blsPrivKey, hash.Bytes()) -// pubKeyBytes, _ := pubKey.MarshalBinary() -// if !bls.Verify[bls.G1](pubKeyBytes, hash.Bytes(), signature) { -// t.Errorf("Signature verification failed") -// } -// // return nil, nil -// // } -// // return input[:48], nil -// } +func TestBLSKeys(t *testing.T) { + + iv := make([]byte, 32) + _, err := rand.Read(iv) + assert.NoError(t, err) + blsPrivKey, err := bls.KeyGen[bls.G1](iv, []byte{}, []byte{}) + assert.NoError(t, err) + + pubKey := blsPrivKey.PublicKey() + + // Keccak the value 0x53c61cfb8128ad59244e8c1d26109252ace23d14 + value := common.Hex2Bytes("53c61cfb8128ad59244e8c1d26109252ace23d14") + hash := crypto.Keccak256Hash(value) + t.Logf("Keccak hash: %s", hash.Hex()) + + signature := bls.Sign(blsPrivKey, hash.Bytes()) + pubKeyBytes, _ := pubKey.MarshalBinary() + encodedPubKey := hex.EncodeToString(pubKeyBytes) + t.Logf("Encoded Public Key: %s", encodedPubKey) + + encodedSignature := hex.EncodeToString(signature) + t.Logf("Encoded Signature: %s", encodedSignature) + + pubKey2, err := hex.DecodeString(encodedPubKey) + assert.NoError(t, err) + + var pubkey2bytes bls.PublicKey[bls.G1] + if err := pubkey2bytes.UnmarshalBinary(pubKey2); err != nil { + t.Fatalf("error unmarshalling public key: %v", err) + } + + signature2, err := hex.DecodeString(encodedSignature) + + if !bls.Verify[bls.G1](&pubkey2bytes, hash.Bytes(), signature2) { + t.Errorf("Signature verification failed") + } + // return nil, nil + // } + // return input[:48], nil +} func TestWithdrawStakedAmount(t *testing.T) { t.Parallel()