Skip to content

Commit

Permalink
Check deneb blobs
Browse files Browse the repository at this point in the history
  • Loading branch information
avalonche committed Aug 11, 2023
1 parent 62612f4 commit b46d453
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 34 deletions.
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ linters-settings:
disable:
- fieldalignment
- shadow
gomoddirectives:
replace-allow-list:
- github.com/attestantio/go-builder-client

output:
print-issued-lines: true
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ require (
require (
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
github.com/VictoriaMetrics/fastcache v1.6.0 // indirect
github.com/attestantio/go-builder-client v0.3.2-0.20230626105718-423f7ec4ad24
github.com/attestantio/go-builder-client v0.3.2-0.20230809093013-1fa02af241e1
github.com/attestantio/go-eth2-client v0.18.1-0.20230728160410-bc2888aaf7d7
github.com/btcsuite/btcd v0.22.0-beta // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
Expand Down Expand Up @@ -82,5 +82,3 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/attestantio/go-builder-client => github.com/avalonche/go-builder-client v0.0.0-20230727154356-9a77badf0423
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ 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.3.2-0.20230809093013-1fa02af241e1 h1:c6Jmkd6mryaFuWv2/Pa4aLqi+2QOv3gEN+Krj0Nmiq4=
github.com/attestantio/go-builder-client v0.3.2-0.20230809093013-1fa02af241e1/go.mod h1:8NZx9L/rC7nLhSMbbVR6PXr37tC28wTE4u65n+Pa3BQ=
github.com/attestantio/go-eth2-client v0.18.1-0.20230728160410-bc2888aaf7d7 h1:7CCFg+rn8EppcURkhMLdNv0rl0lwFcAxkwV7kKOSF14=
github.com/attestantio/go-eth2-client v0.18.1-0.20230728160410-bc2888aaf7d7/go.mod h1:KSVlZSW1A3jUg5H8O89DLtqxgJprRfTtI7k89fLdhu0=
github.com/avalonche/go-builder-client v0.0.0-20230727154356-9a77badf0423 h1:JWWVNPwWVThSmcfzKBjRbglwe4c6eEYquALAISClK0U=
github.com/avalonche/go-builder-client v0.0.0-20230727154356-9a77badf0423/go.mod h1:8NZx9L/rC7nLhSMbbVR6PXr37tC28wTE4u65n+Pa3BQ=
github.com/avalonche/go-eth2-client v0.0.0-20230727154722-91c9a241729e h1:4bLKeIfXtiYOuEJyZuXeWWdRwfArYRd7UP4PBJZUVOo=
github.com/avalonche/go-eth2-client v0.0.0-20230727154722-91c9a241729e/go.mod h1:KSVlZSW1A3jUg5H8O89DLtqxgJprRfTtI7k89fLdhu0=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down
63 changes: 41 additions & 22 deletions server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/attestantio/go-eth2-client/api/v1/capella"
"github.com/attestantio/go-eth2-client/api/v1/deneb"
"github.com/attestantio/go-eth2-client/spec/phase0"
denebutil "github.com/attestantio/go-eth2-client/util/deneb"
"github.com/flashbots/go-boost-utils/ssz"
"github.com/flashbots/go-boost-utils/types"
"github.com/flashbots/go-boost-utils/utils"
Expand Down Expand Up @@ -651,26 +652,10 @@ func (m *BoostService) processCapellaPayload(w http.ResponseWriter, req *http.Re
m.respondOK(w, result)
}

func (m *BoostService) processDenebPayload(w http.ResponseWriter, req *http.Request, log *logrus.Entry, payload *deneb.SignedBlindedBlockContents, body []byte) {
if payload == nil || payload.SignedBlindedBlock == nil || payload.SignedBlindedBlobSidecars == nil {
log.WithField("body", string(body)).Error("missing parts of the request payload from the beacon-node")
m.respondError(w, http.StatusBadRequest, "missing parts of the payload")
return
}

func (m *BoostService) processDenebPayload(w http.ResponseWriter, req *http.Request, log *logrus.Entry, payload *deneb.SignedBlindedBlockContents) {
// no need to check if fields are nil as the json unmarshalling library does the nil check for us
blindedBlock := payload.SignedBlindedBlock
if blindedBlock.Message == nil || blindedBlock.Message.Body == nil || blindedBlock.Message.Body.ExecutionPayloadHeader == nil {
log.WithField("body", string(body)).Error("missing parts of the block from the beacon-node")
m.respondError(w, http.StatusBadRequest, "missing parts of the block")
return
}

blindedBlobs := payload.SignedBlindedBlobSidecars
if blindedBlobs == nil {
log.WithField("body", string(body)).Error("missing blobs bundle from the beacon-node")
m.respondError(w, http.StatusBadRequest, "missing blobs bundle")
return
}

// Get the slotUID for this slot
slotUID := ""
Expand Down Expand Up @@ -774,14 +759,48 @@ func (m *BoostService) processDenebPayload(w http.ResponseWriter, req *http.Requ
}

// Ensure that blobs are valid and matches the request
if len(blindedBlobs) != len(blobs.Blobs) {
if len(blindedBlobs) != len(blobs.Blobs) || len(blindedBlobs) != len(blobs.Commitments) || len(blindedBlobs) != len(blobs.Proofs) {
log.WithFields(logrus.Fields{
"requestBlobs": len(blindedBlobs),
"responseBlobs": len(blobs.Blobs),
"requestBlobs": len(blindedBlobs),
}).Error("requestBlobs length does not equal responseBlobs length")
return
}

for i, blindedBlob := range blindedBlobs {
if blindedBlob.Message.KzgCommitment != blobs.Commitments[i] {
log.WithFields(logrus.Fields{
"requestBlobCommitment": blindedBlob.Message.KzgCommitment.String(),
"responseBlobCommiment": blobs.Commitments[i].String(),
"index": blindedBlob.Message.Index,
}).Error("requestBlobCommitment does not equal responseBlobCommiment")
return
}

if blindedBlob.Message.KzgProof != blobs.Proofs[i] {
log.WithFields(logrus.Fields{
"requestBlobProof": blindedBlob.Message.KzgProof.String(),
"responseBlobProof": blobs.Proofs[i].String(),
"index": blindedBlob.Message.Index,
}).Error("requestBlobProof does not equal responseBlobProof")
return
}

blobHelper := denebutil.BeaconBlockBlob{Blob: blobs.Blobs[i]}
blobRoot, err := blobHelper.HashTreeRoot()
if err != nil {
log.WithError(err).Error("error calculating blobRoot")
return
}
if blindedBlob.Message.BlobRoot != blobRoot {
log.WithFields(logrus.Fields{
"requestBlobRoot": blindedBlob.Message.BlobRoot.String(),
"responseBlobRoot": fmt.Sprintf("%#x", blobRoot),
"index": blindedBlob.Message.Index,
}).Error("requestBlobRoot does not equal responseBlobRoot")
return
}
}

// Lock before accessing the shared payload
mu.Lock()
defer mu.Unlock()
Expand Down Expand Up @@ -836,7 +855,7 @@ func (m *BoostService) handleGetPayload(w http.ResponseWriter, req *http.Request
m.processCapellaPayload(w, req, log, payload, body)
return
}
m.processDenebPayload(w, req, log, payload, body)
m.processDenebPayload(w, req, log, payload)
}

// CheckRelays sends a request to each one of the relays previously registered to get their status
Expand Down
4 changes: 2 additions & 2 deletions testdata/signed-blinded-beacon-block-deneb.json
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@
"slot": "12231583639632491026",
"block_parent_root": "0x22de86edc38dc56c4255cba641c83251a2a2dcc7535e773c9a2fb2e8b73758a4",
"proposer_index": "16148839969926959295",
"blob_root": "0x3c1820c62034fc45c10abc983dbce08de28f303192dea32371a902b3e6a1fc29",
"blob_root": "0xb7d05f875f140027ef5118a2247bbb84ce8f2f0f1123623085daf7960c329f5f",
"kzg_commitment": "0x0748ac5c58e66b1fae24289f9014948876fbd78da88931bb6cbcd2e44a01bd07ab4f33e54ec9b9a2ada2e83c840dceb6",
"kzg_proof": "0xc6e27a3ae80243ba7ea88eab107a0675020e0745d75ab6a1553691007a50f7f99f597693ac33ae3cea63bf0b90a734ff"
},
Expand All @@ -327,7 +327,7 @@
"slot": "12231583639632491026",
"block_parent_root": "0x22de86edc38dc56c4255cba641c83251a2a2dcc7535e773c9a2fb2e8b73758a4",
"proposer_index": "16148839969926959295",
"blob_root": "0x3c1820c62034fc45c10abc983dbce08de28f303192dea32371a902b3e6a1fc29",
"blob_root": "0xb7d05f875f140027ef5118a2247bbb84ce8f2f0f1123623085daf7960c329f5f",
"kzg_commitment": "0x0748ac5c58e66b1fae24289f9014948876fbd78da88931bb6cbcd2e44a01bd07ab4f33e54ec9b9a2ada2e83c840dceb6",
"kzg_proof": "0xc6e27a3ae80243ba7ea88eab107a0675020e0745d75ab6a1553691007a50f7f99f597693ac33ae3cea63bf0b90a734ff"
},
Expand Down

0 comments on commit b46d453

Please sign in to comment.