From 680c5fbe61b01f482f628a19831ddffaa99cf404 Mon Sep 17 00:00:00 2001 From: Zsolt Felfoldi Date: Mon, 19 Jan 2026 18:51:09 +0100 Subject: [PATCH 1/5] core, core/vm: implement EIP-7708 --- core/evm.go | 6 +++++- core/types/log.go | 30 ++++++++++++++++++++++++++++++ core/vm/evm.go | 6 +++--- core/vm/gas_table_test.go | 4 ++-- core/vm/instructions.go | 14 ++++++++++++++ core/vm/interpreter_test.go | 2 +- 6 files changed, 55 insertions(+), 7 deletions(-) diff --git a/core/evm.go b/core/evm.go index 18d940fdd2..01a7e4fbc3 100644 --- a/core/evm.go +++ b/core/evm.go @@ -25,6 +25,7 @@ import ( "github.com/ethereum/go-ethereum/core/tracing" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" + "github.com/ethereum/go-ethereum/params" "github.com/holiman/uint256" ) @@ -135,7 +136,10 @@ func CanTransfer(db vm.StateDB, addr common.Address, amount *uint256.Int) bool { } // Transfer subtracts amount from sender and adds amount to recipient using the given Db -func Transfer(db vm.StateDB, sender, recipient common.Address, amount *uint256.Int) { +func Transfer(db vm.StateDB, sender, recipient common.Address, amount *uint256.Int, blockNumber *big.Int, rules *params.Rules) { db.SubBalance(sender, amount, tracing.BalanceChangeTransfer) db.AddBalance(recipient, amount, tracing.BalanceChangeTransfer) + if rules.IsAmsterdam && !amount.IsZero() { + db.AddLog(types.EthTransferLog(blockNumber, sender, recipient, amount)) + } } diff --git a/core/types/log.go b/core/types/log.go index f0e6a3a745..85df7b8891 100644 --- a/core/types/log.go +++ b/core/types/log.go @@ -17,8 +17,11 @@ package types import ( + "math/big" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/holiman/uint256" ) //go:generate go run ../../rlp/rlpgen -type Log -out gen_log_rlp.go @@ -62,3 +65,30 @@ type logMarshaling struct { BlockTimestamp hexutil.Uint64 Index hexutil.Uint } + +var ( + // system contract address + EthTransferLogAddress = common.HexToAddress("0xfffffffffffffffffffffffffffffffffffffffe") + // keccak256('Transfer(address,address,uint256)') + EthTransferLogTopic0 = common.HexToHash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef") +) + +// EthTransferLog creates and ETH transfer log according to EIP-7708. +// Specification: https://eips.ethereum.org/EIPS/eip-7708 +func EthTransferLog(blockNumber *big.Int, from, to common.Address, amount *uint256.Int) *Log { + topics := make([]common.Hash, 3) + topics[0] = EthTransferLogTopic0 + copy(topics[1][common.HashLength-common.AddressLength:], from[:]) + copy(topics[2][common.HashLength-common.AddressLength:], to[:]) + amount32 := amount.Bytes32() + data := make([]byte, 32) + copy(data, amount32[:]) + return &Log{ + Address: EthTransferLogAddress, + Topics: topics, + Data: data, + // This is a non-consensus field, but assigned here because + // core/state doesn't know the current block number. + BlockNumber: blockNumber.Uint64(), + } +} diff --git a/core/vm/evm.go b/core/vm/evm.go index 25a3318c02..69a4f038d7 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -35,7 +35,7 @@ type ( // CanTransferFunc is the signature of a transfer guard function CanTransferFunc func(StateDB, common.Address, *uint256.Int) bool // TransferFunc is the signature of a transfer function - TransferFunc func(StateDB, common.Address, common.Address, *uint256.Int) + TransferFunc func(StateDB, common.Address, common.Address, *uint256.Int, *big.Int, *params.Rules) // GetHashFunc returns the n'th block hash in the blockchain // and is used by the BLOCKHASH EVM op code. GetHashFunc func(uint64) common.Hash @@ -280,7 +280,7 @@ func (evm *EVM) Call(caller common.Address, addr common.Address, input []byte, g } evm.StateDB.CreateAccount(addr) } - evm.Context.Transfer(evm.StateDB, caller, addr, value) + evm.Context.Transfer(evm.StateDB, caller, addr, value, evm.Context.BlockNumber, &evm.chainRules) if isPrecompile { ret, gas, err = RunPrecompiledContract(p, input, gas, evm.Config.Tracer) @@ -549,7 +549,7 @@ func (evm *EVM) create(caller common.Address, code []byte, gas uint64, value *ui } gas = gas - consumed } - evm.Context.Transfer(evm.StateDB, caller, address, value) + evm.Context.Transfer(evm.StateDB, caller, address, value, evm.Context.BlockNumber, &evm.chainRules) // Initialise a new contract and set the code that is to be used by the EVM. // The contract is a scoped environment for this execution context only. diff --git a/core/vm/gas_table_test.go b/core/vm/gas_table_test.go index 7fe76b0a63..e9b1d3771b 100644 --- a/core/vm/gas_table_test.go +++ b/core/vm/gas_table_test.go @@ -94,7 +94,7 @@ func TestEIP2200(t *testing.T) { vmctx := BlockContext{ CanTransfer: func(StateDB, common.Address, *uint256.Int) bool { return true }, - Transfer: func(StateDB, common.Address, common.Address, *uint256.Int) {}, + Transfer: func(StateDB, common.Address, common.Address, *uint256.Int, *big.Int, *params.Rules) {}, } evm := NewEVM(vmctx, statedb, params.AllEthashProtocolChanges, Config{ExtraEips: []int{2200}}) @@ -144,7 +144,7 @@ func TestCreateGas(t *testing.T) { statedb.Finalise(true) vmctx := BlockContext{ CanTransfer: func(StateDB, common.Address, *uint256.Int) bool { return true }, - Transfer: func(StateDB, common.Address, common.Address, *uint256.Int) {}, + Transfer: func(StateDB, common.Address, common.Address, *uint256.Int, *big.Int, *params.Rules) {}, BlockNumber: big.NewInt(0), } config := Config{} diff --git a/core/vm/instructions.go b/core/vm/instructions.go index baf6df8117..d625f02e78 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -898,6 +898,13 @@ func opSelfdestruct(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, error) { } // Clear any leftover funds for the account being destructed. evm.StateDB.SubBalance(this, balance, tracing.BalanceDecreaseSelfdestruct) + if evm.chainRules.IsAmsterdam && !balance.IsZero() { + if this != beneficiary { + evm.StateDB.AddLog(types.EthTransferLog(evm.Context.BlockNumber, this, beneficiary, balance)) + } else { + evm.StateDB.AddLog(types.EthTransferLog(evm.Context.BlockNumber, this, common.Address{}, balance)) + } + } evm.StateDB.SelfDestruct(this) if tracer := evm.Config.Tracer; tracer != nil { @@ -936,6 +943,13 @@ func opSelfdestruct6780(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, erro evm.StateDB.SubBalance(this, balance, tracing.BalanceDecreaseSelfdestruct) evm.StateDB.AddBalance(beneficiary, balance, tracing.BalanceIncreaseSelfdestruct) } + if evm.chainRules.IsAmsterdam && !balance.IsZero() { + if this != beneficiary { + evm.StateDB.AddLog(types.EthTransferLog(evm.Context.BlockNumber, this, beneficiary, balance)) + } else if newContract { + evm.StateDB.AddLog(types.EthTransferLog(evm.Context.BlockNumber, this, common.Address{}, balance)) + } + } if tracer := evm.Config.Tracer; tracer != nil { if tracer.OnEnter != nil { diff --git a/core/vm/interpreter_test.go b/core/vm/interpreter_test.go index 79531f78d2..f0bf9cf1e4 100644 --- a/core/vm/interpreter_test.go +++ b/core/vm/interpreter_test.go @@ -40,7 +40,7 @@ var loopInterruptTests = []string{ func TestLoopInterrupt(t *testing.T) { address := common.BytesToAddress([]byte("contract")) vmctx := BlockContext{ - Transfer: func(StateDB, common.Address, common.Address, *uint256.Int) {}, + Transfer: func(StateDB, common.Address, common.Address, *uint256.Int, *big.Int, *params.Rules) {}, } for i, tt := range loopInterruptTests { From 18bbd5f291bca40b3c08c43e87ecbdab53445c66 Mon Sep 17 00:00:00 2001 From: Zsolt Felfoldi Date: Tue, 20 Jan 2026 04:08:48 +0100 Subject: [PATCH 2/5] core: add test for ETH transfer logs --- core/eth_transfer_logs_test.go | 169 +++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 core/eth_transfer_logs_test.go diff --git a/core/eth_transfer_logs_test.go b/core/eth_transfer_logs_test.go new file mode 100644 index 0000000000..9c168e58a3 --- /dev/null +++ b/core/eth_transfer_logs_test.go @@ -0,0 +1,169 @@ +// Copyright 2026 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see . + +package core + +import ( + "encoding/binary" + "math/big" + "reflect" + "testing" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/consensus/beacon" + "github.com/ethereum/go-ethereum/consensus/ethash" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/params" +) + +var ethTransferTestCode = common.FromHex("6080604052600436106100345760003560e01c8063574ffc311461003957806366e41cb714610090578063f8a8fd6d1461009a575b600080fd5b34801561004557600080fd5b5061004e6100a4565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6100986100ac565b005b6100a26100f5565b005b63deadbeef81565b7f38e80b5c85ba49b7280ccc8f22548faa62ae30d5a008a1b168fba5f47f5d1ee560405160405180910390a1631234567873ffffffffffffffffffffffffffffffffffffffff16ff5b7f24ec1d3ff24c2f6ff210738839dbc339cd45a5294d85c79361016243157aae7b60405160405180910390a163deadbeef73ffffffffffffffffffffffffffffffffffffffff166002348161014657fe5b046040516024016040516020818303038152906040527f66e41cb7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040518082805190602001908083835b602083106101fd57805182526020820191506020810190506020830392506101da565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d806000811461025f576040519150601f19603f3d011682016040523d82523d6000602084013e610264565b606091505b50505056fea265627a7a723158202cce817a434785d8560c200762f972d453ccd30694481be7545f9035a512826364736f6c63430005100032") + +/* +pragma solidity >=0.4.22 <0.6.0; + +contract TestLogs { + + address public constant target_contract = 0x00000000000000000000000000000000DeaDBeef; + address payable constant selfdestruct_addr = 0x0000000000000000000000000000000012345678; + + event Response(bool success, bytes data); + event TestEvent(); + event TestEvent2(); + + function test() public payable { + emit TestEvent(); + target_contract.call.value(msg.value/2)(abi.encodeWithSignature("test2()")); + } + function test2() public payable { + emit TestEvent2(); + selfdestruct(selfdestruct_addr); + } +} +*/ + +// TestEthTransferLogs tests EIP-7708 ETH transfer log output by simulating a +// scenario including transaction, CALL and SELFDESTRUCT value transfers, and +// also "ordinary" logs emitted. The same scenario is also tested with no value +// transferred. +func TestEthTransferLogs(t *testing.T) { + testEthTransferLogs(t, 1_000_000_000) + testEthTransferLogs(t, 0) +} + +func testEthTransferLogs(t *testing.T, value uint64) { + var ( + key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") + addr1 = crypto.PubkeyToAddress(key1.PublicKey) + addr2 = common.HexToAddress("cafebabe") // caller + addr3 = common.HexToAddress("deadbeef") // callee + addr4 = common.HexToAddress("12345678") // selfdestruct target + testEvent = crypto.Keccak256Hash([]byte("TestEvent()")) + testEvent2 = crypto.Keccak256Hash([]byte("TestEvent2()")) + config = *params.MergedTestChainConfig + signer = types.LatestSigner(&config) + engine = beacon.New(ethash.NewFaker()) + ) + + //TODO remove this hacky config initialization when final Amsterdam config is available + config.AmsterdamTime = new(uint64) + blobConfig := *config.BlobScheduleConfig + blobConfig.Amsterdam = blobConfig.Osaka + config.BlobScheduleConfig = &blobConfig + + gspec := &Genesis{ + Config: &config, + Alloc: types.GenesisAlloc{ + addr1: {Balance: newGwei(1000000000)}, + addr2: {Code: ethTransferTestCode}, + addr3: {Code: ethTransferTestCode}, + }, + } + _, blocks, receipts := GenerateChainWithGenesis(gspec, engine, 1, func(i int, b *BlockGen) { + tx := types.MustSignNewTx(key1, signer, &types.DynamicFeeTx{ + ChainID: gspec.Config.ChainID, + Nonce: 0, + To: &addr2, + Gas: 500_000, + GasFeeCap: newGwei(5), + GasTipCap: newGwei(5), + Value: big.NewInt(int64(value)), + Data: common.FromHex("f8a8fd6d"), + }) + b.AddTx(tx) + }) + + blockHash := blocks[0].Hash() + txHash := blocks[0].Transactions()[0].Hash() + addr2hash := func(addr common.Address) (hash common.Hash) { + copy(hash[12:], addr[:]) + return + } + u256 := func(amount uint64) []byte { + data := make([]byte, 32) + binary.BigEndian.PutUint64(data[24:], amount) + return data + } + + var expLogs = []*types.Log{ + { + Address: types.EthTransferLogAddress, + Topics: []common.Hash{types.EthTransferLogTopic0, addr2hash(addr1), addr2hash(addr2)}, + Data: u256(value), + }, + { + Address: addr2, + Topics: []common.Hash{testEvent}, + Data: nil, + }, + { + Address: types.EthTransferLogAddress, + Topics: []common.Hash{types.EthTransferLogTopic0, addr2hash(addr2), addr2hash(addr3)}, + Data: u256(value / 2), + }, + { + Address: addr3, + Topics: []common.Hash{testEvent2}, + Data: nil, + }, + { + Address: types.EthTransferLogAddress, + Topics: []common.Hash{types.EthTransferLogTopic0, addr2hash(addr3), addr2hash(addr4)}, + Data: u256(value / 2), + }, + } + if value == 0 { + // no ETH transfer logs expected with zero value + expLogs = []*types.Log{expLogs[1], expLogs[3]} + } + for i, log := range expLogs { + log.BlockNumber = 1 + log.BlockHash = blockHash + log.BlockTimestamp = 10 + log.TxIndex = 0 + log.TxHash = txHash + log.Index = uint(i) + } + + if len(expLogs) != len(receipts[0][0].Logs) { + t.Fatalf("Incorrect number of logs (expected: %d, got: %d)", len(expLogs), len(receipts[0][0].Logs)) + } + for i, log := range receipts[0][0].Logs { + if !reflect.DeepEqual(expLogs[i], log) { + t.Fatalf("Incorrect log at index %d (expected: %v, got: %v)", i, expLogs[i], log) + } + } +} From 6f742a146942cc4038940d4d3a8f5c57a3d00260 Mon Sep 17 00:00:00 2001 From: zsfelfoldi Date: Wed, 21 Jan 2026 03:52:58 +0100 Subject: [PATCH 3/5] core: update according to latest specs --- core/eth_transfer_logs_test.go | 6 +++--- core/types/log.go | 37 +++++++++++++++++++++++++--------- core/vm/instructions.go | 4 ++-- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/core/eth_transfer_logs_test.go b/core/eth_transfer_logs_test.go index 9c168e58a3..673db3632f 100644 --- a/core/eth_transfer_logs_test.go +++ b/core/eth_transfer_logs_test.go @@ -120,7 +120,7 @@ func testEthTransferLogs(t *testing.T, value uint64) { var expLogs = []*types.Log{ { - Address: types.EthTransferLogAddress, + Address: types.EthSystemLogAddress, Topics: []common.Hash{types.EthTransferLogTopic0, addr2hash(addr1), addr2hash(addr2)}, Data: u256(value), }, @@ -130,7 +130,7 @@ func testEthTransferLogs(t *testing.T, value uint64) { Data: nil, }, { - Address: types.EthTransferLogAddress, + Address: types.EthSystemLogAddress, Topics: []common.Hash{types.EthTransferLogTopic0, addr2hash(addr2), addr2hash(addr3)}, Data: u256(value / 2), }, @@ -140,7 +140,7 @@ func testEthTransferLogs(t *testing.T, value uint64) { Data: nil, }, { - Address: types.EthTransferLogAddress, + Address: types.EthSystemLogAddress, Topics: []common.Hash{types.EthTransferLogTopic0, addr2hash(addr3), addr2hash(addr4)}, Data: u256(value / 2), }, diff --git a/core/types/log.go b/core/types/log.go index 85df7b8891..a6765fce21 100644 --- a/core/types/log.go +++ b/core/types/log.go @@ -68,25 +68,42 @@ type logMarshaling struct { var ( // system contract address - EthTransferLogAddress = common.HexToAddress("0xfffffffffffffffffffffffffffffffffffffffe") + EthSystemLogAddress = common.HexToAddress("0xfffffffffffffffffffffffffffffffffffffffe") // keccak256('Transfer(address,address,uint256)') EthTransferLogTopic0 = common.HexToHash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef") + // keccak256('Selfdestruct(address,uint256)') + EthBurnLogTopic0 = common.HexToHash("0x4bfaba3443c1a1836cd362418edc679fc96cae8449cbefccb6457cdf2c943083") ) // EthTransferLog creates and ETH transfer log according to EIP-7708. // Specification: https://eips.ethereum.org/EIPS/eip-7708 func EthTransferLog(blockNumber *big.Int, from, to common.Address, amount *uint256.Int) *Log { - topics := make([]common.Hash, 3) - topics[0] = EthTransferLogTopic0 - copy(topics[1][common.HashLength-common.AddressLength:], from[:]) - copy(topics[2][common.HashLength-common.AddressLength:], to[:]) amount32 := amount.Bytes32() - data := make([]byte, 32) - copy(data, amount32[:]) return &Log{ - Address: EthTransferLogAddress, - Topics: topics, - Data: data, + Address: EthSystemLogAddress, + Topics: []common.Hash{ + EthTransferLogTopic0, + common.BytesToHash(from.Bytes()), + common.BytesToHash(to.Bytes()), + }, + Data: amount32[:], + // This is a non-consensus field, but assigned here because + // core/state doesn't know the current block number. + BlockNumber: blockNumber.Uint64(), + } +} + +// EthBurnLog creates and ETH self-destruct burn log according to EIP-7708. +// Specification: https://eips.ethereum.org/EIPS/eip-7708 +func EthBurnLog(blockNumber *big.Int, from common.Address, amount *uint256.Int) *Log { + amount32 := amount.Bytes32() + return &Log{ + Address: EthSystemLogAddress, + Topics: []common.Hash{ + EthBurnLogTopic0, + common.BytesToHash(from.Bytes()), + }, + Data: amount32[:], // This is a non-consensus field, but assigned here because // core/state doesn't know the current block number. BlockNumber: blockNumber.Uint64(), diff --git a/core/vm/instructions.go b/core/vm/instructions.go index d625f02e78..880cb23140 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -902,7 +902,7 @@ func opSelfdestruct(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, error) { if this != beneficiary { evm.StateDB.AddLog(types.EthTransferLog(evm.Context.BlockNumber, this, beneficiary, balance)) } else { - evm.StateDB.AddLog(types.EthTransferLog(evm.Context.BlockNumber, this, common.Address{}, balance)) + evm.StateDB.AddLog(types.EthBurnLog(evm.Context.BlockNumber, this, balance)) } } evm.StateDB.SelfDestruct(this) @@ -947,7 +947,7 @@ func opSelfdestruct6780(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, erro if this != beneficiary { evm.StateDB.AddLog(types.EthTransferLog(evm.Context.BlockNumber, this, beneficiary, balance)) } else if newContract { - evm.StateDB.AddLog(types.EthTransferLog(evm.Context.BlockNumber, this, common.Address{}, balance)) + evm.StateDB.AddLog(types.EthBurnLog(evm.Context.BlockNumber, this, balance)) } } From 087fbb33aa733bcb3748386151e72a7e8cda756a Mon Sep 17 00:00:00 2001 From: Zsolt Felfoldi Date: Thu, 22 Jan 2026 03:29:03 +0100 Subject: [PATCH 4/5] core: emit logs for balance after selfdestruct --- core/state/statedb.go | 15 +++++++++++++++ core/state_processor.go | 13 +++++++++++++ core/types/log.go | 8 ++++---- core/vm/instructions.go | 9 +-------- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/core/state/statedb.go b/core/state/statedb.go index 39160aa1c7..852f45e935 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -737,6 +737,21 @@ func (s *StateDB) GetRefund() uint64 { return s.refund } +type RemovedAccountWithBalance struct { + Address common.Address + Balance *uint256.Int +} + +func (s *StateDB) GetRemovedAccountsWithBalance() (list []RemovedAccountWithBalance) { + for addr := range s.journal.dirties { + if obj, exist := s.stateObjects[addr]; exist && + obj.selfDestructed && !obj.Balance().IsZero() { + list = append(list, RemovedAccountWithBalance{Address: obj.address, Balance: obj.Balance()}) + } + } + return list +} + // Finalise finalises the state by removing the destructed objects and clears // the journal as well as the refunds. Finalise, however, will not push any updates // into the tries just yet. Only IntermediateRoot or Commit will do that. diff --git a/core/state_processor.go b/core/state_processor.go index b4b22e4318..93137dad52 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -19,6 +19,7 @@ package core import ( "fmt" "math/big" + "sort" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/consensus/misc" @@ -155,6 +156,18 @@ func ApplyTransactionWithEVM(msg *Message, gp *GasPool, statedb *state.StateDB, if err != nil { return nil, err } + if evm.ChainConfig().IsAmsterdam(blockNumber, blockTime) { + // Emit Selfdesctruct logs where accounts with non-empty balances have been deleted + removedWithBalance := statedb.GetRemovedAccountsWithBalance() + if removedWithBalance != nil { + sort.Slice(removedWithBalance, func(i, j int) bool { + return removedWithBalance[i].Address.Cmp(removedWithBalance[j].Address) < 0 + }) + for _, sd := range removedWithBalance { + statedb.AddLog(types.EthSelfDestructLog(blockNumber, sd.Address, sd.Balance)) + } + } + } // Update the state with pending changes. var root []byte if evm.ChainConfig().IsByzantium(blockNumber) { diff --git a/core/types/log.go b/core/types/log.go index a6765fce21..3dd7fb1723 100644 --- a/core/types/log.go +++ b/core/types/log.go @@ -72,7 +72,7 @@ var ( // keccak256('Transfer(address,address,uint256)') EthTransferLogTopic0 = common.HexToHash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef") // keccak256('Selfdestruct(address,uint256)') - EthBurnLogTopic0 = common.HexToHash("0x4bfaba3443c1a1836cd362418edc679fc96cae8449cbefccb6457cdf2c943083") + EthSelfDestructLogTopic0 = common.HexToHash("0x4bfaba3443c1a1836cd362418edc679fc96cae8449cbefccb6457cdf2c943083") ) // EthTransferLog creates and ETH transfer log according to EIP-7708. @@ -93,14 +93,14 @@ func EthTransferLog(blockNumber *big.Int, from, to common.Address, amount *uint2 } } -// EthBurnLog creates and ETH self-destruct burn log according to EIP-7708. +// EthSelfDestructLog creates and ETH self-destruct burn log according to EIP-7708. // Specification: https://eips.ethereum.org/EIPS/eip-7708 -func EthBurnLog(blockNumber *big.Int, from common.Address, amount *uint256.Int) *Log { +func EthSelfDestructLog(blockNumber *big.Int, from common.Address, amount *uint256.Int) *Log { amount32 := amount.Bytes32() return &Log{ Address: EthSystemLogAddress, Topics: []common.Hash{ - EthBurnLogTopic0, + EthSelfDestructLogTopic0, common.BytesToHash(from.Bytes()), }, Data: amount32[:], diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 880cb23140..aaf4280db1 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -898,13 +898,6 @@ func opSelfdestruct(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, error) { } // Clear any leftover funds for the account being destructed. evm.StateDB.SubBalance(this, balance, tracing.BalanceDecreaseSelfdestruct) - if evm.chainRules.IsAmsterdam && !balance.IsZero() { - if this != beneficiary { - evm.StateDB.AddLog(types.EthTransferLog(evm.Context.BlockNumber, this, beneficiary, balance)) - } else { - evm.StateDB.AddLog(types.EthBurnLog(evm.Context.BlockNumber, this, balance)) - } - } evm.StateDB.SelfDestruct(this) if tracer := evm.Config.Tracer; tracer != nil { @@ -947,7 +940,7 @@ func opSelfdestruct6780(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, erro if this != beneficiary { evm.StateDB.AddLog(types.EthTransferLog(evm.Context.BlockNumber, this, beneficiary, balance)) } else if newContract { - evm.StateDB.AddLog(types.EthBurnLog(evm.Context.BlockNumber, this, balance)) + evm.StateDB.AddLog(types.EthSelfDestructLog(evm.Context.BlockNumber, this, balance)) } } From 4ac12f4c66b6a81cdbcbe4d0994bf858ba82cdd8 Mon Sep 17 00:00:00 2001 From: Zsolt Felfoldi Date: Thu, 22 Jan 2026 12:02:51 +0100 Subject: [PATCH 5/5] core, params: add comments, move consts to params --- core/eth_transfer_logs_test.go | 12 ++++++------ core/state/statedb.go | 7 +++++++ core/types/log.go | 18 +++++------------- params/protocol_params.go | 8 ++++++++ 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/core/eth_transfer_logs_test.go b/core/eth_transfer_logs_test.go index 673db3632f..815b56b588 100644 --- a/core/eth_transfer_logs_test.go +++ b/core/eth_transfer_logs_test.go @@ -120,8 +120,8 @@ func testEthTransferLogs(t *testing.T, value uint64) { var expLogs = []*types.Log{ { - Address: types.EthSystemLogAddress, - Topics: []common.Hash{types.EthTransferLogTopic0, addr2hash(addr1), addr2hash(addr2)}, + Address: params.SystemAddress, + Topics: []common.Hash{params.EthTransferLogEvent, addr2hash(addr1), addr2hash(addr2)}, Data: u256(value), }, { @@ -130,8 +130,8 @@ func testEthTransferLogs(t *testing.T, value uint64) { Data: nil, }, { - Address: types.EthSystemLogAddress, - Topics: []common.Hash{types.EthTransferLogTopic0, addr2hash(addr2), addr2hash(addr3)}, + Address: params.SystemAddress, + Topics: []common.Hash{params.EthTransferLogEvent, addr2hash(addr2), addr2hash(addr3)}, Data: u256(value / 2), }, { @@ -140,8 +140,8 @@ func testEthTransferLogs(t *testing.T, value uint64) { Data: nil, }, { - Address: types.EthSystemLogAddress, - Topics: []common.Hash{types.EthTransferLogTopic0, addr2hash(addr3), addr2hash(addr4)}, + Address: params.SystemAddress, + Topics: []common.Hash{params.EthTransferLogEvent, addr2hash(addr3), addr2hash(addr4)}, Data: u256(value / 2), }, } diff --git a/core/state/statedb.go b/core/state/statedb.go index 852f45e935..8f7fe9cd6c 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -742,6 +742,13 @@ type RemovedAccountWithBalance struct { Balance *uint256.Int } +// GetRemovedAccountsWithBalance returns a list of accounts scheduled for +// removal which still have positive balance. The purpose of this function is +// to handle a corner case of EIP-7708 where a self-destructed account might +// still receive funds between sending/burning its previous balance and actual +// removal. In this case the burning of these remaining balances still need to +// be logged. +// Specification EIP-7708: https://eips.ethereum.org/EIPS/eip-7708 func (s *StateDB) GetRemovedAccountsWithBalance() (list []RemovedAccountWithBalance) { for addr := range s.journal.dirties { if obj, exist := s.stateObjects[addr]; exist && diff --git a/core/types/log.go b/core/types/log.go index 3dd7fb1723..54c20bad15 100644 --- a/core/types/log.go +++ b/core/types/log.go @@ -21,6 +21,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/params" "github.com/holiman/uint256" ) @@ -66,23 +67,14 @@ type logMarshaling struct { Index hexutil.Uint } -var ( - // system contract address - EthSystemLogAddress = common.HexToAddress("0xfffffffffffffffffffffffffffffffffffffffe") - // keccak256('Transfer(address,address,uint256)') - EthTransferLogTopic0 = common.HexToHash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef") - // keccak256('Selfdestruct(address,uint256)') - EthSelfDestructLogTopic0 = common.HexToHash("0x4bfaba3443c1a1836cd362418edc679fc96cae8449cbefccb6457cdf2c943083") -) - // EthTransferLog creates and ETH transfer log according to EIP-7708. // Specification: https://eips.ethereum.org/EIPS/eip-7708 func EthTransferLog(blockNumber *big.Int, from, to common.Address, amount *uint256.Int) *Log { amount32 := amount.Bytes32() return &Log{ - Address: EthSystemLogAddress, + Address: params.SystemAddress, Topics: []common.Hash{ - EthTransferLogTopic0, + params.EthTransferLogEvent, common.BytesToHash(from.Bytes()), common.BytesToHash(to.Bytes()), }, @@ -98,9 +90,9 @@ func EthTransferLog(blockNumber *big.Int, from, to common.Address, amount *uint2 func EthSelfDestructLog(blockNumber *big.Int, from common.Address, amount *uint256.Int) *Log { amount32 := amount.Bytes32() return &Log{ - Address: EthSystemLogAddress, + Address: params.SystemAddress, Topics: []common.Hash{ - EthSelfDestructLogTopic0, + params.EthSelfDestructLogEvent, common.BytesToHash(from.Bytes()), }, Data: amount32[:], diff --git a/params/protocol_params.go b/params/protocol_params.go index bb506af015..98f3fa90f3 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -220,3 +220,11 @@ var ( ConsolidationQueueAddress = common.HexToAddress("0x0000BBdDc7CE488642fb579F8B00f3a590007251") ConsolidationQueueCode = common.FromHex("3373fffffffffffffffffffffffffffffffffffffffe1460d35760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1461019a57600182026001905f5b5f82111560685781019083028483029004916001019190604d565b9093900492505050366060146088573661019a573461019a575f5260205ff35b341061019a57600154600101600155600354806004026004013381556001015f358155600101602035815560010160403590553360601b5f5260605f60143760745fa0600101600355005b6003546002548082038060021160e7575060025b5f5b8181146101295782810160040260040181607402815460601b815260140181600101548152602001816002015481526020019060030154905260010160e9565b910180921461013b5790600255610146565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff141561017357505f5b6001546001828201116101885750505f61018e565b01600190035b5f555f6001556074025ff35b5f5ffd") ) + +// System log events. +var ( + // EIP-7708 - System logs emitted for ETH transfer and self-destruct balance burn + EthTransferLogEvent = common.HexToHash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef") // keccak256('Transfer(address,address,uint256)') + EthSelfDestructLogEvent = common.HexToHash("0x4bfaba3443c1a1836cd362418edc679fc96cae8449cbefccb6457cdf2c943083") // keccak256('Selfdestruct(address,uint256)') + +)