diff --git a/beacon/engine/types.go b/beacon/engine/types.go index 936daf8b95..b29f09118c 100644 --- a/beacon/engine/types.go +++ b/beacon/engine/types.go @@ -18,10 +18,11 @@ package engine import ( "fmt" - "github.com/ethereum/go-ethereum/core/types/bal" "math/big" "slices" + "github.com/ethereum/go-ethereum/core/types/bal" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" diff --git a/cmd/evm/internal/t8ntool/execution.go b/cmd/evm/internal/t8ntool/execution.go index 2147b2b7ad..4d456a1e16 100644 --- a/cmd/evm/internal/t8ntool/execution.go +++ b/cmd/evm/internal/t8ntool/execution.go @@ -258,7 +258,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig, snapshot = statedb.Snapshot() gp = gaspool.Snapshot() ) - _, receipt, err := core.ApplyTransactionWithEVM(msg, gaspool, statedb, vmContext.BlockNumber, blockHash, pre.Env.Timestamp, tx, evm) + _, _, receipt, err := core.ApplyTransactionWithEVM(msg, gaspool, statedb, vmContext.BlockNumber, blockHash, pre.Env.Timestamp, tx, evm) if err != nil { statedb.RevertToSnapshot(snapshot) log.Info("rejected tx", "index", i, "hash", tx.Hash(), "from", msg.From, "error", err) @@ -327,11 +327,11 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig, return nil, nil, nil, NewError(ErrorEVM, fmt.Errorf("could not parse requests logs: %v", err)) } // EIP-7002 - if _, err := core.ProcessWithdrawalQueue(&requests, evm); err != nil { + if _, _, err := core.ProcessWithdrawalQueue(&requests, evm); err != nil { return nil, nil, nil, NewError(ErrorEVM, fmt.Errorf("could not process withdrawal requests: %v", err)) } // EIP-7251 - if _, err := core.ProcessConsolidationQueue(&requests, evm); err != nil { + if _, _, err := core.ProcessConsolidationQueue(&requests, evm); err != nil { return nil, nil, nil, NewError(ErrorEVM, fmt.Errorf("could not process consolidation requests: %v", err)) } } diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index d41ea7ad94..14ebffb63a 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -21,13 +21,14 @@ import ( "bytes" "errors" "fmt" - "github.com/ethereum/go-ethereum/core/types/bal" "io" "math/big" "math/rand" "sync" "time" + "github.com/ethereum/go-ethereum/core/types/bal" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/lru" @@ -579,28 +580,6 @@ func (c *Clique) Finalize(chain consensus.ChainHeaderReader, header *types.Heade return nil, nil } -<<<<<<< HEAD -======= -// FinalizeAndAssemble implements consensus.Engine, ensuring no uncles are set, -// nor block rewards given, and returns the final block. -func (c *Clique) FinalizeAndAssemble(ctx context.Context, chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, body *types.Body, receipts []*types.Receipt, createBAL func(*bal.StateAccessList, *bal.StateMutations) *bal.BlockAccessList) (*types.Block, error) { - if createBAL != nil { - panic("BALs not supported") - } - if len(body.Withdrawals) > 0 { - return nil, errors.New("clique does not support withdrawals") - } - // Finalize block - c.Finalize(chain, header, state, body) - - // Assign the final state root to header. - header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number)) - - // Assemble and return the final block for sealing. - return types.NewBlock(header, &types.Body{Transactions: body.Transactions}, receipts, trie.NewStackTrie(nil)), nil -} - ->>>>>>> 1d26ca9bc1 (all: implement BAL single-threaded execution and validation) // Authorize injects a private key into the consensus engine to mint new blocks // with. func (c *Clique) Authorize(signer common.Address) { diff --git a/core/rawdb/accessors_chain_test.go b/core/rawdb/accessors_chain_test.go index c35f56ee07..d52e1cdab3 100644 --- a/core/rawdb/accessors_chain_test.go +++ b/core/rawdb/accessors_chain_test.go @@ -32,7 +32,6 @@ import ( "github.com/ethereum/go-ethereum/crypto/keccak" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" - "github.com/holiman/uint256" ) // Tests block header storage and retrieval operations. @@ -906,13 +905,17 @@ func makeTestBAL(t *testing.T) (rlp.RawValue, *bal.BlockAccessList) { t.Helper() cb := bal.NewConstructionBlockAccessList() - addr := common.HexToAddress("0x1111111111111111111111111111111111111111") - cb.AccountRead(addr) - cb.StorageRead(addr, common.BytesToHash([]byte{0x01})) - cb.StorageWrite(0, addr, common.BytesToHash([]byte{0x02}), common.BytesToHash([]byte{0xaa})) - cb.BalanceChange(0, addr, uint256.NewInt(100)) - cb.NonceChange(addr, 0, 1) + /* + TODO MariusVanDerWijden fix after rebase + addr := common.HexToAddress("0x1111111111111111111111111111111111111111") + + cb.AccountRead(addr) + cb.StorageRead(addr, common.BytesToHash([]byte{0x01})) + cb.StorageWrite(0, addr, common.BytesToHash([]byte{0x02}), common.BytesToHash([]byte{0xaa})) + cb.BalanceChange(0, addr, uint256.NewInt(100)) + cb.NonceChange(addr, 0, 1) + */ var buf bytes.Buffer if err := cb.EncodeRLP(&buf); err != nil { t.Fatalf("failed to encode BAL: %v", err) diff --git a/core/state/state_object.go b/core/state/state_object.go index 010ea23c9e..5a66ba1f7a 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -19,11 +19,12 @@ package state import ( "bytes" "fmt" - "github.com/ethereum/go-ethereum/core/types/bal" "maps" "slices" "time" + "github.com/ethereum/go-ethereum/core/types/bal" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" diff --git a/core/state/statedb.go b/core/state/statedb.go index 3094629814..5cdcc04eaa 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -20,7 +20,6 @@ package state import ( "errors" "fmt" - "github.com/ethereum/go-ethereum/core/types/bal" "maps" "slices" "sort" @@ -28,6 +27,8 @@ import ( "sync/atomic" "time" + "github.com/ethereum/go-ethereum/core/types/bal" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/stateless" "github.com/ethereum/go-ethereum/core/tracing" diff --git a/core/state/statedb_hooked.go b/core/state/statedb_hooked.go index af3ffffd7a..ae6d795cd3 100644 --- a/core/state/statedb_hooked.go +++ b/core/state/statedb_hooked.go @@ -18,10 +18,11 @@ package state import ( "bytes" - "github.com/ethereum/go-ethereum/core/types/bal" "math/big" "sort" + "github.com/ethereum/go-ethereum/core/types/bal" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/stateless" "github.com/ethereum/go-ethereum/core/tracing" diff --git a/core/types.go b/core/types.go index b5ea870ad9..52161df523 100644 --- a/core/types.go +++ b/core/types.go @@ -18,9 +18,10 @@ package core import ( "context" - "github.com/ethereum/go-ethereum/core/types/bal" "sync/atomic" + "github.com/ethereum/go-ethereum/core/types/bal" + "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" diff --git a/core/types/bal/bal.go b/core/types/bal/bal.go index be0134c99a..506b6b514b 100644 --- a/core/types/bal/bal.go +++ b/core/types/bal/bal.go @@ -19,9 +19,10 @@ package bal import ( "bytes" "encoding/json" + "maps" + "github.com/ethereum/go-ethereum/common" "github.com/holiman/uint256" - "maps" ) // ConstructionAccountAccesses contains post-block account state for mutations as well as diff --git a/core/types/bal/bal_test.go b/core/types/bal/bal_test.go index 10a58611bb..19df58c38a 100644 --- a/core/types/bal/bal_test.go +++ b/core/types/bal/bal_test.go @@ -25,6 +25,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/internal/testrand" + "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" "github.com/holiman/uint256" ) @@ -37,48 +38,51 @@ func equalBALs(a *BlockAccessList, b *BlockAccessList) bool { } func makeTestConstructionBAL() ConstructionBlockAccessList { - return map[common.Address]*ConstructionAccountAccesses{ - common.BytesToAddress([]byte{0xff, 0xff}): { - StorageWrites: map[common.Hash]map[uint16]common.Hash{ - common.BytesToHash([]byte{0x01}): { - 1: common.BytesToHash([]byte{1, 2, 3, 4}), - 2: common.BytesToHash([]byte{1, 2, 3, 4, 5, 6}), + return ConstructionBlockAccessList{ + list: map[common.Address]*ConstructionAccountAccesses{ + common.BytesToAddress([]byte{0xff, 0xff}): { + StorageWrites: map[common.Hash]map[uint16]common.Hash{ + common.BytesToHash([]byte{0x01}): { + 1: common.BytesToHash([]byte{1, 2, 3, 4}), + 2: common.BytesToHash([]byte{1, 2, 3, 4, 5, 6}), + }, + common.BytesToHash([]byte{0x10}): { + 20: common.BytesToHash([]byte{1, 2, 3, 4}), + }, }, - common.BytesToHash([]byte{0x10}): { - 20: common.BytesToHash([]byte{1, 2, 3, 4}), + StorageReads: map[common.Hash]struct{}{ + common.BytesToHash([]byte{1, 2, 3, 4, 5, 6, 7}): {}, }, - }, - StorageReads: map[common.Hash]struct{}{ - common.BytesToHash([]byte{1, 2, 3, 4, 5, 6, 7}): {}, - }, - BalanceChanges: map[uint16]*uint256.Int{ - 1: uint256.NewInt(100), - 2: uint256.NewInt(500), - }, - NonceChanges: map[uint16]uint64{ - 1: 2, - 2: 6, - }, - CodeChanges: map[uint16][]byte{0: common.Hex2Bytes("deadbeef")}, - }, - common.BytesToAddress([]byte{0xff, 0xff, 0xff}): { - StorageWrites: map[common.Hash]map[uint16]common.Hash{ - common.BytesToHash([]byte{0x01}): { - 2: common.BytesToHash([]byte{1, 2, 3, 4, 5, 6}), - 3: common.BytesToHash([]byte{1, 2, 3, 4, 5, 6, 7, 8}), + BalanceChanges: map[uint16]*uint256.Int{ + 1: uint256.NewInt(100), + 2: uint256.NewInt(500), }, + NonceChanges: map[uint16]uint64{ + 1: 2, + 2: 6, + }, + CodeChanges: map[uint16][]byte{0: common.Hex2Bytes("deadbeef")}, }, - StorageReads: map[common.Hash]struct{}{ - common.BytesToHash([]byte{1, 2, 3, 4, 5, 6, 7, 8}): {}, - }, - BalanceChanges: map[uint16]*uint256.Int{ - 2: uint256.NewInt(100), - 3: uint256.NewInt(500), - }, - NonceChanges: map[uint16]uint64{ - 1: 2, + common.BytesToAddress([]byte{0xff, 0xff, 0xff}): { + StorageWrites: map[common.Hash]map[uint16]common.Hash{ + common.BytesToHash([]byte{0x01}): { + 2: common.BytesToHash([]byte{1, 2, 3, 4, 5, 6}), + 3: common.BytesToHash([]byte{1, 2, 3, 4, 5, 6, 7, 8}), + }, + }, + StorageReads: map[common.Hash]struct{}{ + common.BytesToHash([]byte{1, 2, 3, 4, 5, 6, 7, 8}): {}, + }, + BalanceChanges: map[uint16]*uint256.Int{ + 2: uint256.NewInt(100), + 3: uint256.NewInt(500), + }, + NonceChanges: map[uint16]uint64{ + 1: 2, + }, }, }, + transactionCount: 1, } } @@ -212,7 +216,7 @@ func TestBlockAccessListCopy(t *testing.T) { } // Make sure the mutations on copy won't affect the origin - for _, aa := range cpyCpy { + for _, aa := range *cpyCpy { for i := 0; i < len(aa.StorageReads); i++ { aa.StorageReads[i] = &EncodedStorage{new(uint256.Int).SetBytes(testrand.Bytes(32))} } @@ -226,7 +230,7 @@ func TestBlockAccessListValidation(t *testing.T) { // Validate the block access list after RLP decoding testBALMaxIndex := 20 enc := makeTestBAL(true) - if err := enc.Validate(testBALMaxIndex); err != nil { + if err := enc.Validate(testBALMaxIndex, params.MaxGasLimit); err != nil { t.Fatalf("Unexpected validation error: %v", err) } var buf bytes.Buffer @@ -238,14 +242,14 @@ func TestBlockAccessListValidation(t *testing.T) { if err := dec.DecodeRLP(rlp.NewStream(bytes.NewReader(buf.Bytes()), 0)); err != nil { t.Fatalf("Unexpected RLP-decode error: %v", err) } - if err := dec.Validate(testBALMaxIndex); err != nil { + if err := dec.Validate(testBALMaxIndex, params.MaxGasLimit); err != nil { t.Fatalf("Unexpected validation error: %v", err) } // Validate the derived block access list cBAL := makeTestConstructionBAL() listB := cBAL.ToEncodingObj() - if err := listB.Validate(testBALMaxIndex); err != nil { + if err := listB.Validate(testBALMaxIndex, params.MaxGasLimit); err != nil { t.Fatalf("Unexpected validation error: %v", err) } } diff --git a/eth/protocols/snap/handler_test.go b/eth/protocols/snap/handler_test.go index 3f6a43a059..53f88d4832 100644 --- a/eth/protocols/snap/handler_test.go +++ b/eth/protocols/snap/handler_test.go @@ -37,12 +37,13 @@ func makeTestBAL(minSize int) *bal.BlockAccessList { n := minSize/33 + 1 // 33 bytes per storage read slot in RLP access := bal.AccountAccess{ Address: common.HexToAddress("0x01"), - StorageReads: make([][32]byte, n), + StorageReads: make([]*bal.EncodedStorage, n), } for i := range access.StorageReads { - binary.BigEndian.PutUint64(access.StorageReads[i][24:], uint64(i)) + read := access.StorageReads[i].ToHash() + binary.BigEndian.PutUint64(read[24:], uint64(i)) } - return &bal.BlockAccessList{Accesses: []bal.AccountAccess{access}} + return &bal.BlockAccessList{access} } // getChainWithBALs creates a minimal test chain with BALs stored for each block. diff --git a/eth/tracers/internal/tracetest/selfdestruct_state_test.go b/eth/tracers/internal/tracetest/selfdestruct_state_test.go index 39067e8efc..20641201c3 100644 --- a/eth/tracers/internal/tracetest/selfdestruct_state_test.go +++ b/eth/tracers/internal/tracetest/selfdestruct_state_test.go @@ -620,7 +620,7 @@ func TestSelfdestructStateTracer(t *testing.T) { } context := core.NewEVMBlockContext(block.Header(), blockchain, nil) evm := vm.NewEVM(context, hookedState, tt.genesis.Config, vm.Config{Tracer: tracer.Hooks()}) - _, _, err = core.ApplyTransactionWithEVM(msg, core.NewGasPool(msg.GasLimit), statedb, block.Number(), block.Hash(), block.Time(), tx, evm) + _, _, _, err = core.ApplyTransactionWithEVM(msg, core.NewGasPool(msg.GasLimit), statedb, block.Number(), block.Hash(), block.Time(), tx, evm) if err != nil { t.Fatalf("failed to execute transaction: %v", err) }