From e017cda49082ccdb19b4ec6df833be8532edb066 Mon Sep 17 00:00:00 2001 From: halo3mic Date: Wed, 14 Feb 2024 16:35:51 +0000 Subject: [PATCH 1/7] add params BlobGasUsed and ExcessBlobGas to block bid --- core/vm/contracts_suave_eth.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/vm/contracts_suave_eth.go b/core/vm/contracts_suave_eth.go index d50a3f8bd..0cd52fb0c 100644 --- a/core/vm/contracts_suave_eth.go +++ b/core/vm/contracts_suave_eth.go @@ -346,6 +346,8 @@ func executableDataToDenebExecutionPayload(data *dencun.ExecutableData) (*specDe BlockHash: [32]byte(data.BlockHash), Transactions: transactionData, Withdrawals: withdrawalData, + BlobGasUsed: *data.BlobGasUsed, + ExcessBlobGas: *data.ExcessBlobGas, }, nil } From 890c835f3caceda584ebeb6a954cdc73acfbd8e6 Mon Sep 17 00:00:00 2001 From: halo3mic Date: Wed, 14 Feb 2024 17:48:03 +0000 Subject: [PATCH 2/7] check for nil pointers --- core/vm/contracts_suave_eth.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/core/vm/contracts_suave_eth.go b/core/vm/contracts_suave_eth.go index 0cd52fb0c..21644e527 100644 --- a/core/vm/contracts_suave_eth.go +++ b/core/vm/contracts_suave_eth.go @@ -330,7 +330,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), @@ -346,9 +346,17 @@ func executableDataToDenebExecutionPayload(data *dencun.ExecutableData) (*specDe BlockHash: [32]byte(data.BlockHash), Transactions: transactionData, Withdrawals: withdrawalData, - BlobGasUsed: *data.BlobGasUsed, - ExcessBlobGas: *data.ExcessBlobGas, - }, 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) { From b87bbcf38e222aa9ec1dc1206477a9d0e2f8b199 Mon Sep 17 00:00:00 2001 From: halo3mic Date: Wed, 14 Feb 2024 17:58:08 +0000 Subject: [PATCH 3/7] rm the unnecessary newline --- core/vm/contracts_suave_eth.go | 1 - password | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 password diff --git a/core/vm/contracts_suave_eth.go b/core/vm/contracts_suave_eth.go index 21644e527..79ff9949c 100644 --- a/core/vm/contracts_suave_eth.go +++ b/core/vm/contracts_suave_eth.go @@ -356,7 +356,6 @@ func executableDataToDenebExecutionPayload(data *dencun.ExecutableData) (*specDe } return payload, nil - } func (c *suaveRuntime) submitBundleJsonRPC(url string, method string, params []byte) ([]byte, error) { diff --git a/password b/password new file mode 100644 index 000000000..f77b00407 --- /dev/null +++ b/password @@ -0,0 +1 @@ +admin \ No newline at end of file From 44e8e4ad5c0ac11de18fb101e3e7129727378a16 Mon Sep 17 00:00:00 2001 From: halo3mic <46010359+halo3mic@users.noreply.github.com> Date: Wed, 14 Feb 2024 19:12:19 +0000 Subject: [PATCH 4/7] Delete password --- password | 1 - 1 file changed, 1 deletion(-) delete mode 100644 password diff --git a/password b/password deleted file mode 100644 index f77b00407..000000000 --- a/password +++ /dev/null @@ -1 +0,0 @@ -admin \ No newline at end of file From 703e02ebf6a61530f3cd42fc0547ade63f7793fb Mon Sep 17 00:00:00 2001 From: halo3mic Date: Thu, 15 Feb 2024 18:58:30 +0000 Subject: [PATCH 5/7] support for blob txs - poc --- core/vm/contracts_suave_eth.go | 52 +++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/core/vm/contracts_suave_eth.go b/core/vm/contracts_suave_eth.go index 79ff9949c..c63f97d67 100644 --- a/core/vm/contracts_suave_eth.go +++ b/core/vm/contracts_suave_eth.go @@ -260,11 +260,27 @@ func (b *suaveRuntime) buildEthBlock(blockArgs types.BuildBlockArgs, dataID type return nil, nil, fmt.Errorf("could not sign builder record: %w", err) } + log.Info("built block from bundles", "blobs", len(envelope.BlobsBundle.Blobs), "commitments", len(envelope.BlobsBundle.Commitments), "proofs", len(envelope.BlobsBundle.Proofs)) + blobsBundle := &builderDeneb.BlobsBundle{} + for i, blob := range envelope.BlobsBundle.Blobs { + blobFixed, err := convertToFixedArray(blob) + if err != nil { + return nil, nil, fmt.Errorf("could not convert blob to fixed array: %w", err) + } + blobsBundle.Blobs = append(blobsBundle.Blobs, blobFixed) + + committerFixed, err := convertToFixedArray2(envelope.BlobsBundle.Commitments[i]) + blobsBundle.Commitments = append(blobsBundle.Commitments, committerFixed) + + proofFixed, err := convertToFixedArray2(envelope.BlobsBundle.Proofs[i]) + blobsBundle.Proofs = append(blobsBundle.Proofs, proofFixed) + } + bidRequest := builderDeneb.SubmitBlockRequest{ Message: &blockBidMsg, ExecutionPayload: payload, Signature: signature, - BlobsBundle: &builderDeneb.BlobsBundle{}, + BlobsBundle: blobsBundle, } bidBytes, err := bidRequest.MarshalJSON() @@ -272,6 +288,12 @@ func (b *suaveRuntime) buildEthBlock(blockArgs types.BuildBlockArgs, dataID type return nil, nil, fmt.Errorf("could not marshal builder record request: %w", err) } + 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) @@ -280,6 +302,34 @@ func (b *suaveRuntime) buildEthBlock(blockArgs types.BuildBlockArgs, dataID type return bidBytes, envelopeBytes, nil } +func convertToFixedArray(src hexutil.Bytes) ([131072]byte, error) { + var dst [131072]byte // Declare a fixed-size array + + // Check if the source slice exceeds the size of the destination array + if len(src) > len(dst) { + return dst, fmt.Errorf("source slice is too large: %d bytes", len(src)) + } + + // Copy the source slice data into the destination array + copy(dst[:], src) + + return dst, nil +} + +func convertToFixedArray2(src hexutil.Bytes) ([48]byte, error) { + var dst [48]byte // Declare a fixed-size array + + // Check if the source slice exceeds the size of the destination array + if len(src) > len(dst) { + return dst, fmt.Errorf("source slice is too large: %d bytes", len(src)) + } + + // Copy the source slice data into the destination array + copy(dst[:], src) + + return dst, nil +} + func (b *suaveRuntime) privateKeyGen() (string, error) { sk, err := crypto.GenerateKey() if err != nil { From d5d5dcbbb2495cdb01fb2041d8d6ef0c0ef26b15 Mon Sep 17 00:00:00 2001 From: halo3mic Date: Thu, 15 Feb 2024 22:32:08 +0000 Subject: [PATCH 6/7] pretty --- core/vm/contracts_suave_eth.go | 93 ++++++++++++++++------------------ password | 1 - 2 files changed, 44 insertions(+), 50 deletions(-) delete mode 100644 password diff --git a/core/vm/contracts_suave_eth.go b/core/vm/contracts_suave_eth.go index c63f97d67..4fadd0736 100644 --- a/core/vm/contracts_suave_eth.go +++ b/core/vm/contracts_suave_eth.go @@ -8,6 +8,7 @@ import ( "fmt" "math/big" "net/http" + "reflect" "time" "github.com/ethereum/go-ethereum/accounts" @@ -260,22 +261,10 @@ func (b *suaveRuntime) buildEthBlock(blockArgs types.BuildBlockArgs, dataID type return nil, nil, fmt.Errorf("could not sign builder record: %w", err) } - log.Info("built block from bundles", "blobs", len(envelope.BlobsBundle.Blobs), "commitments", len(envelope.BlobsBundle.Commitments), "proofs", len(envelope.BlobsBundle.Proofs)) - blobsBundle := &builderDeneb.BlobsBundle{} - for i, blob := range envelope.BlobsBundle.Blobs { - blobFixed, err := convertToFixedArray(blob) - if err != nil { - return nil, nil, fmt.Errorf("could not convert blob to fixed array: %w", err) - } - blobsBundle.Blobs = append(blobsBundle.Blobs, blobFixed) - - committerFixed, err := convertToFixedArray2(envelope.BlobsBundle.Commitments[i]) - blobsBundle.Commitments = append(blobsBundle.Commitments, committerFixed) - - proofFixed, err := convertToFixedArray2(envelope.BlobsBundle.Proofs[i]) - blobsBundle.Proofs = append(blobsBundle.Proofs, proofFixed) + 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, @@ -288,12 +277,6 @@ func (b *suaveRuntime) buildEthBlock(blockArgs types.BuildBlockArgs, dataID type return nil, nil, fmt.Errorf("could not marshal builder record request: %w", err) } - 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) @@ -302,34 +285,6 @@ func (b *suaveRuntime) buildEthBlock(blockArgs types.BuildBlockArgs, dataID type return bidBytes, envelopeBytes, nil } -func convertToFixedArray(src hexutil.Bytes) ([131072]byte, error) { - var dst [131072]byte // Declare a fixed-size array - - // Check if the source slice exceeds the size of the destination array - if len(src) > len(dst) { - return dst, fmt.Errorf("source slice is too large: %d bytes", len(src)) - } - - // Copy the source slice data into the destination array - copy(dst[:], src) - - return dst, nil -} - -func convertToFixedArray2(src hexutil.Bytes) ([48]byte, error) { - var dst [48]byte // Declare a fixed-size array - - // Check if the source slice exceeds the size of the destination array - if len(src) > len(dst) { - return dst, fmt.Errorf("source slice is too large: %d bytes", len(src)) - } - - // Copy the source slice data into the destination array - copy(dst[:], src) - - return dst, nil -} - func (b *suaveRuntime) privateKeyGen() (string, error) { sk, err := crypto.GenerateKey() if err != nil { @@ -532,3 +487,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 +} diff --git a/password b/password deleted file mode 100644 index f77b00407..000000000 --- a/password +++ /dev/null @@ -1 +0,0 @@ -admin \ No newline at end of file From f63c162737289ae452c98c5c1f750d3b1f3bfdab Mon Sep 17 00:00:00 2001 From: halo3mic Date: Thu, 15 Feb 2024 23:07:16 +0000 Subject: [PATCH 7/7] build and submit for test purposes --- core/vm/contracts_suave_eth.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/vm/contracts_suave_eth.go b/core/vm/contracts_suave_eth.go index 4fadd0736..9b6b64c81 100644 --- a/core/vm/contracts_suave_eth.go +++ b/core/vm/contracts_suave_eth.go @@ -277,6 +277,13 @@ func (b *suaveRuntime) buildEthBlock(blockArgs types.BuildBlockArgs, dataID type 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)