Skip to content

Commit

Permalink
Merge branch 'main' into batch-set-known-validators
Browse files Browse the repository at this point in the history
# Conflicts:
#	services/housekeeper/housekeeper.go
  • Loading branch information
Ofir Elias authored and Ofir Elias committed Apr 29, 2023
2 parents b7f6979 + 28168e1 commit 8447e00
Show file tree
Hide file tree
Showing 8 changed files with 316 additions and 127 deletions.
3 changes: 2 additions & 1 deletion beaconclient/multi_beacon_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package beaconclient

import (
"errors"
"fmt"
"os"
"strings"
"sync"
Expand Down Expand Up @@ -265,7 +266,7 @@ func (c *MultiBeaconClient) PublishBlock(block *common.SignedBeaconBlock) (code
}

log.Error("failed to publish block on any CL node")
return lastErrPublishResp.code, lastErrPublishResp.err
return lastErrPublishResp.code, fmt.Errorf("last error: %w", lastErrPublishResp.err)
}

// GetGenesis returns the genesis info - https://ethereum.github.io/beacon-APIs/#/Beacon/getGenesis
Expand Down
9 changes: 4 additions & 5 deletions common/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ func _HexToSignature(s string) (ret types.Signature) {
var ValidPayloadRegisterValidator = types.SignedValidatorRegistration{
Message: &types.RegisterValidatorRequestMessage{
FeeRecipient: _HexToAddress("0xdb65fEd33dc262Fe09D9a2Ba8F80b329BA25f941"),
Timestamp: 1234356,
GasLimit: 278234191203,
Timestamp: 1606824043,
GasLimit: 30000000,
Pubkey: _HexToPubkey(
"0x8a1d7b8dd64e0aafe7ea7b6c95065c9364cf99d38470c12ee807d55f7de1529ad29ce2c422e0b65e3d5a05c02caca249"),
"0x84e975405f8691ad7118527ee9ee4ed2e4e8bae973f6e29aa9ca9ee4aea83605ae3536d22acc9aa1af0545064eacf82e"),
},
// Signed by 0x4e343a647c5a5c44d76c2c58b63f02cdf3a9a0ec40f102ebc26363b4b1b95033
Signature: _HexToSignature(
"0x8209b5391cd69f392b1f02dbc03bab61f574bb6bb54bf87b59e2a85bdc0756f7db6a71ce1b41b727a1f46ccc77b213bf0df1426177b5b29926b39956114421eaa36ec4602969f6f6370a44de44a6bce6dae2136e5fb594cce2a476354264d1ea"),
"0xaf12df007a0c78abb5575067e5f8b089cfcc6227e4a91db7dd8cf517fe86fb944ead859f0781277d9b78c672e4a18c5d06368b603374673cf2007966cece9540f3a1b3f6f9e1bf421d779c4e8010368e6aac134649c7a009210780d401a778a5"),
}
5 changes: 5 additions & 0 deletions common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ var (
ErrIncorrectLength = errors.New("incorrect length")
)

// SlotPos returns the slot's position in the epoch (1-based, i.e. 1..32)
func SlotPos(slot uint64) uint64 {
return (slot % SlotsPerEpoch) + 1
}

func makeRequest(ctx context.Context, client http.Client, method, url string, payload any) (*http.Response, error) {
var req *http.Request
var err error
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package main

//
// Script to create a signed validator registration
//

import (
"fmt"

"github.com/flashbots/go-boost-utils/bls"
boostTypes "github.com/flashbots/go-boost-utils/types"
"github.com/flashbots/mev-boost-relay/common"
)

var (
gasLimit = 30000000
feeRecipient = "0xdb65fEd33dc262Fe09D9a2Ba8F80b329BA25f941"
timestamp = 1606824043
)

func Perr(err error) {
if err != nil {
panic(err)
}
}

func main() {
mainnetDetails, err := common.NewEthNetworkDetails(common.EthNetworkMainnet)
Perr(err)

sk, pubkey, err := bls.GenerateNewKeypair()
Perr(err)

pk, err := boostTypes.BlsPublicKeyToPublicKey(pubkey)
Perr(err)

// Fill in validator registration details
validatorRegistration := boostTypes.RegisterValidatorRequestMessage{ //nolint:exhaustruct
GasLimit: uint64(gasLimit),
Timestamp: uint64(timestamp),
}

validatorRegistration.Pubkey, err = boostTypes.HexToPubkey(pk.String())
Perr(err)
validatorRegistration.FeeRecipient, err = boostTypes.HexToAddress(feeRecipient)
Perr(err)

sig, err := boostTypes.SignMessage(&validatorRegistration, mainnetDetails.DomainBuilder, sk)
Perr(err)
fmt.Println("privkey:", sk.String())
fmt.Println("pubkey: ", pk.String())
fmt.Println("sig: ", sig.String())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"testing"

boostTypes "github.com/flashbots/go-boost-utils/types"
"github.com/flashbots/mev-boost-relay/common"
"github.com/stretchr/testify/require"
)

// TestValidatorRegistrationSignature can be used to validate the signature of an arbitrary validator registration
func TestValidatorRegistrationSignature(t *testing.T) {
// Fill in validator registration details
pubkey := "0x84e975405f8691ad7118527ee9ee4ed2e4e8bae973f6e29aa9ca9ee4aea83605ae3536d22acc9aa1af0545064eacf82e"
gasLimit := 30000000
feeRecipient := "0xdb65fed33dc262fe09d9a2ba8f80b329ba25f941"
timestamp := 1606824043
signature := "0xaf12df007a0c78abb5575067e5f8b089cfcc6227e4a91db7dd8cf517fe86fb944ead859f0781277d9b78c672e4a18c5d06368b603374673cf2007966cece9540f3a1b3f6f9e1bf421d779c4e8010368e6aac134649c7a009210780d401a778a5"

// Constructing the object
payload := boostTypes.SignedValidatorRegistration{
Message: &boostTypes.RegisterValidatorRequestMessage{
GasLimit: uint64(gasLimit),
Timestamp: uint64(timestamp),
},
}

var err error
payload.Message.Pubkey, err = boostTypes.HexToPubkey(pubkey)
require.NoError(t, err)
payload.Signature, err = boostTypes.HexToSignature(signature)
require.NoError(t, err)
payload.Message.FeeRecipient, err = boostTypes.HexToAddress(feeRecipient)
require.NoError(t, err)

mainnetDetails, err := common.NewEthNetworkDetails(common.EthNetworkMainnet)
require.NoError(t, err)

ok, err := boostTypes.VerifySignature(payload.Message, mainnetDetails.DomainBuilder, payload.Message.Pubkey[:], payload.Signature[:])
require.NoError(t, err)
require.True(t, ok)
}
Loading

0 comments on commit 8447e00

Please sign in to comment.