Skip to content

Commit

Permalink
Add verifications in getHeader handler (#182)
Browse files Browse the repository at this point in the history
* Add parent hash verification in getHeader

Signed-off-by: Luca Georges Francois <[email protected]>

* Remove unnecessary nil check

Co-authored-by: Chris Hager <[email protected]>

* Update error log in getHeader handler

Signed-off-by: Luca Georges Francois <[email protected]>

Co-authored-by: Chris Hager <[email protected]>
  • Loading branch information
0xpanoramix and metachris authored Jul 4, 2022
1 parent 64edd7c commit 3721723
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion server/mock_relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ func (m *mockRelay) MakeGetHeaderResponse(value uint64, hash, publicKey string)
// Fill the payload with custom values.
message := &types.BuilderBid{
Header: &types.ExecutionPayloadHeader{
BlockHash: _HexToHash(hash),
BlockHash: _HexToHash(hash),
ParentHash: _HexToHash("0xe28385e7bd68df656cd0042b74b69c3104b5356ed1f20eb69f1f925df47a3ab7"),
},
Value: types.IntToU256(value),
Pubkey: _HexToPubkey(publicKey),
Expand Down
10 changes: 10 additions & 0 deletions server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,16 @@ func (m *BoostService) handleGetHeader(w http.ResponseWriter, req *http.Request)
return
}

// Verify response coherence with proposer's input data
responseParentHash := responsePayload.Data.Message.Header.ParentHash.String()
if responseParentHash != parentHashHex {
log.WithFields(logrus.Fields{
"originalParentHash": parentHashHex,
"responseParentHash": responseParentHash,
}).Error("proposer and relay parent hashes are not the same")
return
}

// Compare value of header, skip processing this result if lower fee than current
mu.Lock()
defer mu.Unlock()
Expand Down
10 changes: 10 additions & 0 deletions server/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,16 @@ func TestGetHeader(t *testing.T) {
require.Equal(t, http.StatusBadRequest, rr.Code, rr.Body.String())
require.Equal(t, 0, backend.relays[0].GetRequestCount(path))
})

t.Run("Invalid parent hash", func(t *testing.T) {
backend := newTestBackend(t, 1, time.Second)

invalidParentHashPath := getPath(1, types.Hash{}, pubkey)
rr := backend.request(t, http.MethodGet, invalidParentHashPath, nil)

require.Equal(t, `{"code":502,"message":"no successful relay response"}`+"\n", rr.Body.String())
require.Equal(t, 0, backend.relays[0].GetRequestCount(path))
})
}

func TestGetPayload(t *testing.T) {
Expand Down

0 comments on commit 3721723

Please sign in to comment.