From 6f742a146942cc4038940d4d3a8f5c57a3d00260 Mon Sep 17 00:00:00 2001 From: zsfelfoldi Date: Wed, 21 Jan 2026 03:52:58 +0100 Subject: [PATCH] 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)) } }