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

Use go-eth2-client's IsInfinity() to check relay pubkey #630

Merged
merged 4 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
linters:
enable-all: true
disable:
- dupl
- exhaustruct
- funlen
- gochecknoglobals
Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/flashbots/mev-boost
go 1.21

require (
github.com/ethereum/go-ethereum v1.13.10
github.com/flashbots/go-boost-utils v1.8.0
github.com/ethereum/go-ethereum v1.13.14
github.com/flashbots/go-boost-utils v1.8.1
github.com/flashbots/go-utils v0.5.0
github.com/google/uuid v1.6.0
github.com/gorilla/mux v1.8.1
Expand Down Expand Up @@ -59,7 +59,6 @@ require (

require (
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/VictoriaMetrics/fastcache v1.12.1 // indirect
github.com/attestantio/go-builder-client v0.4.2
github.com/attestantio/go-eth2-client v0.19.10
github.com/btcsuite/btcd v0.22.0-beta // indirect
Expand All @@ -68,7 +67,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/ferranbt/fastssz v0.1.3 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
Expand Down
15 changes: 7 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ github.com/VictoriaMetrics/fastcache v1.12.1 h1:i0mICQuojGDL3KblA7wUNlY5lOK6a4bw
github.com/VictoriaMetrics/fastcache v1.12.1/go.mod h1:tX04vaqcNoQeGLD+ra5pU5sWkuxnzWhEzLwhP9w653o=
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/attestantio/go-builder-client v0.4.2 h1:EycfAFqQV+ooc2z6hmTsbuH4TCLknr0aO0nHLHLMpJM=
github.com/attestantio/go-builder-client v0.4.2/go.mod h1:e02i/WO4fjs3/u9oIZEjiC8CK1Qyxy4cpiMMGKx4VqQ=
Expand Down Expand Up @@ -95,16 +93,16 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw=
github.com/ethereum/c-kzg-4844 v0.4.0 h1:3MS1s4JtA868KpJxroZoepdV0ZKBp3u/O5HcZ7R3nlY=
github.com/ethereum/c-kzg-4844 v0.4.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0=
github.com/ethereum/go-ethereum v1.13.10 h1:Ppdil79nN+Vc+mXfge0AuUgmKWuVv4eMqzoIVSdqZek=
github.com/ethereum/go-ethereum v1.13.10/go.mod h1:sc48XYQxCzH3fG9BcrXCOOgQk2JfZzNAmIKnceogzsA=
github.com/ethereum/go-ethereum v1.13.14 h1:EwiY3FZP94derMCIam1iW4HFVrSgIcpsu0HwTQtm6CQ=
github.com/ethereum/go-ethereum v1.13.14/go.mod h1:TN8ZiHrdJwSe8Cb6x+p0hs5CxhJZPbqB7hHkaUXcmIU=
github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/ferranbt/fastssz v0.1.3 h1:ZI+z3JH05h4kgmFXdHuR1aWYsgrg7o+Fw7/NCzM16Mo=
github.com/ferranbt/fastssz v0.1.3/go.mod h1:0Y9TEd/9XuFlh7mskMPfXiI2Dkw4Ddg9EyXt1W7MRvE=
github.com/flashbots/go-boost-utils v1.8.0 h1:z3K1hw+Fbl9AGMNQKnK7Bvf0M/rKgjfruAEvra+Z8Mg=
github.com/flashbots/go-boost-utils v1.8.0/go.mod h1:Ry1Rw8Lx5v1rpAR0+IvR4sV10jYAeQaGVM3vRD8mYdM=
github.com/flashbots/go-boost-utils v1.8.1 h1:AD+1+4oCbBjXLK8IqWHYznD95K6/MmqXhozv5fFOCkU=
github.com/flashbots/go-boost-utils v1.8.1/go.mod h1:jFi2H1el7jGPr2ShkWpYPfKsY9vwsFNmBPJRCO7IPg8=
github.com/flashbots/go-utils v0.5.0 h1:ldjWta9B9//DJU2QcwRbErez3+1aKhSn6EoFc6d5kPY=
github.com/flashbots/go-utils v0.5.0/go.mod h1:LauDwifaRdSK0mS5X34GR59pJtUu1T/lOFNdff1BqtI=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
Expand All @@ -125,8 +123,8 @@ github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxI
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8=
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho=
Expand Down Expand Up @@ -474,6 +472,7 @@ golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
2 changes: 1 addition & 1 deletion server/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import "errors"
// ErrMissingRelayPubkey is returned if a new RelayEntry URL has no public key.
var ErrMissingRelayPubkey = errors.New("missing relay public key")

// ErrPointAtInfinityPubkey is returned if a new RelayEntry URL has an all-zero public key.
// ErrPointAtInfinityPubkey is returned if a new RelayEntry URL has point-at-infinity public key.
var ErrPointAtInfinityPubkey = errors.New("relay public key cannot be the point-at-infinity")
69 changes: 35 additions & 34 deletions server/mock_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@ func TestHexToHash(t *testing.T) {
expectedPanic: true,
expectedHash: nil,
},
/*
{
name: "Should panic because of invalid hexadecimal input",
hex: "foo",
expectedPanic: true,
expectedHash: nil,
},
*/
{
name: "Should panic because of invalid hexadecimal input",
hex: "foo",
expectedPanic: true,
expectedHash: nil,
},
{
name: "Should not panic and convert hexadecimal input to hash",
hex: common.Hash{0x01}.String(),
Expand Down Expand Up @@ -115,14 +113,12 @@ func TestHexToAddress(t *testing.T) {
expectedPanic: true,
expectedAddress: nil,
},
/*
{
name: "Should panic because of invalid hexadecimal input",
hex: "foo",
expectedPanic: true,
expectedAddress: nil,
},
*/
{
name: "Should panic because of invalid hexadecimal input",
hex: "foo",
expectedPanic: true,
expectedAddress: nil,
},
{
name: "Should not panic and convert hexadecimal input to address",
hex: common.Address{0x01}.String(),
Expand All @@ -149,6 +145,15 @@ func TestHexToAddress(t *testing.T) {

// Same as for TestHexToHash and TestHexToAddress.
func TestHexToPublicKey(t *testing.T) {
publicKey := phase0.BLSPubKey{
0x82, 0xf6, 0xe7, 0xcc, 0x57, 0xa2, 0xce, 0x68,
0xec, 0x41, 0x32, 0x1b, 0xeb, 0xc5, 0x5b, 0xcb,
0x31, 0x94, 0x5f, 0xe6, 0x6a, 0x8e, 0x67, 0xeb,
0x82, 0x51, 0x42, 0x5f, 0xab, 0x4c, 0x6a, 0x38,
0xc1, 0x0c, 0x53, 0x21, 0x0a, 0xea, 0x97, 0x96,
0xdd, 0x0b, 0xa0, 0x44, 0x1b, 0x46, 0x76, 0x2a,
}

testCases := []struct {
name string
hex string
Expand All @@ -162,19 +167,17 @@ func TestHexToPublicKey(t *testing.T) {
expectedPanic: true,
expectedPublicKey: nil,
},
/*
{
name: "Should panic because of invalid hexadecimal input",
hex: "foo",
expectedPanic: true,
expectedSignature: nil,
},
*/
{
name: "Should panic because of invalid hexadecimal input",
hex: "foo",
expectedPanic: true,
expectedPublicKey: nil,
},
{
name: "Should not panic and convert hexadecimal input to public key",
hex: phase0.BLSPubKey{0x01}.String(),
hex: publicKey.String(),
expectedPanic: false,
expectedPublicKey: &phase0.BLSPubKey{0x01},
expectedPublicKey: &publicKey,
},
}

Expand Down Expand Up @@ -232,14 +235,12 @@ func TestHexToSignature(t *testing.T) {
expectedPanic: true,
expectedSignature: nil,
},
/*
{
name: "Should panic because of invalid hexadecimal input",
hex: "foo",
expectedPanic: true,
expectedSignature: nil,
},
*/
{
name: "Should panic because of invalid hexadecimal input",
hex: "foo",
expectedPanic: true,
expectedSignature: nil,
},
{
name: "Should not panic and convert hexadecimal input to signature",
hex: hexutil.Encode(sigBytes),
Expand Down
6 changes: 1 addition & 5 deletions server/relay_entry.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package server

import (
"bytes"
"net/url"
"strings"

"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/flashbots/go-boost-utils/utils"
)

// The point-at-infinity is 48 zero bytes.
var pointAtInfinityPubkey = [48]byte{}

// RelayEntry represents a relay that mev-boost connects to.
type RelayEntry struct {
PublicKey phase0.BLSPubKey
Expand Down Expand Up @@ -53,7 +49,7 @@ func NewRelayEntry(relayURL string) (entry RelayEntry, err error) {
}

// Check if the public key is the point-at-infinity.
if bytes.Equal(entry.PublicKey[:], pointAtInfinityPubkey[:]) {
if entry.PublicKey.IsInfinity() {
return entry, ErrPointAtInfinityPubkey
}

Expand Down
21 changes: 16 additions & 5 deletions server/relay_entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"fmt"
"testing"

"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/flashbots/go-boost-utils/types"
"github.com/flashbots/go-boost-utils/utils"
"github.com/stretchr/testify/require"
)

func TestParseRelaysURLs(t *testing.T) {
// Used to fake a relay's public key.
publicKey := phase0.BLSPubKey{0x01}
publicKey, err := utils.HexToPubkey("0x82f6e7cc57a2ce68ec41321bebc55bcb31945fe66a8e67eb8251425fab4c6a38c10c53210aea9796dd0ba0441b46762a")
require.NoError(t, err)

testCases := []struct {
name string
Expand Down Expand Up @@ -64,15 +65,25 @@ func TestParseRelaysURLs(t *testing.T) {
expectedURL: "https://" + publicKey.String() + "@12.345.678:9999",
},
{
name: "Relay URL with invalid public key",
name: "Relay URL with an invalid public key (wrong length)",
relayURL: "http://0x123456@foo.com",
expectedErr: types.ErrLength,
},
{
name: "Relay URL with point-at-infinity public key",
relayURL: "http://0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000@foo.com",
name: "Relay URL with an invalid public key (not on the curve)",
relayURL: "http://0xac6e78dfe25ecd6110b8e780608cce0dab71fdd5ebea22a16c0205200f2f8e2e3ad3b71d3499c54ad14d6c21b41a37ae@foo.com",
expectedErr: utils.ErrInvalidPubkey,
},
{
name: "Relay URL with an invalid public key (point-at-infinity)",
relayURL: "http://0xc00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000@foo.com",
expectedErr: ErrPointAtInfinityPubkey,
},
{
name: "Relay URL with an invalid public key (all zero)",
relayURL: "http://0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000@foo.com",
expectedErr: utils.ErrInvalidPubkey,
},
{
name: "Relay URL with query arg",
relayURL: fmt.Sprintf("http://%s@foo.com?id=foo&bar=1", publicKey.String()),
Expand Down
Loading