diff --git a/beacon/engine/types.go b/beacon/engine/types.go index f9ca49a97f..a73691ca05 100644 --- a/beacon/engine/types.go +++ b/beacon/engine/types.go @@ -18,7 +18,6 @@ package engine import ( "fmt" - "github.com/ethereum/go-ethereum/params" "math/big" "slices" @@ -195,20 +194,20 @@ func decodeTransactions(enc [][]byte) ([]*types.Transaction, error) { // and that the blockhash of the constructed block matches the parameters. Nil // Withdrawals value will propagate through the returned block. Empty // Withdrawals value must be passed via non-nil, length 0 value in params. -func ExecutableDataToBlock(execParams ExecutableData, versionedHashes []common.Hash, beaconRoot *common.Hash) (*types.Block, error) { - txs, err := decodeTransactions(execParams.Transactions) +func ExecutableDataToBlock(params ExecutableData, versionedHashes []common.Hash, beaconRoot *common.Hash) (*types.Block, error) { + txs, err := decodeTransactions(params.Transactions) if err != nil { return nil, err } - if len(execParams.ExtraData) > int(params.MaximumExtraDataSize) { - return nil, fmt.Errorf("invalid extradata length: %v", len(execParams.ExtraData)) + if len(params.ExtraData) > 32 { + return nil, fmt.Errorf("invalid extradata length: %v", len(params.ExtraData)) } - if len(execParams.LogsBloom) != 256 { - return nil, fmt.Errorf("invalid logsBloom length: %v", len(execParams.LogsBloom)) + if len(params.LogsBloom) != 256 { + return nil, fmt.Errorf("invalid logsBloom length: %v", len(params.LogsBloom)) } // Check that baseFeePerGas is not negative or too big - if execParams.BaseFeePerGas != nil && (execParams.BaseFeePerGas.Sign() == -1 || execParams.BaseFeePerGas.BitLen() > 256) { - return nil, fmt.Errorf("invalid baseFeePerGas: %v", execParams.BaseFeePerGas) + if params.BaseFeePerGas != nil && (params.BaseFeePerGas.Sign() == -1 || params.BaseFeePerGas.BitLen() > 256) { + return nil, fmt.Errorf("invalid baseFeePerGas: %v", params.BaseFeePerGas) } var blobHashes []common.Hash for _, tx := range txs { @@ -226,34 +225,34 @@ func ExecutableDataToBlock(execParams ExecutableData, versionedHashes []common.H // ExecutableData before withdrawals are enabled by marshaling // Withdrawals as the json null value. var withdrawalsRoot *common.Hash - if execParams.Withdrawals != nil { - h := types.DeriveSha(types.Withdrawals(execParams.Withdrawals), trie.NewStackTrie(nil)) + if params.Withdrawals != nil { + h := types.DeriveSha(types.Withdrawals(params.Withdrawals), trie.NewStackTrie(nil)) withdrawalsRoot = &h } header := &types.Header{ - ParentHash: execParams.ParentHash, + ParentHash: params.ParentHash, UncleHash: types.EmptyUncleHash, - Coinbase: execParams.FeeRecipient, - Root: execParams.StateRoot, + Coinbase: params.FeeRecipient, + Root: params.StateRoot, TxHash: types.DeriveSha(types.Transactions(txs), trie.NewStackTrie(nil)), - ReceiptHash: execParams.ReceiptsRoot, - Bloom: types.BytesToBloom(execParams.LogsBloom), + ReceiptHash: params.ReceiptsRoot, + Bloom: types.BytesToBloom(params.LogsBloom), Difficulty: common.Big0, - Number: new(big.Int).SetUint64(execParams.Number), - GasLimit: execParams.GasLimit, - GasUsed: execParams.GasUsed, - Time: execParams.Timestamp, - BaseFee: execParams.BaseFeePerGas, - Extra: execParams.ExtraData, - MixDigest: execParams.Random, + Number: new(big.Int).SetUint64(params.Number), + GasLimit: params.GasLimit, + GasUsed: params.GasUsed, + Time: params.Timestamp, + BaseFee: params.BaseFeePerGas, + Extra: params.ExtraData, + MixDigest: params.Random, WithdrawalsHash: withdrawalsRoot, - ExcessBlobGas: execParams.ExcessBlobGas, - BlobGasUsed: execParams.BlobGasUsed, + ExcessBlobGas: params.ExcessBlobGas, + BlobGasUsed: params.BlobGasUsed, ParentBeaconRoot: beaconRoot, } - block := types.NewBlockWithHeader(header).WithBody(types.Body{Transactions: txs, Uncles: nil, Withdrawals: execParams.Withdrawals}) - if block.Hash() != execParams.BlockHash { - return nil, fmt.Errorf("blockhash mismatch, want %x, got %x", execParams.BlockHash, block.Hash()) + block := types.NewBlockWithHeader(header).WithBody(types.Body{Transactions: txs, Uncles: nil, Withdrawals: params.Withdrawals}) + if block.Hash() != params.BlockHash { + return nil, fmt.Errorf("blockhash mismatch, want %x, got %x", params.BlockHash, block.Hash()) } return block, nil } diff --git a/consensus/beacon/consensus.go b/consensus/beacon/consensus.go index b8946e0c71..19763ed303 100644 --- a/consensus/beacon/consensus.go +++ b/consensus/beacon/consensus.go @@ -229,7 +229,7 @@ func (beacon *Beacon) VerifyUncles(chain consensus.ChainReader, block *types.Blo // (c) the extradata is limited to 32 bytes func (beacon *Beacon) verifyHeader(chain consensus.ChainHeaderReader, header, parent *types.Header) error { // Ensure that the header's extra-data section is of a reasonable size - if len(header.Extra) > 32 { + if len(header.Extra) > int(params.MaximumExtraDataSize) { return fmt.Errorf("extra-data longer than 32 bytes (%d)", len(header.Extra)) } // Verify the seal parts. Ensure the nonce and uncle hash are the expected value.