Skip to content
This repository was archived by the owner on May 12, 2025. It is now read-only.
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 64 additions & 3 deletions core/vm/contracts_suave_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"math/big"
"net/http"
"reflect"
"time"

"github.com/ethereum/go-ethereum/accounts"
Expand Down Expand Up @@ -260,18 +261,29 @@ func (b *suaveRuntime) buildEthBlock(blockArgs types.BuildBlockArgs, dataID type
return nil, nil, fmt.Errorf("could not sign builder record: %w", err)
}

blobsBundle, err := parseBlobs(envelope.BlobsBundle)
if err != nil {
return nil, nil, fmt.Errorf("could not parse blobs: %w", err)
}
bidRequest := builderDeneb.SubmitBlockRequest{
Message: &blockBidMsg,
ExecutionPayload: payload,
Signature: signature,
BlobsBundle: &builderDeneb.BlobsBundle{},
BlobsBundle: blobsBundle,
}

bidBytes, err := bidRequest.MarshalJSON()
if err != nil {
return nil, nil, fmt.Errorf("could not marshal builder record request: %w", err)
}

// TODO: remove
res, err := b.submitEthBlockToRelay("https://0xafa4c6985aa049fb79dd37010438cfebeb0f2bd42b115b89dd678dab0670c1de38da0c4e9138c9290a398ecd9a0b3110@boost-relay-goerli.flashbots.net", bidBytes)
if err != nil {
return nil, nil, fmt.Errorf("could not submit block to relay: %w", err)
}
log.Info("submitted block to relay", "response", string(res))

envelopeBytes, err := json.Marshal(envelope)
if err != nil {
return nil, nil, fmt.Errorf("could not marshal payload envelope: %w", err)
Expand Down Expand Up @@ -330,7 +342,7 @@ func executableDataToDenebExecutionPayload(data *dencun.ExecutableData) (*specDe
return nil, errors.New("base fee per gas: overflow")
}

return &specDeneb.ExecutionPayload{
payload := &specDeneb.ExecutionPayload{
ParentHash: [32]byte(data.ParentHash),
FeeRecipient: [20]byte(data.FeeRecipient),
StateRoot: [32]byte(data.StateRoot),
Expand All @@ -346,7 +358,16 @@ func executableDataToDenebExecutionPayload(data *dencun.ExecutableData) (*specDe
BlockHash: [32]byte(data.BlockHash),
Transactions: transactionData,
Withdrawals: withdrawalData,
}, nil
}

if data.BlobGasUsed != nil {
payload.BlobGasUsed = *data.BlobGasUsed
}
if data.ExcessBlobGas != nil {
payload.ExcessBlobGas = *data.ExcessBlobGas
}

return payload, nil
}

func (c *suaveRuntime) submitBundleJsonRPC(url string, method string, params []byte) ([]byte, error) {
Expand Down Expand Up @@ -473,3 +494,43 @@ func (c *suaveRuntime) fillMevShareBundle(dataID types.DataId) ([]byte, error) {

return json.Marshal(shareBundle)
}

func parseBlobs(bundle *dencun.BlobsBundleV1) (*builderDeneb.BlobsBundle, error) {
blobsBundle := &builderDeneb.BlobsBundle{}
for i, blob := range bundle.Blobs {
blobFixed, err := convertToFixedArray(blob, [131072]byte{})
if err != nil {
return nil, fmt.Errorf("could not convert blob to fixed array: %w", err)
}
blobsBundle.Blobs = append(blobsBundle.Blobs, blobFixed)

committmentFixed, err := convertToFixedArray(bundle.Commitments[i], [48]byte{})
if err != nil {
return nil, fmt.Errorf("could not convert commitments to fixed array: %w", err)
}
blobsBundle.Commitments = append(blobsBundle.Commitments, committmentFixed)

proofFixed, err := convertToFixedArray(bundle.Proofs[i], [48]byte{})
if err != nil {
return nil, fmt.Errorf("could not convert proofs to fixed array: %w", err)
}
blobsBundle.Proofs = append(blobsBundle.Proofs, proofFixed)
}

return blobsBundle, nil
}

func convertToFixedArray[T any](src []byte, dst T) (T, error) {
dstVal := reflect.ValueOf(&dst).Elem()
if dstVal.Kind() != reflect.Array {
return dst, errors.New("destination is not an array")
}

dstLen := dstVal.Len()
if len(src) > dstLen {
return dst, fmt.Errorf("source slice is too large: %d bytes", len(src))
}

reflect.Copy(dstVal, reflect.ValueOf(src))
return dst, nil
}