Skip to content

Commit 7a41242

Browse files
committed
all: implement 6110
1 parent aded1ca commit 7a41242

File tree

21 files changed

+519
-85
lines changed

21 files changed

+519
-85
lines changed

beacon/engine/types.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type ExecutableData struct {
7676
Withdrawals []*types.Withdrawal `json:"withdrawals"`
7777
BlobGasUsed *uint64 `json:"blobGasUsed"`
7878
ExcessBlobGas *uint64 `json:"excessBlobGas"`
79-
Deposits []*types.Deposit `json:"depositReceipts"`
79+
Deposits types.Deposits `json:"depositRequests"`
8080
}
8181

8282
// JSON type overrides for executableData.
@@ -231,10 +231,15 @@ func ExecutableDataToBlock(params ExecutableData, versionedHashes []common.Hash,
231231
h := types.DeriveSha(types.Withdrawals(params.Withdrawals), trie.NewStackTrie(nil))
232232
withdrawalsRoot = &h
233233
}
234-
var depositsRoot *common.Hash
234+
235+
var (
236+
requestsHash *common.Hash
237+
requests types.Requests
238+
)
235239
if params.Deposits != nil {
236-
h := types.DeriveSha(types.Deposits(params.Deposits), trie.NewStackTrie(nil))
237-
depositsRoot = &h
240+
requests = params.Deposits.Requests()
241+
h := types.DeriveSha(requests, trie.NewStackTrie(nil))
242+
requestsHash = &h
238243
}
239244
header := &types.Header{
240245
ParentHash: params.ParentHash,
@@ -256,10 +261,10 @@ func ExecutableDataToBlock(params ExecutableData, versionedHashes []common.Hash,
256261
ExcessBlobGas: params.ExcessBlobGas,
257262
BlobGasUsed: params.BlobGasUsed,
258263
ParentBeaconRoot: beaconRoot,
259-
DepositsHash: depositsRoot,
264+
RequestsHash: requestsHash,
260265
}
261266

262-
block := types.NewBlockWithHeader(header).WithBody2(&types.Body{Transactions: txs, Uncles: nil, Withdrawals: params.Withdrawals, Deposits: params.Deposits})
267+
block := types.NewBlockWithHeader(header).WithBody2(&types.Body{Transactions: txs, Uncles: nil, Withdrawals: params.Withdrawals, Requests: requests})
263268
if block.Hash() != params.BlockHash {
264269
return nil, fmt.Errorf("blockhash mismatch, want %x, got %x", params.BlockHash, block.Hash())
265270
}

cmd/evm/internal/t8ntool/execution.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ type ExecutionResult struct {
6666
WithdrawalsRoot *common.Hash `json:"withdrawalsRoot,omitempty"`
6767
CurrentExcessBlobGas *math.HexOrDecimal64 `json:"currentExcessBlobGas,omitempty"`
6868
CurrentBlobGasUsed *math.HexOrDecimal64 `json:"blobGasUsed,omitempty"`
69+
RequestsRoot *common.Hash `json:"requestsRoot,omitempty"`
70+
DepositRequests *types.Deposits `json:"depositRequests,omitempty"`
6971
}
7072

7173
type ommer struct {
@@ -368,6 +370,23 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
368370
execRs.CurrentExcessBlobGas = (*math.HexOrDecimal64)(&excessBlobGas)
369371
execRs.CurrentBlobGasUsed = (*math.HexOrDecimal64)(&blobGasUsed)
370372
}
373+
if chainConfig.IsPrague(vmContext.BlockNumber, vmContext.Time) {
374+
// Parse the requests from the logs
375+
var allLogs []*types.Log
376+
for _, receipt := range receipts {
377+
allLogs = append(allLogs, receipt.Logs...)
378+
}
379+
requests, err := core.ParseDepositLogs(allLogs)
380+
if err != nil {
381+
return nil, nil, nil, NewError(ErrorEVM, fmt.Errorf("could not parse requests logs: %v", err))
382+
}
383+
// Calculate the requests root
384+
h := types.DeriveSha(requests, trie.NewStackTrie(nil))
385+
execRs.RequestsRoot = &h
386+
// Get the deposits from the requests
387+
deposits := requests.Deposits()
388+
execRs.DepositRequests = &deposits
389+
}
371390
// Re-create statedb instance with new root upon the updated database
372391
// for accessing latest states.
373392
statedb, err = state.New(root, statedb.Database(), nil)

consensus/beacon/consensus.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ func (beacon *Beacon) FinalizeAndAssemble(chain consensus.ChainHeaderReader, hea
388388
header.Root = state.IntermediateRoot(true)
389389

390390
// Assemble and return the final block.
391-
return types.NewBlockWithWithdrawals(header, body.Transactions, body.Uncles, receipts, body.Withdrawals, trie.NewStackTrie(nil)), nil
391+
return types.NewBlockWithRequests(header, body.Transactions, body.Uncles, receipts, body.Withdrawals, body.Requests, trie.NewStackTrie(nil)), nil
392392
}
393393

394394
// Seal generates a new sealing request for the given input block and pushes

core/block_validator.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,32 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
121121

122122
// ValidateState validates the various changes that happen after a state transition,
123123
// such as amount of used gas, the receipt roots and the state root itself.
124-
func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateDB, receipts types.Receipts, usedGas uint64) error {
124+
func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateDB, res *ProcessResult) error {
125+
if res == nil {
126+
return fmt.Errorf("nil ProcessResult value")
127+
}
125128
header := block.Header()
126-
if block.GasUsed() != usedGas {
127-
return fmt.Errorf("invalid gas used (remote: %d local: %d)", block.GasUsed(), usedGas)
129+
if block.GasUsed() != res.GasUsed {
130+
return fmt.Errorf("invalid gas used (remote: %d local: %d)", block.GasUsed(), res.GasUsed)
128131
}
129132
// Validate the received block's bloom with the one derived from the generated receipts.
130133
// For valid blocks this should always validate to true.
131-
rbloom := types.CreateBloom(receipts)
134+
rbloom := types.CreateBloom(res.Receipts)
132135
if rbloom != header.Bloom {
133136
return fmt.Errorf("invalid bloom (remote: %x local: %x)", header.Bloom, rbloom)
134137
}
135138
// The receipt Trie's root (R = (Tr [[H1, R1], ... [Hn, Rn]]))
136-
receiptSha := types.DeriveSha(receipts, trie.NewStackTrie(nil))
139+
receiptSha := types.DeriveSha(res.Receipts, trie.NewStackTrie(nil))
137140
if receiptSha != header.ReceiptHash {
138141
return fmt.Errorf("invalid receipt root hash (remote: %x local: %x)", header.ReceiptHash, receiptSha)
139142
}
143+
// Validate the parsed requests match the expected header value.
144+
if header.RequestsHash != nil {
145+
depositSha := types.DeriveSha(res.Requests, trie.NewStackTrie(nil))
146+
if depositSha != *header.RequestsHash {
147+
return fmt.Errorf("invalid deposit root hash (remote: %x local: %x)", *header.RequestsHash, depositSha)
148+
}
149+
}
140150
// Validate the state root against the received state root and throw
141151
// an error if they don't match.
142152
if root := statedb.IntermediateRoot(v.config.IsEIP158(header.Number)); header.Root != root {

core/blockchain.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,16 +1914,16 @@ func (bc *BlockChain) processBlock(block *types.Block, statedb *state.StateDB, s
19141914

19151915
// Process block using the parent state as reference point
19161916
pstart := time.Now()
1917-
receipts, logs, usedGas, err := bc.processor.Process(block, statedb, bc.vmConfig)
1917+
res, err := bc.processor.Process(block, statedb, bc.vmConfig)
19181918
if err != nil {
1919-
bc.reportBlock(block, receipts, err)
1919+
bc.reportBlock(block, nil, err)
19201920
return nil, err
19211921
}
19221922
ptime := time.Since(pstart)
19231923

19241924
vstart := time.Now()
1925-
if err := bc.validator.ValidateState(block, statedb, receipts, usedGas); err != nil {
1926-
bc.reportBlock(block, receipts, err)
1925+
if err := bc.validator.ValidateState(block, statedb, res); err != nil {
1926+
bc.reportBlock(block, res.Receipts, err)
19271927
return nil, err
19281928
}
19291929
vtime := time.Since(vstart)
@@ -1952,9 +1952,9 @@ func (bc *BlockChain) processBlock(block *types.Block, statedb *state.StateDB, s
19521952
)
19531953
if !setHead {
19541954
// Don't set the head, only insert the block
1955-
err = bc.writeBlockWithState(block, receipts, statedb)
1955+
err = bc.writeBlockWithState(block, res.Receipts, statedb)
19561956
} else {
1957-
status, err = bc.writeBlockAndSetHead(block, receipts, logs, statedb, false)
1957+
status, err = bc.writeBlockAndSetHead(block, res.Receipts, res.Logs, statedb, false)
19581958
}
19591959
if err != nil {
19601960
return nil, err
@@ -1968,7 +1968,7 @@ func (bc *BlockChain) processBlock(block *types.Block, statedb *state.StateDB, s
19681968
blockWriteTimer.Update(time.Since(wstart) - statedb.AccountCommits - statedb.StorageCommits - statedb.SnapshotCommits - statedb.TrieDBCommits)
19691969
blockInsertTimer.UpdateSince(start)
19701970

1971-
return &blockProcessingResult{usedGas: usedGas, procTime: proctime, status: status}, nil
1971+
return &blockProcessingResult{usedGas: res.GasUsed, procTime: proctime, status: status}, nil
19721972
}
19731973

19741974
// insertSideChain is called when an import batch hits upon a pruned ancestor

core/blockchain_test.go

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,14 @@ func testBlockChainImport(chain types.Blocks, blockchain *BlockChain) error {
163163
if err != nil {
164164
return err
165165
}
166-
receipts, _, usedGas, err := blockchain.processor.Process(block, statedb, vm.Config{})
166+
res, err := blockchain.processor.Process(block, statedb, vm.Config{})
167167
if err != nil {
168-
blockchain.reportBlock(block, receipts, err)
168+
blockchain.reportBlock(block, res.Receipts, err)
169169
return err
170170
}
171-
err = blockchain.validator.ValidateState(block, statedb, receipts, usedGas)
171+
err = blockchain.validator.ValidateState(block, statedb, res)
172172
if err != nil {
173-
blockchain.reportBlock(block, receipts, err)
173+
blockchain.reportBlock(block, res.Receipts, err)
174174
return err
175175
}
176176

@@ -4220,3 +4220,86 @@ func TestEIP3651(t *testing.T) {
42204220
t.Fatalf("sender balance incorrect: expected %d, got %d", expected, actual)
42214221
}
42224222
}
4223+
4224+
func TestEIP6110(t *testing.T) {
4225+
var (
4226+
engine = beacon.NewFaker()
4227+
4228+
// A sender who makes transactions, has some funds
4229+
key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
4230+
addr = crypto.PubkeyToAddress(key.PublicKey)
4231+
funds = new(big.Int).Mul(common.Big1, big.NewInt(params.Ether))
4232+
config = *params.AllEthashProtocolChanges
4233+
gspec = &Genesis{
4234+
Config: &config,
4235+
Alloc: types.GenesisAlloc{
4236+
addr: {Balance: funds},
4237+
params.BeaconDepositContractAddress: {
4238+
// Simple deposit generator, source: https://gist.github.com/lightclient/54abb2af2465d6969fa6d1920b9ad9d7
4239+
Code: common.Hex2Bytes("6080604052366103aa575f603067ffffffffffffffff811115610025576100246103ae565b5b6040519080825280601f01601f1916602001820160405280156100575781602001600182028036833780820191505090505b5090505f8054906101000a900460ff1660f81b815f8151811061007d5761007c6103db565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053505f602067ffffffffffffffff8111156100c7576100c66103ae565b5b6040519080825280601f01601f1916602001820160405280156100f95781602001600182028036833780820191505090505b5090505f8054906101000a900460ff1660f81b815f8151811061011f5761011e6103db565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053505f600867ffffffffffffffff811115610169576101686103ae565b5b6040519080825280601f01601f19166020018201604052801561019b5781602001600182028036833780820191505090505b5090505f8054906101000a900460ff1660f81b815f815181106101c1576101c06103db565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053505f606067ffffffffffffffff81111561020b5761020a6103ae565b5b6040519080825280601f01601f19166020018201604052801561023d5781602001600182028036833780820191505090505b5090505f8054906101000a900460ff1660f81b815f81518110610263576102626103db565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053505f600867ffffffffffffffff8111156102ad576102ac6103ae565b5b6040519080825280601f01601f1916602001820160405280156102df5781602001600182028036833780820191505090505b5090505f8054906101000a900460ff1660f81b815f81518110610305576103046103db565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053505f8081819054906101000a900460ff168092919061035090610441565b91906101000a81548160ff021916908360ff160217905550507f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c585858585856040516103a09594939291906104d9565b60405180910390a1005b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f60ff82169050919050565b5f61044b82610435565b915060ff820361045e5761045d610408565b5b600182019050919050565b5f81519050919050565b5f82825260208201905092915050565b8281835e5f83830152505050565b5f601f19601f8301169050919050565b5f6104ab82610469565b6104b58185610473565b93506104c5818560208601610483565b6104ce81610491565b840191505092915050565b5f60a0820190508181035f8301526104f181886104a1565b9050818103602083015261050581876104a1565b9050818103604083015261051981866104a1565b9050818103606083015261052d81856104a1565b9050818103608083015261054181846104a1565b9050969550505050505056fea26469706673582212208569967e58690162d7d6fe3513d07b393b4c15e70f41505cbbfd08f53eba739364736f6c63430008190033"),
4240+
Nonce: 0,
4241+
Balance: big.NewInt(0),
4242+
},
4243+
},
4244+
}
4245+
)
4246+
4247+
gspec.Config.BerlinBlock = common.Big0
4248+
gspec.Config.LondonBlock = common.Big0
4249+
gspec.Config.TerminalTotalDifficulty = common.Big0
4250+
gspec.Config.TerminalTotalDifficultyPassed = true
4251+
gspec.Config.ShanghaiTime = u64(0)
4252+
gspec.Config.CancunTime = u64(0)
4253+
gspec.Config.PragueTime = u64(0)
4254+
signer := types.LatestSigner(gspec.Config)
4255+
4256+
_, blocks, _ := GenerateChainWithGenesis(gspec, engine, 1, func(i int, b *BlockGen) {
4257+
for i := 0; i < 5; i++ {
4258+
txdata := &types.DynamicFeeTx{
4259+
ChainID: gspec.Config.ChainID,
4260+
Nonce: uint64(i),
4261+
To: &params.BeaconDepositContractAddress,
4262+
Gas: 500000,
4263+
GasFeeCap: newGwei(5),
4264+
GasTipCap: big.NewInt(2),
4265+
AccessList: nil,
4266+
Data: []byte{},
4267+
}
4268+
tx := types.NewTx(txdata)
4269+
tx, _ = types.SignTx(tx, signer, key)
4270+
b.AddTx(tx)
4271+
}
4272+
})
4273+
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), nil, gspec, nil, engine, vm.Config{Tracer: logger.NewMarkdownLogger(&logger.Config{DisableStack: true}, os.Stderr).Hooks()}, nil, nil)
4274+
if err != nil {
4275+
t.Fatalf("failed to create tester chain: %v", err)
4276+
}
4277+
defer chain.Stop()
4278+
if n, err := chain.InsertChain(blocks); err != nil {
4279+
t.Fatalf("block %d: failed to insert into chain: %v", n, err)
4280+
}
4281+
4282+
block := chain.GetBlockByNumber(1)
4283+
if len(block.Deposits()) != 5 {
4284+
t.Fatalf("failed to retreive deposits: have %d, want %d", len(block.Deposits()), 5)
4285+
}
4286+
4287+
// Verify each index is correct.
4288+
for want, d := range block.Deposits() {
4289+
if got := int(d.PublicKey[0]); got != want {
4290+
t.Fatalf("invalid pubkey: have %d, want %d", got, want)
4291+
}
4292+
if got := int(d.WithdrawalCredentials[0]); got != want {
4293+
t.Fatalf("invalid withdrawal credentials: have %d, want %d", got, want)
4294+
}
4295+
if d.Amount != uint64(want) {
4296+
t.Fatalf("invalid amounbt: have %d, want %d", d.Amount, want)
4297+
}
4298+
if got := int(d.Signature[0]); got != want {
4299+
t.Fatalf("invalid signature: have %d, want %d", got, want)
4300+
}
4301+
if d.Index != uint64(want) {
4302+
t.Fatalf("invalid index: have %d, want %d", d.Index, want)
4303+
}
4304+
}
4305+
}

core/chain_makers.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,18 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
346346
gen(i, b)
347347
}
348348

349-
body := types.Body{Transactions: b.txs, Uncles: b.uncles, Withdrawals: b.withdrawals}
349+
var requests types.Requests
350+
if config.IsPrague(b.header.Number, b.header.Time) {
351+
for _, r := range b.receipts {
352+
d, err := ParseDepositLogs(r.Logs)
353+
if err != nil {
354+
panic(fmt.Sprintf("failed to parse deposit log: %v", err))
355+
}
356+
requests = append(requests, d...)
357+
}
358+
}
359+
360+
body := types.Body{Transactions: b.txs, Uncles: b.uncles, Withdrawals: b.withdrawals, Requests: requests}
350361
block, err := b.engine.FinalizeAndAssemble(cm, b.header, statedb, &body, b.receipts)
351362
if err != nil {
352363
panic(err)

core/rawdb/accessors_chain.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ func ReadBlock(db ethdb.Reader, hash common.Hash, number uint64) *types.Block {
753753
if body == nil {
754754
return nil
755755
}
756-
return types.NewBlockWithHeader(header).WithBody(body.Transactions, body.Uncles).WithWithdrawals(body.Withdrawals)
756+
return types.NewBlockWithHeader(header).WithBody2(body)
757757
}
758758

759759
// WriteBlock serializes a block into the database, header and body separately.
@@ -843,7 +843,7 @@ func ReadBadBlock(db ethdb.Reader, hash common.Hash) *types.Block {
843843
}
844844
for _, bad := range badBlocks {
845845
if bad.Header.Hash() == hash {
846-
return types.NewBlockWithHeader(bad.Header).WithBody(bad.Body.Transactions, bad.Body.Uncles).WithWithdrawals(bad.Body.Withdrawals)
846+
return types.NewBlockWithHeader(bad.Header).WithBody2(bad.Body)
847847
}
848848
}
849849
return nil
@@ -862,7 +862,7 @@ func ReadAllBadBlocks(db ethdb.Reader) []*types.Block {
862862
}
863863
var blocks []*types.Block
864864
for _, bad := range badBlocks {
865-
blocks = append(blocks, types.NewBlockWithHeader(bad.Header).WithBody(bad.Body.Transactions, bad.Body.Uncles).WithWithdrawals(bad.Body.Withdrawals))
865+
blocks = append(blocks, types.NewBlockWithHeader(bad.Header).WithBody2(bad.Body))
866866
}
867867
return blocks
868868
}

core/state_processor.go

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func NewStateProcessor(config *params.ChainConfig, bc *BlockChain, engine consen
5757
// Process returns the receipts and logs accumulated during the process and
5858
// returns the amount of gas that was used in the process. If any of the
5959
// transactions failed to execute due to insufficient gas it will return an error.
60-
func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, []*types.Log, uint64, error) {
60+
func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (*ProcessResult, error) {
6161
var (
6262
receipts types.Receipts
6363
usedGas = new(uint64)
@@ -76,6 +76,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
7676
context = NewEVMBlockContext(header, p.bc, nil)
7777
vmenv = vm.NewEVM(context, vm.TxContext{}, statedb, p.config, cfg)
7878
signer = types.MakeSigner(p.config, header.Number, header.Time)
79+
err error
7980
)
8081
if beaconRoot := block.BeaconRoot(); beaconRoot != nil {
8182
ProcessBeaconBlockRoot(*beaconRoot, vmenv, statedb)
@@ -84,26 +85,40 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
8485
for i, tx := range block.Transactions() {
8586
msg, err := TransactionToMessage(tx, signer, header.BaseFee)
8687
if err != nil {
87-
return nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
88+
return nil, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
8889
}
8990
statedb.SetTxContext(tx.Hash(), i)
9091

9192
receipt, err := ApplyTransactionWithEVM(msg, p.config, gp, statedb, blockNumber, blockHash, tx, usedGas, vmenv)
9293
if err != nil {
93-
return nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
94+
return nil, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
9495
}
9596
receipts = append(receipts, receipt)
9697
allLogs = append(allLogs, receipt.Logs...)
9798
}
9899
// Fail if Shanghai not enabled and len(withdrawals) is non-zero.
99100
withdrawals := block.Withdrawals()
100101
if len(withdrawals) > 0 && !p.config.IsShanghai(block.Number(), block.Time()) {
101-
return nil, nil, 0, errors.New("withdrawals before shanghai")
102+
return nil, errors.New("withdrawals before shanghai")
102103
}
104+
// Read requests if Prague is enabled.
105+
var requests types.Requests
106+
if p.config.IsPrague(block.Number(), block.Time()) {
107+
requests, err = ParseDepositLogs(allLogs)
108+
if err != nil {
109+
return nil, err
110+
}
111+
}
112+
103113
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
104114
p.engine.Finalize(p.bc, header, statedb, block.Body())
105115

106-
return receipts, allLogs, *usedGas, nil
116+
return &ProcessResult{
117+
Receipts: receipts,
118+
Requests: requests,
119+
Logs: allLogs,
120+
GasUsed: *usedGas,
121+
}, nil
107122
}
108123

109124
// ApplyTransactionWithEVM attempts to apply a transaction to the given state database
@@ -202,3 +217,19 @@ func ProcessBeaconBlockRoot(beaconRoot common.Hash, vmenv *vm.EVM, statedb *stat
202217
_, _, _ = vmenv.Call(vm.AccountRef(msg.From), *msg.To, msg.Data, 30_000_000, common.U2560)
203218
statedb.Finalise(true)
204219
}
220+
221+
// ParseDepositLogs extracts the EIP-6110 deposit values from logs emitted by
222+
// BeaconDepositContract.
223+
func ParseDepositLogs(logs []*types.Log) (types.Requests, error) {
224+
var deposits types.Requests
225+
for _, log := range logs {
226+
if log.Address == params.BeaconDepositContractAddress {
227+
d, err := types.UnpackIntoDeposit(log.Data)
228+
if err != nil {
229+
return nil, fmt.Errorf("unable to parse deposit data: %v", err)
230+
}
231+
deposits = append(deposits, types.NewRequest(d))
232+
}
233+
}
234+
return deposits, nil
235+
}

0 commit comments

Comments
 (0)