Skip to content

Commit a30e0dc

Browse files
committed
core/types,catalyst,engine: add new engine api methods for prague and 6110 deposit type
1 parent de597af commit a30e0dc

File tree

8 files changed

+234
-8
lines changed

8 files changed

+234
-8
lines changed

beacon/engine/types.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var (
3636
PayloadV1 PayloadVersion = 0x1
3737
PayloadV2 PayloadVersion = 0x2
3838
PayloadV3 PayloadVersion = 0x3
39+
PayloadV4 PayloadVersion = 0x4
3940
)
4041

4142
//go:generate go run github.com/fjl/gencodec -type PayloadAttributes -field-override payloadAttributesMarshaling -out gen_blockparams.go
@@ -76,6 +77,7 @@ type ExecutableData struct {
7677
Withdrawals []*types.Withdrawal `json:"withdrawals"`
7778
BlobGasUsed *uint64 `json:"blobGasUsed"`
7879
ExcessBlobGas *uint64 `json:"excessBlobGas"`
80+
Deposits []*types.Deposit `json:"depositReceipts"`
7981
ExecutionWitness *types.ExecutionWitness `json:"executionWitness,omitempty"`
8082
}
8183

@@ -231,6 +233,11 @@ func ExecutableDataToBlock(data ExecutableData, versionedHashes []common.Hash, b
231233
h := types.DeriveSha(types.Withdrawals(data.Withdrawals), trie.NewStackTrie(nil))
232234
withdrawalsRoot = &h
233235
}
236+
var depositsRoot *common.Hash
237+
if data.Deposits != nil {
238+
h := types.DeriveSha(types.Deposits(data.Deposits), trie.NewStackTrie(nil))
239+
depositsRoot = &h
240+
}
234241
header := &types.Header{
235242
ParentHash: data.ParentHash,
236243
UncleHash: types.EmptyUncleHash,
@@ -251,9 +258,10 @@ func ExecutableDataToBlock(data ExecutableData, versionedHashes []common.Hash, b
251258
ExcessBlobGas: data.ExcessBlobGas,
252259
BlobGasUsed: data.BlobGasUsed,
253260
ParentBeaconRoot: beaconRoot,
261+
DepositsHash: depositsRoot,
254262
}
255263
block := types.NewBlockWithHeader(header)
256-
block = block.WithBody(types.Body{Transactions: txs, Uncles: nil, Withdrawals: data.Withdrawals})
264+
block = block.WithBody(types.Body{Transactions: txs, Uncles: nil, Withdrawals: data.Withdrawals, Deposits: data.Deposits})
257265
block = block.WithWitness(data.ExecutionWitness)
258266
if block.Hash() != data.BlockHash {
259267
return nil, fmt.Errorf("blockhash mismatch, want %x, got %x", data.BlockHash, block.Hash())
@@ -282,6 +290,7 @@ func BlockToExecutableData(block *types.Block, fees *big.Int, sidecars []*types.
282290
Withdrawals: block.Withdrawals(),
283291
BlobGasUsed: block.BlobGasUsed(),
284292
ExcessBlobGas: block.ExcessBlobGas(),
293+
Deposits: block.Deposits(),
285294
ExecutionWitness: block.ExecutionWitness(),
286295
}
287296
bundle := BlobsBundleV1{

core/types/block.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ type Header struct {
102102

103103
// ParentBeaconRoot was added by EIP-4788 and is ignored in legacy headers.
104104
ParentBeaconRoot *common.Hash `json:"parentBeaconBlockRoot" rlp:"optional"`
105+
106+
// DepositsHash was added by EIP-6110 and is ignored in legacy headers.
107+
DepositsHash *common.Hash `json:"depositsRoot" rlp:"optional"`
105108
}
106109

107110
// field type overrides for gencodec
@@ -180,6 +183,7 @@ type Body struct {
180183
Transactions []*Transaction
181184
Uncles []*Header
182185
Withdrawals []*Withdrawal `rlp:"optional"`
186+
Deposits []*Deposit `rlp:"optional"`
183187
}
184188

185189
// Block represents an Ethereum block.
@@ -204,6 +208,7 @@ type Block struct {
204208
uncles []*Header
205209
transactions Transactions
206210
withdrawals Withdrawals
211+
deposits Deposits
207212

208213
// witness is not an encoded part of the block body.
209214
// It is held in Block in order for easy relaying to the places
@@ -226,6 +231,7 @@ type extblock struct {
226231
Txs []*Transaction
227232
Uncles []*Header
228233
Withdrawals []*Withdrawal `rlp:"optional"`
234+
Deposits []*Deposit `rlp:"optional"`
229235
}
230236

231237
// NewBlock creates a new block. The input data is copied, changes to header and to the
@@ -315,6 +321,10 @@ func CopyHeader(h *Header) *Header {
315321
cpy.ParentBeaconRoot = new(common.Hash)
316322
*cpy.ParentBeaconRoot = *h.ParentBeaconRoot
317323
}
324+
if h.DepositsHash != nil {
325+
cpy.DepositsHash = new(common.Hash)
326+
*cpy.DepositsHash = *h.DepositsHash
327+
}
318328
return &cpy
319329
}
320330

@@ -343,7 +353,7 @@ func (b *Block) EncodeRLP(w io.Writer) error {
343353
// Body returns the non-header content of the block.
344354
// Note the returned data is not an independent copy.
345355
func (b *Block) Body() *Body {
346-
return &Body{b.transactions, b.uncles, b.withdrawals}
356+
return &Body{b.transactions, b.uncles, b.withdrawals, b.deposits}
347357
}
348358

349359
// Accessors for body data. These do not return a copy because the content
@@ -352,6 +362,7 @@ func (b *Block) Body() *Body {
352362
func (b *Block) Uncles() []*Header { return b.uncles }
353363
func (b *Block) Transactions() Transactions { return b.transactions }
354364
func (b *Block) Withdrawals() Withdrawals { return b.withdrawals }
365+
func (b *Block) Deposits() Deposits { return b.deposits }
355366

356367
func (b *Block) Transaction(hash common.Hash) *Transaction {
357368
for _, transaction := range b.transactions {

core/types/deposit.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Copyright 2024 The go-ethereum Authors
2+
// This file is part of the go-ethereum library.
3+
//
4+
// The go-ethereum library is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Lesser General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// The go-ethereum library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Lesser General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Lesser General Public License
15+
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
16+
17+
package types
18+
19+
import (
20+
"bytes"
21+
"reflect"
22+
23+
"github.com/ethereum/go-ethereum/common"
24+
"github.com/ethereum/go-ethereum/common/hexutil"
25+
"github.com/ethereum/go-ethereum/rlp"
26+
)
27+
28+
//go:generate go run github.com/fjl/gencodec -type Deposit -field-override depositMarshaling -out gen_deposit_json.go
29+
30+
// Deposit contians EIP-6110 deposit data.
31+
type Deposit struct {
32+
PublicKey BLSPublicKey `json:"pubkey"`
33+
WithdrawalCredentials common.Hash `json:"withdrawalCredentials"`
34+
Amount uint64 `json:"amount"` // in gwei
35+
Signature BLSSignature `json:"signature"`
36+
Index uint64 `json:"index"`
37+
}
38+
39+
type depositMarshaling struct {
40+
PublicKey hexutil.Bytes
41+
WithdrawalCredentials hexutil.Bytes
42+
Amount hexutil.Uint64
43+
Signature hexutil.Bytes
44+
Index hexutil.Uint64
45+
}
46+
47+
// Deposit implements DerivableList for withdrawals.
48+
type Deposits []*Deposit
49+
50+
// Len returns the length of s.
51+
func (s Deposits) Len() int { return len(s) }
52+
53+
// EncodeIndex encodes the i'th deposit to s.
54+
func (s Deposits) EncodeIndex(i int, w *bytes.Buffer) {
55+
rlp.Encode(w, s[i])
56+
}
57+
58+
// misc bls types
59+
////
60+
61+
var (
62+
pubkeyT = reflect.TypeOf(BLSPublicKey{})
63+
sigT = reflect.TypeOf(BLSSignature{})
64+
)
65+
66+
type BLSPublicKey [48]byte
67+
68+
// UnmarshalJSON parses a hash in hex syntax.
69+
func (h *BLSPublicKey) UnmarshalJSON(input []byte) error {
70+
return hexutil.UnmarshalFixedJSON(pubkeyT, input, h[:])
71+
}
72+
73+
// MarshalText returns the hex representation of h.
74+
func (h BLSPublicKey) MarshalText() ([]byte, error) {
75+
return hexutil.Bytes(h[:]).MarshalText()
76+
}
77+
78+
type BLSSignature [96]byte
79+
80+
// UnmarshalJSON parses a hash in hex syntax.
81+
func (h *BLSSignature) UnmarshalJSON(input []byte) error {
82+
return hexutil.UnmarshalFixedJSON(sigT, input, h[:])
83+
}
84+
85+
// MarshalText returns the hex representation of h.
86+
func (h BLSSignature) MarshalText() ([]byte, error) {
87+
return hexutil.Bytes(h[:]).MarshalText()
88+
}

core/types/gen_deposit_json.go

Lines changed: 70 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/types/gen_header_json.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/types/gen_header_rlp.go

Lines changed: 13 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/types/hashes.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ var (
4141
// EmptyWithdrawalsHash is the known hash of the empty withdrawal set.
4242
EmptyWithdrawalsHash = common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
4343

44+
// EmptyDepositsHash is the known hash of the empty deposits set.
45+
EmptyDepositsHash = common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
46+
4447
// EmptyVerkleHash is the known hash of an empty verkle trie.
4548
EmptyVerkleHash = common.Hash{}
4649
)

0 commit comments

Comments
 (0)