Skip to content

Commit

Permalink
Check deneb blobs
Browse files Browse the repository at this point in the history
  • Loading branch information
avalonche authored and metachris committed Jan 11, 2024
1 parent 7a2bd25 commit 14ed275
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 41 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
16 changes: 6 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ require (
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/crate-crypto/go-kzg-4844 v0.3.0 // indirect
github.com/ethereum/c-kzg-4844 v0.3.1 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 // indirect
github.com/getsentry/sentry-go v0.18.0 // indirect
github.com/goccy/go-yaml v1.11.2 // indirect
github.com/gofrs/flock v0.8.1 // indirect
Expand All @@ -49,9 +47,9 @@ require (
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/protobuf v1.30.0 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
Expand All @@ -61,7 +59,7 @@ 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.8
github.com/attestantio/go-eth2-client v0.19.7
github.com/btcsuite/btcd v0.22.0-beta // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
Expand All @@ -88,5 +86,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
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +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-eth2-client v0.18.3 h1:hUSYh+uMLyw4mJcXWcvrPLd8ozJl61aWMdx5Cpq9hxk=
github.com/attestantio/go-eth2-client v0.18.3/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/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=
github.com/attestantio/go-eth2-client v0.19.7 h1:1cX2rYz9tMZGhXTCe5Ax3C9fmHx1igih21+MU1eO5ls=
github.com/attestantio/go-eth2-client v0.19.7/go.mod h1:mZve1kV9Ctj0I1HH9gdg+MnI8lZ+Cb2EktEtOYrBlsM=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
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 14ed275

Please sign in to comment.