Skip to content

Commit

Permalink
Use go-eth2-client's IsInfinity() to check relay pubkey (#630)
Browse files Browse the repository at this point in the history
* Use IsInfinity() to check relay pubkey

* Disable dupl linter

* Fix import order
  • Loading branch information
jtraglia authored Apr 4, 2024
1 parent b17921a commit 74a8ecb
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 57 deletions.
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
69 changes: 35 additions & 34 deletions server/mock/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
2 changes: 1 addition & 1 deletion server/types/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")
6 changes: 1 addition & 5 deletions server/types/relay_entry.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package types

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 @@ -61,7 +57,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/types/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

0 comments on commit 74a8ecb

Please sign in to comment.