diff --git a/beacon/engine/types.go b/beacon/engine/types.go index 7f0e71e0fc..8687a6f504 100644 --- a/beacon/engine/types.go +++ b/beacon/engine/types.go @@ -252,7 +252,9 @@ func ExecutableDataToBlock(data ExecutableData, versionedHashes []common.Hash, b BlobGasUsed: data.BlobGasUsed, ParentBeaconRoot: beaconRoot, } - block := types.NewBlockWithHeader(header).WithBody(types.Body{Transactions: txs, Uncles: nil, Withdrawals: data.Withdrawals, Witness: data.ExecutionWitness}) + block := types.NewBlockWithHeader(header) + block = block.WithBody(types.Body{Transactions: txs, Uncles: nil, Withdrawals: data.Withdrawals}) + block = block.WithWitness(data.ExecutionWitness) if block.Hash() != data.BlockHash { return nil, fmt.Errorf("blockhash mismatch, want %x, got %x", data.BlockHash, block.Hash()) } diff --git a/consensus/beacon/consensus.go b/consensus/beacon/consensus.go index 9e06105249..3095404330 100644 --- a/consensus/beacon/consensus.go +++ b/consensus/beacon/consensus.go @@ -404,15 +404,15 @@ func (beacon *Beacon) FinalizeAndAssemble(chain consensus.ChainHeaderReader, hea return nil, fmt.Errorf("error opening pre-state tree root: %w", err) } - vtrpre, okpre := preTrie.(*trie.VerkleTrie) - vtrpost, okpost := state.GetTrie().(*trie.VerkleTrie) + vktPreTrie, okpre := preTrie.(*trie.VerkleTrie) + vktPostTrie, okpost := state.GetTrie().(*trie.VerkleTrie) if okpre && okpost { if len(keys) > 0 { - p, k, err := vtrpre.Proof(vtrpost, keys, vtrpre.FlatdbNodeResolver) + verkleProof, stateDiff, err := vktPreTrie.Proof(vktPostTrie, keys, vktPreTrie.FlatdbNodeResolver) if err != nil { return nil, fmt.Errorf("error generating verkle proof for block %d: %w", header.Number, err) } - block.SetVerkleProof(p, k) + return block.WithWitness(&types.ExecutionWitness{StateDiff: stateDiff, VerkleProof: verkleProof}), nil } } } diff --git a/core/types/block.go b/core/types/block.go index 371884d933..2988cb4d43 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -179,8 +179,7 @@ func (h *Header) EmptyReceipts() bool { type Body struct { Transactions []*Transaction Uncles []*Header - Withdrawals []*Withdrawal `rlp:"optional"` - Witness *ExecutionWitness `rlp:"-"` + Withdrawals []*Withdrawal `rlp:"optional"` } // Block represents an Ethereum block. @@ -341,7 +340,7 @@ func (b *Block) EncodeRLP(w io.Writer) error { // Body returns the non-header content of the block. // Note the returned data is not an independent copy. func (b *Block) Body() *Body { - return &Body{b.transactions, b.uncles, b.withdrawals, b.witness} + return &Body{b.transactions, b.uncles, b.withdrawals} } // Accessors for body data. These do not return a copy because the content @@ -473,7 +472,6 @@ func (b *Block) WithBody(body Body) *Block { transactions: slices.Clone(body.Transactions), uncles: make([]*Header, len(body.Uncles)), withdrawals: slices.Clone(body.Withdrawals), - witness: body.Witness, } for i := range body.Uncles { block.uncles[i] = CopyHeader(body.Uncles[i]) @@ -481,6 +479,21 @@ func (b *Block) WithBody(body Body) *Block { return block } +func (b *Block) WithWitness(witness *ExecutionWitness) *Block { + + block := &Block{ + header: b.header, + transactions: slices.Clone(b.transactions), + uncles: make([]*Header, len(b.uncles)), + withdrawals: slices.Clone(b.withdrawals), + witness: witness, + } + for i := range b.uncles { + block.uncles[i] = CopyHeader(b.uncles[i]) + } + return block +} + // Hash returns the keccak256 hash of b's header. // The hash is computed on the first call and cached thereafter. func (b *Block) Hash() common.Hash {