From b46d453b933695eb7c893772c16fe66329a50749 Mon Sep 17 00:00:00 2001 From: avalonche Date: Sat, 12 Aug 2023 06:16:49 +1000 Subject: [PATCH] Check deneb blobs --- .golangci.yml | 3 - go.mod | 4 +- go.sum | 6 +- server/service.go | 63 ++++++++++++------- .../signed-blinded-beacon-block-deneb.json | 4 +- 5 files changed, 46 insertions(+), 34 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index c7199509..e461ee1b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -60,9 +60,6 @@ linters-settings: disable: - fieldalignment - shadow - gomoddirectives: - replace-allow-list: - - github.com/attestantio/go-builder-client output: print-issued-lines: true diff --git a/go.mod b/go.mod index 74777e16..ee3bfe42 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index 6f3a1109..547aa4c1 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/server/service.go b/server/service.go index 543cefa1..97b1f515 100644 --- a/server/service.go +++ b/server/service.go @@ -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" @@ -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 := "" @@ -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() @@ -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 diff --git a/testdata/signed-blinded-beacon-block-deneb.json b/testdata/signed-blinded-beacon-block-deneb.json index 5cd2f2d8..d62bd30b 100644 --- a/testdata/signed-blinded-beacon-block-deneb.json +++ b/testdata/signed-blinded-beacon-block-deneb.json @@ -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" }, @@ -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" },